/** * 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 AlphaFilter(); } //self::$filter->setAllowWhiteSpace($this->allowWhiteSpace); self::$filter->setAllowWhiteSpace($this->options['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 "); } foreach ($valuesExpected as $input => $expected) { $actual = $this->filter->filter($input); $this->assertEquals($expected, $actual); } }