Exemplo n.º 1
0
 public function testCustomValidation()
 {
     /* @var $nameField \Mindy\Orm\Fields\Field */
     $model = new User();
     $this->assertFalse($model->isValid());
     $this->assertEquals(['username' => ['Cannot be empty', 'Minimal length is 3']], $model->getErrors());
     $nameField = $model->getField('username');
     $this->assertEquals(['Cannot be empty', 'Minimal length is 3'], $nameField->getErrors());
     $this->assertFalse($nameField->isValid());
     $this->assertEquals(['Cannot be empty', 'Minimal length is 3'], $nameField->getErrors());
     $model->username = '******';
     $this->assertEquals('hi', $model->username);
     $this->assertFalse($model->isValid());
     $this->assertEquals('hi', $model->username);
     $model->username = '******';
     $model->isValid();
     $this->assertEquals(['username' => ['Maximum length is 20']], $model->getErrors());
     $model->isValid();
     $this->assertEquals(['username' => ['Maximum length is 20']], $model->getErrors());
 }