7 * This source file is subject to the new BSD license that is bundled
8 * with this package in the file LICENSE.txt.
9 * It is also available through the world-wide-web at this URL:
10 * http://framework.zend.com/license/new-bsd
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@zend.com so we can send you a copy immediately.
16 * @package Zend_Validate
17 * @subpackage UnitTests
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
27 require_once dirname(__FILE__
) . '/../../TestHelper.php';
30 * @see Zend_Validate_Regex
32 require_once 'Zend/Validate/Regex.php';
37 * @package Zend_Validate
38 * @subpackage UnitTests
39 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
40 * @license http://framework.zend.com/license/new-bsd New BSD License
41 * @group Zend_Validate
43 class Zend_Validate_RegexTest
extends PHPUnit_Framework_TestCase
46 * Ensures that the validator follows expected behavior
50 public function testBasic()
53 * The elements of each array are, in order:
55 * - expected validation result
56 * - array of test input values
58 $valuesExpected = array(
59 array('/[a-z]/', true, array('abc123', 'foo', 'a', 'z')),
60 array('/[a-z]/', false, array('123', 'A'))
62 foreach ($valuesExpected as $element) {
63 $validator = new Zend_Validate_Regex($element[0]);
64 foreach ($element[2] as $input) {
65 $this->assertEquals($element[1], $validator->isValid($input));
71 * Ensures that getMessages() returns expected default value
75 public function testGetMessages()
77 $validator = new Zend_Validate_Regex('/./');
78 $this->assertEquals(array(), $validator->getMessages());
82 * Ensures that getPattern() returns expected value
86 public function testGetPattern()
88 $validator = new Zend_Validate_Regex('/./');
89 $this->assertEquals('/./', $validator->getPattern());
93 * Ensures that a bad pattern results in a thrown exception upon isValid() call
97 public function testBadPattern()
100 $validator = new Zend_Validate_Regex('/');
101 $validator->isValid('anything');
102 $this->fail('Expected Zend_Validate_Exception not thrown for bad pattern');
103 } catch (Zend_Validate_Exception
$e) {
104 $this->assertContains('Internal error while', $e->getMessage());
111 public function testNonStringValidation()
113 $validator = new Zend_Validate_Regex('/./');
114 $this->assertFalse($validator->isValid(array(1 => 1)));