From 3dcee365fd928a20951c6d568542381f16336b3c Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Tue, 12 Aug 2014 16:43:25 -0600 Subject: [PATCH] Add testing for Nonascii data format objects --- .../doc/Horde/Imap/Client/UPGRADING | 1 + framework/Imap_Client/package.xml | 14 ++ .../Data/Format/Astring/NonasciiTest.php | 38 ++++ .../Imap/Client/Data/Format/AstringTest.php | 96 ++++------- .../Data/Format/Nstring/NonasciiTest.php | 38 ++++ .../Imap/Client/Data/Format/NstringTest.php | 93 ++++------ .../Data/Format/String/NonasciiTest.php | 38 ++++ .../Client/Data/Format/String/TestBase.php | 162 ++++++++++++++++++ .../Imap/Client/Data/Format/StringTest.php | 115 +++---------- 9 files changed, 377 insertions(+), 218 deletions(-) create mode 100644 framework/Imap_Client/test/Horde/Imap/Client/Data/Format/Astring/NonasciiTest.php create mode 100644 framework/Imap_Client/test/Horde/Imap/Client/Data/Format/Nstring/NonasciiTest.php create mode 100644 framework/Imap_Client/test/Horde/Imap/Client/Data/Format/String/NonasciiTest.php create mode 100644 framework/Imap_Client/test/Horde/Imap/Client/Data/Format/String/TestBase.php diff --git a/framework/Imap_Client/doc/Horde/Imap/Client/UPGRADING b/framework/Imap_Client/doc/Horde/Imap/Client/UPGRADING index 639fecf2932..0f9f1bc9976 100644 --- a/framework/Imap_Client/doc/Horde/Imap/Client/UPGRADING +++ b/framework/Imap_Client/doc/Horde/Imap/Client/UPGRADING @@ -14,6 +14,7 @@ This lists the API changes between releases of the package. Upgrading to 2.25.0 =================== + - Horde_Imap_Client_Data_Format_Astring_Nonascii - Horde_Imap_Client_Data_Format_Nstring_Nonascii - Horde_Imap_Client_Data_Format_String_Nonascii diff --git a/framework/Imap_Client/package.xml b/framework/Imap_Client/package.xml index 5249b200576..412761de73a 100644 --- a/framework/Imap_Client/package.xml +++ b/framework/Imap_Client/package.xml @@ -276,6 +276,9 @@ + + + @@ -283,6 +286,13 @@ + + + + + + + @@ -640,11 +650,15 @@ + + + + diff --git a/framework/Imap_Client/test/Horde/Imap/Client/Data/Format/Astring/NonasciiTest.php b/framework/Imap_Client/test/Horde/Imap/Client/Data/Format/Astring/NonasciiTest.php new file mode 100644 index 00000000000..616d0d1719a --- /dev/null +++ b/framework/Imap_Client/test/Horde/Imap/Client/Data/Format/Astring/NonasciiTest.php @@ -0,0 +1,38 @@ + + * @category Horde + * @copyright 2011-2014 Horde LLC + * @ignore + * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 + * @package Imap_Client + * @subpackage UnitTests + */ +class Horde_Imap_Client_Data_Format_Astring_NonasciiTest +extends Horde_Imap_Client_Data_Format_AstringTest +{ + protected $cname = 'Horde_Imap_Client_Data_Format_Astring_Nonascii'; + + public function nonasciiInputProvider() + { + return array( + array(true) + ); + } + +} diff --git a/framework/Imap_Client/test/Horde/Imap/Client/Data/Format/AstringTest.php b/framework/Imap_Client/test/Horde/Imap/Client/Data/Format/AstringTest.php index 818b33783c4..3b95ba97bc5 100644 --- a/framework/Imap_Client/test/Horde/Imap/Client/Data/Format/AstringTest.php +++ b/framework/Imap_Client/test/Horde/Imap/Client/Data/Format/AstringTest.php @@ -24,27 +24,18 @@ * @subpackage UnitTests */ class Horde_Imap_Client_Data_Format_AstringTest -extends Horde_Imap_Client_Data_Format_TestBase +extends Horde_Imap_Client_Data_Format_String_TestBase { + protected $cname = 'Horde_Imap_Client_Data_Format_Astring'; + protected function getTestObs() { return array( - new Horde_Imap_Client_Data_Format_Astring('Foo'), - new Horde_Imap_Client_Data_Format_Astring('Foo('), + new $this->cname('Foo'), + new $this->cname('Foo('), /* This is an invalid atom, but valid (non-quoted) astring. */ - new Horde_Imap_Client_Data_Format_Astring('Foo]'), - new Horde_Imap_Client_Data_Format_Astring('') - ); - } - - /** - * @dataProvider stringRepresentationProvider - */ - public function testStringRepresentation($ob, $expected) - { - $this->assertEquals( - $expected, - strval($ob) + new $this->cname('Foo]'), + new $this->cname('') ); } @@ -58,17 +49,6 @@ public function stringRepresentationProvider() )); } - /** - * @dataProvider escapeProvider - */ - public function testEscape($ob, $expected) - { - $this->assertEquals( - $expected, - $ob->escape() - ); - } - public function escapeProvider() { return $this->createProviderArray(array( @@ -79,41 +59,29 @@ public function escapeProvider() )); } - /** - * @dataProvider obsProvider - */ - public function testVerify($ob) - { - // Don't throw Exception - $ob->verify(); - } - - /** - * @dataProvider obsProvider - */ - public function testBinary($ob) + public function verifyProvider() { - $this->assertFalse($ob->binary()); + return $this->createProviderArray(array( + true, + true, + true, + true + )); } - /** - * @dataProvider obsProvider - */ - public function testLiteral($ob) + public function binaryProvider() { - $this->assertFalse($ob->literal()); + return $this->createProviderArray(array( + false, + false, + false, + false + )); } - /** - * @dataProvider quotedProvider - */ - public function testQuoted($ob, $expected) + public function literalProvider() { - if ($expected) { - $this->assertTrue($ob->quoted()); - } else { - $this->assertFalse($ob->quoted()); - } + return $this->binaryProvider(); } public function quotedProvider() @@ -126,17 +94,6 @@ public function quotedProvider() )); } - /** - * @dataProvider escapeStreamProvider - */ - public function testEscapeStream($ob, $expected) - { - $this->assertEquals( - $expected, - stream_get_contents($ob->escapeStream(), -1, 0) - ); - } - public function escapeStreamProvider() { return $this->createProviderArray(array( @@ -147,4 +104,11 @@ public function escapeStreamProvider() )); } + public function nonasciiInputProvider() + { + return array( + array(false) + ); + } + } diff --git a/framework/Imap_Client/test/Horde/Imap/Client/Data/Format/Nstring/NonasciiTest.php b/framework/Imap_Client/test/Horde/Imap/Client/Data/Format/Nstring/NonasciiTest.php new file mode 100644 index 00000000000..c3c99ae7b9d --- /dev/null +++ b/framework/Imap_Client/test/Horde/Imap/Client/Data/Format/Nstring/NonasciiTest.php @@ -0,0 +1,38 @@ + + * @category Horde + * @copyright 2011-2014 Horde LLC + * @ignore + * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 + * @package Imap_Client + * @subpackage UnitTests + */ +class Horde_Imap_Client_Data_Format_Nstring_NonasciiTest +extends Horde_Imap_Client_Data_Format_NstringTest +{ + protected $cname = 'Horde_Imap_Client_Data_Format_Nstring_Nonascii'; + + public function nonasciiInputProvider() + { + return array( + array(true) + ); + } + +} diff --git a/framework/Imap_Client/test/Horde/Imap/Client/Data/Format/NstringTest.php b/framework/Imap_Client/test/Horde/Imap/Client/Data/Format/NstringTest.php index 4cc815ec5a3..8b6f1887fbe 100644 --- a/framework/Imap_Client/test/Horde/Imap/Client/Data/Format/NstringTest.php +++ b/framework/Imap_Client/test/Horde/Imap/Client/Data/Format/NstringTest.php @@ -24,27 +24,18 @@ * @subpackage UnitTests */ class Horde_Imap_Client_Data_Format_NstringTest -extends Horde_Imap_Client_Data_Format_TestBase +extends Horde_Imap_Client_Data_Format_String_TestBase { + protected $cname = 'Horde_Imap_Client_Data_Format_Nstring'; + protected function getTestObs() { return array( - new Horde_Imap_Client_Data_Format_Nstring('Foo'), - new Horde_Imap_Client_Data_Format_Nstring('Foo('), + new $this->cname('Foo'), + new $this->cname('Foo('), /* This is an invalid atom, but valid nstring. */ - new Horde_Imap_Client_Data_Format_Nstring('Foo]'), - new Horde_Imap_Client_Data_Format_Nstring() - ); - } - - /** - * @dataProvider stringRepresentationProvider - */ - public function testStringRepresentation($ob, $expected) - { - $this->assertEquals( - $expected, - strval($ob) + new $this->cname('Foo]'), + new $this->cname() ); } @@ -58,17 +49,6 @@ public function stringRepresentationProvider() )); } - /** - * @dataProvider escapeProvider - */ - public function testEscape($ob, $expected) - { - $this->assertEquals( - $expected, - $ob->escape() - ); - } - public function escapeProvider() { return $this->createProviderArray(array( @@ -79,41 +59,29 @@ public function escapeProvider() )); } - /** - * @dataProvider obsProvider - */ - public function testVerify($ob) - { - // Don't throw Exception - $ob->verify(); - } - - /** - * @dataProvider obsProvider - */ - public function testBinary($ob) + public function verifyProvider() { - $this->assertFalse($ob->binary()); + return $this->createProviderArray(array( + true, + true, + true, + true + )); } - /** - * @dataProvider obsProvider - */ - public function testLiteral($ob) + public function binaryProvider() { - $this->assertFalse($ob->literal()); + return $this->createProviderArray(array( + false, + false, + false, + false + )); } - /** - * @dataProvider quotedProvider - */ - public function testQuoted($ob, $expected) + public function literalProvider() { - if ($expected) { - $this->assertTrue($ob->quoted()); - } else { - $this->assertFalse($ob->quoted()); - } + return $this->binaryProvider(); } public function quotedProvider() @@ -126,14 +94,15 @@ public function quotedProvider() )); } - /** - * @dataProvider escapeProvider - */ - public function testEscapeStream($ob, $expected) + public function escapeStreamProvider() + { + return $this->escapeProvider(); + } + + public function nonasciiInputProvider() { - $this->assertEquals( - $expected, - stream_get_contents($ob->escapeStream(), -1, 0) + return array( + array(false) ); } diff --git a/framework/Imap_Client/test/Horde/Imap/Client/Data/Format/String/NonasciiTest.php b/framework/Imap_Client/test/Horde/Imap/Client/Data/Format/String/NonasciiTest.php new file mode 100644 index 00000000000..0a00fd8fa43 --- /dev/null +++ b/framework/Imap_Client/test/Horde/Imap/Client/Data/Format/String/NonasciiTest.php @@ -0,0 +1,38 @@ + + * @category Horde + * @copyright 2011-2014 Horde LLC + * @ignore + * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 + * @package Imap_Client + * @subpackage UnitTests + */ +class Horde_Imap_Client_Data_Format_String_NonasciiTest +extends Horde_Imap_Client_Data_Format_StringTest +{ + protected $cname = 'Horde_Imap_Client_Data_Format_String_Nonascii'; + + public function nonasciiInputProvider() + { + return array( + array(true) + ); + } + +} diff --git a/framework/Imap_Client/test/Horde/Imap/Client/Data/Format/String/TestBase.php b/framework/Imap_Client/test/Horde/Imap/Client/Data/Format/String/TestBase.php new file mode 100644 index 00000000000..6a91245b5b3 --- /dev/null +++ b/framework/Imap_Client/test/Horde/Imap/Client/Data/Format/String/TestBase.php @@ -0,0 +1,162 @@ + + * @category Horde + * @copyright 2014 Horde LLC + * @ignore + * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 + * @package Imap_Client + * @subpackage UnitTests + */ +abstract class Horde_Imap_Client_Data_Format_String_TestBase +extends Horde_Imap_Client_Data_Format_TestBase +{ + protected $cname; + + /** + * @dataProvider stringRepresentationProvider + */ + public function testStringRepresentation($ob, $expected) + { + $this->assertEquals( + $expected, + strval($ob) + ); + } + + abstract public function stringRepresentationProvider(); + + /** + * @dataProvider escapeProvider + */ + public function testEscape($ob, $expected) + { + try { + $this->assertEquals( + $expected, + $ob->escape() + ); + } catch (Horde_Imap_Client_Data_Format_Exception $e) { + if ($expected !== false) { + $this->fail(); + } + } + } + + abstract public function escapeProvider(); + + /** + * @dataProvider verifyProvider + */ + public function testVerify($ob, $result) + { + try { + $ob->verify(); + if (!$result) { + $this->fail(); + } + } catch (Horde_Imap_Client_Data_Format_Exception $e) { + if ($result) { + $this->fail(); + } + } + } + + abstract public function verifyProvider(); + + /** + * @dataProvider binaryProvider + */ + public function testBinary($ob, $expected) + { + if ($expected) { + $this->assertTrue($ob->binary()); + } else { + $this->assertFalse($ob->binary()); + } + } + + abstract public function binaryProvider(); + + /** + * @dataProvider literalProvider + */ + public function testLiteral($ob, $expected) + { + if ($expected) { + $this->assertTrue($ob->literal()); + } else { + $this->assertFalse($ob->literal()); + } + } + + abstract public function literalProvider(); + + /** + * @dataProvider quotedProvider + */ + public function testQuoted($ob, $expected) + { + if ($expected) { + $this->assertTrue($ob->quoted()); + } else { + $this->assertFalse($ob->quoted()); + } + } + + abstract public function quotedProvider(); + + /** + * @dataProvider escapeStreamProvider + */ + public function testEscapeStream($ob, $expected) + { + try { + $this->assertEquals( + $expected, + stream_get_contents($ob->escapeStream(), -1, 0) + ); + } catch (Horde_Imap_Client_Data_Format_Exception $e) { + if ($expected !== false) { + $this->fail(); + } + } + } + + abstract public function escapeStreamProvider(); + + /** + * @dataProvider nonasciiInputProvider + */ + public function testNonasciiInput($result) + { + try { + new $this->cname('Envoyé'); + if (!$result) { + $this->fail(); + } + } catch (Horde_Imap_Client_Data_Format_Exception $e) { + if ($result) { + $this->fail(); + } + } + } + + abstract public function nonasciiInputProvider(); + +} diff --git a/framework/Imap_Client/test/Horde/Imap/Client/Data/Format/StringTest.php b/framework/Imap_Client/test/Horde/Imap/Client/Data/Format/StringTest.php index 07f03103200..621a3004bf7 100644 --- a/framework/Imap_Client/test/Horde/Imap/Client/Data/Format/StringTest.php +++ b/framework/Imap_Client/test/Horde/Imap/Client/Data/Format/StringTest.php @@ -24,30 +24,21 @@ * @subpackage UnitTests */ class Horde_Imap_Client_Data_Format_StringTest -extends Horde_Imap_Client_Data_Format_TestBase +extends Horde_Imap_Client_Data_Format_String_TestBase { + protected $cname = 'Horde_Imap_Client_Data_Format_String'; + protected function getTestObs() { return array( - new Horde_Imap_Client_Data_Format_String('Foo'), - new Horde_Imap_Client_Data_Format_String('Foo('), + new $this->cname('Foo'), + new $this->cname('Foo('), /* This is an invalid atom, but valid string. */ - new Horde_Imap_Client_Data_Format_String('Foo]'), + new $this->cname('Foo]'), /* This string requires a literal. */ - new Horde_Imap_Client_Data_Format_String("Foo\n]"), + new $this->cname("Foo\n]"), /* This string requires a binary literal. */ - new Horde_Imap_Client_Data_Format_String("12\x00\n3") - ); - } - - /** - * @dataProvider stringRepresentationProvider - */ - public function testStringRepresentation($ob, $expected) - { - $this->assertEquals( - $expected, - strval($ob) + new $this->cname("12\x00\n3") ); } @@ -62,23 +53,6 @@ public function stringRepresentationProvider() )); } - /** - * @dataProvider escapeProvider - */ - public function testEscape($ob, $expected) - { - try { - $this->assertEquals( - $expected, - $ob->escape() - ); - } catch (Horde_Imap_Client_Data_Format_Exception $e) { - if ($expected !== false) { - $this->fail(); - } - } - } - public function escapeProvider() { return $this->createProviderArray(array( @@ -90,25 +64,15 @@ public function escapeProvider() )); } - /** - * @dataProvider obsProvider - */ - public function testVerify($ob) + public function verifyProvider() { - // Don't throw Exception - $ob->verify(); - } - - /** - * @dataProvider binaryProvider - */ - public function testBinary($ob, $expected) - { - if ($expected) { - $this->assertTrue($ob->binary()); - } else { - $this->assertFalse($ob->binary()); - } + return $this->createProviderArray(array( + true, + true, + true, + true, + true + )); } public function binaryProvider() @@ -122,18 +86,6 @@ public function binaryProvider() )); } - /** - * @dataProvider literalProvider - */ - public function testLiteral($ob, $expected) - { - if ($expected) { - $this->assertTrue($ob->literal()); - } else { - $this->assertFalse($ob->literal()); - } - } - public function literalProvider() { return $this->createProviderArray(array( @@ -145,18 +97,6 @@ public function literalProvider() )); } - /** - * @dataProvider quotedProvider - */ - public function testQuoted($ob, $expected) - { - if ($expected) { - $this->assertTrue($ob->quoted()); - } else { - $this->assertFalse($ob->quoted()); - } - } - public function quotedProvider() { return $this->createProviderArray(array( @@ -168,21 +108,16 @@ public function quotedProvider() )); } - /** - * @dataProvider escapeProvider - */ - public function testEscapeStream($ob, $expected) + public function escapeStreamProvider() { - try { - $this->assertEquals( - $expected, - stream_get_contents($ob->escapeStream(), -1, 0) - ); - } catch (Horde_Imap_Client_Data_Format_Exception $e) { - if ($expected !== false) { - $this->fail(); - } - } + return $this->escapeProvider(); + } + + public function nonasciiInputProvider() + { + return array( + array(false) + ); } }