Phalcon\Test\integration\Forms\FormCest::clearFormElementsAndUsingValidation PHP Method

clearFormElementsAndUsingValidation() public method

Tests clearing the Form Elements and using Form::isValid
Since: 2016-10-01
Author: Serghei Iakovlev ([email protected])
public clearFormElementsAndUsingValidation ( IntegrationTester $I )
$I IntegrationTester
    public function clearFormElementsAndUsingValidation(IntegrationTester $I)
    {
        $password = new Password('password', ['placeholder' => 'Insert your Password']);
        $password->addValidators([new PresenceOf(['message' => 'The field is required', 'cancelOnFail' => true]), new StringLength(['min' => 7, 'messageMinimum' => 'The text is too short'])]);
        $form = new Form();
        $form->add($password);
        $I->assertNull($form->get('password')->getValue());
        $input = '<input type="password" id="password" name="password" placeholder="Insert your Password">';
        $I->assertEquals($input, $form->render('password'));
        $_POST = ['password' => 'secret'];
        $I->assertEquals('secret', $form->get('password')->getValue());
        $input = '<input type="password" id="password" name="password" value="secret" placeholder="Insert your Password">';
        $I->assertEquals($input, $form->render('password'));
        $I->assertFalse($form->isValid($_POST));
        $actual = $form->getMessages();
        $expected = Group::__set_state(['_position' => 0, '_messages' => [Message::__set_state(['_type' => 'TooShort', '_message' => 'The text is too short', '_field' => 'password', '_code' => '0'])]]);
        $I->assertEquals($actual, $expected);
        $form->clear(['password']);
        $I->assertNull($form->get('password')->getValue());
        $input = '<input type="password" id="password" name="password" placeholder="Insert your Password">';
        $I->assertEquals($input, $form->render('password'));
        $I->assertEquals(['password' => 'secret'], $_POST);
    }