diff --git a/src/BaseName.php b/src/BaseName.php index 6391286c..48807ca4 100644 --- a/src/BaseName.php +++ b/src/BaseName.php @@ -17,29 +17,17 @@ class BaseName extends AbstractFilter * Returns basename($value). * * If the value provided is non-scalar, the value will remain unfiltered - * and an E_USER_WARNING will be raised indicating it's unfilterable. * * @param string $value * @return string|mixed */ public function filter($value) { - if (null === $value) { - return null; - } - if (!is_scalar($value)) { - trigger_error( - sprintf( - '%s expects parameter to be scalar, "%s" given; cannot filter', - __METHOD__, - (is_object($value) ? get_class($value) : gettype($value)) - ), - E_USER_WARNING - ); return $value; } + $value = (string) $value; - return basename((string) $value); + return basename($value); } } diff --git a/src/Callback.php b/src/Callback.php index 3fbb00e6..51392e16 100644 --- a/src/Callback.php +++ b/src/Callback.php @@ -67,7 +67,7 @@ public function getCallback() /** * Sets parameters for the callback * - * @param mixed $params + * @param array $params * @return self */ public function setCallbackParams($params) diff --git a/src/Compress.php b/src/Compress.php index 4b04f925..f6a49e77 100644 --- a/src/Compress.php +++ b/src/Compress.php @@ -201,6 +201,10 @@ public function __call($method, $options) */ public function filter($value) { + if (!is_string($value)) { + return $value; + } + return $this->getAdapter()->compress($value); } } diff --git a/src/DateTimeFormatter.php b/src/DateTimeFormatter.php index 740da2d0..9b0065d6 100644 --- a/src/DateTimeFormatter.php +++ b/src/DateTimeFormatter.php @@ -41,13 +41,14 @@ public function __construct($options = null) public function setFormat($format) { $this->format = $format; + return $this; } /** * Filter a datetime string by normalizing it to the filters specified format * - * @param string $value + * @param DateTime|string|integer $value * @throws Exception\InvalidArgumentException * @return string */ @@ -60,6 +61,10 @@ public function filter($value) throw new Exception\InvalidArgumentException('Invalid date string provided', $e->getCode(), $e); } + if ($result === false) { + return $value; + } + return $result; } @@ -73,7 +78,14 @@ protected function normalizeDateTime($value) { if ($value === '' || $value === null) { return $value; - } elseif (is_int($value)) { + } + + if (!is_string($value) && !is_int($value) && !$value instanceof DateTime) { + return $value; + } + + if (is_int($value)) { + //timestamp $value = new DateTime('@' . $value); } elseif (!$value instanceof DateTime) { $value = new DateTime($value); diff --git a/src/Decompress.php b/src/Decompress.php index 9b821bf1..3489c70c 100644 --- a/src/Decompress.php +++ b/src/Decompress.php @@ -24,7 +24,7 @@ class Decompress extends Compress */ public function __invoke($value) { - return $this->getAdapter()->decompress($value); + return $this->filter($value); } /** @@ -37,6 +37,10 @@ public function __invoke($value) */ public function filter($value) { + if (!is_string($value) && $value !== null) { + return $value; + } + return $this->getAdapter()->decompress($value); } } diff --git a/src/Decrypt.php b/src/Decrypt.php index 360c479a..9c8e8492 100644 --- a/src/Decrypt.php +++ b/src/Decrypt.php @@ -24,6 +24,10 @@ class Decrypt extends Encrypt */ public function filter($value) { + if (!is_string($value)) { + return $value; + } + return $this->adapter->decrypt($value); } } diff --git a/src/Digits.php b/src/Digits.php index 325bb758..eea9b58a 100644 --- a/src/Digits.php +++ b/src/Digits.php @@ -19,28 +19,16 @@ class Digits extends AbstractFilter * Returns the string $value, removing all but digit characters * * If the value provided is non-scalar, the value will remain unfiltered - * and an E_USER_WARNING will be raised indicating it's unfilterable. * * @param string $value * @return string|mixed */ public function filter($value) { - if (null === $value) { - return null; - } - if (!is_scalar($value)) { - trigger_error( - sprintf( - '%s expects parameter to be scalar, "%s" given; cannot filter', - __METHOD__, - (is_object($value) ? get_class($value) : gettype($value)) - ), - E_USER_WARNING - ); return $value; } + $value = (string) $value; if (!StringUtils::hasPcreUnicodeSupport()) { // POSIX named classes are not supported, use alternative 0-9 match @@ -53,6 +41,6 @@ public function filter($value) $pattern = '/[\p{^N}]/'; } - return preg_replace($pattern, '', (string) $value); + return preg_replace($pattern, '', $value); } } diff --git a/src/Dir.php b/src/Dir.php index 16e580e7..58bdb77d 100644 --- a/src/Dir.php +++ b/src/Dir.php @@ -21,6 +21,11 @@ class Dir extends AbstractFilter */ public function filter($value) { - return dirname((string) $value); + if (!is_scalar($value)) { + return $value; + } + $value = (string) $value; + + return dirname($value); } } diff --git a/src/Encrypt.php b/src/Encrypt.php index 93dc87a1..adb13843 100644 --- a/src/Encrypt.php +++ b/src/Encrypt.php @@ -19,6 +19,8 @@ class Encrypt extends AbstractFilter { /** * Encryption adapter + * + * @param Encrypt\EncryptionAlgorithmInterface */ protected $adapter; @@ -38,6 +40,7 @@ public function __construct($options = null) /** * Returns the name of the set adapter + * @todo inconsitent: get adapter should return the adapter and not the name * * @return string */ @@ -117,6 +120,10 @@ public function __call($method, $options) */ public function filter($value) { + if (!is_string($value)) { + return $value; + } + return $this->adapter->encrypt($value); } } diff --git a/src/File/Decrypt.php b/src/File/Decrypt.php index c5970d53..4d84fc3b 100644 --- a/src/File/Decrypt.php +++ b/src/File/Decrypt.php @@ -58,13 +58,23 @@ public function setFilename($filename = null) */ public function filter($value) { + if (!is_scalar($value) && !is_array($value)) { + return $value; + } + // An uploaded file? Retrieve the 'tmp_name' - $isFileUpload = (is_array($value) && isset($value['tmp_name'])); - if ($isFileUpload) { + $isFileUpload = false; + if (is_array($value)) { + if (!isset($value['tmp_name'])) { + return $value; + } + + $isFileUpload = true; $uploadData = $value; $value = $value['tmp_name']; } + if (!file_exists($value)) { throw new Exception\InvalidArgumentException("File '$value' not found"); } diff --git a/src/File/Encrypt.php b/src/File/Encrypt.php index 44612611..9e32b4ce 100644 --- a/src/File/Encrypt.php +++ b/src/File/Encrypt.php @@ -58,9 +58,18 @@ public function setFilename($filename = null) */ public function filter($value) { + if (!is_scalar($value) && !is_array($value)) { + return $value; + } + // An uploaded file? Retrieve the 'tmp_name' - $isFileUpload = (is_array($value) && isset($value['tmp_name'])); - if ($isFileUpload) { + $isFileUpload = false; + if (is_array($value)) { + if (!isset($value['tmp_name'])) { + return $value; + } + + $isFileUpload = true; $uploadData = $value; $value = $value['tmp_name']; } diff --git a/src/File/LowerCase.php b/src/File/LowerCase.php index d903a51f..15d31482 100644 --- a/src/File/LowerCase.php +++ b/src/File/LowerCase.php @@ -26,9 +26,18 @@ class LowerCase extends StringToLower */ public function filter($value) { + if (!is_scalar($value) && !is_array($value)) { + return $value; + } + // An uploaded file? Retrieve the 'tmp_name' - $isFileUpload = (is_array($value) && isset($value['tmp_name'])); - if ($isFileUpload) { + $isFileUpload = false; + if (is_array($value)) { + if (!isset($value['tmp_name'])) { + return $value; + } + + $isFileUpload = true; $uploadData = $value; $value = $value['tmp_name']; } diff --git a/src/File/Rename.php b/src/File/Rename.php index 41e363ed..4ea75c6b 100644 --- a/src/File/Rename.php +++ b/src/File/Rename.php @@ -160,9 +160,18 @@ public function getNewName($value, $source = false) */ public function filter($value) { + if (!is_scalar($value) && !is_array($value)) { + return $value; + } + // An uploaded file? Retrieve the 'tmp_name' - $isFileUpload = (is_array($value) && isset($value['tmp_name'])); - if ($isFileUpload) { + $isFileUpload = false; + if (is_array($value)) { + if (!isset($value['tmp_name'])) { + return $value; + } + + $isFileUpload = true; $uploadData = $value; $value = $value['tmp_name']; } diff --git a/src/File/RenameUpload.php b/src/File/RenameUpload.php index 09d42ec9..89f50bf0 100644 --- a/src/File/RenameUpload.php +++ b/src/File/RenameUpload.php @@ -159,12 +159,21 @@ public function getRandomize() */ public function filter($value) { + if (!is_scalar($value) && !is_array($value)) { + return $value; + } + // An uploaded file? Retrieve the 'tmp_name' - $isFileUpload = (is_array($value) && isset($value['tmp_name'])); - if ($isFileUpload) { + $isFileUpload = false; + if (is_array($value)) { + if (!isset($value['tmp_name'])) { + return $value; + } + + $isFileUpload = true; $uploadData = $value; $sourceFile = $value['tmp_name']; - } else { + } else{ $uploadData = array( 'tmp_name' => $value, 'name' => $value, diff --git a/src/File/UpperCase.php b/src/File/UpperCase.php index dde7930d..22bf0927 100644 --- a/src/File/UpperCase.php +++ b/src/File/UpperCase.php @@ -26,9 +26,18 @@ class UpperCase extends StringToUpper */ public function filter($value) { + if (!is_scalar($value) && !is_array($value)) { + return $value; + } + // An uploaded file? Retrieve the 'tmp_name' - $isFileUpload = (is_array($value) && isset($value['tmp_name'])); - if ($isFileUpload) { + $isFileUpload = false; + if (is_array($value)) { + if (!isset($value['tmp_name'])) { + return $value; + } + + $isFileUpload = true; $uploadData = $value; $value = $value['tmp_name']; } diff --git a/src/HtmlEntities.php b/src/HtmlEntities.php index 2b249f20..4eddc4f3 100644 --- a/src/HtmlEntities.php +++ b/src/HtmlEntities.php @@ -174,7 +174,6 @@ public function setDoubleQuote($doubleQuote) * equivalents where they exist * * If the value provided is non-scalar, the value will remain unfiltered - * and an E_USER_WARNING will be raised indicating it's unfilterable. * * @param string $value * @return string|mixed @@ -182,29 +181,18 @@ public function setDoubleQuote($doubleQuote) */ public function filter($value) { - if (null === $value) { - return null; - } - if (!is_scalar($value)) { - trigger_error( - sprintf( - '%s expects parameter to be scalar, "%s" given; cannot filter', - __METHOD__, - (is_object($value) ? get_class($value) : gettype($value)) - ), - E_USER_WARNING - ); return $value; } + $value = (string) $value; - $filtered = htmlentities((string) $value, $this->getQuoteStyle(), $this->getEncoding(), $this->getDoubleQuote()); - if (strlen((string) $value) && !strlen($filtered)) { + $filtered = htmlentities($value, $this->getQuoteStyle(), $this->getEncoding(), $this->getDoubleQuote()); + if (strlen($value) && !strlen($filtered)) { if (!function_exists('iconv')) { throw new Exception\DomainException('Encoding mismatch has resulted in htmlentities errors'); } $enc = $this->getEncoding(); - $value = iconv('', $this->getEncoding() . '//IGNORE', (string) $value); + $value = iconv('', $this->getEncoding() . '//IGNORE', $value); $filtered = htmlentities($value, $this->getQuoteStyle(), $enc, $this->getDoubleQuote()); if (!strlen($filtered)) { throw new Exception\DomainException('Encoding mismatch has resulted in htmlentities errors'); diff --git a/src/Int.php b/src/Int.php index 12c10eee..0f2b80db 100644 --- a/src/Int.php +++ b/src/Int.php @@ -17,29 +17,17 @@ class Int extends AbstractFilter * Returns (int) $value * * If the value provided is non-scalar, the value will remain unfiltered - * and an E_USER_WARNING will be raised indicating it's unfilterable. * * @param string $value * @return int|mixed */ public function filter($value) { - if (null === $value) { - return null; - } - if (!is_scalar($value)) { - trigger_error( - sprintf( - '%s expects parameter to be scalar, "%s" given; cannot filter', - __METHOD__, - (is_object($value) ? get_class($value) : gettype($value)) - ), - E_USER_WARNING - ); return $value; } + $value = (string) $value; - return (int) ((string) $value); + return (int) $value; } } diff --git a/src/PregReplace.php b/src/PregReplace.php index 1bbbcf0a..91a59823 100644 --- a/src/PregReplace.php +++ b/src/PregReplace.php @@ -129,6 +129,10 @@ public function getReplacement() */ public function filter($value) { + if (!is_scalar($value) && !is_array($value)) { + return $value; + } + if ($this->options['pattern'] === null) { throw new Exception\RuntimeException(sprintf( 'Filter %s does not have a valid pattern set', diff --git a/src/RealPath.php b/src/RealPath.php index d90766d5..3af276e2 100644 --- a/src/RealPath.php +++ b/src/RealPath.php @@ -67,30 +67,17 @@ public function getExists() * Returns realpath($value) * * If the value provided is non-scalar, the value will remain unfiltered - * and an E_USER_WARNING will be raised indicating it's unfilterable. * * @param string $value * @return string|mixed */ public function filter($value) { - if (null === $value) { - return null; - } - - if (!is_scalar($value)) { - trigger_error( - sprintf( - '%s expects parameter to be scalar, "%s" given; cannot filter', - __METHOD__, - (is_object($value) ? get_class($value) : gettype($value)) - ), - E_USER_WARNING - ); + if(!is_string($value)){ return $value; } - $path = (string) $value; + if ($this->options['exists']) { return realpath($path); } diff --git a/src/StringToLower.php b/src/StringToLower.php index 1b162961..3d6f66a4 100644 --- a/src/StringToLower.php +++ b/src/StringToLower.php @@ -42,33 +42,21 @@ public function __construct($encodingOrOptions = null) * Returns the string $value, converting characters to lowercase as necessary * * If the value provided is non-scalar, the value will remain unfiltered - * and an E_USER_WARNING will be raised indicating it's unfilterable. * * @param string $value * @return string|mixed */ public function filter($value) { - if (null === $value) { - return null; - } - if (!is_scalar($value)) { - trigger_error( - sprintf( - '%s expects parameter to be scalar, "%s" given; cannot filter', - __METHOD__, - (is_object($value) ? get_class($value) : gettype($value)) - ), - E_USER_WARNING - ); return $value; } + $value = (string) $value; if ($this->options['encoding'] !== null) { - return mb_strtolower((string) $value, $this->options['encoding']); + return mb_strtolower($value, $this->options['encoding']); } - return strtolower((string) $value); + return strtolower($value); } } diff --git a/src/StringToUpper.php b/src/StringToUpper.php index 951a4f60..7f4c78e1 100644 --- a/src/StringToUpper.php +++ b/src/StringToUpper.php @@ -42,33 +42,21 @@ public function __construct($encodingOrOptions = null) * Returns the string $value, converting characters to uppercase as necessary * * If the value provided is non-scalar, the value will remain unfiltered - * and an E_USER_WARNING will be raised indicating it's unfilterable. * * @param string $value * @return string|mixed */ public function filter($value) { - if (null === $value) { - return null; - } - if (!is_scalar($value)) { - trigger_error( - sprintf( - '%s expects parameter to be scalar, "%s" given; cannot filter', - __METHOD__, - (is_object($value) ? get_class($value) : gettype($value)) - ), - E_USER_WARNING - ); return $value; } + $value = (string) $value; if ($this->options['encoding'] !== null) { - return mb_strtoupper((string) $value, $this->options['encoding']); + return mb_strtoupper($value, $this->options['encoding']); } - return strtoupper((string) $value); + return strtoupper($value); } } diff --git a/src/StringTrim.php b/src/StringTrim.php index db617266..b44d8a73 100644 --- a/src/StringTrim.php +++ b/src/StringTrim.php @@ -73,16 +73,16 @@ public function getCharList() */ public function filter($value) { - // Do not filter non-string values if (!is_string($value)) { return $value; } + $value = (string) $value; if (null === $this->options['charlist']) { - return $this->unicodeTrim((string) $value); + return $this->unicodeTrim($value); } - return $this->unicodeTrim((string) $value, $this->options['charlist']); + return $this->unicodeTrim($value, $this->options['charlist']); } /** diff --git a/src/StripNewlines.php b/src/StripNewlines.php index 0c8a922e..7ce57202 100644 --- a/src/StripNewlines.php +++ b/src/StripNewlines.php @@ -17,11 +17,14 @@ class StripNewlines extends AbstractFilter * * Returns $value without newline control characters * - * @param string $value - * @return string + * @param string|array $value + * @return string|array */ public function filter($value) { + if (!is_scalar($value) && !is_array($value)) { + return $value; + } return str_replace(array("\n", "\r"), '', $value); } } diff --git a/src/StripTags.php b/src/StripTags.php index b875c074..185e7d23 100644 --- a/src/StripTags.php +++ b/src/StripTags.php @@ -167,7 +167,6 @@ public function setAttributesAllowed($attributesAllowed) * Defined by Zend\Filter\FilterInterface * * If the value provided is non-scalar, the value will remain unfiltered - * and an E_USER_WARNING will be raised indicating it's unfilterable. * * @todo improve docblock descriptions * @param string $value @@ -175,22 +174,9 @@ public function setAttributesAllowed($attributesAllowed) */ public function filter($value) { - if (null === $value) { - return null; - } - if (!is_scalar($value)) { - trigger_error( - sprintf( - '%s expects parameter to be scalar, "%s" given; cannot filter', - __METHOD__, - (is_object($value) ? get_class($value) : gettype($value)) - ), - E_USER_WARNING - ); return $value; } - $value = (string) $value; // Strip HTML comments first diff --git a/src/UriNormalize.php b/src/UriNormalize.php index 6dfe5840..b7e9bba1 100644 --- a/src/UriNormalize.php +++ b/src/UriNormalize.php @@ -84,6 +84,11 @@ public function setEnforcedScheme($enforcedScheme) */ public function filter($value) { + if (!is_scalar($value)) { + return $value; + } + $value = (string) $value; + $defaultScheme = $this->defaultScheme ?: $this->enforcedScheme; // Reset default scheme if it is not a known scheme diff --git a/src/Word/CamelCaseToSeparator.php b/src/Word/CamelCaseToSeparator.php index f50c88e3..0a06586b 100644 --- a/src/Word/CamelCaseToSeparator.php +++ b/src/Word/CamelCaseToSeparator.php @@ -16,11 +16,15 @@ class CamelCaseToSeparator extends AbstractSeparator /** * Defined by Zend\Filter\Filter * - * @param string $value - * @return string + * @param string|array $value + * @return string|array */ public function filter($value) { + if (!is_scalar($value) && !is_array($value)) { + return $value; + } + if (StringUtils::hasPcreUnicodeSupport()) { $pattern = array('#(?<=(?:\p{Lu}))(\p{Lu}\p{Ll})#', '#(?<=(?:\p{Ll}|\p{Nd}))(\p{Lu})#'); $replacement = array($this->separator . '\1', $this->separator . '\1'); diff --git a/src/Word/DashToSeparator.php b/src/Word/DashToSeparator.php index 1fd43470..086aaa2b 100644 --- a/src/Word/DashToSeparator.php +++ b/src/Word/DashToSeparator.php @@ -14,11 +14,15 @@ class DashToSeparator extends AbstractSeparator /** * Defined by Zend\Filter\Filter * - * @param string $value - * @return string + * @param string|array $value + * @return string|array */ public function filter($value) { + if (!is_scalar($value) && !is_array($value)) { + return $value; + } + return preg_replace('#-#', $this->separator, $value); } } diff --git a/src/Word/SeparatorToCamelCase.php b/src/Word/SeparatorToCamelCase.php index ce63cf31..2804570b 100644 --- a/src/Word/SeparatorToCamelCase.php +++ b/src/Word/SeparatorToCamelCase.php @@ -16,11 +16,15 @@ class SeparatorToCamelCase extends AbstractSeparator /** * Defined by Zend\Filter\Filter * - * @param string $value - * @return string + * @param string|array $value + * @return string|array */ public function filter($value) { + if (!is_scalar($value) && !is_array($value)) { + return $value; + } + // a unicode safe way of converting characters to \x00\x00 notation $pregQuotedSeparator = preg_quote($this->separator, '#'); diff --git a/src/Word/SeparatorToSeparator.php b/src/Word/SeparatorToSeparator.php index 90e465b4..ed5b50f7 100644 --- a/src/Word/SeparatorToSeparator.php +++ b/src/Word/SeparatorToSeparator.php @@ -78,11 +78,15 @@ public function getReplacementSeparator() * * Returns the string $value, replacing the searched separators with the defined ones * - * @param string $value - * @return string + * @param string|array $value + * @return string|array */ public function filter($value) { + if (!is_scalar($value) && !is_array($value)) { + return $value; + } + if ($this->searchSeparator == null) { throw new Exception\RuntimeException('You must provide a search separator for this filter to work.'); } diff --git a/test/BaseNameTest.php b/test/BaseNameTest.php index 69cca754..6c4b7702 100644 --- a/test/BaseNameTest.php +++ b/test/BaseNameTest.php @@ -6,17 +6,17 @@ * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ - namespace ZendTest\Filter; use Zend\Filter\BaseName as BaseNameFilter; use Zend\Stdlib\ErrorHandler; /** - * @group Zend_Filter + * @group Zend_Filter */ class BaseNameTest extends \PHPUnit_Framework_TestCase { + /** * Ensures that the filter follows expected behavior * @@ -26,40 +26,34 @@ public function testBasic() { $filter = new BaseNameFilter(); $valuesExpected = array( - '/path/to/filename' => 'filename', + '/path/to/filename' => 'filename', '/path/to/filename.ext' => 'filename.ext' - ); + ); foreach ($valuesExpected as $input => $output) { $this->assertEquals($output, $filter($input)); } } - /** - * Ensures that a warning is raised if array is used - * - * @return void - */ - public function testWarningIsRaisedIfArrayUsed() + public function returnUnfilteredDataProvider() { - $filter = new BaseNameFilter(); - $input = array('/path/to/filename', '/path/to/filename.ext'); - - ErrorHandler::start(E_USER_WARNING); - $filtered = $filter->filter($input); - $err = ErrorHandler::stop(); - - $this->assertEquals($input, $filtered); - $this->assertInstanceOf('ErrorException', $err); - $this->assertContains('cannot filter', $err->getMessage()); + return array( + array(null), + array(new \stdClass()), + array(array( + '/path/to/filename', + '/path/to/filename.ext' + )) + ); } /** + * @dataProvider returnUnfilteredDataProvider * @return void */ - public function testReturnsNullIfNullIsUsed() + public function testReturnUnfiltered($input) { - $filter = new BaseNameFilter(); - $filtered = $filter->filter(null); - $this->assertNull($filtered); + $filter = new BaseNameFilter(); + + $this->assertEquals($input, $filter($input)); } } diff --git a/test/CompressTest.php b/test/CompressTest.php index 8b7afee0..8bb333cf 100644 --- a/test/CompressTest.php +++ b/test/CompressTest.php @@ -227,4 +227,27 @@ public function testInvalidMethod() $this->setExpectedException('\Zend\Filter\Exception\BadMethodCallException', 'Unknown method'); $filter->invalidMethod(); } + + public function returnUnfilteredDataProvider() + { + return array( + array(null), + array(new \stdClass()), + array(array( + 'compress me', + 'compress me too, please' + )) + ); + } + + /** + * @dataProvider returnUnfilteredDataProvider + * @return void + */ + public function testReturnUnfiltered($input) + { + $filter = new CompressFilter('bz2'); + + $this->assertEquals($input, $filter($input)); + } } diff --git a/test/DateTimeFormatterTest.php b/test/DateTimeFormatterTest.php index fcd53741..eefd6993 100644 --- a/test/DateTimeFormatterTest.php +++ b/test/DateTimeFormatterTest.php @@ -9,8 +9,8 @@ namespace ZendTest\Filter; -use DateTime; use Zend\Filter\DateTimeFormatter; +use DateTime; /** * @group Zend_Filter @@ -29,20 +29,31 @@ public function tearDown() date_default_timezone_set($this->defaultTimezone); } - public function testFormatterDoesNotFormatAnEmptyString() + public function returnUnfilteredDataProvider() { - date_default_timezone_set('UTC'); - - $filter = new DateTimeFormatter(); - $result = $filter->filter(''); - $this->assertEquals('', $result); + return array( + array(null), + array(''), + array(new \stdClass()), + array(array( + '1', + -1 + )), + array(0.53) + ); } - public function testFormatterDoesNotFormatNull() + /** + * @dataProvider returnUnfilteredDataProvider + * @return void + */ + public function testReturnUnfiltered($input) { + date_default_timezone_set('UTC'); + $filter = new DateTimeFormatter(); - $result = $filter->filter(null); - $this->assertEquals(null, $result); + + $this->assertEquals($input, $filter($input)); } public function testFormatterFormatsZero() diff --git a/test/DecompressTest.php b/test/DecompressTest.php index 73d7a213..dba1bbdd 100644 --- a/test/DecompressTest.php +++ b/test/DecompressTest.php @@ -107,4 +107,27 @@ public function testFilterMethodProxiesToDecompress() $content2 = $filter2->filter($archive); $this->assertEquals('compress me', $content2); } + + public function returnUnfilteredDataProvider() + { + return array( + array(null), + array(new \stdClass()), + array(array( + 'decompress me', + 'decompress me too, please' + )) + ); + } + + /** + * @dataProvider returnUnfilteredDataProvider + * @return void + */ + public function testReturnUnfiltered($input) + { + $filter = new DecompressFilter('bz2'); + + $this->assertEquals($input, $filter($input)); + } } diff --git a/test/DecryptTest.php b/test/DecryptTest.php index bf16d2aa..d48c488c 100644 --- a/test/DecryptTest.php +++ b/test/DecryptTest.php @@ -137,6 +137,35 @@ public function testCallingUnknownMethod() $filter = new DecryptFilter(); $filter->getUnknownMethod(); } + + public function returnUnfilteredDataProvider() + { + return array( + array(null), + array(new \stdClass()), + array(array( + 'ec133eb7460682b0020b736ad6d2ef14c35de0f1e5976330ae1dd096ef3b4cb7MTIzNDU2Nzg5MDEyMzQ1NoZvxY1JkeL6TnQP3ug5F0k=', + 'decrypt me too, please' + )) + ); + } + + /** + * @dataProvider returnUnfilteredDataProvider + * @return void + */ + public function testReturnUnfiltered($input) + { + if (!extension_loaded('mcrypt')) { + $this->markTestSkipped('Mcrypt extension not installed'); + } + + $decrypt = new DecryptFilter(array('adapter' => 'BlockCipher', 'key' => 'testkey')); + $decrypt->setVector('1234567890123456890'); + + $decrypted = $decrypt->filter($input); + $this->assertEquals($input, $decrypted); + } } class TestAdapter diff --git a/test/DigitsTest.php b/test/DigitsTest.php index 0e094040..99c0306e 100644 --- a/test/DigitsTest.php +++ b/test/DigitsTest.php @@ -83,32 +83,26 @@ public function testBasic() } } - /** - * Ensures that an error is raised if array is used - * - * @return void - */ - public function testWarningIsRaisedIfArrayUsed() + public function returnUnfilteredDataProvider() { - $filter = new DigitsFilter(); - $input = array('abc123', 'abc 123'); - - ErrorHandler::start(E_USER_WARNING); - $filtered = $filter->filter($input); - $err = ErrorHandler::stop(); - - $this->assertEquals($input, $filtered); - $this->assertInstanceOf('ErrorException', $err); - $this->assertContains('cannot filter', $err->getMessage()); + return array( + array(null), + array(new \stdClass()), + array(array( + 'abc123', + 'abc 123' + )) + ); } /** + * @dataProvider returnUnfilteredDataProvider * @return void */ - public function testReturnsNullIfNullIsUsed() + public function testReturnUnfiltered($input) { - $filter = new DigitsFilter(); - $filtered = $filter->filter(null); - $this->assertNull($filtered); + $filter = new DigitsFilter(); + + $this->assertEquals($input, $filter($input)); } } diff --git a/test/DirTest.php b/test/DirTest.php index 818660ad..c2583ec9 100644 --- a/test/DirTest.php +++ b/test/DirTest.php @@ -33,4 +33,27 @@ public function testBasic() $this->assertEquals($output, $filter($input)); } } + + public function returnUnfilteredDataProvider() + { + return array( + array(null), + array(new \stdClass()), + array(array( + '/path/to/filename', + '/path/to/filename.ext' + )) + ); + } + + /** + * @dataProvider returnUnfilteredDataProvider + * @return void + */ + public function testReturnUnfiltered($input) + { + $filter = new DirFilter(); + + $this->assertEquals($input, $filter($input)); + } } diff --git a/test/EncryptTest.php b/test/EncryptTest.php index 5d736ef2..30d656d4 100644 --- a/test/EncryptTest.php +++ b/test/EncryptTest.php @@ -143,6 +143,35 @@ public function testCallingUnknownMethod() $filter = new EncryptFilter(); $filter->getUnknownMethod(); } + + public function returnUnfilteredDataProvider() + { + return array( + array(null), + array(new \stdClass()), + array(array( + 'encrypt me', + 'encrypt me too, please' + )) + ); + } + + /** + * @dataProvider returnUnfilteredDataProvider + * @return void + */ + public function testReturnUnfiltered($input) + { + if (!extension_loaded('mcrypt')) { + $this->markTestSkipped('Mcrypt extension not installed'); + } + + $encrypt = new EncryptFilter(array('adapter' => 'BlockCipher', 'key' => 'testkey')); + $encrypt->setVector('1234567890123456890'); + + $encrypted = $encrypt->filter($input); + $this->assertEquals($input, $encrypted); + } } class TestAdapter2 diff --git a/test/File/DecryptTest.php b/test/File/DecryptTest.php index 31f8fda6..d6411967 100644 --- a/test/File/DecryptTest.php +++ b/test/File/DecryptTest.php @@ -115,4 +115,28 @@ public function testNonExistingFile() $this->setExpectedException('\Zend\Filter\Exception\InvalidArgumentException', 'not found'); $filter->filter(dirname(__DIR__).'/_files/nofile.txt'); } + + public function returnUnfilteredDataProvider() + { + return array( + array(null), + array(new \stdClass()), + array(array( + dirname(__DIR__).'/_files/nofile.txt', + dirname(__DIR__).'/_files/nofile2.txt' + )) + ); + } + + /** + * @dataProvider returnUnfilteredDataProvider + * @return void + */ + public function testReturnUnfiltered($input) + { + $filter = new FileDecrypt(); + $filter->setKey('1234567890123456'); + + $this->assertEquals($input, $filter($input)); + } } diff --git a/test/File/EncryptTest.php b/test/File/EncryptTest.php index 4b20a03d..5105318f 100644 --- a/test/File/EncryptTest.php +++ b/test/File/EncryptTest.php @@ -6,32 +6,32 @@ * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ - namespace ZendTest\Filter\File; use Zend\Filter\File\Encrypt as FileEncrypt; use Zend\Filter\File\Decrypt as FileDecrypt; /** - * @group Zend_Filter + * @group Zend_Filter */ class EncryptTest extends \PHPUnit_Framework_TestCase { + public function setUp() { - if (!extension_loaded('mcrypt')) { + if (! extension_loaded('mcrypt')) { $this->markTestSkipped('This filter needs the mcrypt extension'); } - if (file_exists(dirname(__DIR__).'/_files/newencryption.txt')) { - unlink(dirname(__DIR__).'/_files/newencryption.txt'); + if (file_exists(dirname(__DIR__) . '/_files/newencryption.txt')) { + unlink(dirname(__DIR__) . '/_files/newencryption.txt'); } } public function tearDown() { - if (file_exists(dirname(__DIR__).'/_files/newencryption.txt')) { - unlink(dirname(__DIR__).'/_files/newencryption.txt'); + if (file_exists(dirname(__DIR__) . '/_files/newencryption.txt')) { + unlink(dirname(__DIR__) . '/_files/newencryption.txt'); } } @@ -43,48 +43,37 @@ public function tearDown() public function testBasic() { $filter = new FileEncrypt(); - $filter->setFilename(dirname(__DIR__).'/_files/newencryption.txt'); + $filter->setFilename(dirname(__DIR__) . '/_files/newencryption.txt'); - $this->assertEquals( - dirname(__DIR__).'/_files/newencryption.txt', - $filter->getFilename()); + $this->assertEquals(dirname(__DIR__) . '/_files/newencryption.txt', $filter->getFilename()); $filter->setKey('1234567890123456'); - $this->assertEquals(dirname(__DIR__).'/_files/newencryption.txt', - $filter->filter(dirname(__DIR__).'/_files/encryption.txt')); + $this->assertEquals(dirname(__DIR__) . '/_files/newencryption.txt', $filter->filter(dirname(__DIR__) . '/_files/encryption.txt')); - $this->assertEquals( - 'Encryption', - file_get_contents(dirname(__DIR__).'/_files/encryption.txt')); + $this->assertEquals('Encryption', file_get_contents(dirname(__DIR__) . '/_files/encryption.txt')); - $this->assertNotEquals( - 'Encryption', - file_get_contents(dirname(__DIR__).'/_files/newencryption.txt')); + $this->assertNotEquals('Encryption', file_get_contents(dirname(__DIR__) . '/_files/newencryption.txt')); } public function testEncryptionWithDecryption() { $filter = new FileEncrypt(); - $filter->setFilename(dirname(__DIR__).'/_files/newencryption.txt'); + $filter->setFilename(dirname(__DIR__) . '/_files/newencryption.txt'); $filter->setKey('1234567890123456'); - $this->assertEquals(dirname(__DIR__).'/_files/newencryption.txt', - $filter->filter(dirname(__DIR__).'/_files/encryption.txt')); + $this->assertEquals(dirname(__DIR__) . '/_files/newencryption.txt', $filter->filter(dirname(__DIR__) . '/_files/encryption.txt')); - $this->assertNotEquals( - 'Encryption', - file_get_contents(dirname(__DIR__).'/_files/newencryption.txt')); + $this->assertNotEquals('Encryption', file_get_contents(dirname(__DIR__) . '/_files/newencryption.txt')); $filter = new FileDecrypt(); $filter->setKey('1234567890123456'); - $input = $filter->filter(dirname(__DIR__).'/_files/newencryption.txt'); - $this->assertEquals(dirname(__DIR__).'/_files/newencryption.txt', $input); + $input = $filter->filter(dirname(__DIR__) . '/_files/newencryption.txt'); + $this->assertEquals(dirname(__DIR__) . '/_files/newencryption.txt', $input); - $this->assertEquals( - 'Encryption', - trim(file_get_contents(dirname(__DIR__).'/_files/newencryption.txt'))); + $this->assertEquals('Encryption', trim(file_get_contents(dirname(__DIR__) . '/_files/newencryption.txt'))); } /** + * * @return void */ public function testNonExistingFile() @@ -93,10 +82,11 @@ public function testNonExistingFile() $filter->setKey('1234567890123456'); $this->setExpectedException('\Zend\Filter\Exception\InvalidArgumentException', 'not found'); - echo $filter->filter(dirname(__DIR__).'/_files/nofile.txt'); + echo $filter->filter(dirname(__DIR__) . '/_files/nofile.txt'); } /** + * * @return void */ public function testEncryptionInSameFile() @@ -104,11 +94,33 @@ public function testEncryptionInSameFile() $filter = new FileEncrypt(); $filter->setKey('1234567890123456'); - copy(dirname(__DIR__).'/_files/encryption.txt', dirname(__DIR__).'/_files/newencryption.txt'); - $filter->filter(dirname(__DIR__).'/_files/newencryption.txt'); + copy(dirname(__DIR__) . '/_files/encryption.txt', dirname(__DIR__) . '/_files/newencryption.txt'); + $filter->filter(dirname(__DIR__) . '/_files/newencryption.txt'); + + $this->assertNotEquals('Encryption', trim(file_get_contents(dirname(__DIR__) . '/_files/newencryption.txt'))); + } + + public function returnUnfilteredDataProvider() + { + return array( + array(null), + array(new \stdClass()), + array(array( + dirname(__DIR__) . '/_files/nofile.txt', + dirname(__DIR__) . '/_files/nofile2.txt' + )) + ); + } + + /** + * @dataProvider returnUnfilteredDataProvider + * @return void + */ + public function testReturnUnfiltered($input) + { + $filter = new FileEncrypt(); + $filter->setKey('1234567890123456'); - $this->assertNotEquals( - 'Encryption', - trim(file_get_contents(dirname(__DIR__).'/_files/newencryption.txt'))); + $this->assertEquals($input, $filter($input)); } } diff --git a/test/File/LowerCaseTest.php b/test/File/LowerCaseTest.php index 5f12489e..04470e3b 100644 --- a/test/File/LowerCaseTest.php +++ b/test/File/LowerCaseTest.php @@ -127,4 +127,27 @@ public function testCheckSettingOfEncodingWithMethod() $this->assertContains('mbstring is required', $e->getMessage()); } } + + public function returnUnfilteredDataProvider() + { + return array( + array(null), + array(new \stdClass()), + array(array( + dirname(__DIR__).'/_files/nofile.txt', + dirname(__DIR__).'/_files/nofile2.txt' + )) + ); + } + + /** + * @dataProvider returnUnfilteredDataProvider + * @return void + */ + public function testReturnUnfiltered($input) + { + $filter = new FileLowerCase(); + + $this->assertEquals($input, $filter($input)); + } } diff --git a/test/File/RenameTest.php b/test/File/RenameTest.php index e2e9737d..36586924 100644 --- a/test/File/RenameTest.php +++ b/test/File/RenameTest.php @@ -557,4 +557,27 @@ public function testInvalidConstruction() $this->setExpectedException('\Zend\Filter\Exception\InvalidArgumentException', 'Invalid options'); $filter = new FileRename(1234); } + + public function returnUnfilteredDataProvider() + { + return array( + array(null), + array(new \stdClass()), + array(array( + $this->_oldFile, + $this->_origFile + )) + ); + } + + /** + * @dataProvider returnUnfilteredDataProvider + * @return void + */ + public function testReturnUnfiltered($input) + { + $filter = new FileRename($this->_newFile); + + $this->assertEquals($input, $filter($input)); + } } diff --git a/test/File/RenameUploadTest.php b/test/File/RenameUploadTest.php index 8ee410e4..73bad799 100644 --- a/test/File/RenameUploadTest.php +++ b/test/File/RenameUploadTest.php @@ -329,4 +329,31 @@ public function testCanFilterMultipleTimesWithSameResult() $this->assertSame($firstResult, $secondResult); } + + + public function returnUnfilteredDataProvider() + { + return array( + array(null), + array(new \stdClass()), + array(array( + $this->_oldFile, + 'something invalid' + )) + ); + } + + /** + * @dataProvider returnUnfilteredDataProvider + * @return void + */ + public function testReturnUnfiltered($input) + { + $filter = new RenameUploadMock(array( + 'target' => $this->_newFile, + 'randomize' => true, + )); + + $this->assertEquals($input, $filter($input)); + } } diff --git a/test/File/UpperCaseTest.php b/test/File/UpperCaseTest.php index 5ea82a61..fefcb904 100644 --- a/test/File/UpperCaseTest.php +++ b/test/File/UpperCaseTest.php @@ -127,4 +127,28 @@ public function testCheckSettingOfEncodingWithMethod() $this->assertContains('mbstring is required', $e->getMessage()); } } + + public function returnUnfilteredDataProvider() + { + return array( + array(null), + array(new \stdClass()), + array(array( + $this->_newFile, + 'something invalid' + )) + ); + } + + /** + * @dataProvider returnUnfilteredDataProvider + * @return void + */ + public function testReturnUnfiltered($input) + { + $filter = new FileUpperCase(); + $filter->setEncoding('ISO-8859-1'); + + $this->assertEquals($input, $filter($input)); + } } diff --git a/test/HtmlEntitiesTest.php b/test/HtmlEntitiesTest.php index 99d40e3f..e82f740a 100644 --- a/test/HtmlEntitiesTest.php +++ b/test/HtmlEntitiesTest.php @@ -255,31 +255,25 @@ public function testRaisesExceptionIfEncodingMismatchDetectedAndFinalStringIsEmp } } - /** - * Ensures that a warning is raised if array is used - * - * @return void - */ - public function testWarningIsRaisedIfArrayUsed() + public function returnUnfilteredDataProvider() { - $input = array('<', '>'); - - ErrorHandler::start(E_USER_WARNING); - $filtered = $this->_filter->filter($input); - $err = ErrorHandler::stop(); - - $this->assertEquals($input, $filtered); - $this->assertInstanceOf('ErrorException', $err); - $this->assertContains('cannot filter', $err->getMessage()); + return array( + array(null), + array(new \stdClass()), + array(array( + '<', + '>' + )) + ); } /** + * @dataProvider returnUnfilteredDataProvider * @return void */ - public function testReturnsNullIfNullIsUsed() + public function testReturnUnfiltered($input) { - $filtered = $this->_filter->filter(null); - $this->assertNull($filtered); + $this->assertEquals($input, $this->_filter->filter($input)); } /** diff --git a/test/IntTest.php b/test/IntTest.php index c4c7276a..3b4f4239 100644 --- a/test/IntTest.php +++ b/test/IntTest.php @@ -25,6 +25,7 @@ class IntTest extends \PHPUnit_Framework_TestCase public function testBasic() { $filter = new IntFilter(); + $valuesExpected = array( 'string' => 0, '1' => 1, @@ -39,32 +40,26 @@ public function testBasic() } } - /** - * Ensures that a warning is raised if array is used - * - * @return void - */ - public function testWarningIsRaisedIfArrayUsed() + public function returnUnfilteredDataProvider() { - $filter = new IntFilter(); - $input = array('123 test', '456 test'); - - ErrorHandler::start(E_USER_WARNING); - $filtered = $filter->filter($input); - $err = ErrorHandler::stop(); - - $this->assertEquals($input, $filtered); - $this->assertInstanceOf('ErrorException', $err); - $this->assertContains('cannot filter', $err->getMessage()); + return array( + array(null), + array(new \stdClass()), + array(array( + '1', + -1 + )) + ); } /** + * @dataProvider returnUnfilteredDataProvider * @return void */ - public function testReturnsNullIfNullIsUsed() + public function testReturnUnfiltered($input) { - $filter = new IntFilter(); - $filtered = $filter->filter(null); - $this->assertNull($filtered); + $filter = new IntFilter(); + + $this->assertEquals($input, $filter($input)); } } diff --git a/test/PregReplaceTest.php b/test/PregReplaceTest.php index 87d41663..e3eaff19 100644 --- a/test/PregReplaceTest.php +++ b/test/PregReplaceTest.php @@ -6,7 +6,6 @@ * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ - namespace ZendTest\Filter; use Zend\Filter\PregReplace as PregReplaceFilter; @@ -14,11 +13,13 @@ /** * Test class for Zend_Filter_PregReplace. * - * @group Zend_Filter + * @group Zend_Filter */ class PregReplaceTest extends \PHPUnit_Framework_TestCase { + /** + * * @var PregReplaceFilter */ protected $filter; @@ -37,14 +38,14 @@ public function testDetectsPcreUnicodeSupport() public function testPassingPatternToConstructorSetsPattern() { $pattern = '#^controller/(?P[a-z_-]+)#'; - $filter = new PregReplaceFilter($pattern); + $filter = new PregReplaceFilter($pattern); $this->assertEquals($pattern, $filter->getPattern()); } public function testPassingReplacementToConstructorSetsReplacement() { $replace = 'foo/bar'; - $filter = new PregReplaceFilter(null, $replace); + $filter = new PregReplaceFilter(null, $replace); $this->assertEquals($replace, $filter->getReplacement()); } @@ -76,21 +77,38 @@ public function testReplacementAccessorsWork() public function testFilterPerformsRegexReplacement() { $filter = $this->filter; + $filter->setPattern('#^controller/(?P[a-z_-]+)#')->setReplacement('foo/bar'); + $string = 'controller/action'; - $filter->setPattern('#^controller/(?P[a-z_-]+)#') - ->setReplacement('foo/bar'); $filtered = $filter($string); $this->assertNotEquals($string, $filtered); $this->assertEquals('foo/bar', $filtered); } + public function testFilterPerformsRegexReplacementWithArray() + { + $filter = $this->filter; + $filter->setPattern('#^controller/(?P[a-z_-]+)#')->setReplacement('foo/bar'); + + $input = array( + 'controller/action', + 'This should stay the same' + ); + + $filtered = $filter($input); + $this->assertNotEquals($input, $filtered); + $this->assertEquals(array( + 'foo/bar', + 'This should stay the same' + ), $filtered); + } + public function testFilterThrowsExceptionWhenNoMatchPatternPresent() { $filter = $this->filter; $string = 'controller/action'; $filter->setReplacement('foo/bar'); - $this->setExpectedException('Zend\Filter\Exception\RuntimeException', - 'does not have a valid pattern set'); + $this->setExpectedException('Zend\Filter\Exception\RuntimeException', 'does not have a valid pattern set'); $filtered = $filter($string); } @@ -100,4 +118,24 @@ public function testPassingPatternWithExecModifierRaisesException() $this->setExpectedException('Zend\Filter\Exception\InvalidArgumentException', '"e" pattern modifier'); $filter->setPattern('/foo/e'); } + + public function returnUnfilteredDataProvider() + { + return array( + array(null), + array(new \stdClass()) + ); + } + + /** + * @dataProvider returnUnfilteredDataProvider + * @return void + */ + public function testReturnUnfiltered($input) + { + $filter = $this->filter; + $filter->setPattern('#^controller/(?P[a-z_-]+)#')->setReplacement('foo/bar'); + + $this->assertEquals($input, $filter->filter($input)); + } } diff --git a/test/RealPathTest.php b/test/RealPathTest.php index 350940e7..8aac168a 100644 --- a/test/RealPathTest.php +++ b/test/RealPathTest.php @@ -104,34 +104,26 @@ public function testNonExistantPath() $this->assertEquals($path, $filter($path3)); } - /** - * Ensures that a warning is raised if array is used - * - * @return void - */ - public function testWarningIsRaisedIfArrayUsed() + public function returnUnfilteredDataProvider() { - $filter = $this->_filter; - $input = array( - $this->_filesPath . DIRECTORY_SEPARATOR . 'file.1', - $this->_filesPath . DIRECTORY_SEPARATOR . 'file.2' + return array( + array(null), + array(new \stdClass()), + array( + array( + $this->_filesPath . DIRECTORY_SEPARATOR . 'file.1', + $this->_filesPath . DIRECTORY_SEPARATOR . 'file.2' + ) + ) ); - - ErrorHandler::start(E_USER_WARNING); - $filtered = $filter->filter($input); - $err = ErrorHandler::stop(); - - $this->assertEquals($input, $filtered); - $this->assertInstanceOf('ErrorException', $err); - $this->assertContains('cannot filter', $err->getMessage()); } /** + * @dataProvider returnUnfilteredDataProvider * @return void */ - public function testReturnsNullIfNullIsUsed() + public function testReturnUnfiltered($input) { - $filtered = $this->_filter->filter(null); - $this->assertNull($filtered); + $this->assertEquals($input, $this->_filter->filter($input)); } } diff --git a/test/StringToLowerTest.php b/test/StringToLowerTest.php index 80487817..8582c1e4 100644 --- a/test/StringToLowerTest.php +++ b/test/StringToLowerTest.php @@ -156,30 +156,26 @@ public function testDetectMbInternalEncoding() $this->assertEquals(mb_internal_encoding(), $this->_filter->getEncoding()); } - /** - * Ensures that a warning is raised if array is used - * - * @return void - */ - public function testWarningIsRaisedIfArrayUsed() + public function returnUnfilteredDataProvider() { - $input = array('ABC', 'DEF'); - - ErrorHandler::start(E_USER_WARNING); - $filtered = $this->_filter->filter($input); - $err = ErrorHandler::stop(); - - $this->assertEquals($input, $filtered); - $this->assertInstanceOf('ErrorException', $err); - $this->assertContains('cannot filter', $err->getMessage()); + return array( + array(null), + array(new \stdClass()), + array( + array( + 'UPPER CASE WRITTEN', + 'This should stay the same' + ) + ) + ); } /** + * @dataProvider returnUnfilteredDataProvider * @return void */ - public function testReturnsNullIfNullIsUsed() + public function testReturnUnfiltered($input) { - $filtered = $this->_filter->filter(null); - $this->assertNull($filtered); + $this->assertEquals($input, $this->_filter->filter($input)); } } diff --git a/test/StringToUpperTest.php b/test/StringToUpperTest.php index 95deba81..f4171e66 100644 --- a/test/StringToUpperTest.php +++ b/test/StringToUpperTest.php @@ -156,30 +156,24 @@ public function testDetectMbInternalEncoding() $this->assertEquals(mb_internal_encoding(), $this->_filter->getEncoding()); } - /** - * Ensures that a warning is raised if array is used - * - * @return void - */ - public function testWarningIsRaisedIfArrayUsed() + public function returnUnfilteredDataProvider() { - $input = array('abc', 'def'); - - ErrorHandler::start(E_USER_WARNING); - $filtered = $this->_filter->filter($input); - $err = ErrorHandler::stop(); - - $this->assertEquals($input, $filtered); - $this->assertInstanceOf('ErrorException', $err); - $this->assertContains('cannot filter', $err->getMessage()); + return array( + array(null), + array(new \stdClass()), + array(array( + 'lower case written', + 'This should stay the same' + )) + ); } /** + * @dataProvider returnUnfilteredDataProvider * @return void */ - public function testReturnsNullIfNullIsUsed() + public function testReturnUnfiltered($input) { - $filtered = $this->_filter->filter(null); - $this->assertNull($filtered); + $this->assertEquals($input, $this->_filter->filter($input)); } } diff --git a/test/StringTrimTest.php b/test/StringTrimTest.php index b2a5f489..462d41b9 100644 --- a/test/StringTrimTest.php +++ b/test/StringTrimTest.php @@ -9,8 +9,8 @@ namespace ZendTest\Filter; -use stdClass; use Zend\Filter\StringTrim; +use stdClass; /** * @group Zend_Filter diff --git a/test/StripNewlinesTest.php b/test/StripNewlinesTest.php index 8bbd6ee1..e300c092 100644 --- a/test/StripNewlinesTest.php +++ b/test/StripNewlinesTest.php @@ -6,16 +6,16 @@ * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ - namespace ZendTest\Filter; use Zend\Filter\StripNewlines as StripNewlinesFilter; /** - * @group Zend_Filter + * @group Zend_Filter */ class StripNewlinesTest extends \PHPUnit_Framework_TestCase { + /** * Ensures that the filter follows expected behavior * @@ -38,4 +38,37 @@ public function testBasic() $this->assertEquals($output, $filter($input)); } } + + /** + * + * @return void + */ + public function testArrayValues() + { + $filter = new StripNewLinesFilter(); + $expected = array( + "Some text\nthat we have\r\nstuff in" => 'Some textthat we havestuff in', + "Some text\n" => 'Some text' + ); + $this->assertEquals(array_values($expected), $filter(array_keys($expected))); + } + + public function returnUnfilteredDataProvider() + { + return array( + array(null), + array(new \stdClass()) + ); + } + + /** + * @dataProvider returnUnfilteredDataProvider + * @return void + */ + public function testReturnUnfiltered($input) + { + $filter = new StripNewLinesFilter(); + + $this->assertEquals($input, $filter($input)); + } } diff --git a/test/StripTagsTest.php b/test/StripTagsTest.php index ffec9d4b..e50af9ed 100644 --- a/test/StripTagsTest.php +++ b/test/StripTagsTest.php @@ -536,30 +536,24 @@ public function testFilterCanAllowHyphenatedAttributeNames() $this->assertEquals($expected, $this->_filter->filter($input)); } - /** - * Ensures that a warning is raised if array is used - * - * @return void - */ - public function testWarningIsRaisedIfArrayUsed() - { - $input = array('
  • ', '
  • '); - - ErrorHandler::start(E_USER_WARNING); - $filtered = $this->_filter->filter($input); - $err = ErrorHandler::stop(); - - $this->assertEquals($input, $filtered); - $this->assertInstanceOf('ErrorException', $err); - $this->assertContains('cannot filter', $err->getMessage()); + public function returnUnfilteredDataProvider() + { + return array( + array(null), + array(new \stdClass()), + array(array( + '
  • ', + '
  • ' + )) + ); } /** + * @dataProvider returnUnfilteredDataProvider * @return void */ - public function testReturnsNullIfNullIsUsed() + public function testReturnUnfiltered($input) { - $filtered = $this->_filter->filter(null); - $this->assertNull($filtered); + $this->assertEquals($input, $this->_filter->filter($input)); } } diff --git a/test/UriNormalizeTest.php b/test/UriNormalizeTest.php index 0c438036..9e2b46e4 100644 --- a/test/UriNormalizeTest.php +++ b/test/UriNormalizeTest.php @@ -63,4 +63,27 @@ public static function enforcedSchemeTestcaseProvider() array('http', '/just/a/path', '/just/a/path') // cannot be enforced, no host ); } + + public function returnUnfilteredDataProvider() + { + return array( + array(null), + array(new \stdClass()), + array(array( + 'http://www.example.com', + 'file:///home/shahar/secret/../../otherguy/secret' + )) + ); + } + + /** + * @dataProvider returnUnfilteredDataProvider + * @return void + */ + public function testReturnUnfiltered($input) + { + $filter = new UriNormalize(); + + $this->assertEquals($input, $filter($input)); + } } diff --git a/test/Word/CamelCaseToSeparatorTest.php b/test/Word/CamelCaseToSeparatorTest.php index 3e04f8e3..27c1e63d 100644 --- a/test/Word/CamelCaseToSeparatorTest.php +++ b/test/Word/CamelCaseToSeparatorTest.php @@ -47,4 +47,41 @@ public function testFilterSeperatesMultipleUppercasedLettersAndUnderscores() $this->assertNotEquals($string, $filtered); $this->assertEquals('These_Are_SOME_Camel_CASED_Words', $filtered); } + + /** + * @return void + */ + public function testFilterSupportArray() + { + $filter = new CamelCaseToSeparatorFilter(); + + $input = array( + 'CamelCasedWords', + 'somethingDifferent' + ); + + $filtered = $filter($input); + + $this->assertNotEquals($input, $filtered); + $this->assertEquals(array('Camel Cased Words', 'something Different'), $filtered); + } + + public function returnUnfilteredDataProvider() + { + return array( + array(null), + array(new \stdClass()) + ); + } + + /** + * @dataProvider returnUnfilteredDataProvider + * @return void + */ + public function testReturnUnfiltered($input) + { + $filter = new CamelCaseToSeparatorFilter(); + + $this->assertEquals($input, $filter($input)); + } } diff --git a/test/Word/DashToSeparatorTest.php b/test/Word/DashToSeparatorTest.php index 9a68fa69..1c01ecc5 100644 --- a/test/Word/DashToSeparatorTest.php +++ b/test/Word/DashToSeparatorTest.php @@ -38,4 +38,42 @@ public function testFilterSeparatesDashedWordsWithSomeString() $this->assertEquals('dash:-:separated:-:words', $filtered); } + /** + * @return void + */ + public function testFilterSupportArray() + { + $filter = new DashToSeparatorFilter(); + + $input = array( + 'dash-separated-words', + 'something-different' + ); + + $filtered = $filter($input); + + $this->assertNotEquals($input, $filtered); + $this->assertEquals(array('dash separated words', 'something different'), $filtered); + } + + + public function returnUnfilteredDataProvider() + { + return array( + array(null), + array(new \stdClass()) + ); + } + + /** + * @dataProvider returnUnfilteredDataProvider + * @return void + */ + public function testReturnUnfiltered($input) + { + $filter = new DashToSeparatorFilter(); + + $this->assertEquals($input, $filter($input)); + } + } diff --git a/test/Word/SeparatorToCamelCaseTest.php b/test/Word/SeparatorToCamelCaseTest.php index bfbaeedd..08b3bba6 100644 --- a/test/Word/SeparatorToCamelCaseTest.php +++ b/test/Word/SeparatorToCamelCaseTest.php @@ -71,4 +71,41 @@ public function testFilterSeparatesUniCodeCamelCasedUserWordsWithProvidedSeparat $this->assertNotEquals($string, $filtered); $this->assertEquals('TestÅ uma', $filtered); } + + /** + * @return void + */ + public function testFilterSupportArray() + { + $filter = new SeparatorToCamelCaseFilter(); + + $input = array( + 'camel cased words', + 'something different' + ); + + $filtered = $filter($input); + + $this->assertNotEquals($input, $filtered); + $this->assertEquals(array('CamelCasedWords', 'SomethingDifferent'), $filtered); + } + + public function returnUnfilteredDataProvider() + { + return array( + array(null), + array(new \stdClass()) + ); + } + + /** + * @dataProvider returnUnfilteredDataProvider + * @return void + */ + public function testReturnUnfiltered($input) + { + $filter = new SeparatorToCamelCaseFilter(); + + $this->assertEquals($input, $filter($input)); + } } diff --git a/test/Word/SeparatorToSeparatorTest.php b/test/Word/SeparatorToSeparatorTest.php index 6cf6403a..985a13da 100644 --- a/test/Word/SeparatorToSeparatorTest.php +++ b/test/Word/SeparatorToSeparatorTest.php @@ -28,6 +28,23 @@ public function testFilterSeparatesWordsByDefault() $this->assertEquals('dash-separated-words', $filtered); } + public function testFilterSupportArray() + { + $filter = new SeparatorToSeparatorFilter(); + + $input = array( + 'dash separated words', + '=test something' + ); + $filtered = $filter($input); + + $this->assertNotEquals($input, $filtered); + $this->assertEquals(array( + 'dash-separated-words', + '=test-something' + ), $filtered); + } + public function testFilterSeparatesWordsWithSearchSpecified() { $string = 'dash=separated=words'; @@ -48,4 +65,22 @@ public function testFilterSeparatesWordsWithSearchAndReplacementSpecified() $this->assertEquals('dash?separated?words', $filtered); } + public function returnUnfilteredDataProvider() + { + return array( + array(null), + array(new \stdClass()) + ); + } + + /** + * @dataProvider returnUnfilteredDataProvider + * @return void + */ + public function testReturnUnfiltered($input) + { + $filter = new SeparatorToSeparatorFilter('=', '?'); + + $this->assertEquals($input, $filter($input)); + } }