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
anton
committed
Jan 26, 2013
1 parent
806245f
commit a254cb1
Showing
1 changed file
with
49 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,49 @@ | ||
<?php | ||
|
||
Yii::import('appManager.components.AmPhpValidator'); | ||
|
||
class AmPhpValidatorTest extends CTestCase | ||
{ | ||
public $validator; | ||
public $model; | ||
|
||
public function setUp() | ||
{ | ||
$this->validator = new AmPhpValidator; | ||
$this->validator->attributes = array('foo'); | ||
|
||
$this->model = new ModelMock; | ||
} | ||
|
||
/** | ||
* @dataProvider provider | ||
*/ | ||
public function testValidate($value, $isCorrect) | ||
{ | ||
$this->model->foo = $value; | ||
|
||
$this->validator->validate($this->model); | ||
$this->assertSame($isCorrect, !$this->model->hasErrors(), $value); | ||
} | ||
|
||
public function provider() | ||
{ | ||
return array( | ||
array('invalid text', false), | ||
array('"valid text"', true), | ||
array("'valid text'", true), | ||
array('23' , true), | ||
array('23.3' , true), | ||
array('null' , true), | ||
array('array()' , true), | ||
array('array(' , false), | ||
array('array("test"=>"ok")', true), | ||
); | ||
} | ||
|
||
} | ||
|
||
class ModelMock extends CFormModel | ||
{ | ||
public $foo; | ||
} |