コード例 #1
0
 public function testValidateNoFile()
 {
     $model = new ValidatorTestModel(__CLASS__);
     $uploadedFile = new CUploadedFile('test.txt', __FILE__, 'text/plain', 40, UPLOAD_ERR_NO_FILE);
     $model->uploaded_file = $uploadedFile;
     $this->assertFalse($model->validate(), 'File with error passed validation!');
 }
コード例 #2
0
 /**
  * https://github.com/yiisoft/yii/issues/1669
  * @dataProvider providerIssue1669
  */
 public function testIssue1669($value, $assertion)
 {
     $model = new ValidatorTestModel('CNumberValidatorTest');
     $model->number = $value;
     $model->validate(array('number'));
     $this->assertSame($assertion, $model->getErrors());
 }
コード例 #3
0
 public function testIs()
 {
     // null value
     $model1 = new ValidatorTestModel('CStringValidatorTest');
     $model1->validate(array('string3'));
     $this->assertTrue($model1->hasErrors('string3'));
     $this->assertSame(array('Error message.'), $model1->getErrors('string3'));
     // 9 characters length value
     $model2 = new ValidatorTestModel('CStringValidatorTest');
     $model2->string3 = '123456789';
     $model2->validate(array('string3'));
     $this->assertTrue($model2->hasErrors('string3'));
     $this->assertSame(array('Error message.'), $model2->getErrors('string3'));
     // 11 characters length value
     $model3 = new ValidatorTestModel('CStringValidatorTest');
     $model3->string3 = '12345678901';
     $model3->validate(array('string3'));
     $this->assertTrue($model3->hasErrors('string3'));
     $this->assertSame(array('Error message.'), $model3->getErrors('string3'));
     // 10 characters length value
     $model4 = new ValidatorTestModel('CStringValidatorTest');
     $model4->string3 = '1234567890';
     $model4->validate(array('string3'));
     $this->assertFalse($model4->hasErrors('string3'));
     $this->assertNotSame(array('Error message.'), $model4->getErrors('string3'));
     // array value: https://github.com/yiisoft/yii/issues/1955
     $model5 = new ValidatorTestModel('CStringValidatorTest');
     $model5->string3 = array('1234567890');
     $model5->validate(array('string3'));
     $this->assertTrue($model5->hasErrors('string3'));
 }
コード例 #4
0
 public function testEmptyWithSpaces()
 {
     $model = new ValidatorTestModel('CRequiredValidatorTest');
     $model->address = ' ';
     $model->validate(array('address'));
     $this->assertArrayHasKey('address', $model->getErrors());
 }
コード例 #5
0
 /**
  * https://github.com/yiisoft/yii/issues/1955
  */
 public function testArrayValue()
 {
     $model = new ValidatorTestModel('CEmailValidatorTest');
     $model->email = array('*****@*****.**');
     $model->validate(array('email'));
     $this->assertTrue($model->hasErrors('email'));
     $this->assertEquals(array('Email is not a valid email address.'), $model->getErrors('email'));
 }
コード例 #6
0
 public function testZeroNumber()
 {
     $model = new ValidatorTestModel('CRangeValidatorTest');
     $model->string1 = 0;
     $model->string2 = 0;
     $model->validate(array('string1', 'string2'));
     $this->assertArrayNotHasKey('string1', $model->getErrors());
     $this->assertArrayHasKey('string2', $model->getErrors());
 }
コード例 #7
0
 /**
  * https://github.com/yiisoft/yii/issues/2845
  */
 public function testNonStrict()
 {
     $comparisons = array(array(1, true), array('1', true), array(' 1', true), array('1 ', true), array(2, false), array(12, false));
     foreach ($comparisons as $comparison) {
         $model = new ValidatorTestModel('CRangeValidatorTest');
         $model->string3 = $comparison[0];
         $model->validate(array('string3'));
         if ($comparison[1]) {
             $this->assertArrayNotHasKey('string3', $model->getErrors(), var_export($comparison[0], true) . ' should be valid but it is not.');
         } else {
             $this->assertArrayHasKey('string3', $model->getErrors(), var_export($comparison[0], true) . ' should not be valid but it is.');
         }
     }
 }
コード例 #8
0
 public function testEmpty()
 {
     $model = new ValidatorTestModel('CUrlValidatorTest');
     $model->validate(array('url'));
     $this->assertArrayHasKey('url', $model->getErrors());
 }
コード例 #9
0
 /**
  * https://github.com/yiisoft/yii/issues/1955
  */
 public function testArrayValue()
 {
     $model = new ValidatorTestModel('CUrlValidatorTest');
     $model->url = array('http://yiiframework.com/');
     $model->validate(array('url'));
     $this->assertTrue($model->hasErrors('url'));
     $this->assertEquals(array('Url is not a valid URL.'), $model->getErrors('url'));
 }