Exemple #1
0
 public function testGetCustomHtmlPattern()
 {
     $constraint = new Regex(array('pattern' => '((?![0-9]$|[a-z]+).)*', 'htmlPattern' => 'foobar'));
     $this->assertSame('((?![0-9]$|[a-z]+).)*', $constraint->pattern);
     $this->assertSame('foobar', $constraint->getHtmlPattern());
 }
Exemple #2
0
 public function testHtmlPattern()
 {
     // Specified htmlPattern
     $constraint = new Regex(array('pattern' => '/^[a-z]+$/i', 'htmlPattern' => '[a-zA-Z]+'));
     $this->assertEquals('[a-zA-Z]+', $constraint->getHtmlPattern());
     // Disabled htmlPattern
     $constraint = new Regex(array('pattern' => '/^[a-z]+$/i', 'htmlPattern' => false));
     $this->assertNull($constraint->getHtmlPattern());
     // Cannot be converted
     $constraint = new Regex(array('pattern' => '/^[a-z]+$/i'));
     $this->assertNull($constraint->getHtmlPattern());
     // Automatically converted
     $constraint = new Regex(array('pattern' => '/^[a-z]+$/'));
     $this->assertEquals('[a-z]+', $constraint->getHtmlPattern());
     // Automatically converted, adds .*
     $constraint = new Regex(array('pattern' => '/[a-z]+/'));
     $this->assertEquals('.*[a-z]+.*', $constraint->getHtmlPattern());
     // Dropped because of match=false
     $constraint = new Regex(array('pattern' => '/[a-z]+/', 'match' => false));
     $this->assertNull($constraint->getHtmlPattern());
 }