Пример #1
0
 public function testText()
 {
     $input = Input::text();
     $this->genericElementTest($input);
     $this->genericInputTest($input, 'text');
     //Validators
     $input->maxlength(5);
     $input->val('String');
     $this->assertFalse($input->isValid());
     $input->val('Strin');
     $this->assertTrue($input->isValid());
     $input->required();
     $input->val('');
     $this->assertFalse($input->isValid());
     $input->val('0');
     $this->assertTrue($input->isValid());
     $input->pattern('[0-9]');
     $this->assertTrue($input->isValid());
     $input->val('nn');
     $this->assertFalse($input->isValid());
     $input->pattern('/[a-z]{2}/');
     $input->val('/a/');
     $this->assertFalse($input->isValid());
     $input->val('/ab/');
     $this->assertTrue($input->isValid());
 }
Пример #2
0
 public function testText()
 {
     $input = Input::text();
     $this->genericElementTest($input);
     $this->genericInputTest($input, 'text');
     //Validators
     $input->maxlength(5);
     $input->val('String');
     $this->assertFalse($input->isValid());
     $input->val('Strin');
     $this->assertTrue($input->isValid());
     $input->required();
     $input->val('');
     $this->assertFalse($input->isValid());
     $input->val('0');
     $this->assertTrue($input->isValid());
     $input->pattern('[0-9]');
     $this->assertTrue($input->isValid());
     $input->val('nn');
     $this->assertFalse($input->isValid());
     $input->pattern('/[a-z]{2}/');
     $input->val('/a/');
     $this->assertFalse($input->isValid());
     $input->val('/ab/');
     $this->assertTrue($input->isValid());
     $input->addValidator('is-dave', function ($input) {
         return $input->val() === 'dave' ?: 'This value must be "dave"';
     });
     $this->assertFalse($input->isValid());
     $input->removeAttr('pattern');
     $input->val('dave');
     $this->assertTrue($input->isValid());
 }