-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#13149] - Added test form and failing test
- Loading branch information
Showing
2 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
$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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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); | ||
} | ||
} |