Permalink
Browse files

added php validator test

  • Loading branch information...
1 parent 806245f commit a254cb1d327ca3cd5bc282a96b6e6adff80bd51f anton committed Jan 26, 2013
Showing with 49 additions and 0 deletions.
  1. +49 −0 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.