From dfab2d76f9302183c8b7002bacb74700dfe4891f Mon Sep 17 00:00:00 2001 From: Denis Portnov Date: Tue, 3 Jul 2012 02:07:22 +0400 Subject: [PATCH 01/17] Alnum, Alpha --- src/Alnum.php | 124 ++++++++++---------------------- src/Alpha.php | 171 ++------------------------------------------- test/AlnumTest.php | 105 +++++++++++++--------------- test/AlphaTest.php | 97 +++++++++++-------------- 4 files changed, 132 insertions(+), 365 deletions(-) diff --git a/src/Alnum.php b/src/Alnum.php index 3f70b2f7..676d285c 100644 --- a/src/Alnum.php +++ b/src/Alnum.php @@ -20,9 +20,9 @@ namespace Zend\Filter; +use Locale; use Traversable; use Zend\Stdlib\ArrayUtils; -use Zend\Locale\Locale as ZendLocale; /** * @category Zend @@ -30,135 +30,85 @@ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ -class Alnum extends AbstractFilter +class Alnum extends AbstractLocale { /** - * Whether to allow white space characters; off by default - * - * @var boolean + * @var array */ - protected $allowWhiteSpace; - - /** - * Is PCRE is compiled with UTF-8 and Unicode support - * - * @var mixed - **/ - protected static $unicodeEnabled; - - /** - * Locale to use - * - * @var ZendLocale object - */ - protected $locale; + protected $options = array( + 'locale' => null, + 'allow_white_space' => false, + ); /** * Sets default option values for this instance * - * @param boolean|Traversable|array $allowWhiteSpace + * @param array|Traversable|boolean|null $options */ - public function __construct($options = false) + public function __construct($options = null) { - if ($options instanceof Traversable) { - $options = ArrayUtils::iteratorToArray($options); - } - if (!is_array($options)) { - $options = func_get_args(); - $temp = array(); - if (!empty($options)) { - $temp['allowWhiteSpace'] = array_shift($options); + if ($options !== null) { + if ($options instanceof Traversable) { + $options = iterator_to_array($options); } - if (!empty($options)) { - $temp['locale'] = array_shift($options); + if (!is_array($options)) { + $args = func_get_args(); + if (isset($args[0])) { + $this->setAllowWhiteSpace($args[0]); + } + if (isset($args[1])) { + $this->setLocale($args[1]); + } + } else { + $this->setOptions($options); } - - $options = $temp; - } - - if (null === self::$unicodeEnabled) { - self::$unicodeEnabled = (@preg_match('/\pL/u', 'a')) ? true : false; - } - - if (array_key_exists('allowWhiteSpace', $options)) { - $this->setAllowWhiteSpace($options['allowWhiteSpace']); } - - if (!array_key_exists('locale', $options)) { - $options['locale'] = null; - } - - $this->setLocale($options['locale']); - } - - /** - * Returns the allowWhiteSpace option - * - * @return boolean - */ - public function getAllowWhiteSpace() - { - return $this->allowWhiteSpace; } /** * Sets the allowWhiteSpace option * - * @param boolean $allowWhiteSpace + * @param boolean $flag * @return Alnum Provides a fluent interface */ - public function setAllowWhiteSpace($allowWhiteSpace) + public function setAllowWhiteSpace($flag = true) { - $this->allowWhiteSpace = (boolean) $allowWhiteSpace; + $this->options['allow_white_space'] = (boolean) $flag; return $this; } /** - * Returns the locale option - * - * @return string - */ - public function getLocale() - { - return $this->locale; - } - - /** - * Sets the locale option + * Whether white space is allowed * - * @param boolean $locale - * @return Alnum Provides a fluent interface + * @return boolean */ - public function setLocale($locale = null) + public function getAllowWhiteSpace() { - $this->locale = ZendLocale::findLocale($locale); - return $this; + return $this->options['allow_white_space']; } /** * Defined by Zend\Filter\FilterInterface * - * Returns the string $value, removing all but alphabetic and digit characters + * Returns $value as string with all non-alphanumeric characters removed * - * @param string $value + * @param mixed $value * @return string */ public function filter($value) { - $whiteSpace = $this->allowWhiteSpace ? '\s' : ''; + $whiteSpace = $this->options['allow_white_space'] ? '\s' : ''; + $language = Locale::getPrimaryLanguage($this->getLocale()); - if (!self::$unicodeEnabled) { + if (!static::hasPcreUnicodeSupport()) { // POSIX named classes are not supported, use alternative a-zA-Z0-9 match $pattern = '/[^a-zA-Z0-9' . $whiteSpace . ']/'; - } elseif (((string) $this->locale == 'ja') - || ((string) $this->locale == 'ko') - || ((string) $this->locale == 'zh') - ) { - // Use english alphabeth + } elseif ($language == 'ja'|| $language == 'ko' || $language == 'zh') { + // Use english alphabet $pattern = '/[^a-zA-Z0-9' . $whiteSpace . ']/u'; } else { - // Use native language alphabeth + // Use native language alphabet $pattern = '/[^\p{L}\p{N}' . $whiteSpace . ']/u'; } diff --git a/src/Alpha.php b/src/Alpha.php index 34d98bf7..3670467d 100644 --- a/src/Alpha.php +++ b/src/Alpha.php @@ -20,9 +20,7 @@ namespace Zend\Filter; -use Traversable; -use Zend\Locale\Locale as ZendLocale; -use Zend\Stdlib\ArrayUtils; +use Locale; /** * @category Zend @@ -30,150 +28,8 @@ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ -class Alpha extends AbstractFilter +class Alpha extends Alnum { - /** - * Whether to allow white space characters; off by default - * - * @var boolean - */ - protected $allowWhiteSpace; - - /** - * Is PCRE is compiled with UTF-8 and Unicode support - * - * @var mixed - **/ - protected static $unicodeEnabled; - - /** - * Locale to use - * - * @var \Zend\Locale\Locale object - */ - protected $locale; - - /** - * Sets default option values for this instance - * - * @param boolean $allowWhiteSpace - * @return void - */ - public function __construct($options = false) - { - if ($options instanceof Traversable) { - $options = ArrayUtils::iteratorToArray($options); - } elseif (!is_array($options)) { - $options = func_get_args(); - $temp = array(); - if (!empty($options)) { - $temp['allowWhiteSpace'] = array_shift($options); - } - - if (!empty($options)) { - $temp['locale'] = array_shift($options); - } - - $options = $temp; - } - - if (array_key_exists('unicodeEnabled', $options)) { - $this->setUnicodeEnabled($options['unicodeEnabled']); - } - - if (array_key_exists('allowWhiteSpace', $options)) { - $this->setAllowWhiteSpace($options['allowWhiteSpace']); - } - - if (!array_key_exists('locale', $options)) { - $options['locale'] = null; - } - - $this->setLocale($options['locale']); - } - - /** - * Returns the allowWhiteSpace option - * - * @return boolean - */ - public function getAllowWhiteSpace() - { - return $this->allowWhiteSpace; - } - - /** - * Sets the allowWhiteSpace option - * - * @param boolean $allowWhiteSpace - * @return Alpha Provides a fluent interface - */ - public function setAllowWhiteSpace($allowWhiteSpace) - { - $this->allowWhiteSpace = (boolean) $allowWhiteSpace; - return $this; - } - - /** - * Toggle unicode matching capabilities - * - * @param bool $flag - * @return Alpha - */ - public function setUnicodeEnabled($flag) - { - $flag = (bool) $flag; - if (!$flag) { - static::$unicodeEnabled = $flag; - return; - } - - if (!static::isUnicodeCapable()) { - throw new Exception\RuntimeException(sprintf( - '%s cannot be unicode enabled; installed PCRE is not capable', - __CLASS__ - )); - } - - static::$unicodeEnabled = $flag; - return $this; - } - - /** - * Is this instance unicode enabled? - * - * @return bool - */ - public function isUnicodeEnabled() - { - if (null === static::$unicodeEnabled) { - static::$unicodeEnabled = static::isUnicodeCapable(); - } - return static::$unicodeEnabled; - } - - /** - * Returns the locale option - * - * @return string - */ - public function getLocale() - { - return $this->locale; - } - - /** - * Sets the locale option - * - * @param boolean $locale - * @return Alpha Provides a fluent interface - */ - public function setLocale($locale = null) - { - $this->locale = ZendLocale::findLocale($locale); - return $this; - } - /** * Defined by Zend\Filter\FilterInterface * @@ -184,16 +40,13 @@ public function setLocale($locale = null) */ public function filter($value) { - $whiteSpace = $this->allowWhiteSpace ? '\s' : ''; + $whiteSpace = $this->options['allow_white_space'] ? '\s' : ''; + $language = Locale::getPrimaryLanguage($this->getLocale()); - $locale = (string) $this->locale; - if (!$this->isUnicodeEnabled()) { - // POSIX named classes are not supported, use alternative a-zA-Z match + if (!static::hasPcreUnicodeSupport()) { + // POSIX named classes are not supported, use alternative [a-zA-Z] match $pattern = '/[^a-zA-Z' . $whiteSpace . ']/'; - } elseif (($locale == 'ja') - || ($locale == 'ko') - || ($locale == 'zh') - ) { + } elseif ($language == 'ja' || $language == 'ko' || $language == 'zh') { // Use english alphabet $pattern = '/[^a-zA-Z' . $whiteSpace . ']/u'; } else { @@ -203,14 +56,4 @@ public function filter($value) return preg_replace($pattern, '', (string) $value); } - - /** - * Are we unicode capable? - * - * @return bool - */ - protected static function isUnicodeCapable() - { - return (@preg_match('/\pL/u', 'a') ? true : false); - } } diff --git a/test/AlnumTest.php b/test/AlnumTest.php index d8ba6588..411f6d78 100644 --- a/test/AlnumTest.php +++ b/test/AlnumTest.php @@ -22,7 +22,7 @@ namespace ZendTest\Filter; use Zend\Filter\Alnum as AlnumFilter; -use Zend\Locale\Locale as ZendLocale; +use Locale; /** * @category Zend @@ -39,28 +39,28 @@ class AlnumTest extends \PHPUnit_Framework_TestCase * * @var AlnumFilter */ - protected $_filter; + protected $filter; /** * Is PCRE is compiled with UTF-8 and Unicode support * * @var mixed **/ - protected static $_unicodeEnabled; + protected static $unicodeEnabled; /** * Locale in browser. * - * @var ZendLocale object + * @var string object */ - protected $_locale; + protected $locale; /** * The Alphabet means english alphabet. * * @var boolean */ - protected static $_meansEnglishAlphabet; + protected static $meansEnglishAlphabet; /** * Creates a new AlnumFilter object for each test method @@ -69,16 +69,12 @@ class AlnumTest extends \PHPUnit_Framework_TestCase */ public function setUp() { - $this->_filter = new AlnumFilter(); - if (null === self::$_unicodeEnabled) { - self::$_unicodeEnabled = (@preg_match('/\pL/u', 'a')) ? true : false; - } - if (null === self::$_meansEnglishAlphabet) { - $this->_locale = new ZendLocale('auto'); - self::$_meansEnglishAlphabet = in_array($this->_locale->getLanguage(), - array('ja') - ); - } + $this->filter = new AlnumFilter(); + + $this->locale = Locale::getDefault(); + $language = Locale::getPrimaryLanguage($this->locale); + self::$meansEnglishAlphabet = in_array($language, array('ja')); + self::$unicodeEnabled = (@preg_match('/\pL/u', 'a')) ? true : false; } /** @@ -88,7 +84,7 @@ public function setUp() */ public function testBasic() { - if (!self::$_unicodeEnabled) { + if (!self::$unicodeEnabled) { // POSIX named classes are not supported, use alternative a-zA-Z match $valuesExpected = array( 'abc123' => 'abc123', @@ -96,9 +92,10 @@ public function testBasic() 'abcxyz' => 'abcxyz', 'AZ@#4.3' => 'AZ43', '' => '' - ); - } if (self::$_meansEnglishAlphabet) { - //The Alphabet means english alphabet. + ); + } elseif (self::$meansEnglishAlphabet) { + // The Alphabet means english alphabet. + /** * The first element contains multibyte alphabets and digits. * But , AlnumFilter is expected to return only singlebyte alphabets and digits. @@ -114,22 +111,19 @@ public function testBasic() } else { //The Alphabet means each language's alphabet. $valuesExpected = array( - 'abc123' => 'abc123', - 'abc 123' => 'abc123', - 'abcxyz' => 'abcxyz', - 'če2t3ně' => 'če2t3ně', - 'grz5e4gżółka' => 'grz5e4gżółka', - 'Be3l5gië' => 'Be3l5gië', - '' => '' - ); + 'abc123' => 'abc123', + 'abc 123' => 'abc123', + 'abcxyz' => 'abcxyz', + 'če2t3ně' => 'če2t3ně', + 'grz5e4gżółka' => 'grz5e4gżółka', + 'Be3l5gië' => 'Be3l5gië', + '' => '' + ); } - $filter = $this->_filter; - foreach ($valuesExpected as $input => $output) { - $this->assertEquals( - $output, - $result = $filter($input), - "Expected '$input' to filter to '$output', but received '$result' instead" - ); + + foreach ($valuesExpected as $input => $expected) { + $actual = $this->filter->filter($input); + $this->assertEquals($expected, $actual); } } @@ -140,9 +134,9 @@ public function testBasic() */ public function testAllowWhiteSpace() { - $this->_filter->setAllowWhiteSpace(true); + $this->filter->setAllowWhiteSpace(true); - if (!self::$_unicodeEnabled) { + if (!self::$unicodeEnabled) { // POSIX named classes are not supported, use alternative a-zA-Z match $valuesExpected = array( 'abc123' => 'abc123', @@ -152,34 +146,29 @@ public function testAllowWhiteSpace() '' => '', "\n" => "\n", " \t " => " \t " - ); - } - - if (self::$_meansEnglishAlphabet) { + ); + } elseif (self::$meansEnglishAlphabet) { //The Alphabet means english alphabet. $valuesExpected = array( - 'a B 45' => 'a B 5', - 'z3 x' => 'z3x' - ); + 'a B 45' => 'a B 5', + 'z3 x' => 'z3x' + ); } else { //The Alphabet means each language's alphabet. $valuesExpected = array( - 'abc123' => 'abc123', - 'abc 123' => 'abc 123', - 'abcxyz' => 'abcxyz', - 'če2 t3ně' => 'če2 t3ně', - 'gr z5e4gżółka' => 'gr z5e4gżółka', - 'Be3l5 gië' => 'Be3l5 gië', - '' => '', + 'abc123' => 'abc123', + 'abc 123' => 'abc 123', + 'abcxyz' => 'abcxyz', + 'če2 t3ně' => 'če2 t3ně', + 'gr z5e4gżółka' => 'gr z5e4gżółka', + 'Be3l5 gië' => 'Be3l5 gië', + '' => '', ); } - $filter = $this->_filter; - foreach ($valuesExpected as $input => $output) { - $this->assertEquals( - $output, - $result = $filter($input), - "Expected '$input' to filter to '$output', but received '$result' instead" - ); + + foreach ($valuesExpected as $input => $expected) { + $actual = $this->filter->filter($input); + $this->assertEquals($expected, $actual); } } } diff --git a/test/AlphaTest.php b/test/AlphaTest.php index 157ca994..2e16ebaf 100644 --- a/test/AlphaTest.php +++ b/test/AlphaTest.php @@ -22,7 +22,7 @@ namespace ZendTest\Filter; use Zend\Filter\Alpha as AlphaFilter; -use Zend\Locale\Locale; +use Locale; /** * @category Zend @@ -39,50 +39,42 @@ class AlphaTest extends \PHPUnit_Framework_TestCase * * @var AlphaFilter */ - protected $_filter; + protected $filter; /** * Is PCRE is compiled with UTF-8 and Unicode support * * @var mixed **/ - protected static $_unicodeEnabled; + protected static $unicodeEnabled; /** * Locale in browser. * - * @var Locale object + * @var string */ - protected $_locale; + protected $locale; /** * The Alphabet means english alphabet. * * @var boolean */ - protected static $_meansEnglishAlphabet; + protected static $meansEnglishAlphabet; /** - * Creates a new AlphaFilter object for each test method + * Creates a new AlnumFilter object for each test method * * @return void */ public function setUp() { - if (null === self::$_unicodeEnabled) { - self::$_unicodeEnabled = (@preg_match('/\pL/u', 'a')) ? true : false; - } + $this->filter = new AlphaFilter(); - $this->_locale = new Locale('auto'); - if (null === self::$_meansEnglishAlphabet) { - self::$_meansEnglishAlphabet = in_array($this->_locale->getLanguage(), - array('ja') - ); - } - $this->_filter = new AlphaFilter(array( - 'unicodeEnabled' => self::$_unicodeEnabled, - 'locale' => $this->_locale, - )); + $this->locale = Locale::getDefault(); + $language = Locale::getPrimaryLanguage($this->locale); + self::$meansEnglishAlphabet = in_array($language, array('ja')); + self::$unicodeEnabled = (@preg_match('/\pL/u', 'a')) ? true : false; } /** @@ -92,15 +84,15 @@ public function setUp() */ public function testBasic() { - if (!self::$_unicodeEnabled) { + if (!self::$unicodeEnabled) { // POSIX named classes are not supported, use alternative a-zA-Z match $valuesExpected = array( 'abc123' => 'abc', 'abc 123' => 'abc', 'abcxyz' => 'abcxyz', '' => '' - ); - } else if (self::$_meansEnglishAlphabet) { + ); + } elseif (self::$meansEnglishAlphabet) { //The Alphabet means english alphabet. /** * The first element contains multibyte alphabets. @@ -111,12 +103,12 @@ public function testBasic() * The last contains only singlebyte alphabets. */ $valuesExpected = array( - 'aABbc' => 'aBc', - 'z Y x' => 'zx', - 'W1v3U4t' => 'vt', + 'aABbc' => 'aBc', + 'z Y x' => 'zx', + 'W1v3U4t' => 'vt', ',sй.rλ:qν_p' => 'srqp', - 'onml' => 'onml' - ); + 'onml' => 'onml' + ); } else { //The Alphabet means each language's alphabet. $valuesExpected = array( @@ -128,16 +120,12 @@ public function testBasic() 'grzegżółka' => 'grzegżółka', 'België' => 'België', '' => '' - ); + ); } - $filter = $this->_filter; - foreach ($valuesExpected as $input => $output) { - $this->assertEquals( - $output, - $result = $filter($input), - "Expected '$input' to filter to '$output', but received '$result' instead" - ); + foreach ($valuesExpected as $input => $expected) { + $actual = $this->filter->filter($input); + $this->assertEquals($expected, $actual); } } @@ -148,23 +136,24 @@ public function testBasic() */ public function testAllowWhiteSpace() { - $this->_filter->setAllowWhiteSpace(true); - if (!self::$_unicodeEnabled) { + $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) { + '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' - ); + 'a B' => 'a B', + 'zY x' => 'zx' + ); } else { //The Alphabet means each language's alphabet. $valuesExpected = array( @@ -181,13 +170,9 @@ public function testAllowWhiteSpace() ); } - $filter = $this->_filter; - foreach ($valuesExpected as $input => $output) { - $this->assertEquals( - $output, - $result = $filter($input), - "Expected '$input' to filter to '$output', but received '$result' instead" - ); + foreach ($valuesExpected as $input => $expected) { + $actual = $this->filter->filter($input); + $this->assertEquals($expected, $actual); } } } From 2a3d528f1ed7d94e9791c5a43c4e6c28c8616d05 Mon Sep 17 00:00:00 2001 From: Denis Portnov Date: Tue, 3 Jul 2012 02:08:35 +0400 Subject: [PATCH 02/17] Boolean, Null --- src/Boolean.php | 310 +++++------- src/Null.php | 135 +++-- test/BooleanTest.php | 1116 ++++++++++++++++-------------------------- test/NullTest.php | 486 +++++++++--------- 4 files changed, 839 insertions(+), 1208 deletions(-) diff --git a/src/Boolean.php b/src/Boolean.php index e36a1597..415b2eef 100644 --- a/src/Boolean.php +++ b/src/Boolean.php @@ -22,7 +22,7 @@ use Traversable; use Zend\Stdlib\ArrayUtils; -use Zend\Locale\Locale; + /** * @category Zend @@ -30,54 +30,46 @@ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ -class Boolean extends AbstractFilter +class Boolean extends AbstractLocale { - const BOOLEAN = 1; - const INTEGER = 2; - const FLOAT = 4; - const STRING = 8; - const ZERO = 16; - const EMPTY_ARRAY = 32; - const NULL = 64; - const PHP = 127; - const FALSE_STRING = 128; - const YES = 256; - const ALL = 511; - - protected $_constants = array( - self::BOOLEAN => 'boolean', - self::INTEGER => 'integer', - self::FLOAT => 'float', - self::STRING => 'string', - self::ZERO => 'zero', - self::EMPTY_ARRAY => 'array', - self::NULL => 'null', - self::PHP => 'php', - self::FALSE_STRING => 'false', - self::YES => 'yes', - self::ALL => 'all', - ); + const TYPE_BOOLEAN = 1; + const TYPE_INTEGER = 2; + const TYPE_FLOAT = 4; + const TYPE_STRING = 8; + const TYPE_ZERO_STRING = 16; + const TYPE_EMPTY_ARRAY = 32; + const TYPE_NULL = 64; + const TYPE_PHP = 127; + const TYPE_FALSE_STRING = 128; + const TYPE_LOCALIZED = 256; + const TYPE_ALL = 511; /** - * Internal type to detect - * - * @var integer - */ - protected $_type = self::PHP; - - /** - * Internal locale - * * @var array */ - protected $_locale = array('auto'); + protected $constants = array( + self::TYPE_BOOLEAN => 'boolean', + self::TYPE_INTEGER => 'integer', + self::TYPE_FLOAT => 'float', + self::TYPE_STRING => 'string', + self::TYPE_ZERO_STRING => 'zero', + self::TYPE_EMPTY_ARRAY => 'array', + self::TYPE_NULL => 'null', + self::TYPE_PHP => 'php', + self::TYPE_FALSE_STRING => 'false', + self::TYPE_LOCALIZED => 'localized', + self::TYPE_ALL => 'all', + ); /** - * Internal mode - * - * @var boolean + * @var array */ - protected $_casting = true; + protected $options = array( + 'type' => self::TYPE_PHP, + 'casting' => true, + 'locale' => null, + 'translations' => array(), + ); /** * Constructor @@ -86,52 +78,30 @@ class Boolean extends AbstractFilter */ public function __construct($options = null) { - if ($options instanceof Traversable) { - $options = ArrayUtils::iteratorToArray($options); - } - if (!is_array($options)) { - $options = func_get_args(); - $temp = array(); - if (!empty($options)) { - $temp['type'] = array_shift($options); - } - - if (!empty($options)) { - $temp['casting'] = array_shift($options); + if ($options !== null) { + if ($options instanceof Traversable) { + $options = ArrayUtils::iteratorToArray($options); } - if (!empty($options)) { - $temp['locale'] = array_shift($options); + if (!is_array($options)) { + $args = func_get_args(); + if (isset($args[0])) { + $this->setType($args[0]); + } + if (isset($args[1])) { + $this->setCasting($args[1]); + } + if (isset($args[2])) { + $this->setLocale($args[2]); + } + } else { + $this->setOptions($options); } - - $options = $temp; } - - if (array_key_exists('type', $options)) { - $this->setType($options['type']); - } - - if (array_key_exists('casting', $options)) { - $this->setCasting($options['casting']); - } - - if (array_key_exists('locale', $options)) { - $this->setLocale($options['locale']); - } - } - - /** - * Returns the set null types - * - * @return int - */ - public function getType() - { - return $this->_type; } /** - * Set the null types + * Set boolean types * * @param integer|array $type * @throws Exception\InvalidArgumentException @@ -141,61 +111,52 @@ public function setType($type = null) { if (is_array($type)) { $detected = 0; - foreach($type as $value) { + foreach ($type as $value) { if (is_int($value)) { $detected += $value; - } elseif (in_array($value, $this->_constants)) { - $detected += array_search($value, $this->_constants); + } elseif (in_array($value, $this->constants)) { + $detected += array_search($value, $this->constants); } } $type = $detected; - } elseif (is_string($type) && in_array($type, $this->_constants)) { - $type = array_search($type, $this->_constants); + } elseif (is_string($type) && in_array($type, $this->constants)) { + $type = array_search($type, $this->constants); } - if (!is_int($type) || ($type < 0) || ($type > self::ALL)) { - throw new Exception\InvalidArgumentException('Unknown type'); + if (!is_int($type) || ($type < 0) || ($type > self::TYPE_ALL)) { + throw new Exception\InvalidArgumentException(sprintf( + 'Unknown type value "%s" (%s)', + $type, + gettype($type) + )); } - $this->_type = $type; + $this->options['type'] = $type; return $this; } /** - * Returns the set locale + * Returns defined boolean types * - * @return array + * @return int */ - public function getLocale() + public function getType() { - return $this->_locale; + return $this->options['type']; } /** - * Set the locales which are accepted + * Set the working mode * - * @param string|array|\Zend\Locale\Locale $locale - * @throws Exception\ExceptionInterface + * @param boolean $flag When true this filter works like cast + * When false it recognises only true and false + * and all other values are returned as is * @return Boolean */ - public function setLocale($locale = null) + public function setCasting($flag = true) { - if (is_string($locale)) { - $locale = array($locale); - } elseif ($locale instanceof Locale) { - $locale = array($locale->toString()); - } elseif (!is_array($locale)) { - throw new Exception\InvalidArgumentException('Locale has to be string, array or an instance of Zend_Locale'); - } - - foreach ($locale as $single) { - if (!Locale::isLocale($single)) { - throw new Exception\InvalidArgumentException("Unknown locale '$single'"); - } - } - - $this->_locale = $locale; + $this->options['casting'] = (boolean) $flag; return $this; } @@ -206,20 +167,41 @@ public function setLocale($locale = null) */ public function getCasting() { - return $this->_casting; + return $this->options['casting']; } /** - * Set the working mode - * - * @param boolean $locale When true this filter works like cast - * When false it recognises only true and false - * and all other values are returned as is + * @param array $translations + * @return Boolean + */ + public function setTranslations(array $translations) + { + foreach ($translations as $locale => $translation) { + $this->addTranslation($locale, $translation); + } + return $this; + } + + /** + * @return array + */ + public function getTranslations() + { + return $this->options['translations']; + } + + /** + * @param string $locale + * @param array $translation * @return Boolean + * @throws Exception\InvalidArgumentException */ - public function setCasting($casting = true) + public function addTranslation($locale, array $translation) { - $this->_casting = (boolean) $casting; + foreach ($translation as $message => $flag) { + $this->options['translations'][$locale][$message] = (bool) $flag; + } + return $this; } @@ -236,98 +218,92 @@ public function filter($value) $type = $this->getType(); $casting = $this->getCasting(); - // STRING YES (Localized) - if ($type >= self::YES) { - $type -= self::YES; + // LOCALIZED + if ($type >= self::TYPE_LOCALIZED) { + $type -= self::TYPE_LOCALIZED; if (is_string($value)) { - $locales = $this->getLocale(); - foreach ($locales as $locale) { - if ($this->_getLocalizedQuestion($value, false, $locale) === false) { - return false; - } - - if (!$casting && ($this->_getLocalizedQuestion($value, true, $locale) === true)) { - return true; - } + $locale = $this->getLocale(); + if (isset($this->options['translations'][$locale][$value])) { + return (bool) $this->options['translations'][$locale][$value]; } } } - // STRING FALSE ('false') - if ($type >= self::FALSE_STRING) { - $type -= self::FALSE_STRING; + // FALSE_STRING ('false') + if ($type >= self::TYPE_FALSE_STRING) { + $type -= self::TYPE_FALSE_STRING; if (is_string($value) && (strtolower($value) == 'false')) { return false; } - if ((!$casting) && is_string($value) && (strtolower($value) == 'true')) { + if (!$casting && is_string($value) && (strtolower($value) == 'true')) { return true; } } // NULL (null) - if ($type >= self::NULL) { - $type -= self::NULL; + if ($type >= self::TYPE_NULL) { + $type -= self::TYPE_NULL; if ($value === null) { return false; } } // EMPTY_ARRAY (array()) - if ($type >= self::EMPTY_ARRAY) { - $type -= self::EMPTY_ARRAY; + if ($type >= self::TYPE_EMPTY_ARRAY) { + $type -= self::TYPE_EMPTY_ARRAY; if (is_array($value) && ($value == array())) { return false; } } - // ZERO ('0') - if ($type >= self::ZERO) { - $type -= self::ZERO; + // ZERO_STRING ('0') + if ($type >= self::TYPE_ZERO_STRING) { + $type -= self::TYPE_ZERO_STRING; if (is_string($value) && ($value == '0')) { return false; } - if ((!$casting) && (is_string($value)) && ($value == '1')) { + if (!$casting && (is_string($value)) && ($value == '1')) { return true; } } // STRING ('') - if ($type >= self::STRING) { - $type -= self::STRING; + if ($type >= self::TYPE_STRING) { + $type -= self::TYPE_STRING; if (is_string($value) && ($value == '')) { return false; } } // FLOAT (0.0) - if ($type >= self::FLOAT) { - $type -= self::FLOAT; + if ($type >= self::TYPE_FLOAT) { + $type -= self::TYPE_FLOAT; if (is_float($value) && ($value == 0.0)) { return false; } - if ((!$casting) && is_float($value) && ($value == 1.0)) { + if (!$casting && is_float($value) && ($value == 1.0)) { return true; } } // INTEGER (0) - if ($type >= self::INTEGER) { - $type -= self::INTEGER; + if ($type >= self::TYPE_INTEGER) { + $type -= self::TYPE_INTEGER; if (is_int($value) && ($value == 0)) { return false; } - if ((!$casting) && is_int($value) && ($value == 1)) { + if (!$casting && is_int($value) && ($value == 1)) { return true; } } // BOOLEAN (false) - if ($type >= self::BOOLEAN) { - $type -= self::BOOLEAN; + if ($type >= self::TYPE_BOOLEAN) { + $type -= self::TYPE_BOOLEAN; if (is_bool($value)) { return $value; } @@ -339,32 +315,4 @@ public function filter($value) return $value; } - - /** - * Determine the value of a localized string, and compare it to a given value - * - * @param string $value - * @param boolean $yes - * @param array $locale - * @return boolean - */ - protected function _getLocalizedQuestion($value, $yes, $locale) - { - if ($yes == true) { - $question = 'yes'; - $return = true; - } else { - $question = 'no'; - $return = false; - } - $str = Locale::getTranslation($question, 'question', $locale); - $str = explode(':', $str); - if (!empty($str)) { - foreach($str as $no) { - if (($no == $value) || (strtolower($no) == strtolower($value))) { - return $return; - } - } - } - } } diff --git a/src/Null.php b/src/Null.php index 3826a86e..9720aa30 100644 --- a/src/Null.php +++ b/src/Null.php @@ -31,30 +31,33 @@ */ class Null extends AbstractFilter { - const BOOLEAN = 1; - const INTEGER = 2; - const EMPTY_ARRAY = 4; - const STRING = 8; - const ZERO = 16; - const FLOAT = 32; - const ALL = 63; - - protected $_constants = array( - self::BOOLEAN => 'boolean', - self::INTEGER => 'integer', - self::EMPTY_ARRAY => 'array', - self::STRING => 'string', - self::ZERO => 'zero', - self::FLOAT => 'float', - self::ALL => 'all', + const TYPE_BOOLEAN = 1; + const TYPE_INTEGER = 2; + const TYPE_EMPTY_ARRAY = 4; + const TYPE_STRING = 8; + const TYPE_ZERO_STRING = 16; + const TYPE_FLOAT = 32; + const TYPE_ALL = 63; + + /** + * @var array + */ + protected $constants = array( + self::TYPE_BOOLEAN => 'boolean', + self::TYPE_INTEGER => 'integer', + self::TYPE_EMPTY_ARRAY => 'array', + self::TYPE_STRING => 'string', + self::TYPE_ZERO_STRING => 'zero', + self::TYPE_FLOAT => 'float', + self::TYPE_ALL => 'all', ); /** - * Internal type to detect - * - * @var integer + * @var array */ - protected $_type = self::ALL; + protected $options = array( + 'type' => self::TYPE_ALL, + ); /** * Constructor @@ -63,69 +66,65 @@ class Null extends AbstractFilter */ public function __construct($options = null) { - if ($options instanceof Traversable) { - $options = ArrayUtils::iteratorToArray($options); - } - if (!is_array($options)) { - $options = func_get_args(); - $temp = array(); - if (!empty($options)) { - $temp = array_shift($options); + if ($options !== null) { + if ($options instanceof Traversable) { + $options = iterator_to_array($options); } - $options = $temp; - } elseif (is_array($options) && array_key_exists('type', $options)) { - $options = $options['type']; - } - if (!empty($options)) { - $this->setType($options); + if (!is_array($options)) { + $this->setType($options); + } else { + $this->setOptions($options); + } } } /** - * Returns the set null types - * - * @return array - */ - public function getType() - { - return $this->_type; - } - - /** - * Set the null types + * Set boolean types * * @param integer|array $type * @throws Exception\InvalidArgumentException - * @return Null + * @return Boolean */ public function setType($type = null) { if (is_array($type)) { $detected = 0; - foreach($type as $value) { + foreach ($type as $value) { if (is_int($value)) { $detected += $value; - } else if (in_array($value, $this->_constants)) { - $detected += array_search($value, $this->_constants); + } elseif (in_array($value, $this->constants)) { + $detected += array_search($value, $this->constants); } } $type = $detected; - } else if (is_string($type)) { - if (in_array($type, $this->_constants)) { - $type = array_search($type, $this->_constants); - } + } elseif (is_string($type) && in_array($type, $this->constants)) { + $type = array_search($type, $this->constants); } - if (!is_int($type) || ($type < 0) || ($type > self::ALL)) { - throw new Exception\InvalidArgumentException('Unknown type'); + if (!is_int($type) || ($type < 0) || ($type > self::TYPE_ALL)) { + throw new Exception\InvalidArgumentException(sprintf( + 'Unknown type value "%s" (%s)', + $type, + gettype($type) + )); } - $this->_type = $type; + $this->options['type'] = $type; return $this; } + /** + * Returns defined boolean types + * + * @return int + */ + public function getType() + { + return $this->options['type']; + } + /** * Defined by Zend\Filter\FilterInterface * @@ -140,48 +139,48 @@ public function filter($value) $type = $this->getType(); // FLOAT (0.0) - if ($type >= self::FLOAT) { - $type -= self::FLOAT; + if ($type >= self::TYPE_FLOAT) { + $type -= self::TYPE_FLOAT; if (is_float($value) && ($value == 0.0)) { return null; } } // STRING ZERO ('0') - if ($type >= self::ZERO) { - $type -= self::ZERO; + if ($type >= self::TYPE_ZERO_STRING) { + $type -= self::TYPE_ZERO_STRING; if (is_string($value) && ($value == '0')) { return null; } } // STRING ('') - if ($type >= self::STRING) { - $type -= self::STRING; + if ($type >= self::TYPE_STRING) { + $type -= self::TYPE_STRING; if (is_string($value) && ($value == '')) { return null; } } // EMPTY_ARRAY (array()) - if ($type >= self::EMPTY_ARRAY) { - $type -= self::EMPTY_ARRAY; + if ($type >= self::TYPE_EMPTY_ARRAY) { + $type -= self::TYPE_EMPTY_ARRAY; if (is_array($value) && ($value == array())) { return null; } } // INTEGER (0) - if ($type >= self::INTEGER) { - $type -= self::INTEGER; + if ($type >= self::TYPE_INTEGER) { + $type -= self::TYPE_INTEGER; if (is_int($value) && ($value == 0)) { return null; } } // BOOLEAN (false) - if ($type >= self::BOOLEAN) { - $type -= self::BOOLEAN; + if ($type >= self::TYPE_BOOLEAN) { + $type -= self::TYPE_BOOLEAN; if (is_bool($value) && ($value == false)) { return null; } diff --git a/test/BooleanTest.php b/test/BooleanTest.php index 8501d644..28bf342a 100644 --- a/test/BooleanTest.php +++ b/test/BooleanTest.php @@ -34,764 +34,470 @@ */ class BooleanTest extends \PHPUnit_Framework_TestCase { - /** - * Zend_Filter_Boolean object - * - * @var Zend_Filter_Boolean - */ - protected $_filter; - - /** - * Creates a new Zend_Filter_Boolean object for each test method - * - * @return void - */ - public function setUp() - { - $this->_filter = new BooleanFilter(); - } - - /** - * Ensures that the filter follows expected behavior - * - * @return void - */ - public function testBasic() - { - $filter = $this->_filter; - $this->assertFalse($filter(false)); - $this->assertTrue($filter(true)); - $this->assertFalse($filter(0)); - $this->assertTrue($filter(1)); - $this->assertFalse($filter(0.0)); - $this->assertTrue($filter(1.0)); - $this->assertFalse($filter('')); - $this->assertTrue($filter('abc')); - $this->assertFalse($filter('0')); - $this->assertTrue($filter('1')); - $this->assertFalse($filter(array())); - $this->assertTrue($filter(array('xxx'))); - $this->assertFalse($filter(null)); - $this->assertTrue($filter('false')); - $this->assertTrue($filter('true')); - $this->assertTrue($filter('no')); - $this->assertTrue($filter('yes')); - } - - /** - * Ensures that the filter follows expected behavior - * - * @return void - */ - public function testOnlyBoolean() - { - $filter = $this->_filter; - $filter->setType(BooleanFilter::BOOLEAN); - $this->assertFalse($filter(false)); - $this->assertTrue($filter(true)); - $this->assertTrue($filter(0)); - $this->assertTrue($filter(1)); - $this->assertTrue($filter(0.0)); - $this->assertTrue($filter(1.0)); - $this->assertTrue($filter('')); - $this->assertTrue($filter('abc')); - $this->assertTrue($filter('0')); - $this->assertTrue($filter('1')); - $this->assertTrue($filter(array())); - $this->assertTrue($filter(array('xxx'))); - $this->assertTrue($filter(null)); - $this->assertTrue($filter('false')); - $this->assertTrue($filter('true')); - $this->assertTrue($filter('no')); - $this->assertTrue($filter('yes')); - } - - /** - * Ensures that the filter follows expected behavior - * - * @return void - */ - public function testOnlyInteger() - { - $filter = $this->_filter; - $filter->setType(BooleanFilter::INTEGER); - $this->assertTrue($filter(false)); - $this->assertTrue($filter(true)); - $this->assertFalse($filter(0)); - $this->assertTrue($filter(1)); - $this->assertTrue($filter(0.0)); - $this->assertTrue($filter(1.0)); - $this->assertTrue($filter('')); - $this->assertTrue($filter('abc')); - $this->assertTrue($filter('0')); - $this->assertTrue($filter('1')); - $this->assertTrue($filter(array())); - $this->assertTrue($filter(array('xxx'))); - $this->assertTrue($filter(null)); - $this->assertTrue($filter('false')); - $this->assertTrue($filter('true')); - $this->assertTrue($filter('no')); - $this->assertTrue($filter('yes')); - } - - /** - * Ensures that the filter follows expected behavior - * - * @return void - */ - public function testOnlyFloat() - { - $filter = $this->_filter; - $filter->setType(BooleanFilter::FLOAT); - $this->assertTrue($filter(false)); - $this->assertTrue($filter(true)); - $this->assertTrue($filter(0)); - $this->assertTrue($filter(1)); - $this->assertFalse($filter(0.0)); - $this->assertTrue($filter(1.0)); - $this->assertTrue($filter('')); - $this->assertTrue($filter('abc')); - $this->assertTrue($filter('0')); - $this->assertTrue($filter('1')); - $this->assertTrue($filter(array())); - $this->assertTrue($filter(array('xxx'))); - $this->assertTrue($filter(null)); - $this->assertTrue($filter('false')); - $this->assertTrue($filter('true')); - $this->assertTrue($filter('no')); - $this->assertTrue($filter('yes')); - } - - /** - * Ensures that the filter follows expected behavior - * - * @return void - */ - public function testOnlyString() - { - $filter = $this->_filter; - $filter->setType(BooleanFilter::STRING); - $this->assertTrue($filter(false)); - $this->assertTrue($filter(true)); - $this->assertTrue($filter(0)); - $this->assertTrue($filter(1)); - $this->assertTrue($filter(0.0)); - $this->assertTrue($filter(1.0)); - $this->assertFalse($filter('')); - $this->assertTrue($filter('abc')); - $this->assertTrue($filter('0')); - $this->assertTrue($filter('1')); - $this->assertTrue($filter(array())); - $this->assertTrue($filter(array('xxx'))); - $this->assertTrue($filter(null)); - $this->assertTrue($filter('false')); - $this->assertTrue($filter('true')); - $this->assertTrue($filter('no')); - $this->assertTrue($filter('yes')); - } - - /** - * Ensures that the filter follows expected behavior - * - * @return void - */ - public function testOnlyZero() + public function testConstructorOptions() { - $filter = $this->_filter; - $filter->setType(BooleanFilter::ZERO); - $this->assertTrue($filter(false)); - $this->assertTrue($filter(true)); - $this->assertTrue($filter(0)); - $this->assertTrue($filter(1)); - $this->assertTrue($filter(0.0)); - $this->assertTrue($filter(1.0)); - $this->assertTrue($filter('')); - $this->assertTrue($filter('abc')); - $this->assertFalse($filter('0')); - $this->assertTrue($filter('1')); - $this->assertTrue($filter(array())); - $this->assertTrue($filter(array('xxx'))); - $this->assertTrue($filter(null)); - $this->assertTrue($filter('false')); - $this->assertTrue($filter('true')); - $this->assertTrue($filter('no')); - $this->assertTrue($filter('yes')); + $filter = new BooleanFilter(array( + 'type' => BooleanFilter::TYPE_INTEGER, + 'casting' => false, + 'locale' => 'en_EN', + )); + $this->assertEquals(BooleanFilter::TYPE_INTEGER, $filter->getType()); + $this->assertEquals(false, $filter->getCasting()); + $this->assertEquals('en_EN', $filter->getLocale()); } - /** - * Ensures that the filter follows expected behavior - * - * @return void - */ - public function testOnlyArray() + public function testConstructorParams() { - $filter = $this->_filter; - $filter->setType(BooleanFilter::EMPTY_ARRAY); - $this->assertTrue($filter(false)); - $this->assertTrue($filter(true)); - $this->assertTrue($filter(0)); - $this->assertTrue($filter(1)); - $this->assertTrue($filter(0.0)); - $this->assertTrue($filter(1.0)); - $this->assertTrue($filter('')); - $this->assertTrue($filter('abc')); - $this->assertTrue($filter('0')); - $this->assertTrue($filter('1')); - $this->assertFalse($filter(array())); - $this->assertTrue($filter(array('xxx'))); - $this->assertTrue($filter(null)); - $this->assertTrue($filter('false')); - $this->assertTrue($filter('true')); - $this->assertTrue($filter('no')); - $this->assertTrue($filter('yes')); - } + $filter = new BooleanFilter(BooleanFilter::TYPE_INTEGER, false, 'en_EN'); - /** - * Ensures that the filter follows expected behavior - * - * @return void - */ - public function testOnlyNull() - { - $filter = $this->_filter; - $filter->setType(BooleanFilter::NULL); - $this->assertTrue($filter(false)); - $this->assertTrue($filter(true)); - $this->assertTrue($filter(0)); - $this->assertTrue($filter(1)); - $this->assertTrue($filter(0.0)); - $this->assertTrue($filter(1.0)); - $this->assertTrue($filter('')); - $this->assertTrue($filter('abc')); - $this->assertTrue($filter('0')); - $this->assertTrue($filter('1')); - $this->assertTrue($filter(array())); - $this->assertTrue($filter(array('xxx'))); - $this->assertFalse($filter(null)); - $this->assertTrue($filter('false')); - $this->assertTrue($filter('true')); - $this->assertTrue($filter('no')); - $this->assertTrue($filter('yes')); + $this->assertEquals(BooleanFilter::TYPE_INTEGER, $filter->getType()); + $this->assertEquals(false, $filter->getCasting()); + $this->assertEquals('en_EN', $filter->getLocale()); } /** - * Ensures that the filter follows expected behavior - * - * @return void + * @param mixed $value + * @param bool $expected + * @dataProvider defaultTestProvider */ - public function testOnlyPHP() + public function testDefault($value, $expected) { - $filter = $this->_filter; - $filter->setType(BooleanFilter::PHP); - $this->assertFalse($filter(false)); - $this->assertTrue($filter(true)); - $this->assertFalse($filter(0)); - $this->assertTrue($filter(1)); - $this->assertFalse($filter(0.0)); - $this->assertTrue($filter(1.0)); - $this->assertFalse($filter('')); - $this->assertTrue($filter('abc')); - $this->assertFalse($filter('0')); - $this->assertTrue($filter('1')); - $this->assertFalse($filter(array())); - $this->assertTrue($filter(array('xxx'))); - $this->assertFalse($filter(null)); - $this->assertTrue($filter('false')); - $this->assertTrue($filter('true')); - $this->assertTrue($filter('no')); - $this->assertTrue($filter('yes')); + $filter = new BooleanFilter(); + $this->assertSame($expected, $filter->filter($value)); } /** - * Ensures that the filter follows expected behavior - * - * @return void + * @param mixed $value + * @param bool $expected + * @dataProvider noCastingTestProvider */ - public function testOnlyFalseString() + public function testNoCasting($value, $expected) { - $filter = $this->_filter; - $filter->setType(BooleanFilter::FALSE_STRING); - $this->assertTrue($filter(false)); - $this->assertTrue($filter(true)); - $this->assertTrue($filter(0)); - $this->assertTrue($filter(1)); - $this->assertTrue($filter(0.0)); - $this->assertTrue($filter(1.0)); - $this->assertTrue($filter('')); - $this->assertTrue($filter('abc')); - $this->assertTrue($filter('0')); - $this->assertTrue($filter('1')); - $this->assertTrue($filter(array())); - $this->assertTrue($filter(array('xxx'))); - $this->assertTrue($filter(null)); - $this->assertFalse($filter('false')); - $this->assertTrue($filter('true')); - $this->assertTrue($filter('no')); - $this->assertTrue($filter('yes')); + $filter = new BooleanFilter('all', false); + $this->assertEquals($expected, $filter->filter($value)); } /** - * Ensures that the filter follows expected behavior - * - * @return void + * @param int $type + * @param array $testData + * @dataProvider typeTestProvider */ - public function testOnlyYes() + public function testTypes($type, $testData) { - $filter = $this->_filter; - $filter->setType(BooleanFilter::YES); - $filter->setLocale('en'); - $this->assertTrue($filter(false)); - $this->assertTrue($filter(true)); - $this->assertTrue($filter(0)); - $this->assertTrue($filter(1)); - $this->assertTrue($filter(0.0)); - $this->assertTrue($filter(1.0)); - $this->assertTrue($filter('')); - $this->assertTrue($filter('abc')); - $this->assertTrue($filter('0')); - $this->assertTrue($filter('1')); - $this->assertTrue($filter(array())); - $this->assertTrue($filter(array('xxx'))); - $this->assertTrue($filter(null)); - $this->assertTrue($filter('false')); - $this->assertTrue($filter('true')); - $this->assertFalse($filter('no')); - $this->assertTrue($filter('yes')); + $filter = new BooleanFilter($type); + foreach ($testData as $data) { + list($value, $expected) = $data; + $message = sprintf( + '%s (%s) is not filtered as %s; type = %s', + var_export($value, true), + gettype($value), + var_export($expected, true), + $type + ); + $this->assertSame($expected, $filter->filter($value), $message); + } } /** - * Ensures that the filter follows expected behavior - * - * @return void + * @param array $typeData + * @param array $testData + * @dataProvider combinedTypeTestProvider */ - public function testOnlyAll() + public function testCombinedTypes($typeData, $testData) { - $filter = $this->_filter; - $filter->setType(BooleanFilter::ALL); - $filter->setLocale('en'); - $this->assertFalse($filter(false)); - $this->assertTrue($filter(true)); - $this->assertFalse($filter(0)); - $this->assertTrue($filter(1)); - $this->assertFalse($filter(0.0)); - $this->assertTrue($filter(1.0)); - $this->assertFalse($filter('')); - $this->assertTrue($filter('abc')); - $this->assertFalse($filter('0')); - $this->assertTrue($filter('1')); - $this->assertFalse($filter(array())); - $this->assertTrue($filter(array('xxx'))); - $this->assertFalse($filter(null)); - $this->assertFalse($filter('false')); - $this->assertTrue($filter('true')); - $this->assertFalse($filter('no')); - $this->assertTrue($filter('yes')); + foreach ($typeData as $type) { + $filter = new BooleanFilter(array('type' => $type)); + foreach ($testData as $data) { + list($value, $expected) = $data; + $message = sprintf( + '%s (%s) is not filtered as %s; type = %s', + var_export($value, true), + gettype($value), + var_export($expected, true), + var_export($type, true) + ); + $this->assertSame($expected, $filter->filter($value), $message); + } + } } - /** - * Ensures that the filter follows expected behavior - * - * @return void - */ - public function testArrayConstantNotation() + public function testLocalized() { - $filter = new BooleanFilter( - array( - 'type' => array( - BooleanFilter::ZERO, - BooleanFilter::STRING, - BooleanFilter::BOOLEAN, + $filter = new BooleanFilter(array( + 'type' => BooleanFilter::TYPE_LOCALIZED, + 'locale' => 'en_EN', + 'translations' => array( + 'en_EN' => array( + 'yes' => true, + 'y' => true, + 'no' => false, + 'n' => false, ), - ) - ); - - $this->assertFalse($filter(false)); - $this->assertTrue($filter(true)); - $this->assertTrue($filter(0)); - $this->assertTrue($filter(1)); - $this->assertTrue($filter(0.0)); - $this->assertTrue($filter(1.0)); - $this->assertFalse($filter('')); - $this->assertTrue($filter('abc')); - $this->assertFalse($filter('0')); - $this->assertTrue($filter('1')); - $this->assertTrue($filter(array())); - $this->assertTrue($filter(array('xxx'))); - $this->assertTrue($filter(null)); - $this->assertTrue($filter('false')); - $this->assertTrue($filter('true')); - $this->assertTrue($filter('no')); - $this->assertTrue($filter('yes')); - } - - /** - * Ensures that the filter follows expected behavior - * - * @return void - */ - public function testArrayConfigNotation() - { - $filter = new BooleanFilter( - array( - 'type' => array( - BooleanFilter::ZERO, - BooleanFilter::STRING, - BooleanFilter::BOOLEAN, + 'en_US' => array( + 'yay' => true, + 'yes' => true, + 'nay' => false, + 'no' => false, ), - 'test' => false, - ) - ); - - $this->assertFalse($filter(false)); - $this->assertTrue($filter(true)); - $this->assertTrue($filter(0)); - $this->assertTrue($filter(1)); - $this->assertTrue($filter(0.0)); - $this->assertTrue($filter(1.0)); - $this->assertFalse($filter('')); - $this->assertTrue($filter('abc')); - $this->assertFalse($filter('0')); - $this->assertTrue($filter('1')); - $this->assertTrue($filter(array())); - $this->assertTrue($filter(array('xxx'))); - $this->assertTrue($filter(null)); - $this->assertTrue($filter('false')); - $this->assertTrue($filter('true')); - $this->assertTrue($filter('no')); - $this->assertTrue($filter('yes')); - } - - /** - * Ensures that the filter follows expected behavior - * - * @return void - */ - public function testMultiConstantNotation() - { - $filter = new BooleanFilter( - BooleanFilter::ZERO + BooleanFilter::STRING + BooleanFilter::BOOLEAN - ); - - $this->assertFalse($filter(false)); - $this->assertTrue($filter(true)); - $this->assertTrue($filter(0)); - $this->assertTrue($filter(1)); - $this->assertTrue($filter(0.0)); - $this->assertTrue($filter(1.0)); - $this->assertFalse($filter('')); - $this->assertTrue($filter('abc')); - $this->assertFalse($filter('0')); - $this->assertTrue($filter('1')); - $this->assertTrue($filter(array())); - $this->assertTrue($filter(array('xxx'))); - $this->assertTrue($filter(null)); - $this->assertTrue($filter('false')); - $this->assertTrue($filter('true')); - $this->assertTrue($filter('no')); - $this->assertTrue($filter('yes')); - } - - /** - * Ensures that the filter follows expected behavior - * - * @return void - */ - public function testStringNotation() - { - $filter = new BooleanFilter( - array( - 'type' => array('zero', 'string', 'boolean') - ) - ); + ), + )); - $this->assertFalse($filter(false)); - $this->assertTrue($filter(true)); - $this->assertTrue($filter(0)); - $this->assertTrue($filter(1)); - $this->assertTrue($filter(0.0)); - $this->assertTrue($filter(1.0)); - $this->assertFalse($filter('')); - $this->assertTrue($filter('abc')); - $this->assertFalse($filter('0')); - $this->assertTrue($filter('1')); - $this->assertTrue($filter(array())); - $this->assertTrue($filter(array('xxx'))); - $this->assertTrue($filter(null)); - $this->assertTrue($filter('false')); - $this->assertTrue($filter('true')); - $this->assertTrue($filter('no')); - $this->assertTrue($filter('yes')); - } + $this->assertTrue($filter->filter('yes')); + $this->assertFalse($filter->filter('n')); - /** - * Ensures that the filter follows expected behavior - * - * @return void - */ - public function testSingleStringNotation() - { - $filter = new BooleanFilter( - 'boolean' - ); - - $this->assertFalse($filter(false)); - $this->assertTrue($filter(true)); - $this->assertTrue($filter(0)); - $this->assertTrue($filter(1)); - $this->assertTrue($filter(0.0)); - $this->assertTrue($filter(1.0)); - $this->assertTrue($filter('')); - $this->assertTrue($filter('abc')); - $this->assertTrue($filter('0')); - $this->assertTrue($filter('1')); - $this->assertTrue($filter(array())); - $this->assertTrue($filter(array('xxx'))); - $this->assertTrue($filter(null)); - $this->assertTrue($filter('false')); - $this->assertTrue($filter('true')); - $this->assertTrue($filter('no')); - $this->assertTrue($filter('yes')); + $filter->setLocale('en_US'); + $this->assertTrue($filter->filter('yay')); + $this->assertFalse($filter->filter('nay')); } - /** - * Ensures that the filter follows expected behavior - * - * @return void - */ - public function testSettingLocale() + public function testSettingFalseType() { - $filter = $this->_filter; - $filter->setType(BooleanFilter::ALL); - $filter->setLocale('de'); - $this->assertFalse($filter(false)); - $this->assertTrue($filter(true)); - $this->assertFalse($filter(0)); - $this->assertTrue($filter(1)); - $this->assertFalse($filter(0.0)); - $this->assertTrue($filter(1.0)); - $this->assertFalse($filter('')); - $this->assertTrue($filter('abc')); - $this->assertFalse($filter('0')); - $this->assertTrue($filter('1')); - $this->assertFalse($filter(array())); - $this->assertTrue($filter(array('xxx'))); - $this->assertFalse($filter(null)); - $this->assertFalse($filter('false')); - $this->assertTrue($filter('true')); - $this->assertTrue($filter('no')); - $this->assertTrue($filter('yes')); - $this->assertFalse($filter('nein')); - $this->assertTrue($filter('ja')); + $filter = new BooleanFilter(); + $this->setExpectedException('\Zend\Filter\Exception\InvalidArgumentException', 'Unknown type value'); + $filter->setType(true); } - /** - * Ensures that the filter follows expected behavior - * - * @return void - */ - public function testSettingLocalePerConstructorString() + public function testGettingDefaultType() { - $filter = new BooleanFilter( - 'all', true, 'de' - ); - - $this->assertFalse($filter(false)); - $this->assertTrue($filter(true)); - $this->assertFalse($filter(0)); - $this->assertTrue($filter(1)); - $this->assertFalse($filter(0.0)); - $this->assertTrue($filter(1.0)); - $this->assertFalse($filter('')); - $this->assertTrue($filter('abc')); - $this->assertFalse($filter('0')); - $this->assertTrue($filter('1')); - $this->assertFalse($filter(array())); - $this->assertTrue($filter(array('xxx'))); - $this->assertFalse($filter(null)); - $this->assertFalse($filter('false')); - $this->assertTrue($filter('true')); - $this->assertTrue($filter('no')); - $this->assertTrue($filter('yes')); - $this->assertFalse($filter('nein')); - $this->assertTrue($filter('ja')); + $filter = new BooleanFilter(); + $this->assertEquals(127, $filter->getType()); } - /** - * Ensures that the filter follows expected behavior - * - * @return void - */ - public function testConfigObject() + static public function defaultTestProvider() { - $options = array('type' => 'all', 'locale' => 'de'); - $config = new \Zend\Config\Config($options); - - $filter = new BooleanFilter( - $config + return array( + array(false, false), + array(true, true), + array(0, false), + array(1, true), + array(0.0, false), + array(1.0, true), + array('', false), + array('abc', true), + array('0', false), + array('1', true), + array(array(), false), + array(array(0), true), + array(null, false), + array('false', true), + array('true', true), + array('no', true), + array('yes', true), ); - - $this->assertFalse($filter(false)); - $this->assertTrue($filter(true)); - $this->assertFalse($filter(0)); - $this->assertTrue($filter(1)); - $this->assertFalse($filter(0.0)); - $this->assertTrue($filter(1.0)); - $this->assertFalse($filter('')); - $this->assertTrue($filter('abc')); - $this->assertFalse($filter('0')); - $this->assertTrue($filter('1')); - $this->assertFalse($filter(array())); - $this->assertTrue($filter(array('xxx'))); - $this->assertFalse($filter(null)); - $this->assertFalse($filter('false')); - $this->assertTrue($filter('true')); - $this->assertTrue($filter('no')); - $this->assertTrue($filter('yes')); - $this->assertFalse($filter('nein')); - $this->assertTrue($filter('ja')); } - /** - * Ensures that the filter follows expected behavior - * - * @return void - */ - public function testSettingLocalePerConstructorArray() + static public function noCastingTestProvider() { - $filter = new BooleanFilter( - array('type' => 'all', 'locale' => 'de') + return array( + array(false, false), + array(true, true), + array(0, false), + array(1, true), + array(2, 2), + array(0.0, false), + array(1.0, true), + array(0.5, 0.5), + array('', false), + array('abc', 'abc'), + array('0', false), + array('1', true), + array('2', '2'), + array(array(), false), + array(array(0), array(0)), + array(null, null), + array('false', false), + array('true', true), ); - - $this->assertFalse($filter(false)); - $this->assertTrue($filter(true)); - $this->assertFalse($filter(0)); - $this->assertTrue($filter(1)); - $this->assertFalse($filter(0.0)); - $this->assertTrue($filter(1.0)); - $this->assertFalse($filter('')); - $this->assertTrue($filter('abc')); - $this->assertFalse($filter('0')); - $this->assertTrue($filter('1')); - $this->assertFalse($filter(array())); - $this->assertTrue($filter(array('xxx'))); - $this->assertFalse($filter(null)); - $this->assertFalse($filter('false')); - $this->assertTrue($filter('true')); - $this->assertTrue($filter('no')); - $this->assertTrue($filter('yes')); - $this->assertFalse($filter('nein')); - $this->assertTrue($filter('ja')); } - /** - * Ensures that the filter follows expected behavior - * - * @return void - */ - public function testSettingLocaleInstance() + static public function typeTestProvider() { - $locale = new Locale('de'); - $filter = new BooleanFilter( - array('type' => 'all', 'locale' => $locale) + return array( + array( + BooleanFilter::TYPE_BOOLEAN, + array( + array(false, false), + array(true, true), + array(0, true), + array(1, true), + array(0.0, true), + array(1.0, true), + array('', true), + array('abc', true), + array('0', true), + array('1', true), + array(array(), true), + array(array(0), true), + array(null, true), + array('false', true), + array('true', true), + array('no', true), + array('yes', true), + ) + ), + array( + BooleanFilter::TYPE_INTEGER, + array( + array(false, true), + array(true, true), + array(0, false), + array(1, true), + array(0.0, true), + array(1.0, true), + array('', true), + array('abc', true), + array('0', true), + array('1', true), + array(array(), true), + array(array(0), true), + array(null, true), + array('false', true), + array('true', true), + array('no', true), + array('yes', true), + ) + ), + array( + BooleanFilter::TYPE_FLOAT, + array( + array(false, true), + array(true, true), + array(0, true), + array(1, true), + array(0.0, false), + array(1.0, true), + array('', true), + array('abc', true), + array('0', true), + array('1', true), + array(array(), true), + array(array(0), true), + array(null, true), + array('false', true), + array('true', true), + array('no', true), + array('yes', true), + ) + ), + array( + BooleanFilter::TYPE_STRING, + array( + array(false, true), + array(true, true), + array(0, true), + array(1, true), + array(0.0, true), + array(1.0, true), + array('', false), + array('abc', true), + array('0', true), + array('1', true), + array(array(), true), + array(array(0), true), + array(null, true), + array('false', true), + array('true', true), + array('no', true), + array('yes', true), + ) + ), + array( + BooleanFilter::TYPE_ZERO_STRING, + array( + array(false, true), + array(true, true), + array(0, true), + array(1, true), + array(0.0, true), + array(1.0, true), + array('', true), + array('abc', true), + array('0', false), + array('1', true), + array(array(), true), + array(array(0), true), + array(null, true), + array('false', true), + array('true', true), + array('no', true), + array('yes', true), + ) + ), + array( + BooleanFilter::TYPE_EMPTY_ARRAY, + array( + array(false, true), + array(true, true), + array(0, true), + array(1, true), + array(0.0, true), + array(1.0, true), + array('', true), + array('abc', true), + array('0', true), + array('1', true), + array(array(), false), + array(array(0), true), + array(null, true), + array('false', true), + array('true', true), + array('no', true), + array('yes', true), + ) + ), + array( + BooleanFilter::TYPE_NULL, + array( + array(false, true), + array(true, true), + array(0, true), + array(1, true), + array(0.0, true), + array(1.0, true), + array('', true), + array('abc', true), + array('0', true), + array('1', true), + array(array(), true), + array(array(0), true), + array(null, false), + array('false', true), + array('true', true), + array('no', true), + array('yes', true), + ) + ), + array( + BooleanFilter::TYPE_PHP, + array( + array(false, false), + array(true, true), + array(0, false), + array(1, true), + array(0.0, false), + array(1.0, true), + array('', false), + array('abc', true), + array('0', false), + array('1', true), + array(array(), false), + array(array(0), true), + array(null, false), + array('false', true), + array('true', true), + array('no', true), + array('yes', true), + ) + ), + array( + BooleanFilter::TYPE_FALSE_STRING, + array( + array(false, true), + array(true, true), + array(0, true), + array(1, true), + array(0.0, true), + array(1.0, true), + array('', true), + array('abc', true), + array('0', true), + array('1', true), + array(array(), true), + array(array(0), true), + array(null, true), + array('false', false), + array('true', true), + array('no', true), + array('yes', true), + ) + ), + // default behaviour with no translations provided + // all values filtered as true + array( + BooleanFilter::TYPE_LOCALIZED, + array( + array(false, true), + array(true, true), + array(0, true), + array(1, true), + array(0.0, true), + array(1.0, true), + array('', true), + array('abc', true), + array('0', true), + array('1', true), + array(array(), true), + array(array(0), true), + array(null, true), + array('false', true), + array('true', true), + array('no', true), + array('yes', true), + ) + ), + array( + BooleanFilter::TYPE_ALL, + array( + array(false, false), + array(true, true), + array(0, false), + array(1, true), + array(0.0, false), + array(1.0, true), + array('', false), + array('abc', true), + array('0', false), + array('1', true), + array(array(), false), + array(array(0), true), + array(null, false), + array('false', false), + array('true', true), + array('no', true), + array('yes', true), + ) + ), ); - - $this->assertFalse($filter(false)); - $this->assertTrue($filter(true)); - $this->assertFalse($filter(0)); - $this->assertTrue($filter(1)); - $this->assertFalse($filter(0.0)); - $this->assertTrue($filter(1.0)); - $this->assertFalse($filter('')); - $this->assertTrue($filter('abc')); - $this->assertFalse($filter('0')); - $this->assertTrue($filter('1')); - $this->assertFalse($filter(array())); - $this->assertTrue($filter(array('xxx'))); - $this->assertFalse($filter(null)); - $this->assertFalse($filter('false')); - $this->assertTrue($filter('true')); - $this->assertTrue($filter('no')); - $this->assertTrue($filter('yes')); - $this->assertFalse($filter('nein')); - $this->assertTrue($filter('ja')); } - /** - * Ensures that the filter follows expected behavior - * - * @return void - */ - public function testWithoutCasting() + static public function combinedTypeTestProvider() { - $locale = new Locale('de'); - $filter = new BooleanFilter( - array('type' => 'all', 'casting' => false, 'locale' => $locale) + return array( + array( + array( + array( + BooleanFilter::TYPE_ZERO_STRING, + BooleanFilter::TYPE_STRING, + BooleanFilter::TYPE_BOOLEAN, + ), + array( + 'zero', + 'string', + 'boolean', + ), + BooleanFilter::TYPE_ZERO_STRING | BooleanFilter::TYPE_STRING | BooleanFilter::TYPE_BOOLEAN, + BooleanFilter::TYPE_ZERO_STRING + BooleanFilter::TYPE_STRING + BooleanFilter::TYPE_BOOLEAN, + ), + array( + array(false, false), + array(true, true), + array(0, true), + array(1, true), + array(0.0, true), + array(1.0, true), + array('', false), + array('abc', true), + array('0', false), + array('1', true), + array(array(), true), + array(array(0), true), + array(null, true), + array('false', true), + array('true', true), + array('no', true), + array('yes', true), + ) + ) ); - - $this->assertFalse($filter(false)); - $this->assertTrue($filter(true)); - $this->assertFalse($filter(0)); - $this->assertTrue($filter(1)); - $this->assertEquals(2, $filter(2)); - $this->assertFalse($filter(0.0)); - $this->assertTrue($filter(1.0)); - $this->assertEquals(0.5, $filter(0.5)); - $this->assertFalse($filter('')); - $this->assertEquals('abc', $filter('abc')); - $this->assertFalse($filter('0')); - $this->assertTrue($filter('1')); - $this->assertEquals('2', $filter('2')); - $this->assertFalse($filter(array())); - $this->assertEquals(array('xxx'), $filter(array('xxx'))); - $this->assertEquals(null, $filter(null)); - $this->assertFalse($filter('false')); - $this->assertTrue($filter('true')); - $this->assertEquals('no', $filter('no')); - $this->assertEquals('yes', $filter('yes')); - $this->assertFalse($filter('nein')); - $this->assertTrue($filter('ja')); - } - - /** - * Ensures that the filter follows expected behavior - * - * @return void - */ - public function testSettingFalseType() - { - $this->setExpectedException('\Zend\Filter\Exception\InvalidArgumentException', 'Unknown'); - $this->_filter->setType(true); - } - - /** - * Ensures that the filter follows expected behavior - * - * @return void - */ - public function testGetType() - { - $this->assertEquals(127, $this->_filter->getType()); - } - - /** - * Ensures that the filter follows expected behavior - * - * @return void - */ - public function testSettingFalseLocaleType() - { - $this->setExpectedException('\Zend\Filter\Exception\InvalidArgumentException', 'Locale has to be'); - $this->_filter->setLocale(true); - } - - /** - * Ensures that the filter follows expected behavior - * - * @return void - */ - public function testSettingUnknownLocale() - { - $this->setExpectedException('\Zend\Filter\Exception\InvalidArgumentException', 'Unknown locale'); - $this->_filter->setLocale('yy'); } } diff --git a/test/NullTest.php b/test/NullTest.php index 8a2f9942..f2926961 100644 --- a/test/NullTest.php +++ b/test/NullTest.php @@ -33,297 +33,275 @@ */ class NullTest extends \PHPUnit_Framework_TestCase { - /** - * Zend_Filter_Null object - * - * @var Zend_Filter_Null - */ - protected $_filter; - - /** - * Creates a new Zend_Filter_Null object for each test method - * - * @return void - */ - public function setUp() + public function testConstructorOptions() { - $this->_filter = new NullFilter(); - } + $filter = new NullFilter(array( + 'type' => NullFilter::TYPE_INTEGER, + )); - /** - * Ensures that the filter follows expected behavior - * - * @return void - */ - public function testBasic() - { - $filter = $this->_filter; - $this->assertEquals(null, $filter(0.0)); - $this->assertEquals(null, $filter('0')); - $this->assertEquals(null, $filter('')); - $this->assertEquals(null, $filter(0)); - $this->assertEquals(null, $filter(array())); - $this->assertEquals(null, $filter(false)); - $this->assertEquals('test', $filter('test')); - $this->assertEquals(true, $filter(true)); + $this->assertEquals(NullFilter::TYPE_INTEGER, $filter->getType()); } - /** - * Ensures that the filter follows expected behavior - * - * @return void - */ - public function testOnlyBoolean() + public function testConstructorParams() { - $filter = $this->_filter; - $filter->setType(NullFilter::BOOLEAN); - $this->assertEquals(0.0, $filter(0.0)); - $this->assertEquals('0', $filter('0')); - $this->assertEquals('', $filter('')); - $this->assertEquals(0, $filter(0)); - $this->assertEquals(array(), $filter(array())); - $this->assertEquals(null, $filter(false)); - $this->assertEquals('test', $filter('test')); - $this->assertEquals(true, $filter(true)); - } + $filter = new NullFilter(NullFilter::TYPE_INTEGER); - /** - * Ensures that the filter follows expected behavior - * - * @return void - */ - public function testOnlyInteger() - { - $filter = $this->_filter; - $filter->setType(NullFilter::INTEGER); - $this->assertEquals(0.0, $filter(0.0)); - $this->assertEquals('0', $filter('0')); - $this->assertEquals('', $filter('')); - $this->assertEquals(null, $filter(0)); - $this->assertEquals(array(), $filter(array())); - $this->assertEquals(false, $filter(false)); - $this->assertEquals('test', $filter('test')); - $this->assertEquals(true, $filter(true)); + $this->assertEquals(NullFilter::TYPE_INTEGER, $filter->getType()); } - + /** - * Ensures that the filter follows expected behavior - * - * @return void + * @param mixed $value + * @param bool $expected + * @dataProvider defaultTestProvider */ - public function testOnlyArray() + public function testDefault($value, $expected) { - $filter = $this->_filter; - $filter->setType(NullFilter::EMPTY_ARRAY); - $this->assertEquals(0.0, $filter(0.0)); - $this->assertEquals('0', $filter('0')); - $this->assertEquals('', $filter('')); - $this->assertEquals(0, $filter(0)); - $this->assertEquals(null, $filter(array())); - $this->assertEquals(false, $filter(false)); - $this->assertEquals('test', $filter('test')); - $this->assertEquals(true, $filter(true)); - } + $filter = new NullFilter(); + $this->assertSame($expected, $filter->filter($value)); + } /** - * Ensures that the filter follows expected behavior - * - * @return void + * @param int $type + * @param array $testData + * @dataProvider typeTestProvider */ - public function testOnlyString() + public function testTypes($type, $testData) { - $filter = $this->_filter; - $filter->setType(NullFilter::STRING); - $this->assertEquals(0.0, $filter(0.0)); - $this->assertEquals('0', $filter('0')); - $this->assertEquals(null, $filter('')); - $this->assertEquals(0, $filter(0)); - $this->assertEquals(array(), $filter(array())); - $this->assertEquals(false, $filter(false)); - $this->assertEquals('test', $filter('test')); - $this->assertEquals(true, $filter(true)); + $filter = new NullFilter($type); + foreach ($testData as $data) { + list($value, $expected) = $data; + $message = sprintf( + '%s (%s) is not filtered as %s; type = %s', + var_export($value, true), + gettype($value), + var_export($expected, true), + $type + ); + $this->assertSame($expected, $filter->filter($value), $message); + } } /** - * Ensures that the filter follows expected behavior - * - * @return void + * @param array $typeData + * @param array $testData + * @dataProvider combinedTypeTestProvider */ - public function testOnlyZero() + public function testCombinedTypes($typeData, $testData) { - $filter = $this->_filter; - $filter->setType(NullFilter::ZERO); - $this->assertEquals(0.0, $filter(0.0)); - $this->assertEquals(null, $filter('0')); - $this->assertEquals('', $filter('')); - $this->assertEquals(0, $filter(0)); - $this->assertEquals(array(), $filter(array())); - $this->assertEquals(false, $filter(false)); - $this->assertEquals('test', $filter('test')); - $this->assertEquals(true, $filter(true)); + foreach ($typeData as $type) { + $filter = new NullFilter(array('type' => $type)); + foreach ($testData as $data) { + list($value, $expected) = $data; + $message = sprintf( + '%s (%s) is not filtered as %s; type = %s', + var_export($value, true), + gettype($value), + var_export($expected, true), + var_export($type, true) + ); + $this->assertSame($expected, $filter->filter($value), $message); + } + } } - /** - * Ensures that the filter follows expected behavior - * - * @return void - */ - public function testArrayConstantNotation() + public function testSettingFalseType() { - $filter = new NullFilter( - array( - NullFilter::ZERO, - NullFilter::STRING, - NullFilter::BOOLEAN, - ) - ); - - $this->assertEquals(0.0, $filter(0.0)); - $this->assertEquals(null, $filter('0')); - $this->assertEquals(null, $filter('')); - $this->assertEquals(0, $filter(0)); - $this->assertEquals(array(), $filter(array())); - $this->assertEquals(null, $filter(false)); - $this->assertEquals('test', $filter('test')); - $this->assertEquals(true, $filter(true)); + $filter = new NullFilter(); + $this->setExpectedException('\Zend\Filter\Exception\InvalidArgumentException', 'Unknown type value'); + $filter->setType(true); } - /** - * Ensures that the filter follows expected behavior - * - * @return void - */ - public function testArrayConfigNotation() + public function testGettingDefaultType() { - $filter = new NullFilter( - array( - 'type' => array( - NullFilter::ZERO, - NullFilter::STRING, - NullFilter::BOOLEAN), - 'test' => false - ) - ); - - $this->assertEquals(0.0, $filter(0.0)); - $this->assertEquals(null, $filter('0')); - $this->assertEquals(null, $filter('')); - $this->assertEquals(0, $filter(0)); - $this->assertEquals(array(), $filter(array())); - $this->assertEquals(null, $filter(false)); - $this->assertEquals('test', $filter('test')); - $this->assertEquals(true, $filter(true)); + $filter = new NullFilter(); + $this->assertEquals(63, $filter->getType()); } - /** - * Ensures that the filter follows expected behavior - * - * @return void - */ - public function testMultiConstantNotation() + static public function defaultTestProvider() { - $filter = new NullFilter( - NullFilter::ZERO + NullFilter::STRING + NullFilter::BOOLEAN + return array( + array(null, null), + array(false, null), + array(true, true), + array(0, null), + array(1, 1), + array(0.0, null), + array(1.0, 1.0), + array('', null), + array('abc', 'abc'), + array('0', null), + array('1', '1'), + array(array(), null), + array(array(0), array(0)), ); - - $this->assertEquals(0.0, $filter(0.0)); - $this->assertEquals(null, $filter('0')); - $this->assertEquals(null, $filter('')); - $this->assertEquals(0, $filter(0)); - $this->assertEquals(array(), $filter(array())); - $this->assertEquals(null, $filter(false)); - $this->assertEquals('test', $filter('test')); - $this->assertEquals(true, $filter(true)); } - /** - * Ensures that the filter follows expected behavior - * - * @return void - */ - public function testStringNotation() + static public function typeTestProvider() { - $filter = new NullFilter( + return array( array( - 'zero', 'string', 'boolean' - ) + NullFilter::TYPE_BOOLEAN, + array( + array(null, null), + array(false, null), + array(true, true), + array(0, 0), + array(1, 1), + array(0.0, 0.0), + array(1.0, 1.0), + array('', ''), + array('abc', 'abc'), + array('0', '0'), + array('1', '1'), + array(array(), array()), + array(array(0), array(0)), + ) + ), + array( + NullFilter::TYPE_INTEGER, + array( + array(null, null), + array(false, false), + array(true, true), + array(0, null), + array(1, 1), + array(0.0, 0.0), + array(1.0, 1.0), + array('', ''), + array('abc', 'abc'), + array('0', '0'), + array('1', '1'), + array(array(), array()), + array(array(0), array(0)), + ) + ), + array( + NullFilter::TYPE_EMPTY_ARRAY, + array( + array(null, null), + array(false, false), + array(true, true), + array(0, 0), + array(1, 1), + array(0.0, 0.0), + array(1.0, 1.0), + array('', ''), + array('abc', 'abc'), + array('0', '0'), + array('1', '1'), + array(array(), null), + array(array(0), array(0)), + ) + ), + array( + NullFilter::TYPE_STRING, + array( + array(null, null), + array(false, false), + array(true, true), + array(0, 0), + array(1, 1), + array(0.0, 0.0), + array(1.0, 1.0), + array('', null), + array('abc', 'abc'), + array('0', '0'), + array('1', '1'), + array(array(), array()), + array(array(0), array(0)), + ) + ), + array( + NullFilter::TYPE_ZERO_STRING, + array( + array(null, null), + array(false, false), + array(true, true), + array(0, 0), + array(1, 1), + array(0.0, 0.0), + array(1.0, 1.0), + array('', ''), + array('abc', 'abc'), + array('0', null), + array('1', '1'), + array(array(), array()), + array(array(0), array(0)), + ) + ), + array( + NullFilter::TYPE_FLOAT, + array( + array(null, null), + array(false, false), + array(true, true), + array(0, 0), + array(1, 1), + array(0.0, null), + array(1.0, 1.0), + array('', ''), + array('abc', 'abc'), + array('0', '0'), + array('1', '1'), + array(array(), array()), + array(array(0), array(0)), + ) + ), + array( + NullFilter::TYPE_ALL, + array( + array(null, null), + array(false, null), + array(true, true), + array(0, null), + array(1, 1), + array(0.0, null), + array(1.0, 1.0), + array('', null), + array('abc', 'abc'), + array('0', null), + array('1', '1'), + array(array(), null), + array(array(0), array(0)), + ) + ), ); - - $this->assertEquals(0.0, $filter(0.0)); - $this->assertEquals(null, $filter('0')); - $this->assertEquals(null, $filter('')); - $this->assertEquals(0, $filter(0)); - $this->assertEquals(array(), $filter(array())); - $this->assertEquals(null, $filter(false)); - $this->assertEquals('test', $filter('test')); - $this->assertEquals(true, $filter(true)); } - /** - * Ensures that the filter follows expected behavior - * - * @return void - */ - public function testSingleStringNotation() + static public function combinedTypeTestProvider() { - $filter = new NullFilter( - 'boolean' + return array( + array( + array( + array( + NullFilter::TYPE_ZERO_STRING, + NullFilter::TYPE_STRING, + NullFilter::TYPE_BOOLEAN, + ), + array( + 'zero', + 'string', + 'boolean', + ), + NullFilter::TYPE_ZERO_STRING | NullFilter::TYPE_STRING | NullFilter::TYPE_BOOLEAN, + NullFilter::TYPE_ZERO_STRING + NullFilter::TYPE_STRING + NullFilter::TYPE_BOOLEAN, + ), + array( + array(null, null), + array(false, null), + array(true, true), + array(0, 0), + array(1, 1), + array(0.0, 0.0), + array(1.0, 1.0), + array('', null), + array('abc', 'abc'), + array('0', null), + array('1', '1'), + array(array(), array()), + array(array(0), array(0)), + ) + ) ); - - $this->assertEquals(0.0, $filter(0.0)); - $this->assertEquals('0', $filter('0')); - $this->assertEquals(null, $filter('')); - $this->assertEquals(0, $filter(0)); - $this->assertEquals(array(), $filter(array())); - $this->assertEquals(false, $filter(false)); - $this->assertEquals('test', $filter('test')); - $this->assertEquals(true, $filter(true)); - } - - /** - * Ensures that the filter follows expected behavior - * - * @return void - */ - public function testSettingFalseType() - { - $this->setExpectedException('\Zend\Filter\Exception\InvalidArgumentException', 'Unknown'); - $this->_filter->setType(true); - } - - /** - * Ensures that the filter follows expected behavior - * - * @return void - */ - public function testGetType() - { - $this->assertEquals(63, $this->_filter->getType()); - } - - /** - * @group ZF-10388 - */ - public function testDataTypeFloat() - { - $filter = $this->_filter; - $this->assertEquals(null, $filter(0.0)); - } - - /** - * @group ZF-10388 - */ - public function testOnlyFloat() - { - $filter = $this->_filter; - $filter->setType(NullFilter::FLOAT); - $this->assertEquals(null, $filter(0.0)); - $this->assertEquals('0', $filter('0')); - $this->assertEquals('', $filter('')); - $this->assertEquals(0, $filter(0)); - $this->assertEquals(array(), $filter(array())); - $this->assertEquals(false, $filter(false)); - $this->assertEquals('test', $filter('test')); - $this->assertEquals(true, $filter(true)); } } From 4735cec82522febcf901d24d6004881f3d7d8a5b Mon Sep 17 00:00:00 2001 From: Denis Portnov Date: Tue, 3 Jul 2012 02:09:45 +0400 Subject: [PATCH 03/17] String filters --- src/File/LowerCase.php | 21 +++--------- src/File/UpperCase.php | 21 +++--------- src/StringToLower.php | 72 ++++++++-------------------------------- src/StringToUpper.php | 74 +++++++++--------------------------------- src/StringTrim.php | 71 ++++++++++++++++++++-------------------- 5 files changed, 74 insertions(+), 185 deletions(-) diff --git a/src/File/LowerCase.php b/src/File/LowerCase.php index d20019da..ccc75aaa 100644 --- a/src/File/LowerCase.php +++ b/src/File/LowerCase.php @@ -19,7 +19,8 @@ */ namespace Zend\Filter\File; -use Zend\Filter; + +use Zend\Filter\StringToLower; use Zend\Filter\Exception; /** @@ -28,20 +29,8 @@ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ -class LowerCase extends Filter\StringToLower +class LowerCase extends StringToLower { - /** - * Adds options to the filter at initiation - * - * @param string $options - */ - public function __construct($options = null) - { - if (!empty($options)) { - $this->setEncoding($options); - } - } - /** * Defined by Zend\Filter\Filter * @@ -52,7 +41,7 @@ public function __construct($options = null) * @throws Exception\InvalidArgumentException * @throws Exception\RuntimeException */ - public function __invoke($value) + public function filter($value) { if (!file_exists($value)) { throw new Exception\InvalidArgumentException("File '$value' not found"); @@ -67,7 +56,7 @@ public function __invoke($value) throw new Exception\RuntimeException("Problem while reading file '$value'"); } - $content = parent::__invoke($content); + $content = parent::filter($content); $result = file_put_contents($value, $content); if (!$result) { diff --git a/src/File/UpperCase.php b/src/File/UpperCase.php index b37938a3..ccb5bc40 100644 --- a/src/File/UpperCase.php +++ b/src/File/UpperCase.php @@ -19,7 +19,8 @@ */ namespace Zend\Filter\File; -use Zend\Filter; + +use Zend\Filter\StringToUpper; use Zend\Filter\Exception; /** @@ -28,20 +29,8 @@ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ -class UpperCase extends Filter\StringToUpper +class UpperCase extends StringToUpper { - /** - * Adds options to the filter at initiation - * - * @param string $options - */ - public function __construct($options = null) - { - if (!empty($options)) { - $this->setEncoding($options); - } - } - /** * Defined by Zend\Filter\FilterInterface * @@ -52,7 +41,7 @@ public function __construct($options = null) * @throws Exception\RuntimeException * @throws Exception\InvalidArgumentException */ - public function __invoke($value) + public function filter($value) { if (!file_exists($value)) { throw new Exception\InvalidArgumentException("File '$value' not found"); @@ -67,7 +56,7 @@ public function __invoke($value) throw new Exception\RuntimeException("Problem while reading file '$value'"); } - $content = parent::__invoke($content); + $content = parent::filter($content); $result = file_put_contents($value, $content); if (!$result) { diff --git a/src/StringToLower.php b/src/StringToLower.php index 95ae501f..5ceb2cd4 100644 --- a/src/StringToLower.php +++ b/src/StringToLower.php @@ -21,7 +21,6 @@ namespace Zend\Filter; use Traversable; -use Zend\Stdlib\ArrayUtils; /** * @category Zend @@ -29,14 +28,14 @@ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ -class StringToLower extends AbstractFilter +class StringToLower extends AbstractUnicode { /** - * Encoding for the input string - * - * @var string + * @var array */ - protected $_encoding = null; + protected $options = array( + 'encoding' => null, + ); /** * Constructor @@ -45,59 +44,16 @@ class StringToLower extends AbstractFilter */ public function __construct($options = null) { - if ($options instanceof Traversable) { - $options = ArrayUtils::iteratorToArray($options); - } - if (!is_array($options)) { - $options = func_get_args(); - $temp = array(); - if (!empty($options)) { - $temp['encoding'] = array_shift($options); + if ($options !== null) { + if ($options instanceof Traversable) { + $options = iterator_to_array($options); } - $options = $temp; - } - - if (!array_key_exists('encoding', $options) && function_exists('mb_internal_encoding')) { - $options['encoding'] = mb_internal_encoding(); - } - - if (array_key_exists('encoding', $options)) { - $this->setEncoding($options['encoding']); - } - } - - /** - * Returns the set encoding - * - * @return string - */ - public function getEncoding() - { - return $this->_encoding; - } - - /** - * Set the input encoding for the given string - * - * @param string $encoding - * @return StringToLower Provides a fluent interface - * @throws Exception\ExceptionInterface - */ - public function setEncoding($encoding = null) - { - if ($encoding !== null) { - if (!function_exists('mb_strtolower')) { - throw new Exception\ExtensionNotLoadedException('mbstring is required for this feature'); - } - - $encoding = (string) $encoding; - if (!in_array(strtolower($encoding), array_map('strtolower', mb_list_encodings()))) { - throw new Exception\InvalidArgumentException("The given encoding '$encoding' is not supported by mbstring"); + if (!is_array($options)) { + $this->setEncoding($options); + } else { + $this->setOptions($options); } } - - $this->_encoding = $encoding; - return $this; } /** @@ -110,8 +66,8 @@ public function setEncoding($encoding = null) */ public function filter($value) { - if ($this->_encoding !== null) { - return mb_strtolower((string) $value, $this->_encoding); + if ($this->options['encoding'] !== null) { + return mb_strtolower((string) $value, $this->options['encoding']); } return strtolower((string) $value); diff --git a/src/StringToUpper.php b/src/StringToUpper.php index d2ca0a63..02d95cfa 100644 --- a/src/StringToUpper.php +++ b/src/StringToUpper.php @@ -21,7 +21,6 @@ namespace Zend\Filter; use Traversable; -use Zend\Stdlib\ArrayUtils; /** * @category Zend @@ -29,14 +28,14 @@ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ -class StringToUpper extends AbstractFilter +class StringToUpper extends AbstractUnicode { /** - * Encoding for the input string - * - * @var string + * @var array */ - protected $_encoding = null; + protected $options = array( + 'encoding' => null, + ); /** * Constructor @@ -45,73 +44,30 @@ class StringToUpper extends AbstractFilter */ public function __construct($options = null) { - if ($options instanceof Traversable) { - $options = ArrayUtils::iteratorToArray($options); - } - if (!is_array($options)) { - $options = func_get_args(); - $temp = array(); - if (!empty($options)) { - $temp['encoding'] = array_shift($options); + if ($options !== null) { + if ($options instanceof Traversable) { + $options = iterator_to_array($options); } - $options = $temp; - } - - if (!array_key_exists('encoding', $options) && function_exists('mb_internal_encoding')) { - $options['encoding'] = mb_internal_encoding(); - } - - if (array_key_exists('encoding', $options)) { - $this->setEncoding($options['encoding']); - } - } - - /** - * Returns the set encoding - * - * @return string - */ - public function getEncoding() - { - return $this->_encoding; - } - - /** - * Set the input encoding for the given string - * - * @param string $encoding - * @return StringToUpper Provides a fluent interface - * @throws Exception\ExceptionInterface - */ - public function setEncoding($encoding = null) - { - if ($encoding !== null) { - if (!function_exists('mb_strtoupper')) { - throw new Exception\ExtensionNotLoadedException('mbstring is required for this feature'); - } - - $encoding = (string) $encoding; - if (!in_array(strtolower($encoding), array_map('strtolower', mb_list_encodings()))) { - throw new Exception\InvalidArgumentException("The given encoding '$encoding' is not supported by mbstring"); + if (!is_array($options)) { + $this->setEncoding($options); + } else { + $this->setOptions($options); } } - - $this->_encoding = $encoding; - return $this; } /** * Defined by Zend\Filter\FilterInterface * - * Returns the string $value, converting characters to uppercase as necessary + * Returns the string $value, converting characters to lowercase as necessary * * @param string $value * @return string */ public function filter($value) { - if ($this->_encoding) { - return mb_strtoupper((string) $value, $this->_encoding); + if ($this->options['encoding'] !== null) { + return mb_strtoupper((string) $value, $this->options['encoding']); } return strtoupper((string) $value); diff --git a/src/StringTrim.php b/src/StringTrim.php index 832bfdfd..093e7c38 100644 --- a/src/StringTrim.php +++ b/src/StringTrim.php @@ -32,14 +32,11 @@ class StringTrim extends AbstractFilter { /** - * List of characters provided to the trim() function - * - * If this is null, then trim() is called with no specific character list, - * and its default behavior will be invoked, trimming whitespace. - * - * @var string|null + * @var array */ - protected $_charList; + protected $options = array( + 'charlist' => null, + ); /** * Sets filter options @@ -48,40 +45,41 @@ class StringTrim extends AbstractFilter */ public function __construct($options = null) { - if ($options instanceof Traversable) { - $options = ArrayUtils::iteratorToArray($options); - } - if (!is_array($options)) { - $options = func_get_args(); - $temp['charlist'] = array_shift($options); - $options = $temp; - } - - if (array_key_exists('charlist', $options)) { - $this->setCharList($options['charlist']); + if ($options !== null) { + if ($options instanceof Traversable) { + $options = iterator_to_array($options); + } + if (!is_array($options)) { + $this->setCharList($options); + } else { + $this->setOptions($options); + } } } /** - * Returns the charList option + * Sets the charList option * - * @return string|null + * @param string $charList + * @return StringTrim Provides a fluent interface */ - public function getCharList() + public function setCharList($charList) { - return $this->_charList; + if (empty($charList)) { + $charList = null; + } + $this->options['charlist'] = $charList; + return $this; } /** - * Sets the charList option + * Returns the charList option * - * @param string|null $charList - * @return StringTrim Provides a fluent interface + * @return string|null */ - public function setCharList($charList) + public function getCharList() { - $this->_charList = $charList; - return $this; + return $this->options['charlist']; } /** @@ -99,11 +97,11 @@ public function filter($value) return $value; } - if (null === $this->_charList) { - return $this->_unicodeTrim((string) $value); + if (null === $this->options['charlist']) { + return $this->unicodeTrim((string) $value); } - return $this->_unicodeTrim((string) $value, $this->_charList); + return $this->unicodeTrim((string) $value, $this->options['charlist']); } /** @@ -114,15 +112,16 @@ public function filter($value) * @param string $charlist * @return string */ - protected function _unicodeTrim($value, $charlist = '\\\\s') + protected function unicodeTrim($value, $charlist = '\\\\s') { $chars = preg_replace( - array( '/[\^\-\]\\\]/S', '/\\\{4}/S', '/\//'), - array( '\\\\\\0', '\\', '\/' ), + array('/[\^\-\]\\\]/S', '/\\\{4}/S', '/\//'), + array('\\\\\\0', '\\', '\/'), $charlist ); - $pattern = '^[' . $chars . ']*|[' . $chars . ']*$'; - return preg_replace("/$pattern/sSD", '', $value); + $pattern = '/^[' . $chars . ']*|[' . $chars . ']*$/sSD'; + + return preg_replace($pattern, '', $value); } } From cd63192a108073fbe38dee6c20eb776a643b30b9 Mon Sep 17 00:00:00 2001 From: Denis Portnov Date: Tue, 3 Jul 2012 02:10:25 +0400 Subject: [PATCH 04/17] Callback, Digits, RealPath --- src/Callback.php | 110 ++++++++++++++++------------------------------- src/Digits.php | 24 +---------- src/RealPath.php | 53 ++++++++++------------- 3 files changed, 62 insertions(+), 125 deletions(-) diff --git a/src/Callback.php b/src/Callback.php index e4f5c3d8..cfc40c5e 100644 --- a/src/Callback.php +++ b/src/Callback.php @@ -21,7 +21,6 @@ namespace Zend\Filter; use Traversable; -use Zend\Stdlib\ArrayUtils; /** * @category Zend @@ -32,96 +31,64 @@ class Callback extends AbstractFilter { /** - * Callback in a call_user_func format - * - * @var string|array - */ - protected $_callback = null; - - /** - * Default options to set for the filter - * - * @var mixed + * @var array */ - protected $_options = null; + protected $options = array( + 'callback' => null, + 'params' => null + ); /** - * Constructor - * - * @param string|array $callback Callback in a call_user_func format - * @param mixed $options (Optional) Default options for this filter + * @param array|Traversable $options */ - public function __construct($options = array()) + public function __construct($options) { if ($options instanceof Traversable) { - $options = ArrayUtils::iteratorToArray($options); - } elseif (!is_array($options) || !array_key_exists('callback', $options)) { - $options = func_get_args(); - $temp['callback'] = array_shift($options); - if (!empty($options)) { - $temp['options'] = array_shift($options); - } - - $options = $temp; + $options = iterator_to_array($options); } - if (!array_key_exists('callback', $options)) { - throw new Exception\InvalidArgumentException('Missing callback to use'); - } - - $this->setCallback($options['callback']); - if (array_key_exists('options', $options)) { - $this->setOptions($options['options']); + if (!is_array($options)) { + $args = func_get_args(); + if (isset($args[0])) { + $callback = $args[0]; + $params = null; + if (isset($args[1])) { + $params = $args[1]; + } + $this->setCallback($callback, $params); + } + } else { + $this->setOptions($options); } } - /** - * Returns the set callback - * - * @return string|array Set callback - */ - public function getCallback() - { - return $this->_callback; - } - /** * Sets a new callback for this filter * - * @param \callable $callback + * @param callable $callback * @return Callback */ - public function setCallback($callback, $options = null) + public function setCallback($callback, $params = null) { if (!is_callable($callback)) { - throw new Exception\InvalidArgumentException('Callback can not be accessed'); + throw new Exception\InvalidArgumentException( + 'Invalid parameter for callback: must be callable' + ); } - $this->_callback = $callback; - $this->setOptions($options); + $this->options['callback'] = $callback; + $this->options['params'] = $params; return $this; } /** - * Returns the set default options - * - * @return mixed - */ - public function getOptions() - { - return $this->_options; - } - - /** - * Sets new default options to the callback filter + * Returns the set callback * - * @param mixed $options Default options to set - * @return Callback + * @return callable */ - public function setOptions($options) + public function getCallback() { - $this->_options = $options; - return $this; + return $this->options['callback']; } /** @@ -132,18 +99,15 @@ public function setOptions($options) */ public function filter($value) { - $options = array(); - - if ($this->_options !== null) { - if (!is_array($this->_options)) { - $options = array($this->_options); + $params = array($value); + if (isset($this->options['params'])) { + if (!is_array($this->options['params'])) { + array_push($params, $this->options['params']); } else { - $options = $this->_options; + $params = $params + $this->options['params']; } } - array_unshift($options, $value); - - return call_user_func_array($this->_callback, $options); + return call_user_func_array($this->options['callback'], $params); } } diff --git a/src/Digits.php b/src/Digits.php index 7fcdd25a..1b7e5892 100644 --- a/src/Digits.php +++ b/src/Digits.php @@ -28,26 +28,6 @@ */ class Digits extends AbstractFilter { - /** - * Is PCRE is compiled with UTF-8 and Unicode support - * - * @var mixed - **/ - protected static $_unicodeEnabled; - - /** - * Class constructor - * - * Checks if PCRE is compiled with UTF-8 and Unicode support - * - */ - public function __construct() - { - if (null === self::$_unicodeEnabled) { - self::$_unicodeEnabled = (@preg_match('/\pL/u', 'a')) ? true : false; - } - } - /** * Defined by Zend\Filter\FilterInterface * @@ -58,10 +38,10 @@ public function __construct() */ public function filter($value) { - if (!self::$_unicodeEnabled) { + if (!static::hasPcreUnicodeSupport()) { // POSIX named classes are not supported, use alternative 0-9 match $pattern = '/[^0-9]/'; - } else if (extension_loaded('mbstring')) { + } elseif (extension_loaded('mbstring')) { // Filter for the value with mbstring $pattern = '/[^[:digit:]]/'; } else { diff --git a/src/RealPath.php b/src/RealPath.php index 306ec718..4483c409 100644 --- a/src/RealPath.php +++ b/src/RealPath.php @@ -20,9 +20,6 @@ namespace Zend\Filter; -use Traversable; -use Zend\Stdlib\ArrayUtils; - /** * @category Zend * @package Zend_Filter @@ -34,7 +31,9 @@ class RealPath extends AbstractFilter /** * @var boolean $_pathExists */ - protected $_exists = true; + protected $options = array( + 'exists' => true + ); /** * Class constructor @@ -43,41 +42,35 @@ class RealPath extends AbstractFilter */ public function __construct($options = true) { - $this->setExists($options); + if (is_bool($options)) { + $this->setExists($options); + } else { + $this->setOptions($options); + } } /** - * Returns true if the filtered path must exist + * Sets if the path has to exist + * TRUE when the path must exist + * FALSE when not existing paths can be given * - * @return boolean + * @param boolean $flag Path must exist + * @return RealPath */ - public function getExists() + public function setExists($flag = true) { - return $this->_exists; + $this->options['exists'] = (boolean) $flag; + return $this; } /** - * Sets if the path has to exist - * TRUE when the path must exist - * FALSE when not existing paths can be given + * Returns true if the filtered path must exist * - * @param boolean|array|Traversable $options Path must exist - * @return RealPath + * @return boolean */ - public function setExists($options) + public function getExists() { - if ($options instanceof Traversable) { - $options = ArrayUtils::iteratorToArray($options); - } - - if (is_array($options)) { - if (isset($options['exists'])) { - $options = (boolean) $options['exists']; - } - } - - $this->_exists = (boolean) $options; - return $this; + return $this->options['exists']; } /** @@ -91,7 +84,7 @@ public function setExists($options) public function filter($value) { $path = (string) $value; - if ($this->_exists) { + if ($this->options['exists']) { return realpath($path); } @@ -101,10 +94,10 @@ public function filter($value) } $drive = ''; - if (substr(PHP_OS, 0, 3) == 'WIN') { + if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { $path = preg_replace('/[\\\\\/]/', DIRECTORY_SEPARATOR, $path); if (preg_match('/([a-zA-Z]\:)(.*)/', $path, $matches)) { - list($fullMatch, $drive, $path) = $matches; + list(, $drive, $path) = $matches; } else { $cwd = getcwd(); $drive = substr($cwd, 0, 2); From eae0b418be1866f49d0392f028c5a5dfe3198f6f Mon Sep 17 00:00:00 2001 From: Denis Portnov Date: Tue, 3 Jul 2012 03:01:54 +0400 Subject: [PATCH 05/17] PregReplace and related --- src/PregReplace.php | 142 +++++++++++++----------------- src/Word/CamelCaseToSeparator.php | 6 +- src/Word/DashToSeparator.php | 2 +- src/Word/SeparatorToCamelCase.php | 6 +- src/Word/SeparatorToSeparator.php | 2 +- test/PregReplaceTest.php | 56 +++++------- 6 files changed, 90 insertions(+), 124 deletions(-) diff --git a/src/PregReplace.php b/src/PregReplace.php index 7372606e..d2624f8d 100644 --- a/src/PregReplace.php +++ b/src/PregReplace.php @@ -31,141 +31,119 @@ */ class PregReplace extends AbstractFilter { - /** - * Pattern to match - * @var mixed - */ - protected $_matchPattern = null; - - /** - * Replacement pattern - * @var mixed - */ - protected $_replacement = ''; - - /** - * Is unicode enabled? - * - * @var bool - */ - static protected $_unicodeSupportEnabled = null; - - /** - * Is Unicode Support Enabled Utility function - * - * @return bool - */ - static public function isUnicodeSupportEnabled() - { - if (self::$_unicodeSupportEnabled === null) { - self::_determineUnicodeSupport(); - } - - return self::$_unicodeSupportEnabled; - } - - /** - * Method to cache the regex needed to determine if unicode support is available - * - * @return bool - */ - static protected function _determineUnicodeSupport() - { - self::$_unicodeSupportEnabled = (@preg_match('/\pL/u', 'a')) ? true : false; - } + protected $options = array( + 'pattern' => null, + 'replacement' => '', + ); /** * Constructor * Supported options are - * 'match' => matching pattern - * 'replace' => replace with this + * 'pattern' => matching pattern + * 'replacement' => replace with this * - * @param string|array $options + * @param array|Traversable|string|null $options * @return void */ - public function __construct($options = array()) + public function __construct($options = null) { if ($options instanceof Traversable) { - $options = ArrayUtils::iteratorToArray($options); - } elseif (!is_array($options)) { - $options = func_get_args(); - $temp = array(); - if (!empty($options)) { - $temp['match'] = array_shift($options); - } - - if (!empty($options)) { - $temp['replace'] = array_shift($options); - } - - $options = $temp; - } - - if (array_key_exists('match', $options)) { - $this->setMatchPattern($options['match']); + $options = iterator_to_array($options); } - if (array_key_exists('replace', $options)) { - $this->setReplacement($options['replace']); + if (!is_array($options) + || (!isset($options['pattern']) && !isset($options['replacement'])) + ) { + $args = func_get_args(); + if (isset($args[0])) { + $this->setPattern($args[0]); + } + if (isset($args[1])) { + $this->setReplacement($args[1]); + } + } else { + $this->setOptions($options); } } /** - * Set the match pattern for the regex being called within filter() + * Set the regex pattern to search for + * @see preg_replace() * - * @param mixed $match - same as the first argument of preg_replace + * @param string|array $pattern - same as the first argument of preg_replace * @return PregReplace + * @throws Exception\InvalidArgumentException */ - public function setMatchPattern($match) + public function setPattern($pattern) { - $this->_matchPattern = $match; + if (!is_array($pattern) && !is_string($pattern)) { + throw new Exception\InvalidArgumentException(sprintf( + '%s expects pattern to be array or string; received "%s"', + __METHOD__, + (is_object($pattern) ? get_class($pattern) : gettype($pattern)) + )); + } + $this->options['pattern'] = $pattern; return $this; } /** * Get currently set match pattern * - * @return string + * @return string|array */ - public function getMatchPattern() + public function getPattern() { - return $this->_matchPattern; + return $this->options['pattern']; } /** - * Set the Replacement pattern/string for the preg_replace called in filter + * Set the replacement array/string + * @see preg_replace() * - * @param mixed $replacement - same as the second argument of preg_replace + * @param array|string $replacement - same as the second argument of preg_replace * @return PregReplace + * @throws Exception\InvalidArgumentException */ public function setReplacement($replacement) { - $this->_replacement = $replacement; + if (!is_array($replacement) && !is_string($replacement)) { + throw new Exception\InvalidArgumentException(sprintf( + '%s expects replacement to be array or string; received "%s"', + __METHOD__, + (is_object($replacement) ? get_class($replacement) : gettype($replacement)) + )); + } + $this->options['replacement'] = $replacement; return $this; } /** * Get currently set replacement value * - * @return string + * @return string|array */ public function getReplacement() { - return $this->_replacement; + return $this->options['replacement']; } /** * Perform regexp replacement as filter * - * @param string $value - * @return string + * @param mixed $value + * @return mixed + * @throws Exception\RuntimeException */ public function filter($value) { - if ($this->_matchPattern == null) { - throw new Exception\RuntimeException(get_called_class() . ' does not have a valid MatchPattern set.'); + if ($this->options['pattern'] === null) { + throw new Exception\RuntimeException(sprintf( + 'Filter %s does not have a valid pattern set', + get_called_class() + )); } - return preg_replace($this->_matchPattern, $this->_replacement, $value); + return preg_replace($this->options['pattern'], $this->options['replacement'], $value); } } diff --git a/src/Word/CamelCaseToSeparator.php b/src/Word/CamelCaseToSeparator.php index ef2261cc..0231eda7 100644 --- a/src/Word/CamelCaseToSeparator.php +++ b/src/Word/CamelCaseToSeparator.php @@ -36,11 +36,11 @@ class CamelCaseToSeparator extends AbstractSeparator */ public function filter($value) { - if (self::isUnicodeSupportEnabled()) { - parent::setMatchPattern(array('#(?<=(?:\p{Lu}))(\p{Lu}\p{Ll})#','#(?<=(?:\p{Ll}|\p{Nd}))(\p{Lu})#')); + if (self::hasPcreUnicodeSupport()) { + parent::setPattern(array('#(?<=(?:\p{Lu}))(\p{Lu}\p{Ll})#','#(?<=(?:\p{Ll}|\p{Nd}))(\p{Lu})#')); parent::setReplacement(array($this->_separator . '\1', $this->_separator . '\1')); } else { - parent::setMatchPattern(array('#(?<=(?:[A-Z]))([A-Z]+)([A-Z][A-z])#', '#(?<=(?:[a-z0-9]))([A-Z])#')); + parent::setPattern(array('#(?<=(?:[A-Z]))([A-Z]+)([A-Z][A-z])#', '#(?<=(?:[a-z0-9]))([A-Z])#')); parent::setReplacement(array('\1' . $this->_separator . '\2', $this->_separator . '\1')); } diff --git a/src/Word/DashToSeparator.php b/src/Word/DashToSeparator.php index 11d1f0fc..2af192ad 100644 --- a/src/Word/DashToSeparator.php +++ b/src/Word/DashToSeparator.php @@ -36,7 +36,7 @@ class DashToSeparator extends AbstractSeparator */ public function filter($value) { - $this->setMatchPattern('#-#'); + $this->setPattern('#-#'); $this->setReplacement($this->_separator); return parent::filter($value); } diff --git a/src/Word/SeparatorToCamelCase.php b/src/Word/SeparatorToCamelCase.php index 584ed1d4..4c62405e 100644 --- a/src/Word/SeparatorToCamelCase.php +++ b/src/Word/SeparatorToCamelCase.php @@ -39,15 +39,15 @@ public function filter($value) // a unicode safe way of converting characters to \x00\x00 notation $pregQuotedSeparator = preg_quote($this->_separator, '#'); - if (self::isUnicodeSupportEnabled()) { - parent::setMatchPattern(array('#('.$pregQuotedSeparator.')(\p{L}{1})#eu','#(^\p{Ll}{1})#eu')); + if (self::hasPcreUnicodeSupport()) { + parent::setPattern(array('#('.$pregQuotedSeparator.')(\p{L}{1})#eu','#(^\p{Ll}{1})#eu')); if (!extension_loaded('mbstring')) { parent::setReplacement(array("strtoupper('\\2')","strtoupper('\\1')")); } else { parent::setReplacement(array("mb_strtoupper('\\2', 'UTF-8')","mb_strtoupper('\\1', 'UTF-8')")); } } else { - parent::setMatchPattern(array('#('.$pregQuotedSeparator.')([A-Za-z]{1})#e','#(^[A-Za-z]{1})#e')); + parent::setPattern(array('#('.$pregQuotedSeparator.')([A-Za-z]{1})#e','#(^[A-Za-z]{1})#e')); parent::setReplacement(array("strtoupper('\\2')","strtoupper('\\1')")); } diff --git a/src/Word/SeparatorToSeparator.php b/src/Word/SeparatorToSeparator.php index dd709998..aa9ce25d 100644 --- a/src/Word/SeparatorToSeparator.php +++ b/src/Word/SeparatorToSeparator.php @@ -117,7 +117,7 @@ protected function _separatorToSeparatorFilter($value) throw new Exception\RuntimeException('You must provide a search separator for this filter to work.'); } - $this->setMatchPattern('#' . preg_quote($this->_searchSeparator, '#') . '#'); + $this->setPattern('#' . preg_quote($this->_searchSeparator, '#') . '#'); $this->setReplacement($this->_replacementSeparator); return parent::filter($value); } diff --git a/test/PregReplaceTest.php b/test/PregReplaceTest.php index 6dd6a7a8..2edbbb4f 100644 --- a/test/PregReplaceTest.php +++ b/test/PregReplaceTest.php @@ -35,16 +35,27 @@ */ class PregReplaceTest extends \PHPUnit_Framework_TestCase { + /** + * @var PregReplaceFilter + */ + protected $filter; + public function setUp() { $this->filter = new PregReplaceFilter(); } - public function testPassingMatchPatternToConstructorSetsMatchPattern() + public function testDetectsPcreUnicodeSupport() + { + $enabled = (@preg_match('/\pL/u', 'a')) ? true : false; + $this->assertEquals($enabled, PregReplaceFilter::hasPcreUnicodeSupport()); + } + + public function testPassingPatternToConstructorSetsPattern() { $pattern = '#^controller/(?P[a-z_-]+)#'; $filter = new PregReplaceFilter($pattern); - $this->assertEquals($pattern, $filter->getMatchPattern()); + $this->assertEquals($pattern, $filter->getPattern()); } public function testPassingReplacementToConstructorSetsReplacement() @@ -54,25 +65,19 @@ public function testPassingReplacementToConstructorSetsReplacement() $this->assertEquals($replace, $filter->getReplacement()); } - public function testIsUnicodeSupportEnabledReturnsSaneValue() - { - $enabled = (@preg_match('/\pL/u', 'a')) ? true : false; - $this->assertEquals($enabled, $this->filter->isUnicodeSupportEnabled()); - } - - public function testMatchPatternInitiallyNull() + public function testPatternIsNullByDefault() { - $this->assertNull($this->filter->getMatchPattern()); + $this->assertNull($this->filter->getPattern()); } - public function testMatchPatternAccessorsWork() + public function testPatternAccessorsWork() { $pattern = '#^controller/(?P[a-z_-]+)#'; - $this->filter->setMatchPattern($pattern); - $this->assertEquals($pattern, $this->filter->getMatchPattern()); + $this->filter->setPattern($pattern); + $this->assertEquals($pattern, $this->filter->getPattern()); } - public function testReplacementInitiallyEmpty() + public function testReplacementIsEmptyByDefault() { $replacement = $this->filter->getReplacement(); $this->assertTrue(empty($replacement)); @@ -89,7 +94,7 @@ public function testFilterPerformsRegexReplacement() { $filter = $this->filter; $string = 'controller/action'; - $filter->setMatchPattern('#^controller/(?P[a-z_-]+)#') + $filter->setPattern('#^controller/(?P[a-z_-]+)#') ->setReplacement('foo/bar'); $filtered = $filter($string); $this->assertNotEquals($string, $filtered); @@ -101,25 +106,8 @@ public function testFilterThrowsExceptionWhenNoMatchPatternPresent() $filter = $this->filter; $string = 'controller/action'; $filter->setReplacement('foo/bar'); - $this->setExpectedException('\Zend\Filter\Exception\RuntimeException', 'does not have a valid MatchPattern set'); + $this->setExpectedException('Zend\Filter\Exception\RuntimeException', + 'does not have a valid pattern set'); $filtered = $filter($string); } - - /** - * @group ZF-9202 - */ - public function testExtendsPregReplace() - { - $startMatchPattern = '~(>){3,}~i'; - $filter = new XPregReplace(); - $this->assertEquals($startMatchPattern, $filter->getMatchPattern()); - } -} - -/** - * @group ZF-9202 - */ -class XPregReplace extends PregReplaceFilter -{ - protected $_matchPattern = '~(>){3,}~i'; } From 99406535c1c3cbe0b355a7e22c92ef8259798d96 Mon Sep 17 00:00:00 2001 From: Denis Portnov Date: Tue, 3 Jul 2012 07:41:47 +0400 Subject: [PATCH 06/17] remove magic in constructor --- src/AbstractFilter.php | 31 +++++++++++++++------ src/Alnum.php | 24 ++++++---------- src/Callback.php | 60 +++++++++++++++++++++------------------- src/Null.php | 2 +- src/PregReplace.php | 4 +-- src/RealPath.php | 12 ++++---- src/StringToLower.php | 13 ++++----- src/StringToUpper.php | 13 ++++----- src/StringTrim.php | 15 +++++----- test/CallbackTest.php | 23 ++++++++++++--- test/FilterChainTest.php | 2 +- test/RealPathTest.php | 4 --- 12 files changed, 109 insertions(+), 94 deletions(-) diff --git a/src/AbstractFilter.php b/src/AbstractFilter.php index 28f778dd..4bd120fb 100644 --- a/src/AbstractFilter.php +++ b/src/AbstractFilter.php @@ -45,6 +45,21 @@ abstract class AbstractFilter implements FilterInterface **/ protected static $hasPcreUnicodeSupport = null; + /** + * @return bool + */ + public static function hasPcreUnicodeSupport() + { + if (static::$hasPcreUnicodeSupport === null) { + if (defined('PREG_BAD_UTF8_OFFSET_ERROR') || @preg_match('/\pL/u', 'a') == 1){ + static::$hasPcreUnicodeSupport = true; + } else { + static::$hasPcreUnicodeSupport = false; + } + } + return static::$hasPcreUnicodeSupport; + } + /** * @param array|Traversable $options * @return AbstractFilter @@ -100,15 +115,13 @@ public function __invoke($value) return $this->filter($value); } - public static function hasPcreUnicodeSupport() + /** + * + * @param mixed $options + * @return bool + */ + protected static function isOptions($options) { - if (static::$hasPcreUnicodeSupport === null) { - if (defined('PREG_BAD_UTF8_OFFSET_ERROR') || @preg_match('/\pL/u', 'a') == 1){ - static::$hasPcreUnicodeSupport = true; - } else { - static::$hasPcreUnicodeSupport = false; - } - } - return static::$hasPcreUnicodeSupport; + return (is_array($options) || $options instanceof Traversable); } } diff --git a/src/Alnum.php b/src/Alnum.php index 676d285c..1c942359 100644 --- a/src/Alnum.php +++ b/src/Alnum.php @@ -43,25 +43,17 @@ class Alnum extends AbstractLocale /** * Sets default option values for this instance * - * @param array|Traversable|boolean|null $options + * @param array|Traversable|boolean|null $allowWhiteSpaceOrOptions + * @param string|null $locale */ - public function __construct($options = null) + public function __construct($allowWhiteSpaceOrOptions = null, $locale = null) { - if ($options !== null) { - if ($options instanceof Traversable) { - $options = iterator_to_array($options); - } - - if (!is_array($options)) { - $args = func_get_args(); - if (isset($args[0])) { - $this->setAllowWhiteSpace($args[0]); - } - if (isset($args[1])) { - $this->setLocale($args[1]); - } + if ($allowWhiteSpaceOrOptions !== null) { + if (!static::isOptions($allowWhiteSpaceOrOptions)){ + $this->setAllowWhiteSpace($allowWhiteSpaceOrOptions); + $this->setLocale($locale); } else { - $this->setOptions($options); + $this->setOptions($allowWhiteSpaceOrOptions); } } } diff --git a/src/Callback.php b/src/Callback.php index cfc40c5e..52ba4806 100644 --- a/src/Callback.php +++ b/src/Callback.php @@ -34,31 +34,20 @@ class Callback extends AbstractFilter * @var array */ protected $options = array( - 'callback' => null, - 'params' => null + 'callback' => null, + 'callback_params' => array() ); /** * @param array|Traversable $options */ - public function __construct($options) + public function __construct($callbackOrOptions, $callbackParams = array()) { - if ($options instanceof Traversable) { - $options = iterator_to_array($options); - } - - if (!is_array($options)) { - $args = func_get_args(); - if (isset($args[0])) { - $callback = $args[0]; - $params = null; - if (isset($args[1])) { - $params = $args[1]; - } - $this->setCallback($callback, $params); - } + if (is_callable($callbackOrOptions)) { + $this->setCallback($callbackOrOptions); + $this->setCallbackParams($callbackParams); } else { - $this->setOptions($options); + $this->setOptions($callbackOrOptions); } } @@ -68,7 +57,7 @@ public function __construct($options) * @param callable $callback * @return Callback */ - public function setCallback($callback, $params = null) + public function setCallback($callback) { if (!is_callable($callback)) { throw new Exception\InvalidArgumentException( @@ -77,7 +66,6 @@ public function setCallback($callback, $params = null) } $this->options['callback'] = $callback; - $this->options['params'] = $params; return $this; } @@ -91,6 +79,28 @@ public function getCallback() return $this->options['callback']; } + /** + * Sets parameters for the callback + * + * @param mixed $params + * @return Callback + */ + public function setCallbackParams($params) + { + $this->options['callback_params'] = (array) $params; + return $this; + } + + /** + * Get parameters for the callback + * + * @return mixed + */ + public function getCallbackParams() + { + return $this->options['callback_params']; + } + /** * Calls the filter per callback * @@ -99,14 +109,8 @@ public function getCallback() */ public function filter($value) { - $params = array($value); - if (isset($this->options['params'])) { - if (!is_array($this->options['params'])) { - array_push($params, $this->options['params']); - } else { - $params = $params + $this->options['params']; - } - } + $params = (array) $this->options['callback_params']; + array_unshift($params, $value); return call_user_func_array($this->options['callback'], $params); } diff --git a/src/Null.php b/src/Null.php index 9720aa30..f3b9704a 100644 --- a/src/Null.php +++ b/src/Null.php @@ -56,7 +56,7 @@ class Null extends AbstractFilter * @var array */ protected $options = array( - 'type' => self::TYPE_ALL, + 'type' => self::TYPE_ALL, ); /** diff --git a/src/PregReplace.php b/src/PregReplace.php index d2624f8d..d5d884dc 100644 --- a/src/PregReplace.php +++ b/src/PregReplace.php @@ -52,8 +52,8 @@ public function __construct($options = null) } if (!is_array($options) - || (!isset($options['pattern']) && !isset($options['replacement'])) - ) { + || (!isset($options['pattern']) && !isset($options['replacement']))) + { $args = func_get_args(); if (isset($args[0])) { $this->setPattern($args[0]); diff --git a/src/RealPath.php b/src/RealPath.php index 4483c409..cca2a73e 100644 --- a/src/RealPath.php +++ b/src/RealPath.php @@ -40,12 +40,14 @@ class RealPath extends AbstractFilter * * @param boolean|\Traversable $options Options to set */ - public function __construct($options = true) + public function __construct($existsOrOptions = true) { - if (is_bool($options)) { - $this->setExists($options); - } else { - $this->setOptions($options); + if ($existsOrOptions !== null) { + if (!static::isOptions($existsOrOptions)){ + $this->setExists($existsOrOptions); + } else { + $this->setOptions($existsOrOptions); + } } } diff --git a/src/StringToLower.php b/src/StringToLower.php index 5ceb2cd4..c134c24f 100644 --- a/src/StringToLower.php +++ b/src/StringToLower.php @@ -42,16 +42,13 @@ class StringToLower extends AbstractUnicode * * @param string|array|Traversable $options OPTIONAL */ - public function __construct($options = null) + public function __construct($encodingOrOptions = null) { - if ($options !== null) { - if ($options instanceof Traversable) { - $options = iterator_to_array($options); - } - if (!is_array($options)) { - $this->setEncoding($options); + if ($encodingOrOptions !== null) { + if (!static::isOptions($encodingOrOptions)){ + $this->setEncoding($encodingOrOptions); } else { - $this->setOptions($options); + $this->setOptions($encodingOrOptions); } } } diff --git a/src/StringToUpper.php b/src/StringToUpper.php index 02d95cfa..f5237c9f 100644 --- a/src/StringToUpper.php +++ b/src/StringToUpper.php @@ -42,16 +42,13 @@ class StringToUpper extends AbstractUnicode * * @param string|array|Traversable $options OPTIONAL */ - public function __construct($options = null) + public function __construct($encodingOrOptions = null) { - if ($options !== null) { - if ($options instanceof Traversable) { - $options = iterator_to_array($options); - } - if (!is_array($options)) { - $this->setEncoding($options); + if ($encodingOrOptions !== null) { + if (!static::isOptions($encodingOrOptions)){ + $this->setEncoding($encodingOrOptions); } else { - $this->setOptions($options); + $this->setOptions($encodingOrOptions); } } } diff --git a/src/StringTrim.php b/src/StringTrim.php index 093e7c38..d42f226f 100644 --- a/src/StringTrim.php +++ b/src/StringTrim.php @@ -43,16 +43,15 @@ class StringTrim extends AbstractFilter * * @param string|array|Traversable $options */ - public function __construct($options = null) + public function __construct($charlistOrOptions = null) { - if ($options !== null) { - if ($options instanceof Traversable) { - $options = iterator_to_array($options); - } - if (!is_array($options)) { - $this->setCharList($options); + if ($charlistOrOptions !== null) { + if (!is_array($charlistOrOptions) + && !$charlistOrOptions instanceof Traversable) + { + $this->setCharList($charlistOrOptions); } else { - $this->setOptions($options); + $this->setOptions($charlistOrOptions); } } } diff --git a/test/CallbackTest.php b/test/CallbackTest.php index a8c7e6de..2ccc210e 100644 --- a/test/CallbackTest.php +++ b/test/CallbackTest.php @@ -39,6 +39,16 @@ public function testObjectCallback() $this->assertEquals('objectCallback-test', $filter('test')); } + public function testConstructorWithOptions() + { + $filter = new CallbackFilter(array( + 'callback' => array($this, 'objectCallbackWithParams'), + 'callback_params' => 0, + )); + + $this->assertEquals('objectCallbackWithParams-test-0', $filter('test')); + } + public function testStaticCallback() { $filter = new CallbackFilter( @@ -49,16 +59,16 @@ public function testStaticCallback() public function testSettingDefaultOptions() { - $filter = new CallbackFilter(array($this, 'objectCallback'), 'options'); - $this->assertEquals('options', $filter->getOptions()); + $filter = new CallbackFilter(array($this, 'objectCallback'), 'param'); + $this->assertEquals(array('param'), $filter->getCallbackParams()); $this->assertEquals('objectCallback-test', $filter('test')); } public function testSettingDefaultOptionsAfterwards() { $filter = new CallbackFilter(array($this, 'objectCallback')); - $filter->setOptions('options'); - $this->assertEquals('options', $filter->getOptions()); + $filter->setCallbackParams('param'); + $this->assertEquals(array('param'), $filter->getCallbackParams()); $this->assertEquals('objectCallback-test', $filter('test')); } @@ -83,4 +93,9 @@ public static function staticCallback($value) { return 'staticCallback-' . $value; } + + public function objectCallbackWithParams($value, $param = null) + { + return 'objectCallbackWithParams-' . $value . '-' . $param; + } } diff --git a/test/FilterChainTest.php b/test/FilterChainTest.php index 11c4dd9a..0aba4e7b 100644 --- a/test/FilterChainTest.php +++ b/test/FilterChainTest.php @@ -78,7 +78,7 @@ public function testAllowsConnectingViaClassShortName() } $chain = new FilterChain(); - $chain->attachByName('string_trim', array('encoding' => 'utf-8'), 100) + $chain->attachByName('string_trim', null, 100) ->attachByName('strip_tags') ->attachByName('string_to_lower', array('encoding' => 'utf-8'), 900); $value = ' ABC '; diff --git a/test/RealPathTest.php b/test/RealPathTest.php index a41547d5..95947309 100644 --- a/test/RealPathTest.php +++ b/test/RealPathTest.php @@ -95,10 +95,6 @@ public function testGetAndSetExistsParameter() $this->_filter->setExists(false); $this->assertFalse($this->_filter->getExists()); - $this->_filter->setExists(true); - $this->_filter->setExists(array('exists' => false)); - $this->assertFalse($this->_filter->getExists()); - $this->_filter->setExists(array('unknown')); $this->assertTrue($this->_filter->getExists()); } From 3dcb18107a2d7bbb5ae50ba4a4bd5aebd1db5e29 Mon Sep 17 00:00:00 2001 From: Denis Portnov Date: Tue, 3 Jul 2012 08:04:15 +0400 Subject: [PATCH 07/17] remove LocalizedToNormalized/NormalizedToLocalized --- src/LocalizedToNormalized.php | 107 ------------- src/NormalizedToLocalized.php | 106 ------------- test/LocalizedToNormalizedTest.php | 198 ------------------------ test/NormalizedToLocalizedTest.php | 236 ----------------------------- 4 files changed, 647 deletions(-) delete mode 100644 src/LocalizedToNormalized.php delete mode 100644 src/NormalizedToLocalized.php delete mode 100644 test/LocalizedToNormalizedTest.php delete mode 100644 test/NormalizedToLocalizedTest.php diff --git a/src/LocalizedToNormalized.php b/src/LocalizedToNormalized.php deleted file mode 100644 index 0bed45ac..00000000 --- a/src/LocalizedToNormalized.php +++ /dev/null @@ -1,107 +0,0 @@ - null, - 'date_format' => null, - 'precision' => null - ); - - /** - * Class constructor - * - * @param array|Traversable $options (Optional) Locale to set - */ - public function __construct($options = null) - { - if ($options instanceof Traversable) { - $options = ArrayUtils::iteratorToArray($options); - } - - if (null !== $options) { - $this->setOptions($options); - } - } - - /** - * Returns the set options - * - * @return array - */ - public function getOptions() - { - return $this->_options; - } - - /** - * Sets options to use - * - * @param array $options (Optional) Options to use - * @return LocalizedToNormalized - */ - public function setOptions(array $options = null) - { - $this->_options = $options + $this->_options; - return $this; - } - - /** - * Defined by Zend\Filter\FilterInterface - * - * Normalizes the given input - * - * @param string $value Value to normalized - * @return string|array The normalized value - */ - public function filter($value) - { - if (Format::isNumber($value, $this->_options)) { - return Format::getNumber($value, $this->_options); - } else if (($this->_options['date_format'] === null) && (strpos($value, ':') !== false)) { - // Special case, no date format specified, detect time input - return Format::getTime($value, $this->_options); - } else if (Format::checkDateFormat($value, $this->_options)) { - // Detect date or time input - return Format::getDate($value, $this->_options); - } - - return $value; - } -} diff --git a/src/NormalizedToLocalized.php b/src/NormalizedToLocalized.php deleted file mode 100644 index 2f6cedc1..00000000 --- a/src/NormalizedToLocalized.php +++ /dev/null @@ -1,106 +0,0 @@ - null, - 'date_format' => null, - 'precision' => null - ); - - /** - * Class constructor - * - * @param array|Traversable $options (Optional) Locale to set - */ - public function __construct($options = null) - { - if ($options instanceof Traversable) { - $options = ArrayUtils::iteratorToArray($options); - } - - if (null !== $options) { - $this->setOptions($options); - } - } - - /** - * Returns the set options - * - * @return array - */ - public function getOptions() - { - return $this->_options; - } - - /** - * Sets options to use - * - * @param array $options (Optional) Options to use - * @return NormalizedToLocalized - */ - public function setOptions(array $options = null) - { - $this->_options = $options + $this->_options; - return $this; - } - - /** - * Defined by Zend\Filter\FilterInterface - * - * Normalizes the given input - * - * @param string $value Value to normalized - * @return string|array The normalized value - */ - public function filter($value) - { - if (is_array($value)) { - $date = new Date($value, $this->_options['locale']); - return $date->toString($this->_options['date_format']); - } else if ($this->_options['precision'] === 0) { - return Format::toInteger($value, $this->_options); - } else if ($this->_options['precision'] === null) { - return Format::toFloat($value, $this->_options); - } - - return Format::toNumber($value, $this->_options); - } -} diff --git a/test/LocalizedToNormalizedTest.php b/test/LocalizedToNormalizedTest.php deleted file mode 100644 index d1146dc0..00000000 --- a/test/LocalizedToNormalizedTest.php +++ /dev/null @@ -1,198 +0,0 @@ - 'de')); - $valuesExpected = array( - '0' => '0', - '1.234' => '1234', - '1,234' => '1.234', - '1.234,56' => '1234.56', - '-1.234' => '-1234', - '-1.234,56' => '-1234.56' - ); - - foreach ($valuesExpected as $input => $output) { - $this->assertEquals($output, $filter($input), 'failed filter of ' . var_export($input, 1)); - } - } - - /** - * Ensures that the filter follows expected behavior - * - * @return void - */ - public function testDateNormalizationWithoutParameters() - { - $filter = new LocalizedToNormalizedFilter(array('locale' => 'de')); - $valuesExpected = array( - '11:22:33' => array( - 'date_format' => 'HH:mm:ss', - 'locale' => 'de', - 'hour' => '11', - 'minute' => '22', - 'second' => '33'), - '20.04.2009' => array( - 'date_format' => 'dd.MM.yyyy', - 'locale' => 'de', - 'day' => '20', - 'month' => '04', - 'year' => '2009'), - '20.April.2009' => array( - 'date_format' => 'dd.MM.yyyy', - 'locale' => 'de', - 'day' => '20', - 'month' => '04', - 'year' => '2009'), - '20.04.09' => array( - 'date_format' => 'dd.MM.yyyy', - 'locale' => 'de', - 'day' => '20', - 'month' => '04', - 'year' => '2009'), - '20.April.09' => array( - 'date_format' => 'dd.MM.yyyy', - 'locale' => 'de', - 'day' => '20', - 'month' => '04', - 'year' => '2009') - ); - - foreach ($valuesExpected as $input => $output) { - $this->assertEquals($output, $filter($input), 'failed filter of ' . var_export($input, 1)); - } - } - - /** - * Ensures that the filter follows expected behavior - * - * @return void - */ - public function testDateNormalizationWithParameters() - { - $filter = new LocalizedToNormalizedFilter(array('locale' => 'de', 'date_format' => 'yyyy.dd.MM')); - $valuesExpected = array( - '2009.20.April' => array( - 'date_format' => 'yyyy.dd.MM', - 'locale' => 'de', - 'day' => '20', - 'month' => '04', - 'year' => '2009'), - '2009.20.04' => array( - 'date_format' => 'yyyy.dd.MM', - 'locale' => 'de', - 'day' => '20', - 'month' => '04', - 'year' => '2009'), - '09.20.04' => array( - 'date_format' => 'yyyy.dd.MM', - 'locale' => 'de', - 'day' => '20', - 'month' => '04', - 'year' => '2009'), - '09.20.April' => array( - 'date_format' => 'yyyy.dd.MM', - 'locale' => 'de', - 'day' => '20', - 'month' => '04', - 'year' => '2009') - ); - - foreach ($valuesExpected as $input => $output) { - $this->assertEquals($output, $filter($input), 'failed filter of ' . var_export($input, 1)); - } - } - - /** - * Ensures that the filter follows expected behavior - * - * @return void - */ - public function testNormalizationToInteger() - { - $filter = new LocalizedToNormalizedFilter(array('locale' => 'de', 'precision' => 0)); - $valuesExpected = array( - '1.234,56' => '1234', - '1,234' => '1', - '1234' => '1234' - ); - - foreach ($valuesExpected as $input => $output) { - $this->assertEquals($output, $filter($input), 'failed filter of ' . var_export($input, 1)); - } - } - - /** - * Ensures that the filter follows expected behavior - * - * @return void - */ - public function testNormalizationToFloat() - { - $filter = new LocalizedToNormalizedFilter(array('locale' => 'de', 'precision' => 2)); - $valuesExpected = array( - '1.234,5678' => '1234.56', - '1,234' => '1.23', - '1.234' => '1234.00' - ); - - foreach ($valuesExpected as $input => $output) { - $this->assertEquals($output, $filter($input), 'failed filter of ' . var_export($input, 1)); - } - } - - /** - * ZF-6532 - */ - public function testLongNumbers() - { - $filter = new LocalizedToNormalizedFilter(array('locale' => 'de', 'precision' => 0)); - $this->assertEquals('1000000', $filter('1.000.000,00')); - $this->assertEquals('10000', $filter(10000)); - - $this->assertEquals(array( - 'date_format' => 'dd.MM.yyyy', - 'locale' => 'de', - 'day' => '1', - 'month' => '2', - 'year' => '4'), $filter('1,2.4')); - } -} diff --git a/test/NormalizedToLocalizedTest.php b/test/NormalizedToLocalizedTest.php deleted file mode 100644 index 0217e7d4..00000000 --- a/test/NormalizedToLocalizedTest.php +++ /dev/null @@ -1,236 +0,0 @@ - 'de')); - $valuesExpected = array( - 1 => '0', - 2 => 0, - 3 => '1234', - 4 => 1234, - 5 => '1.234', - 6 => '1234.56', - 7 => 1234.56, - 8 => '-1234', - 9 => -1234, - 10 => '-1234.56', - 11 => -1234.56 - ); - - $valuesReceived = array( - 1 => '0', - 2 => '0', - 3 => '1.234', - 4 => '1.234', - 5 => '1,234', - 6 => '1.234,56', - 7 => '1.234,56', - 8 => '-1.234', - 9 => '-1.234', - 10 => '-1.234,56', - 11 => '-1.234,56' - ); - - foreach ($valuesExpected as $key => $value) { - $this->assertEquals($valuesReceived[$key], $filter($value), 'failed filter of ' . var_export($value, 1)); - } - } - - /** - * Ensures that the filter follows expected behavior - * - * @return void - */ - public function testDateLocalizationWithoutParameters() - { - $filter = new NormalizedToLocalizedFilter(array('locale' => 'de', 'date_format' => 'HH:mm:ss')); - $valuesExpected[1] = array( - 'hour' => '11', - 'minute' => '22', - 'second' => '33'); - $valuesReceived[1] = '11:22:33'; - - foreach ($valuesExpected as $key => $value) { - $this->assertEquals($valuesReceived[$key], $filter($value), 'failed filter of ' . var_export($value, 1)); - } - - $filter = new NormalizedToLocalizedFilter(array('locale' => 'de', 'date_format' => 'dd.MM.yyyy')); - $valuesExpected[1] = array( - 'date_format' => 'dd.MM.yyyy', - 'locale' => 'de', - 'day' => '20', - 'month' => '04', - 'year' => '2009'); - $valuesReceived[1] = '20.04.2009'; - - $valuesExpected[2] = array( - 'date_format' => null, - 'locale' => 'de', - 'day' => '20', - 'month' => '04', - 'year' => '2009'); - $valuesReceived[2] = '20.04.2009'; - - $valuesExpected[3] = array( - 'date_format' => 'dd.MM.yyyy', - 'day' => '20', - 'month' => '04', - 'year' => '2009'); - $valuesReceived[3] = '20.04.2009'; - - $valuesExpected[4] = array( - 'day' => '20', - 'month' => '04', - 'year' => '2009'); - $valuesReceived[4] = '20.04.2009'; - - foreach ($valuesExpected as $key => $value) { - $this->assertEquals($valuesReceived[$key], $filter($value), 'failed filter of ' . var_export($value, 1)); - } - } - - /** - * Ensures that the filter follows expected behavior - * - * @return void - */ - public function testDateLocalizationWithParameters() - { - $filter = new NormalizedToLocalizedFilter(array('locale' => 'de', 'date_format' => 'yyyy.dd.MM')); - - // Note that any non date array key like date_format or locale does not - // change filter parameters... only day, month and year are used - $valuesExpected[1] = array( - 'date_format' => 'yyyy.dd.MM', - 'locale' => 'de', - 'day' => '20', - 'month' => '04', - 'year' => '2009'); - $valuesReceived[1] = '2009.20.04'; - - $valuesExpected[2] = array( - 'day' => '20', - 'month' => '04', - 'year' => '2009'); - $valuesReceived[2] = '2009.20.04'; - - $valuesExpected[3] = array( - 'locale' => 'de', - 'day' => '20', - 'month' => '04', - 'year' => '2009'); - $valuesReceived[3] = '2009.20.04'; - - $valuesExpected[4] = array( - 'date_format' => null, - 'day' => '20', - 'month' => '04', - 'year' => '2009'); - $valuesReceived[4] = '2009.20.04'; - - foreach ($valuesExpected as $key => $value) { - $this->assertEquals($valuesReceived[$key], $filter($value), 'failed filter of ' . var_export($value, 1)); - } - } - - /** - * Ensures that the filter follows expected behavior - * - * @return void - */ - public function testLocalizationToInteger() - { - $filter = new NormalizedToLocalizedFilter(array('locale' => 'de', 'precision' => 0)); - $valuesExpected = array( - 1 => '1234.56', - 2 => 1234.56, - 3 => '1.234', - 4 => 1.234, - 5 => '1234', - 6 => 1234 - ); - - $valuesReceived = array( - 1 => '1.235', - 2 => '1.235', - 3 => '1', - 4 => '1', - 5 => '1.234', - 6 => '1.234' - ); - - foreach ($valuesExpected as $key => $value) { - $this->assertEquals($valuesReceived[$key], $filter($value), 'failed filter of ' . var_export($value, 1)); - } - } - - /** - * Ensures that the filter follows expected behavior - * - * @return void - */ - public function testLocalizationToFloat() - { - $filter = new NormalizedToLocalizedFilter(array('locale' => 'de', 'precision' => 2)); - - $valuesExpected = array( - 1 => '1234.5678', - 2 => 1234.5678, - 3 => '1.234', - 4 => 1.234, - 5 => '1234', - 6 => 1234 - ); - - $valuesReceived = array( - 1 => '1.234,57', - 2 => '1.234,57', - 3 => '1,23', - 4 => '1,23', - 5 => '1.234,00', - 6 => '1.234,00' - ); - - foreach ($valuesExpected as $key => $value) { - $this->assertEquals($valuesReceived[$key], $filter($value), 'failed filter of ' . var_export($value, 1)); - } - } -} From 02336f41e071daadc095f53ee4e7084d70ba2f98 Mon Sep 17 00:00:00 2001 From: Denis Portnov Date: Tue, 3 Jul 2012 17:08:55 +0400 Subject: [PATCH 08/17] fixed Compress tests --- src/Compress.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Compress.php b/src/Compress.php index 578c78dd..57b9b06c 100644 --- a/src/Compress.php +++ b/src/Compress.php @@ -68,8 +68,16 @@ public function __construct($options = null) * @param array $options * @return Compress */ - public function setOptions(array $options) + public function setOptions($options) { + if (!is_array($options) && !$options instanceof Traversable) { + throw new Exception\InvalidArgumentException(sprintf( + '"%s" expects an array or Traversable; received "%s"', + __METHOD__, + (is_object($options) ? get_class($options) : gettype($options)) + )); + } + foreach ($options as $key => $value) { if ($key == 'options') { $key = 'adapterOptions'; From 60465af4f609c091c052ad60d80ad1a9e4f61aef Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 3 Jul 2012 08:57:10 -0500 Subject: [PATCH 09/17] [zendframework/zf2#1713] Minor CS/flow fixes - use sprintf() for exception messages - use get_class($this) instead of get_called_class() when in non-static context - make conditionals positive when possible for readability - remove Zend\I18n\Filter\FilterPluginManager and put configuration in Zend\Filter\FilterPluginManager --- src/AbstractUnicode.php | 14 ++++++++------ src/Alnum.php | 6 +++--- src/FilterPluginManager.php | 1 + 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/AbstractUnicode.php b/src/AbstractUnicode.php index 7fda2bb4..26ae581c 100644 --- a/src/AbstractUnicode.php +++ b/src/AbstractUnicode.php @@ -40,17 +40,19 @@ public function setEncoding($encoding = null) { if ($encoding !== null) { if (!function_exists('mb_strtolower')) { - throw new Exception\ExtensionNotLoadedException( - get_called_class() . ' requires mbstring extension to be loaded' - ); + throw new Exception\ExtensionNotLoadedException(sprintf( + '%s requires mbstring extension to be loaded', + get_class($this) + )); } $encoding = strtolower($encoding); $mbEncodings = array_map('strtolower', mb_list_encodings()); if (!in_array($encoding, $mbEncodings)) { - throw new Exception\InvalidArgumentException( - "Encoding '{$encoding}' is not supported by mbstring extension" - ); + throw new Exception\InvalidArgumentException(sprintf( + "Encoding '%s' is not supported by mbstring extension", + $encoding + )); } } diff --git a/src/Alnum.php b/src/Alnum.php index 1c942359..58b28379 100644 --- a/src/Alnum.php +++ b/src/Alnum.php @@ -49,11 +49,11 @@ class Alnum extends AbstractLocale public function __construct($allowWhiteSpaceOrOptions = null, $locale = null) { if ($allowWhiteSpaceOrOptions !== null) { - if (!static::isOptions($allowWhiteSpaceOrOptions)){ + if (static::isOptions($allowWhiteSpaceOrOptions)){ + $this->setOptions($allowWhiteSpaceOrOptions); + } else { $this->setAllowWhiteSpace($allowWhiteSpaceOrOptions); $this->setLocale($locale); - } else { - $this->setOptions($allowWhiteSpaceOrOptions); } } } diff --git a/src/FilterPluginManager.php b/src/FilterPluginManager.php index 85f1f4aa..9c56eab6 100644 --- a/src/FilterPluginManager.php +++ b/src/FilterPluginManager.php @@ -72,6 +72,7 @@ class FilterPluginManager extends AbstractPluginManager 'localizedtonormalized' => 'Zend\Filter\LocalizedToNormalized', 'normalizedtolocalized' => 'Zend\Filter\NormalizedToLocalized', 'null' => 'Zend\Filter\Null', + 'numberformat' => 'Zend\I18n\Filter\NumberFormat', 'pregreplace' => 'Zend\Filter\PregReplace', 'realpath' => 'Zend\Filter\RealPath', 'stringtolower' => 'Zend\Filter\StringToLower', From 8cc5d580663432ed12797fd6c4f99aaef8b7914e Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 3 Jul 2012 09:02:56 -0500 Subject: [PATCH 10/17] [zendframework/zf2#1713] Fix failing tests in Compress filter - Due to addition of getOptions() to AbstractFilter, Compress filter no longer was proxying to the underlying adapter. Added an override getOptions() method that now explicitly proxies to the adapter. --- src/Compress.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Compress.php b/src/Compress.php index 57b9b06c..3e75e5d3 100644 --- a/src/Compress.php +++ b/src/Compress.php @@ -175,6 +175,18 @@ public function setAdapterOptions(array $options) return $this; } + /** + * Get individual or all options from underlying adapter + * + * @param null|string $option + * @return mixed + */ + public function getOptions($option = null) + { + $adapter = $this->getAdapter(); + return $adapter->getOptions($option); + } + /** * Calls adapter methods * From 9ff7ef3fb518e47ad0b26a992e5b1257e1fe61b7 Mon Sep 17 00:00:00 2001 From: Denis Portnov Date: Tue, 3 Jul 2012 23:07:46 +0400 Subject: [PATCH 11/17] fix broken tests - Filter\Compress - Alnum validator uses Alnum filter --- test/CompressTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/CompressTest.php b/test/CompressTest.php index 56f2848f..593f4d24 100644 --- a/test/CompressTest.php +++ b/test/CompressTest.php @@ -207,7 +207,7 @@ public function testSetAdapter() $this->assertEquals('Gz', $filter->getAdapterName()); - $filter->setAdapter('\Zend\Filter\Alnum'); + $filter->setAdapter('\Zend\Filter\Boolean'); $this->setExpectedException('\Zend\Filter\Exception\InvalidArgumentException', 'does not implement'); $adapter = $filter->getAdapter(); From 67d242d04411c59244d446bb17cc393152acf969 Mon Sep 17 00:00:00 2001 From: Maks3w Date: Mon, 9 Jul 2012 16:19:42 +0200 Subject: [PATCH 12/17] [CS][Library] Set File Header http://framework.zend.com/wiki/display/ZFDEV2/Coding+Standards#CodingStandards-Files The following script replaces the content between PHP open tag and namespace declaration. for COMPONENT in $(ls -d *) do for FILE in $(find $COMPONENT -name "*.php") do BLOCK="\/\*\*\n \* Zend Framework \(http:\/\/framework\.zend\.com\/\)\n \*\n \* \@link http:\/\/github\.com\/zendframework\/zf2 for the canonical source repository\n \* \@copyright Copyright \(c\) 2005-2012 Zend Technologies USA Inc\. \(http:\/\/www\.zend\.com\)\n \* \@license http:\/\/framework\.zend\.com\/license\/new-bsd New BSD License\n \* \@package Zend_$COMPONENT\n \*\/" perl -0777 -i -pe "s/(<\?php(\s*.*)*\nn)/ Date: Mon, 9 Jul 2012 16:34:21 +0200 Subject: [PATCH 13/17] [CS][test] Remove @copyright & @license for fl in $(find . -name "*.php"); do mv $fl $fl.old; sed '/@copyright/d' $fl.old > $fl; rm -f $fl.old; done; for fl in $(find . -name "*.php"); do mv $fl $fl.old; sed '/@license/d' $fl.old > $fl; rm -f $fl.old; done; --- test/BaseNameTest.php | 4 ---- test/BooleanTest.php | 4 ---- test/CallbackTest.php | 4 ---- test/Compress/Bz2Test.php | 4 ---- test/Compress/GzTest.php | 4 ---- test/Compress/LzfTest.php | 4 ---- test/Compress/RarTest.php | 4 ---- test/Compress/TarLoadArchiveTarTest.php | 4 ---- test/Compress/TarTest.php | 4 ---- test/Compress/ZipTest.php | 4 ---- test/CompressTest.php | 4 ---- test/DecompressTest.php | 4 ---- test/DecryptTest.php | 4 ---- test/DigitsTest.php | 4 ---- test/DirTest.php | 4 ---- test/Encrypt/McryptTest.php | 4 ---- test/Encrypt/OpensslTest.php | 4 ---- test/EncryptTest.php | 4 ---- test/File/DecryptTest.php | 4 ---- test/File/EncryptTest.php | 4 ---- test/File/LowerCaseTest.php | 4 ---- test/File/RenameTest.php | 4 ---- test/File/UpperCaseTest.php | 4 ---- test/FilterChainTest.php | 4 ---- test/HtmlEntitiesTest.php | 4 ---- test/InflectorTest.php | 4 ---- test/IntTest.php | 4 ---- test/NullTest.php | 4 ---- test/PregReplaceTest.php | 4 ---- test/RealPathTest.php | 4 ---- test/StaticFilterTest.php | 4 ---- test/StringToLowerTest.php | 4 ---- test/StringToUpperTest.php | 4 ---- test/StringTrimTest.php | 4 ---- test/StripNewlinesTest.php | 4 ---- test/StripTagsTest.php | 4 ---- test/Word/CamelCaseToDashTest.php | 4 ---- test/Word/CamelCaseToSeparatorTest.php | 4 ---- test/Word/CamelCaseToUnderscoreTest.php | 4 ---- test/Word/DashToCamelCaseTest.php | 4 ---- test/Word/DashToSeparatorTest.php | 4 ---- test/Word/DashToUnderscoreTest.php | 4 ---- test/Word/SeparatorToCamelCaseTest.php | 4 ---- test/Word/SeparatorToDashTest.php | 4 ---- test/Word/SeparatorToSeparatorTest.php | 4 ---- test/Word/UnderscoreToCamelCaseTest.php | 4 ---- test/Word/UnderscoreToDashTest.php | 4 ---- test/Word/UnderscoreToSeparatorTest.php | 4 ---- test/_files/TestNamespace/MyDigits.php | 4 ---- test/_files/TestNamespace/StringEquals.php | 4 ---- 50 files changed, 200 deletions(-) diff --git a/test/BaseNameTest.php b/test/BaseNameTest.php index 8060a8ed..584f0c1a 100644 --- a/test/BaseNameTest.php +++ b/test/BaseNameTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter; @@ -27,8 +25,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Filter */ class BaseNameTest extends \PHPUnit_Framework_TestCase diff --git a/test/BooleanTest.php b/test/BooleanTest.php index 0c40b87e..1ecc7ceb 100644 --- a/test/BooleanTest.php +++ b/test/BooleanTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter; @@ -27,8 +25,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Filter */ class BooleanTest extends \PHPUnit_Framework_TestCase diff --git a/test/CallbackTest.php b/test/CallbackTest.php index 2ccc210e..d39b0ca7 100644 --- a/test/CallbackTest.php +++ b/test/CallbackTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter; @@ -27,8 +25,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Filter */ class CallbackTest extends \PHPUnit_Framework_TestCase diff --git a/test/Compress/Bz2Test.php b/test/Compress/Bz2Test.php index f9b76810..56cb965c 100644 --- a/test/Compress/Bz2Test.php +++ b/test/Compress/Bz2Test.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter\Compress; @@ -28,8 +26,6 @@ * @package Zend_Filter * @subpackage UnitTests * @group Zend_Filter - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ class Bz2Test extends \PHPUnit_Framework_TestCase { diff --git a/test/Compress/GzTest.php b/test/Compress/GzTest.php index 5f5e6130..125b30c1 100644 --- a/test/Compress/GzTest.php +++ b/test/Compress/GzTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter\Compress; @@ -28,8 +26,6 @@ * @package Zend_Filter * @subpackage UnitTests * @group Zend_Filter - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ class GzTest extends \PHPUnit_Framework_TestCase { diff --git a/test/Compress/LzfTest.php b/test/Compress/LzfTest.php index f9f6f3fe..34921b60 100644 --- a/test/Compress/LzfTest.php +++ b/test/Compress/LzfTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter\Compress; @@ -28,8 +26,6 @@ * @package Zend_Filter * @subpackage UnitTests * @group Zend_Filter - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ class LzfTest extends \PHPUnit_Framework_TestCase { diff --git a/test/Compress/RarTest.php b/test/Compress/RarTest.php index ab51c28c..e0f1cd5f 100644 --- a/test/Compress/RarTest.php +++ b/test/Compress/RarTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter\Compress; @@ -28,8 +26,6 @@ * @package Zend_Filter * @subpackage UnitTests * @group Zend_Filter - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ class RarTest extends \PHPUnit_Framework_TestCase { diff --git a/test/Compress/TarLoadArchiveTarTest.php b/test/Compress/TarLoadArchiveTarTest.php index b00a929f..415f6171 100644 --- a/test/Compress/TarLoadArchiveTarTest.php +++ b/test/Compress/TarLoadArchiveTarTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter\Compress; @@ -30,8 +28,6 @@ * @package Zend_Filter * @subpackage UnitTests * @group Zend_Filter - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ class TarLoadArchveTarTest extends \PHPUnit_Framework_TestCase { diff --git a/test/Compress/TarTest.php b/test/Compress/TarTest.php index 5f25056a..a02ff348 100644 --- a/test/Compress/TarTest.php +++ b/test/Compress/TarTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter\Compress; @@ -29,8 +27,6 @@ * @package Zend_Filter * @subpackage UnitTests * @group Zend_Filter - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ class TarTest extends \PHPUnit_Framework_TestCase { diff --git a/test/Compress/ZipTest.php b/test/Compress/ZipTest.php index aaa46688..e9849a0a 100644 --- a/test/Compress/ZipTest.php +++ b/test/Compress/ZipTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter\Compress; @@ -28,8 +26,6 @@ * @package Zend_Filter * @subpackage UnitTests * @group Zend_Filter - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ class ZipTest extends \PHPUnit_Framework_TestCase { diff --git a/test/CompressTest.php b/test/CompressTest.php index 593f4d24..a0637c83 100644 --- a/test/CompressTest.php +++ b/test/CompressTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter; @@ -28,8 +26,6 @@ * @package Zend_Filter * @subpackage UnitTests * @group Zend_Filter - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ class CompressTest extends \PHPUnit_Framework_TestCase { diff --git a/test/DecompressTest.php b/test/DecompressTest.php index 0ae65ef0..71af9f29 100644 --- a/test/DecompressTest.php +++ b/test/DecompressTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter; @@ -28,8 +26,6 @@ * @package Zend_Filter * @subpackage UnitTests * @group Zend_Filter - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ class DecompressTest extends \PHPUnit_Framework_TestCase { diff --git a/test/DecryptTest.php b/test/DecryptTest.php index bb89ea81..e95af1fc 100644 --- a/test/DecryptTest.php +++ b/test/DecryptTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter; @@ -28,8 +26,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Filter */ class DecryptTest extends \PHPUnit_Framework_TestCase diff --git a/test/DigitsTest.php b/test/DigitsTest.php index 0f6e3789..9415baf0 100644 --- a/test/DigitsTest.php +++ b/test/DigitsTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter; @@ -27,8 +25,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Filter */ class DigitsTest extends \PHPUnit_Framework_TestCase diff --git a/test/DirTest.php b/test/DirTest.php index bb72d3fd..a455e375 100644 --- a/test/DirTest.php +++ b/test/DirTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter; @@ -27,8 +25,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Filter */ class DirTest extends \PHPUnit_Framework_TestCase diff --git a/test/Encrypt/McryptTest.php b/test/Encrypt/McryptTest.php index ecaf485f..0200dc33 100644 --- a/test/Encrypt/McryptTest.php +++ b/test/Encrypt/McryptTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter\Encrypt; @@ -27,8 +25,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Filter */ class McryptTest extends \PHPUnit_Framework_TestCase diff --git a/test/Encrypt/OpensslTest.php b/test/Encrypt/OpensslTest.php index fc6f9494..94822b47 100644 --- a/test/Encrypt/OpensslTest.php +++ b/test/Encrypt/OpensslTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter\Encrypt; @@ -27,8 +25,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Filter */ class OpensslTest extends \PHPUnit_Framework_TestCase diff --git a/test/EncryptTest.php b/test/EncryptTest.php index 9bcd049b..efabef86 100644 --- a/test/EncryptTest.php +++ b/test/EncryptTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter; @@ -28,8 +26,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Filter */ class EncryptTest extends \PHPUnit_Framework_TestCase diff --git a/test/File/DecryptTest.php b/test/File/DecryptTest.php index 2069c781..5d7e66d6 100644 --- a/test/File/DecryptTest.php +++ b/test/File/DecryptTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter\File; @@ -28,8 +26,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Filter */ class DecryptTest extends \PHPUnit_Framework_TestCase diff --git a/test/File/EncryptTest.php b/test/File/EncryptTest.php index 3a53b520..8bc2e0d6 100644 --- a/test/File/EncryptTest.php +++ b/test/File/EncryptTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter\File; @@ -28,8 +26,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Filter */ class EncryptTest extends \PHPUnit_Framework_TestCase diff --git a/test/File/LowerCaseTest.php b/test/File/LowerCaseTest.php index 163fc966..af2ca9fb 100644 --- a/test/File/LowerCaseTest.php +++ b/test/File/LowerCaseTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter\File; @@ -27,8 +25,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Filter */ class LowerCaseTest extends \PHPUnit_Framework_TestCase diff --git a/test/File/RenameTest.php b/test/File/RenameTest.php index cf88faf8..37b87c98 100644 --- a/test/File/RenameTest.php +++ b/test/File/RenameTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter\File; @@ -27,8 +25,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Filter */ class RenameTest extends \PHPUnit_Framework_TestCase diff --git a/test/File/UpperCaseTest.php b/test/File/UpperCaseTest.php index 2e65723b..d89091c9 100644 --- a/test/File/UpperCaseTest.php +++ b/test/File/UpperCaseTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter\File; @@ -27,8 +25,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Filter */ class UpperCaseTest extends \PHPUnit_Framework_TestCase diff --git a/test/FilterChainTest.php b/test/FilterChainTest.php index 0aba4e7b..531f80cd 100644 --- a/test/FilterChainTest.php +++ b/test/FilterChainTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter; @@ -28,8 +26,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Filter */ class FilterChainTest extends \PHPUnit_Framework_TestCase diff --git a/test/HtmlEntitiesTest.php b/test/HtmlEntitiesTest.php index e1283307..642043dc 100644 --- a/test/HtmlEntitiesTest.php +++ b/test/HtmlEntitiesTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter; @@ -28,8 +26,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Filter */ class HtmlEntitiesTest extends \PHPUnit_Framework_TestCase diff --git a/test/InflectorTest.php b/test/InflectorTest.php index 2dd41db3..a3cbdec9 100644 --- a/test/InflectorTest.php +++ b/test/InflectorTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter; @@ -30,8 +28,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Filter */ class InflectorTest extends \PHPUnit_Framework_TestCase diff --git a/test/IntTest.php b/test/IntTest.php index 573e96de..28d86610 100644 --- a/test/IntTest.php +++ b/test/IntTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter; @@ -27,8 +25,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Filter */ class IntTest extends \PHPUnit_Framework_TestCase diff --git a/test/NullTest.php b/test/NullTest.php index f2926961..a37f75e9 100644 --- a/test/NullTest.php +++ b/test/NullTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter; @@ -27,8 +25,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Filter */ class NullTest extends \PHPUnit_Framework_TestCase diff --git a/test/PregReplaceTest.php b/test/PregReplaceTest.php index 2edbbb4f..36a948a2 100644 --- a/test/PregReplaceTest.php +++ b/test/PregReplaceTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter; @@ -29,8 +27,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Filter */ class PregReplaceTest extends \PHPUnit_Framework_TestCase diff --git a/test/RealPathTest.php b/test/RealPathTest.php index 95947309..24946510 100644 --- a/test/RealPathTest.php +++ b/test/RealPathTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter; @@ -27,8 +25,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Filter */ class RealPathTest extends \PHPUnit_Framework_TestCase diff --git a/test/StaticFilterTest.php b/test/StaticFilterTest.php index 4ea0334b..cf05c530 100644 --- a/test/StaticFilterTest.php +++ b/test/StaticFilterTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter; @@ -28,8 +26,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Filter */ class StaticFilterTest extends \PHPUnit_Framework_TestCase diff --git a/test/StringToLowerTest.php b/test/StringToLowerTest.php index e891932c..ca4594e8 100644 --- a/test/StringToLowerTest.php +++ b/test/StringToLowerTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter; @@ -27,8 +25,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Filter */ class StringToLowerTest extends \PHPUnit_Framework_TestCase diff --git a/test/StringToUpperTest.php b/test/StringToUpperTest.php index f442a209..6020f66e 100644 --- a/test/StringToUpperTest.php +++ b/test/StringToUpperTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter; @@ -27,8 +25,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Filter */ class StringToUpperTest extends \PHPUnit_Framework_TestCase diff --git a/test/StringTrimTest.php b/test/StringTrimTest.php index d2193704..fddaf768 100644 --- a/test/StringTrimTest.php +++ b/test/StringTrimTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter; @@ -28,8 +26,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Filter */ class StringTrimTest extends \PHPUnit_Framework_TestCase diff --git a/test/StripNewlinesTest.php b/test/StripNewlinesTest.php index 49176d7e..47085701 100644 --- a/test/StripNewlinesTest.php +++ b/test/StripNewlinesTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter; @@ -27,8 +25,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Filter */ class StripNewlinesTest extends \PHPUnit_Framework_TestCase diff --git a/test/StripTagsTest.php b/test/StripTagsTest.php index def35665..5a4313fa 100644 --- a/test/StripTagsTest.php +++ b/test/StripTagsTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter; @@ -27,8 +25,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Filter */ class StripTagsTest extends \PHPUnit_Framework_TestCase diff --git a/test/Word/CamelCaseToDashTest.php b/test/Word/CamelCaseToDashTest.php index 571e509d..517d0d24 100644 --- a/test/Word/CamelCaseToDashTest.php +++ b/test/Word/CamelCaseToDashTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter\Word; @@ -29,8 +27,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Filter */ class CamelCaseToDashTest extends \PHPUnit_Framework_TestCase diff --git a/test/Word/CamelCaseToSeparatorTest.php b/test/Word/CamelCaseToSeparatorTest.php index bdf96330..142e04a6 100644 --- a/test/Word/CamelCaseToSeparatorTest.php +++ b/test/Word/CamelCaseToSeparatorTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter\Word; @@ -29,8 +27,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Filter */ class CamelCaseToSeparatorTest extends \PHPUnit_Framework_TestCase diff --git a/test/Word/CamelCaseToUnderscoreTest.php b/test/Word/CamelCaseToUnderscoreTest.php index 70367356..d058e23a 100644 --- a/test/Word/CamelCaseToUnderscoreTest.php +++ b/test/Word/CamelCaseToUnderscoreTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter\Word; @@ -29,8 +27,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Filter */ class CamelCaseToUnderscoreTest extends \PHPUnit_Framework_TestCase diff --git a/test/Word/DashToCamelCaseTest.php b/test/Word/DashToCamelCaseTest.php index 05bca2d1..8faa4b21 100644 --- a/test/Word/DashToCamelCaseTest.php +++ b/test/Word/DashToCamelCaseTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter\Word; @@ -29,8 +27,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Filter */ class DashToCamelCaseTest extends \PHPUnit_Framework_TestCase diff --git a/test/Word/DashToSeparatorTest.php b/test/Word/DashToSeparatorTest.php index d6c847c2..39d5b059 100644 --- a/test/Word/DashToSeparatorTest.php +++ b/test/Word/DashToSeparatorTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter\Word; @@ -29,8 +27,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Filter */ class DashToSeparatorTest extends \PHPUnit_Framework_TestCase diff --git a/test/Word/DashToUnderscoreTest.php b/test/Word/DashToUnderscoreTest.php index 61f2b575..3b076e18 100644 --- a/test/Word/DashToUnderscoreTest.php +++ b/test/Word/DashToUnderscoreTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter\Word; @@ -29,8 +27,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Filter */ class DashToUnderscoreTest extends \PHPUnit_Framework_TestCase diff --git a/test/Word/SeparatorToCamelCaseTest.php b/test/Word/SeparatorToCamelCaseTest.php index fccff372..2002abcb 100644 --- a/test/Word/SeparatorToCamelCaseTest.php +++ b/test/Word/SeparatorToCamelCaseTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter\Word; @@ -29,8 +27,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Filter */ class SeparatorToCamelCaseTest extends \PHPUnit_Framework_TestCase diff --git a/test/Word/SeparatorToDashTest.php b/test/Word/SeparatorToDashTest.php index 57140462..7e8a9f39 100644 --- a/test/Word/SeparatorToDashTest.php +++ b/test/Word/SeparatorToDashTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter\Word; @@ -29,8 +27,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Filter */ class SeparatorToDashTest extends \PHPUnit_Framework_TestCase diff --git a/test/Word/SeparatorToSeparatorTest.php b/test/Word/SeparatorToSeparatorTest.php index 8c8aab42..f4f73089 100644 --- a/test/Word/SeparatorToSeparatorTest.php +++ b/test/Word/SeparatorToSeparatorTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter\Word; @@ -29,8 +27,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Filter */ class SeparatorToSeparatorTest extends \PHPUnit_Framework_TestCase diff --git a/test/Word/UnderscoreToCamelCaseTest.php b/test/Word/UnderscoreToCamelCaseTest.php index ee463239..cc5148e7 100644 --- a/test/Word/UnderscoreToCamelCaseTest.php +++ b/test/Word/UnderscoreToCamelCaseTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter\Word; @@ -29,8 +27,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Filter */ class UnderscoreToCamelCaseTest extends \PHPUnit_Framework_TestCase diff --git a/test/Word/UnderscoreToDashTest.php b/test/Word/UnderscoreToDashTest.php index 6d850875..3818aceb 100644 --- a/test/Word/UnderscoreToDashTest.php +++ b/test/Word/UnderscoreToDashTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter\Word; @@ -29,8 +27,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Filter */ class UnderscoreToDashTest extends \PHPUnit_Framework_TestCase diff --git a/test/Word/UnderscoreToSeparatorTest.php b/test/Word/UnderscoreToSeparatorTest.php index 63219386..864a7093 100644 --- a/test/Word/UnderscoreToSeparatorTest.php +++ b/test/Word/UnderscoreToSeparatorTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Filter\Word; @@ -29,8 +27,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Filter */ class UnderscoreToSeparatorTest extends \PHPUnit_Framework_TestCase diff --git a/test/_files/TestNamespace/MyDigits.php b/test/_files/TestNamespace/MyDigits.php index fd62e656..5f4d76af 100644 --- a/test/_files/TestNamespace/MyDigits.php +++ b/test/_files/TestNamespace/MyDigits.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace TestNamespace; @@ -29,8 +27,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ class MyDigits extends DigitsValidator { diff --git a/test/_files/TestNamespace/StringEquals.php b/test/_files/TestNamespace/StringEquals.php index 4f68e5f7..89027f8f 100644 --- a/test/_files/TestNamespace/StringEquals.php +++ b/test/_files/TestNamespace/StringEquals.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace TestNamespace; @@ -29,8 +27,6 @@ * @category Zend * @package Zend_Filter * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ class StringEquals extends AbstractValidator { From 3604b7a548f8e27f79db6f7f125ce121abc2ee4f Mon Sep 17 00:00:00 2001 From: Maks3w Date: Mon, 9 Jul 2012 16:41:27 +0200 Subject: [PATCH 14/17] [CS][Tests] Set File Header http://framework.zend.com/wiki/display/ZFDEV2/Coding+Standards#CodingStandards-Files The following script replaces the content between PHP open tag and namespace declaration. for COMPONENT in $(ls -d *) do for FILE in $(find $COMPONENT -name "*.php") do BLOCK="\/\*\*\n \* Zend Framework \(http:\/\/framework\.zend\.com\/\)\n \*\n \* \@link http:\/\/github\.com\/zendframework\/zf2 for the canonical source repository\n \* \@copyright Copyright \(c\) 2005-2012 Zend Technologies USA Inc\. \(http:\/\/www\.zend\.com\)\n \* \@license http:\/\/framework\.zend\.com\/license\/new-bsd New BSD License\n \* \@package Zend_$COMPONENT\n \*\/" perl -0777 -i -pe "s/(<\?php(\s*.*)*\nn)/setPublicKey(array('private' => __DIR__ . '/../_files/publickey.pem')); $this->assertSame($filter, $r); - + $this->setExpectedException('\Zend\Filter\Exception\InvalidArgumentException', 'not valid'); $filter->setPublicKey(123); @@ -157,7 +150,7 @@ public function testSetPublicKey() public function testSetPrivateKey() { $filter = new OpensslEncryption(); - + $filter->setPrivateKey(array('public' => __DIR__ . '/../_files/privatekey.pem')); $test = $filter->getPrivateKey(); $this->assertEquals(array( @@ -177,8 +170,8 @@ public function testSetPrivateKey() d/fxzPfuO/bLpADozTAnYT9Hu3wPrQVLeAfCp0ojqH7DYg== -----END RSA PRIVATE KEY----- '), $test); - - + + $this->setExpectedException('\Zend\Filter\Exception\InvalidArgumentException', 'not valid'); $filter->setPrivateKey(123); @@ -229,7 +222,7 @@ public function testInvalidDecryption() public function testEncryptionWithoutPublicKey() { $filter = new OpensslEncryption(); - + $this->setExpectedException('\Zend\Filter\Exception\RuntimeException', 'without public key'); $filter->encrypt('unknown'); } @@ -310,4 +303,4 @@ public function testEncryptionWithDecryptionAndCompressionWithPackagedKeys() $input = $filter->decrypt($output); $this->assertEquals('teststring', trim($input)); } -} +} \ No newline at end of file diff --git a/test/EncryptTest.php b/test/EncryptTest.php index efabef86..d714b551 100644 --- a/test/EncryptTest.php +++ b/test/EncryptTest.php @@ -1,20 +1,11 @@ Date: Mon, 9 Jul 2012 16:46:59 -0500 Subject: [PATCH 15/17] [zen-49] Correct import statements across framework - Ran a script that would create multiple import statements out of multi-line import statements, and which would sort all import statements in alphabetic order. Script is at https://gist.github.com/3079222 and was run by dropping into the library/Zend folder and typing (in zsh) "for file in **/*.php;do php /path/to/replace-uses.php $file; done" --- src/Compress/Tar.php | 8 ++++---- src/Encrypt/Mcrypt.php | 4 ++-- src/Encrypt/Openssl.php | 4 ++-- src/File/LowerCase.php | 2 +- src/File/Rename.php | 2 +- src/File/UpperCase.php | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Compress/Tar.php b/src/Compress/Tar.php index 94ed1931..d5701ea2 100644 --- a/src/Compress/Tar.php +++ b/src/Compress/Tar.php @@ -10,10 +10,10 @@ namespace Zend\Filter\Compress; -use Archive_Tar, - RecursiveDirectoryIterator, - RecursiveIteratorIterator, - Zend\Filter\Exception; +use Archive_Tar; +use RecursiveDirectoryIterator; +use RecursiveIteratorIterator; +use Zend\Filter\Exception; /** * Compression adapter for Tar diff --git a/src/Encrypt/Mcrypt.php b/src/Encrypt/Mcrypt.php index 6ae838c2..39b8f7fc 100644 --- a/src/Encrypt/Mcrypt.php +++ b/src/Encrypt/Mcrypt.php @@ -11,10 +11,10 @@ namespace Zend\Filter\Encrypt; use Traversable; -use Zend\Stdlib\ArrayUtils; -use Zend\Filter\Exception; use Zend\Filter\Compress; use Zend\Filter\Decompress; +use Zend\Filter\Exception; +use Zend\Stdlib\ArrayUtils; /** * Encryption adapter for mcrypt diff --git a/src/Encrypt/Openssl.php b/src/Encrypt/Openssl.php index eec15276..c6764982 100644 --- a/src/Encrypt/Openssl.php +++ b/src/Encrypt/Openssl.php @@ -11,10 +11,10 @@ namespace Zend\Filter\Encrypt; use Traversable; -use Zend\Stdlib\ArrayUtils; -use Zend\Filter\Exception; use Zend\Filter\Compress; use Zend\Filter\Decompress; +use Zend\Filter\Exception; +use Zend\Stdlib\ArrayUtils; /** * Encryption adapter for openssl diff --git a/src/File/LowerCase.php b/src/File/LowerCase.php index d170fbdb..3148c9a7 100644 --- a/src/File/LowerCase.php +++ b/src/File/LowerCase.php @@ -10,8 +10,8 @@ namespace Zend\Filter\File; -use Zend\Filter\StringToLower; use Zend\Filter\Exception; +use Zend\Filter\StringToLower; /** * @category Zend diff --git a/src/File/Rename.php b/src/File/Rename.php index 1a301e66..b32d5e82 100644 --- a/src/File/Rename.php +++ b/src/File/Rename.php @@ -11,9 +11,9 @@ namespace Zend\Filter\File; use Traversable; -use Zend\Stdlib\ArrayUtils; use Zend\Filter; use Zend\Filter\Exception; +use Zend\Stdlib\ArrayUtils; /** * @category Zend diff --git a/src/File/UpperCase.php b/src/File/UpperCase.php index 769027eb..05a42de2 100644 --- a/src/File/UpperCase.php +++ b/src/File/UpperCase.php @@ -10,8 +10,8 @@ namespace Zend\Filter\File; -use Zend\Filter\StringToUpper; use Zend\Filter\Exception; +use Zend\Filter\StringToUpper; /** * @category Zend From c2796dae0a847e4fcc69e66d88dcaafa871a7f62 Mon Sep 17 00:00:00 2001 From: Maks3w Date: Thu, 12 Jul 2012 21:11:36 +0200 Subject: [PATCH 16/17] [PSR-2] fixers=braces,elseif,short_tag,php_closing_tag,trailing_spaces,linefeed Applied php-cs-fixer --fixers=braces,elseif,short_tag,php_closing_tag,trailing_spaces,linefeed --- src/Compress.php | 4 +-- src/Compress/Gz.php | 4 +-- src/Compress/Rar.php | 2 +- src/Compress/Zip.php | 2 +- src/Encrypt.php | 2 +- src/Encrypt/EncryptionAlgorithmInterface.php | 2 +- src/Encrypt/Mcrypt.php | 4 +-- src/File/Rename.php | 2 +- src/FilterChain.php | 26 ++++++++++---------- src/FilterPluginManager.php | 6 ++--- src/StaticFilter.php | 6 ++--- src/Word/CamelCaseToSeparator.php | 4 +-- src/Word/DashToSeparator.php | 4 +-- test/Compress/RarTest.php | 8 +++--- test/CompressTest.php | 6 ++--- test/File/RenameTest.php | 2 +- test/HtmlEntitiesTest.php | 8 +++--- test/NullTest.php | 4 +-- test/PregReplaceTest.php | 2 +- 19 files changed, 49 insertions(+), 49 deletions(-) diff --git a/src/Compress.php b/src/Compress.php index af7d35fc..ca51e93f 100644 --- a/src/Compress.php +++ b/src/Compress.php @@ -165,8 +165,8 @@ public function setAdapterOptions(array $options) /** * Get individual or all options from underlying adapter - * - * @param null|string $option + * + * @param null|string $option * @return mixed */ public function getOptions($option = null) diff --git a/src/Compress/Gz.php b/src/Compress/Gz.php index 491b953e..8351742a 100644 --- a/src/Compress/Gz.php +++ b/src/Compress/Gz.php @@ -143,7 +143,7 @@ public function compress($content) gzwrite($file, $content); gzclose($file); $compressed = true; - } else if ($this->options['mode'] == 'deflate') { + } elseif ($this->options['mode'] == 'deflate') { $compressed = gzdeflate($content, $this->getLevel()); } else { $compressed = gzcompress($content, $this->getLevel()); @@ -186,7 +186,7 @@ public function decompress($content) $file = gzopen($archive, 'r'); $compressed = gzread($file, $size); gzclose($file); - } else if ($mode == 'deflate') { + } elseif ($mode == 'deflate') { $compressed = gzinflate($content); } else { $compressed = gzuncompress($content); diff --git a/src/Compress/Rar.php b/src/Compress/Rar.php index 2486fb2f..50bf104d 100644 --- a/src/Compress/Rar.php +++ b/src/Compress/Rar.php @@ -182,7 +182,7 @@ public function compress($content) * * @param string $content * @return boolean - * @throws Exception\RuntimeException if archive not found, cannot be opened, + * @throws Exception\RuntimeException if archive not found, cannot be opened, * or error during decompression */ public function decompress($content) diff --git a/src/Compress/Zip.php b/src/Compress/Zip.php index b1586531..5fe62519 100644 --- a/src/Compress/Zip.php +++ b/src/Compress/Zip.php @@ -182,7 +182,7 @@ public function compress($content) * * @param string $content * @return string - * @throws Exception\RuntimeException If archive file not found, target directory not found, + * @throws Exception\RuntimeException If archive file not found, target directory not found, * or error during decompression */ public function decompress($content) diff --git a/src/Encrypt.php b/src/Encrypt.php index db4f2d53..d1680085 100644 --- a/src/Encrypt.php +++ b/src/Encrypt.php @@ -61,7 +61,7 @@ public function setAdapter($options = null) { if (is_string($options)) { $adapter = $options; - } else if (isset($options['adapter'])) { + } elseif (isset($options['adapter'])) { $adapter = $options['adapter']; unset($options['adapter']); } else { diff --git a/src/Encrypt/EncryptionAlgorithmInterface.php b/src/Encrypt/EncryptionAlgorithmInterface.php index 597921ad..9e5f73ac 100644 --- a/src/Encrypt/EncryptionAlgorithmInterface.php +++ b/src/Encrypt/EncryptionAlgorithmInterface.php @@ -36,7 +36,7 @@ public function decrypt($value); /** * Return the adapter name - * + * * @return string */ public function toString(); diff --git a/src/Encrypt/Mcrypt.php b/src/Encrypt/Mcrypt.php index 39b8f7fc..4362c76b 100644 --- a/src/Encrypt/Mcrypt.php +++ b/src/Encrypt/Mcrypt.php @@ -168,7 +168,7 @@ public function setVector($vector = null) } $vector = mcrypt_create_iv($size, $method); - } else if (strlen($vector) != $size) { + } elseif (strlen($vector) != $size) { throw new Exception\InvalidArgumentException('The given vector has a wrong size for the set algorithm'); } @@ -312,7 +312,7 @@ protected function _initCipher($cipher) if (empty($keysizes) || ($this->_encryption['salt'] == true)) { $keysize = mcrypt_enc_get_key_size($cipher); $key = substr(md5($key), 0, $keysize); - } else if (!in_array(strlen($key), $keysizes)) { + } elseif (!in_array(strlen($key), $keysizes)) { throw new Exception\RuntimeException('The given key has a wrong size for the set algorithm'); } diff --git a/src/File/Rename.php b/src/File/Rename.php index 8faf82b8..6fc6e616 100644 --- a/src/File/Rename.php +++ b/src/File/Rename.php @@ -179,7 +179,7 @@ public function filter($value) * @param array $options * @return array */ - protected function _convertOptions($options) + protected function _convertOptions($options) { $files = array(); foreach ($options as $key => $value) { diff --git a/src/FilterChain.php b/src/FilterChain.php index f8fb82d5..49460011 100644 --- a/src/FilterChain.php +++ b/src/FilterChain.php @@ -38,7 +38,7 @@ class FilterChain extends AbstractFilter implements Countable /** * Initialize filter chain - * + * */ public function __construct($options = null) { @@ -90,7 +90,7 @@ public function setOptions($options) /** * Return the count of attached filters - * + * * @return int */ public function count() @@ -100,7 +100,7 @@ public function count() /** * Get plugin manager instance - * + * * @return FilterPluginManager */ public function getPluginManager() @@ -113,8 +113,8 @@ public function getPluginManager() /** * Set plugin manager instance - * - * @param FilterPluginManager $plugins + * + * @param FilterPluginManager $plugins * @return FilterChain */ public function setPluginManager(FilterPluginManager $plugins) @@ -125,9 +125,9 @@ public function setPluginManager(FilterPluginManager $plugins) /** * Retrieve a filter plugin by name - * - * @param mixed $name - * @param array $options + * + * @param mixed $name + * @param array $options * @return Filter */ public function plugin($name, array $options = array()) @@ -138,7 +138,7 @@ public function plugin($name, array $options = array()) /** * Attach a filter to the chain - * + * * @param callback|FilterInterface $callback A Filter implementation or valid PHP callback * @param int $priority Priority at which to enqueue filter; defaults to 1000 (higher executes earlier) * @return FilterChain @@ -161,11 +161,11 @@ public function attach($callback, $priority = self::DEFAULT_PRIORITY) /** * Attach a filter to the chain using a short name * - * Retrieves the filter from the attached plugin broker, and then calls attach() + * Retrieves the filter from the attached plugin broker, and then calls attach() * with the retrieved instance. - * - * @param string $name - * @param mixed $options + * + * @param string $name + * @param mixed $options * @param int $priority Priority at which to enqueue filter; defaults to 1000 (higher executes earlier) * @return FilterChain */ diff --git a/src/FilterPluginManager.php b/src/FilterPluginManager.php index 75e8077d..57f39e1e 100644 --- a/src/FilterPluginManager.php +++ b/src/FilterPluginManager.php @@ -26,7 +26,7 @@ class FilterPluginManager extends AbstractPluginManager { /** * Default set of filters - * + * * @var array */ protected $invokableClasses = array( @@ -87,8 +87,8 @@ class FilterPluginManager extends AbstractPluginManager * * Checks that the filter loaded is either a valid callback or an instance * of FilterInterface. - * - * @param mixed $plugin + * + * @param mixed $plugin * @return void * @throws Exception\RuntimeException if invalid */ diff --git a/src/StaticFilter.php b/src/StaticFilter.php index 57e05897..24305c45 100644 --- a/src/StaticFilter.php +++ b/src/StaticFilter.php @@ -23,8 +23,8 @@ class StaticFilter /** * Set plugin manager for resolving filter classes - * - * @param FilterPluginManager $manager + * + * @param FilterPluginManager $manager * @return void */ public static function setPluginManager(FilterPluginManager $manager = null) @@ -38,7 +38,7 @@ public static function setPluginManager(FilterPluginManager $manager = null) /** * Get plugin manager for loading filter classes - * + * * @return FilterPluginManager */ public static function getPluginManager() diff --git a/src/Word/CamelCaseToSeparator.php b/src/Word/CamelCaseToSeparator.php index 166dae24..cc7ee6d2 100644 --- a/src/Word/CamelCaseToSeparator.php +++ b/src/Word/CamelCaseToSeparator.php @@ -18,8 +18,8 @@ class CamelCaseToSeparator extends AbstractSeparator { /** * Defined by Zend\Filter\Filter - * - * @param string $value + * + * @param string $value * @return string */ public function filter($value) diff --git a/src/Word/DashToSeparator.php b/src/Word/DashToSeparator.php index 9274008b..caf53e0a 100644 --- a/src/Word/DashToSeparator.php +++ b/src/Word/DashToSeparator.php @@ -18,8 +18,8 @@ class DashToSeparator extends AbstractSeparator { /** * Defined by Zend\Filter\Filter - * - * @param string $value + * + * @param string $value * @return string */ public function filter($value) diff --git a/test/Compress/RarTest.php b/test/Compress/RarTest.php index d210d1f2..6c048c8e 100644 --- a/test/Compress/RarTest.php +++ b/test/Compress/RarTest.php @@ -203,19 +203,19 @@ public function testSettingCallback() $this->assertEquals($callback, $filter->getCallback()); } - + public function testSettingCallbackThrowsExceptionOnMissingCallback() { $filter = new RarCompression(); - + $this->setExpectedException('Zend\Filter\Exception\InvalidArgumentException', 'must be between'); $filter->compress('test.txt'); } - + public function testSettingCallbackThrowsExceptionOnInvalidCallback() { $filter = new RarCompression(); - + $this->setExpectedException('Zend\Filter\Exception\InvalidArgumentException', 'must be between'); $filter->setCallback('invalidCallback'); } diff --git a/test/CompressTest.php b/test/CompressTest.php index bfbe4f47..94497f91 100644 --- a/test/CompressTest.php +++ b/test/CompressTest.php @@ -193,9 +193,9 @@ public function testSetAdapter() $filter = new CompressFilter(); $this->assertEquals('Gz', $filter->getAdapterName()); - + $filter->setAdapter('\Zend\Filter\Boolean'); - + $this->setExpectedException('\Zend\Filter\Exception\InvalidArgumentException', 'does not implement'); $adapter = $filter->getAdapter(); } @@ -227,7 +227,7 @@ public function testDecompressArchive() public function testInvalidMethod() { $filter = new CompressFilter(); - + $this->setExpectedException('\Zend\Filter\Exception\BadMethodCallException', 'Unknown method'); $filter->invalidMethod(); } diff --git a/test/File/RenameTest.php b/test/File/RenameTest.php index fb9d4757..e28ebee1 100644 --- a/test/File/RenameTest.php +++ b/test/File/RenameTest.php @@ -358,7 +358,7 @@ public function testGetNewNameExceptionWithExistingFile() array('source' => $this->_oldFile, 'target' => $this->_newFile, 'overwrite' => false)), $filter->getFile()); - + $this->setExpectedException('\Zend\Filter\Exception\InvalidArgumentException', 'could not be renamed'); $this->assertEquals($this->_newFile, $filter->getNewName($this->_oldFile)); } diff --git a/test/HtmlEntitiesTest.php b/test/HtmlEntitiesTest.php index bfbb8513..2d49cb37 100644 --- a/test/HtmlEntitiesTest.php +++ b/test/HtmlEntitiesTest.php @@ -175,7 +175,7 @@ public function testQuoteStyleQuotesEncodeDouble() { $input = "A 'single' and " . '"double"'; $result = "A 'single' and "double""; - + $this->_filter->setQuoteStyle(ENT_COMPAT); $this->assertEquals($result, $this->_filter->filter($input)); } @@ -206,7 +206,7 @@ public function testCorrectsForEncodingMismatch() $string = file_get_contents(dirname(__FILE__) . '/_files/latin-1-text.txt'); - // restore_error_handler can emit an E_WARNING; let's ignore that, as + // restore_error_handler can emit an E_WARNING; let's ignore that, as // we want to test the returned value set_error_handler(array($this, 'errorHandler'), E_NOTICE | E_WARNING); $result = $this->_filter->filter($string); @@ -226,7 +226,7 @@ public function testStripsUnknownCharactersWhenEncodingMismatchDetected() $string = file_get_contents(dirname(__FILE__) . '/_files/latin-1-text.txt'); - // restore_error_handler can emit an E_WARNING; let's ignore that, as + // restore_error_handler can emit an E_WARNING; let's ignore that, as // we want to test the returned value set_error_handler(array($this, 'errorHandler'), E_NOTICE | E_WARNING); $result = $this->_filter->filter($string); @@ -246,7 +246,7 @@ public function testRaisesExceptionIfEncodingMismatchDetectedAndFinalStringIsEmp $string = file_get_contents(dirname(__FILE__) . '/_files/latin-1-dash-only.txt'); - // restore_error_handler can emit an E_WARNING; let's ignore that, as + // restore_error_handler can emit an E_WARNING; let's ignore that, as // we want to test the returned value // Also, explicit try, so that we don't mess up PHPUnit error handlers set_error_handler(array($this, 'errorHandler'), E_NOTICE | E_WARNING); diff --git a/test/NullTest.php b/test/NullTest.php index aa7dcd4b..cb658f20 100644 --- a/test/NullTest.php +++ b/test/NullTest.php @@ -35,7 +35,7 @@ public function testConstructorParams() $this->assertEquals(NullFilter::TYPE_INTEGER, $filter->getType()); } - + /** * @param mixed $value * @param bool $expected @@ -45,7 +45,7 @@ public function testDefault($value, $expected) { $filter = new NullFilter(); $this->assertSame($expected, $filter->filter($value)); - } + } /** * @param int $type diff --git a/test/PregReplaceTest.php b/test/PregReplaceTest.php index d5775f7c..38c6bc14 100644 --- a/test/PregReplaceTest.php +++ b/test/PregReplaceTest.php @@ -26,7 +26,7 @@ class PregReplaceTest extends \PHPUnit_Framework_TestCase * @var PregReplaceFilter */ protected $filter; - + public function setUp() { $this->filter = new PregReplaceFilter(); From 128be4b11a432e78c80ea2bd0e8b7639a9e1b3ed Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Wed, 25 Jul 2012 10:29:04 -0500 Subject: [PATCH 17/17] [zendframework/zf2#1984] Updated filter plugin manager - Replaced encrypt\mcrypt with encrypt\blockcipher --- src/FilterPluginManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FilterPluginManager.php b/src/FilterPluginManager.php index 57f39e1e..8c2d0cba 100644 --- a/src/FilterPluginManager.php +++ b/src/FilterPluginManager.php @@ -47,7 +47,7 @@ class FilterPluginManager extends AbstractPluginManager 'digits' => 'Zend\Filter\Digits', 'dir' => 'Zend\Filter\Dir', 'encrypt' => 'Zend\Filter\Encrypt', - 'encryptmcrypt' => 'Zend\Filter\Encrypt\Mcrypt', + 'encryptblockcipher' => 'Zend\Filter\Encrypt\BlockCipher', 'encryptopenssl' => 'Zend\Filter\Encrypt\Openssl', 'filedecrypt' => 'Zend\Filter\File\Decrypt', 'fileencrypt' => 'Zend\Filter\File\Encrypt',