This repository has been archived by the owner on Dec 12, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
174 additions
and
23 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
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
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,36 @@ | ||
<?php | ||
|
||
namespace Bupy7\Form\Tests\Asset; | ||
|
||
use Zend\InputFilter\InputFilter; | ||
|
||
/** | ||
* Input filter of signin. | ||
*/ | ||
class SignInFilter extends InputFilter | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->add([ | ||
'name' => 'email', | ||
'required' => true, | ||
'validators' => [ | ||
[ | ||
'name' => 'EmailAddress', | ||
], | ||
], | ||
]); | ||
$this->add([ | ||
'name' => 'password', | ||
'required' => true, | ||
'filters' => [ | ||
[ | ||
'name' => 'StringTrim', | ||
], | ||
], | ||
]); | ||
} | ||
} |
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,38 @@ | ||
<?php | ||
|
||
namespace Bupy7\Form\Tests\Asset; | ||
|
||
use Bupy7\Form\FormAbstract; | ||
|
||
/** | ||
* Form of signin. | ||
*/ | ||
class SignInForm extends FormAbstract | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function inputs() | ||
{ | ||
return [ | ||
[ | ||
'name' => 'email', | ||
'required' => true, | ||
'validators' => [ | ||
[ | ||
'name' => 'EmailAddress', | ||
], | ||
], | ||
], | ||
[ | ||
'name' => 'password', | ||
'required' => true, | ||
'filters' => [ | ||
[ | ||
'name' => 'StringTrim', | ||
] | ||
], | ||
], | ||
]; | ||
} | ||
} |
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,81 @@ | ||
<?php | ||
|
||
namespace Bupy7\Form\Tests; | ||
|
||
use PHPUnit_Framework_TestCase; | ||
use Bupy7\Form\Tests\Asset\SignInForm; | ||
use Bupy7\Form\Tests\Asset\SignInFilter; | ||
|
||
/** | ||
* @author Vasilij Belosludcev <https://github.com/bupy7> | ||
* @since 1.0.0 | ||
*/ | ||
class FormAstractTest extends PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* Testing inputs data. | ||
*/ | ||
public function testInputs() | ||
{ | ||
// valid | ||
$signInForm = new SignInForm; | ||
$signInForm->setValues([ | ||
'email' => 'test@gmail.com', | ||
'password' => '12q34e56t78', | ||
]); | ||
$this->assertTrue($signInForm->isValid()); | ||
|
||
// invalid | ||
$signInForm = new SignInForm; | ||
$signInForm->setValues([ | ||
'email' => 'test@gmail.never', | ||
'password' => '', | ||
]); | ||
$this->assertFalse($signInForm->isValid()); | ||
$errors = $signInForm->getErrors(); | ||
$this->assertTrue(!empty($errors)); | ||
} | ||
|
||
/** | ||
* Testing outputs data. | ||
*/ | ||
public function testOutputs() | ||
{ | ||
// valid | ||
$signInForm = new SignInForm; | ||
$signInForm->setValues([ | ||
'email' => 'test@gmail.com', | ||
'password' => ' 12q34e56t78 ', | ||
]); | ||
$this->assertTrue($signInForm->isValid()); | ||
$values = $signInForm->getValues(); | ||
$this->assertEquals('12q34e56t78', $values['password']); | ||
$values = $signInForm->getValues(false); | ||
$this->assertEquals(' 12q34e56t78 ', $values['password']); | ||
|
||
// invalid | ||
$signInForm = new SignInForm; | ||
$signInForm->setValues([ | ||
'email' => 'test@gmail.co2m', | ||
'password' => ' 12q34e56t78 ', | ||
]); | ||
$this->assertFalse($signInForm->isValid()); | ||
$values = $signInForm->getValues(); | ||
$this->assertEquals('12q34e56t78', $values['password']); | ||
$values = $signInForm->getValues(false); | ||
$this->assertEquals(' 12q34e56t78 ', $values['password']); | ||
} | ||
|
||
/** | ||
* Testing instance of input filter. | ||
*/ | ||
public function testInstanceInputFilter() | ||
{ | ||
$signInForm = new SignInForm; | ||
$signInForm->setInputFilter(new SignInFilter); | ||
$this->assertInstanceOf(SignInFilter::class, $signInForm->getInputFilter()); | ||
$signInForm->setValues([]); | ||
$this->assertFalse($signInForm->isValid()); | ||
} | ||
} | ||
|
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
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
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