From 677dfff082ad43399038f125396376e730342db5 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Fri, 10 Sep 2010 23:50:41 -0600 Subject: [PATCH] Convert remainder of IMP tests to PHPUnit --- imp/lib/tests/Imp/Stub/HtmlViewer.php | 60 +++++++++++++++ imp/lib/tests/Imp/Unit/Mime/Viewer/HtmlTest.php | 93 +++++++++++++++++++++++ imp/lib/tests/Imp/Unit/QuotaTest.php | 56 ++++++++++++++ imp/lib/tests/{ => Imp}/fixtures/maildirsize | 0 imp/lib/tests/mime_viewer_html.phpt | 99 ------------------------- imp/lib/tests/quota_maildir.phpt | 23 ------ 6 files changed, 209 insertions(+), 122 deletions(-) create mode 100644 imp/lib/tests/Imp/Stub/HtmlViewer.php create mode 100644 imp/lib/tests/Imp/Unit/Mime/Viewer/HtmlTest.php create mode 100644 imp/lib/tests/Imp/Unit/QuotaTest.php rename imp/lib/tests/{ => Imp}/fixtures/maildirsize (100%) delete mode 100644 imp/lib/tests/mime_viewer_html.phpt delete mode 100644 imp/lib/tests/quota_maildir.phpt diff --git a/imp/lib/tests/Imp/Stub/HtmlViewer.php b/imp/lib/tests/Imp/Stub/HtmlViewer.php new file mode 100644 index 000000000..85248e521 --- /dev/null +++ b/imp/lib/tests/Imp/Stub/HtmlViewer.php @@ -0,0 +1,60 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Imp + * @package IMP + * @subpackage UnitTests + */ + +/** + * Test the IMP HTML Mime Viewer driver. + * Needed because we need to overwrite a protected method. + * + * Copyright 2010 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (GPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. + * + * @author Michael Slusarz + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Imp + * @package IMP + * @subpackage UnitTests + */ +class Imp_Stub_Mime_Viewer_Html extends IMP_Mime_Viewer_Html +{ + public function runTest($html) + { + $this->_imptmp = array( + 'blockimg' => 'imgblock.png', + 'img' => true, + 'imgblock' => false, + 'inline' => true, + 'target' => '_blank' + ); + + $dom = new Horde_Domhtml($html); + $this->_node($dom->dom, $dom->dom); + + return $dom->dom->saveXML($dom->dom->getElementsByTagName('body')->item(0)->firstChild); + } + + protected function _node($doc, $node) + { + if ($node->hasChildNodes()) { + foreach ($node->childNodes as $child) { + $this->_nodeCallback($doc, $child); + $this->_node($doc, $child); + } + } + } + +} diff --git a/imp/lib/tests/Imp/Unit/Mime/Viewer/HtmlTest.php b/imp/lib/tests/Imp/Unit/Mime/Viewer/HtmlTest.php new file mode 100644 index 000000000..aad4db7a3 --- /dev/null +++ b/imp/lib/tests/Imp/Unit/Mime/Viewer/HtmlTest.php @@ -0,0 +1,93 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Imp + * @package IMP + * @subpackage UnitTests + */ + +/** + * Test the IMP HTML Mime Viewer driver. + * + * Copyright 2010 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (GPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. + * + * @author Michael Slusarz + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Imp + * @package IMP + * @subpackage UnitTests + */ +class Imp_Unit_Mime_Viewer_HtmlTest extends PHPUnit_Framework_TestCase +{ + public function setUp() + { + require_once dirname(__FILE__) . '/../../../Stub/HtmlViewer.php'; + $GLOBALS['browser'] = $this->getMock('Horde_Browser'); + } + + // Test regex for converting links to open in a new window. + public function testOpenLinksInNewWindow() + { + $links = array( + 'foo' => '

foo

', + 'example@example.com' => '

example@example.com

', + 'foo Anchor' => '

foo Anchor

', + 'foo example' => '

foo example

', + 'foo example' => '

foo example

', + 'foo example' => '

foo example

', + 'foo Example Email' => '

foo Example Email

', + '' => '', + '' => '' + ); + + $v = new IMP_Stub_Mime_Viewer_Html(new Horde_Mime_Part(), array( + 'browser' => $this->getMock('Horde_Browser'), + 'charset' => 'UTF-8' + )); + + foreach ($links as $key => $val) { + $this->assertEquals( + $val, + $v->runTest($key) + ); + } + } + + // Test regex for hiding images. + public function testHideImages() + { + $images = array( + '' => '', + '' => '', + '' => '', + "Best flight deals" => 'Best flight deals', + '' => '', + '' => '', + '' => '', + '' => '' + ); + + $v = new IMP_Stub_Mime_Viewer_Html(new Horde_Mime_Part(), array( + 'browser' => $this->getMock('Horde_Browser'), + 'charset' => 'UTF-8' + )); + + foreach ($images as $key => $val) { + $this->assertEquals( + $val, + $v->runTest($key) + ); + } + } + +} diff --git a/imp/lib/tests/Imp/Unit/QuotaTest.php b/imp/lib/tests/Imp/Unit/QuotaTest.php new file mode 100644 index 000000000..744402c22 --- /dev/null +++ b/imp/lib/tests/Imp/Unit/QuotaTest.php @@ -0,0 +1,56 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Imp + * @package IMP + * @subpackage UnitTests + */ + +/** + * Prepare the test setup. + */ +require_once dirname(__FILE__) . '/../Autoload.php'; + +/** + * Test the Quota library. + * + * Copyright 2010 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (GPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. + * + * @author Michael Slusarz + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Imp + * @package IMP + * @subpackage UnitTests + */ +class Imp_Unit_QuotaTest extends PHPUnit_Framework_TestCase +{ + public function testMaildir() + { + $quota = IMP_Quota::factory('Maildir', array( + 'path' => dirname(__FILE__) . '/../fixtures' + )); + + $data = $quota->getQuota(); + + $this->assertEquals( + 1000000000, + $data['limit'] + ); + + $this->assertEquals( + 550839239, + $data['usage'] + ); + } + +} diff --git a/imp/lib/tests/fixtures/maildirsize b/imp/lib/tests/Imp/fixtures/maildirsize similarity index 100% rename from imp/lib/tests/fixtures/maildirsize rename to imp/lib/tests/Imp/fixtures/maildirsize diff --git a/imp/lib/tests/mime_viewer_html.phpt b/imp/lib/tests/mime_viewer_html.phpt deleted file mode 100644 index 87722ea3f..000000000 --- a/imp/lib/tests/mime_viewer_html.phpt +++ /dev/null @@ -1,99 +0,0 @@ ---TEST-- -IMP HTML MIME Viewer tests. ---FILE-- - 'none', - 'cli' => true -)); - -require_once dirname(__FILE__) . '/../Mime/Viewer/Html.php'; -class IMP_Html_Viewer_Test extends IMP_Horde_Mime_Viewer_Html -{ - public function runTest($html) - { - $this->_imptmp = array( - 'blockimg' => 'imgblock.png', - 'img' => true, - 'imgblock' => false, - 'inline' => true, - 'target' => '_blank' - ); - - $dom = new Horde_Domhtml($html); - $this->_node($dom->dom, $dom->dom); - - return $dom->dom->saveXML($dom->dom->getElementsByTagName('body')->item(0)->firstChild) . "\n"; - } - - protected function _node($doc, $node) - { - if ($node->hasChildNodes()) { - foreach ($node->childNodes as $child) { - $this->_nodeCallback($doc, $child); - $this->_node($doc, $child); - } - } - } - -} - -$v = new IMP_Html_Viewer_Test(new Horde_Mime_Part()); - -// Test regex for converting links to open in a new window. -$links = array( - 'foo', - 'example@example.com', - 'foo Anchor', - 'foo example', - 'foo example', - 'foo example', - 'foo Example Email', - '', - '' -); - -foreach ($links as $val) { - echo $v->runTest($val); -} - -echo "\n"; - -// Test regex for hiding images. -$images = array( - '', - '', - '', - "Best flight deals", - '', - '', - '', - '' -); - -foreach ($images as $val) { - echo $v->runTest($val); -} - -?> ---EXPECT-- -

foo

-

example@example.com

-

foo Anchor

-

foo example

-

foo example

-

foo example

-

foo Example Email

- - - - - - -Best flight deals - - - - diff --git a/imp/lib/tests/quota_maildir.phpt b/imp/lib/tests/quota_maildir.phpt deleted file mode 100644 index ff0932ad2..000000000 --- a/imp/lib/tests/quota_maildir.phpt +++ /dev/null @@ -1,23 +0,0 @@ ---TEST-- -IMP_Quota_maildir test. ---FILE-- - 'none', - 'cli' => true -)); - -$quota = IMP_Quota::factory('Maildir', array( - 'path' => dirname(__FILE__) . '/fixtures' -)); - -var_export($quota->getQuota()); - -?> ---EXPECT-- -array ( - 'limit' => 1000000000, - 'usage' => 550839239, -) -- 2.11.0