Skip to content

Commit

Permalink
added php validator test
Browse files Browse the repository at this point in the history
  • Loading branch information
anton committed Jan 26, 2013
1 parent 806245f commit a254cb1
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions tests/components/AmPhpValidatorTest.php
@@ -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;
}

0 comments on commit a254cb1

Please sign in to comment.