From: Michael M Slusarz Date: Sat, 11 Sep 2010 05:50:41 +0000 (-0600) Subject: Convert remainder of IMP tests to PHPUnit X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=677dfff082ad43399038f125396376e730342db5;p=horde.git Convert remainder of IMP tests to PHPUnit --- 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/Imp/fixtures/maildirsize b/imp/lib/tests/Imp/fixtures/maildirsize new file mode 100644 index 000000000..229178730 --- /dev/null +++ b/imp/lib/tests/Imp/fixtures/maildirsize @@ -0,0 +1,35 @@ +1000000000S + 543336696 6335 + 3163 1 + 11524 1 + 4030 1 + 218569 1 + 2393 1 + 6594810 1 + 8013 1 + -13894 -4 + 1501 1 + 1687 1 + 7495 1 + 64581 1 + 4918 1 + 21673 1 + 202775 1 + 5133 1 + 1863 1 + 8003 1 + 25389 1 + 4034 1 + 14878 1 + -8003 -1 + 2371 1 + 1947 1 + 1916 1 + 1913 1 + 2064 1 + 2293 1 + 203262 1 + 63545 1 + 35037 1 + 1740 1 + 1920 1 diff --git a/imp/lib/tests/fixtures/maildirsize b/imp/lib/tests/fixtures/maildirsize deleted file mode 100644 index 229178730..000000000 --- a/imp/lib/tests/fixtures/maildirsize +++ /dev/null @@ -1,35 +0,0 @@ -1000000000S - 543336696 6335 - 3163 1 - 11524 1 - 4030 1 - 218569 1 - 2393 1 - 6594810 1 - 8013 1 - -13894 -4 - 1501 1 - 1687 1 - 7495 1 - 64581 1 - 4918 1 - 21673 1 - 202775 1 - 5133 1 - 1863 1 - 8003 1 - 25389 1 - 4034 1 - 14878 1 - -8003 -1 - 2371 1 - 1947 1 - 1916 1 - 1913 1 - 2064 1 - 2293 1 - 203262 1 - 63545 1 - 35037 1 - 1740 1 - 1920 1 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, -)