/** * Returns true if and only if $value contains only alphabetic characters * * @param string $value * @return boolean */ public function isValid($value) { if (!is_string($value)) { $this->_error(self::INVALID); return false; } $this->_setValue($value); if ('' === $value) { $this->_error(self::STRING_EMPTY); return false; } if (null === self::$_filter) { self::$_filter = new \Zend\Filter\Alpha(); } self::$_filter->allowWhiteSpace = $this->allowWhiteSpace; if ($value !== self::$_filter->filter($value)) { $this->_error(self::NOT_ALPHA); return false; } return true; }
/** * Ensures that the filter follows expected behavior * * @return void */ public function testAllowWhiteSpace() { $this->_filter->setAllowWhiteSpace(true); if (!self::$_unicodeEnabled) { // POSIX named classes are not supported, use alternative a-zA-Z match $valuesExpected = array( 'abc123' => 'abc', 'abc 123' => 'abc ', 'abcxyz' => 'abcxyz', '' => '', "\n" => "\n", " \t " => " \t " ); } if (self::$_meansEnglishAlphabet) { //The Alphabet means english alphabet. $valuesExpected = array( 'a B' => 'a B', 'zY x' => 'zx' ); } else { //The Alphabet means each language's alphabet. $valuesExpected = array( 'abc123' => 'abc', 'abc 123' => 'abc ', 'abcxyz' => 'abcxyz', 'četně' => 'četně', 'لعربية' => 'لعربية', 'grzegżółka' => 'grzegżółka', 'België' => 'België', '' => '', "\n" => "\n", " \t " => " \t " ); } $filter = $this->_filter; foreach ($valuesExpected as $input => $output) { $this->assertEquals( $output, $result = $filter($input), "Expected '$input' to filter to '$output', but received '$result' instead" ); } }
/** * @group ZF-11631 */ public function testRegistryLocale() { $locale = new Locale('ja'); \Zend\Registry::set('Zend_Locale', $locale); if (!self::$_unicodeEnabled) { $this->markTestSkipped('Unicode not enabled'); } $valuesExpected = array('aABbc' => 'aBc', 'z Y x' => 'zx', 'W1v3U4t' => 'vt', ',sй.rλ:qν_p' => 'srqp', 'onml' => 'onml'); $filter = new AlphaFilter(); $this->assertEquals('ja', (string) $filter->getLocale()); foreach ($valuesExpected as $input => $output) { $this->assertEquals($output, $result = $filter($input), "Expected '{$input}' to filter to '{$output}', but received '{$result}' instead"); } }