Ejemplo n.º 1
0
 /**
  * CCValidator::required tests
  */
 public function test_required()
 {
     $validator = new CCValidator(array('username' => 'mario', 'password' => '', 'field' => null));
     $this->assertTrue($validator->required('username'));
     $this->assertTrue($validator->not_required('firstname'));
     $this->assertTrue($validator->success());
     $this->assertFalse($validator->failure());
     $this->assertFalse($validator->required('passord'));
     $this->assertFalse($validator->not_required('username'));
     $this->assertTrue($validator->failure());
     $this->assertFalse($validator->success());
     $this->assertInternalType('array', $validator->failed());
     $this->assertFalse($validator->required('field'));
     // test rules syntax
     $this->assertTrue($validator->rules('username', 'required'));
     // test spaces breaks etc.
     $validator = new CCValidator(array('name' => '     '));
     $this->assertFalse($validator->required('name'));
     // test not existing
     $this->assertFalse($validator->required('notexisting'));
     // test numbers
     $validator = new CCValidator(array('count' => '0'));
     $this->assertTrue($validator->required('count'));
     $validator = new CCValidator(array('count' => 0));
     $this->assertTrue($validator->required('count'));
 }