Skip to content

Commit

Permalink
[#13149] - Added test form and failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
niden committed May 16, 2019
1 parent a9f30ff commit 26d6f06
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 0 deletions.
112 changes: 112 additions & 0 deletions tests/_data/fixtures/Forms/ValidationForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php
declare(strict_types=1);

/**
* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <[email protected]>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

namespace Phalcon\Test\Fixtures\Forms;

use Phalcon\Forms\Element\Email;
use Phalcon\Forms\Element\Text;
use Phalcon\Forms\Element\TextArea;
use Phalcon\Forms\Form;
use Phalcon\Validation\Validator\PresenceOf;
use Phalcon\Validation\Validator\StringLength;

class ValidationForm extends Form
{
public function initialize($entity = null, $options = null)
{
// Full Name
$validators = [
new PresenceOf(
[
'message' => 'your :field is required',
'cancelOnFail' => true,
]
),
new StringLength(
[
'max' => 20,
'messageMaximum' => ':field too long',
'min' => 2,
'messageMinimum' => ':field too short',
]
),
];
$field = new Text(
'fullname',
[
'placeholder' => 'First & Last Name',
]
);

$field->addValidators($validators);

$this->add($field);

// Email
$field = new Email(
'email',
[]
);

$validators = [
new PresenceOf(
[
'message' => 'valid :field is required',
'cancelOnFail' => true,
]
),
];

$field->addValidators($validators);

$this->add($field);

// Subject
$field = new Text('subject');
$validators = [
new PresenceOf(
[
'message' => 'your :field is required',
'cancelOnFail' => true,
]
),
];

$field->addValidators($validators);

$this->add($field);

// Message
$field = new TextArea('message');
$validators = [
new PresenceOf(
[
'message' => 'Your message is required',
'cancelOnFail' => true,
]
),
new StringLength(
[
'max' => 300,
'messageMaximum' => "your message can't be longer than 300 characters",
'min' => 4,
'messageMinimum' => 'Tell us what we can do for you',
'cancelOnFail' => true,
]
),
];

$field->addValidators($validators);

$this->add($field);
}
}
26 changes: 26 additions & 0 deletions tests/integration/Forms/Form/IsValidCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Phalcon\Messages\Message;
use Phalcon\Messages\Messages;
use Phalcon\Tag;
use Phalcon\Test\Fixtures\Forms\ValidationForm;
use Phalcon\Test\Fixtures\Traits\DiTrait;
use Phalcon\Validation;
use Phalcon\Validation\Validator\PresenceOf;
Expand Down Expand Up @@ -141,4 +142,29 @@ public function testMergeValidators(IntegrationTester $I)
$form->get('address')->getMessages()
);
}

/**
* Tests Form::isValid()
*
* @issue https://github.com/phalcon/cphalcon/issues/13149
* @author Phalcon Team <[email protected]>
* @since 2018-11-13
*/
public function formsFormRemoveIsValidCancelOnFail(IntegrationTester $I)
{
$form = new ValidationForm();

$data = [
'fullname' => '',
'email' => '',
'subject' => '',
'message' => '',
];

$actual = $form->isValid($data);
$I->assertFalse($actual);

$messages = $form->getMessages();
$I->assertCount(6, $messages);
}
}

0 comments on commit 26d6f06

Please sign in to comment.