Exemplo n.º 1
0
    /**
     * 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"
                );
        }
    }
Exemplo n.º 2
0
 /**
  * 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);
     if ($value !== self::$filter->filter($value)) {
         $this->error(self::NOT_ALPHA);
         return false;
     }
     return true;
 }