Skip to content

Commit

Permalink
Test native PHP utf7-imap conversion code also if mbstring is present…
Browse files Browse the repository at this point in the history
… on system
  • Loading branch information
slusarz committed Aug 19, 2014
1 parent 4db2d3d commit 4e112a1
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 6 deletions.
2 changes: 1 addition & 1 deletion framework/Imap_Client/lib/Horde/Imap/Client/Utf7imap.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Horde_Imap_Client_Utf7imap
*
* @var array
*/
private static $_mbstring = null;
protected static $_mbstring = null;

/**
* Convert a string from UTF7-IMAP to UTF-8.
Expand Down
6 changes: 4 additions & 2 deletions framework/Imap_Client/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<email>slusarz@horde.org</email>
<active>yes</active>
</lead>
<date>2014-08-18</date>
<date>2014-08-19</date>
<version>
<release>2.25.0</release>
<api>2.25.0</api>
Expand Down Expand Up @@ -342,6 +342,7 @@
<dir name="Stub">
<file name="DigestMD5.php" role="test" />
<file name="Socket.php" role="test" />
<file name="Utf7imap.php" role="test" />
</dir> <!-- /test/Horde/Imap/Client/Stub -->
<file name="AllTests.php" role="test" />
<file name="AuthTest.php" role="test" />
Expand Down Expand Up @@ -685,6 +686,7 @@
<install as="Horde/Imap/Client/Socket/ClientSortTest.php" name="test/Horde/Imap/Client/Socket/ClientSortTest.php" />
<install as="Horde/Imap/Client/Stub/DigestMD5.php" name="test/Horde/Imap/Client/Stub/DigestMD5.php" />
<install as="Horde/Imap/Client/Stub/Socket.php" name="test/Horde/Imap/Client/Stub/Socket.php" />
<install as="Horde/Imap/Client/Stub/Utf7imap.php" name="test/Horde/Imap/Client/Stub/Utf7imap.php" />
</filelist>
</phprelease>
<changelog>
Expand Down Expand Up @@ -2643,7 +2645,7 @@
<stability>
<release>stable</release>
<api>stable</api></stability>
<date>2014-08-18</date>
<date>2014-08-19</date>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
* [mms] Fix client-side reverse sorting.
Expand Down
34 changes: 34 additions & 0 deletions framework/Imap_Client/test/Horde/Imap/Client/Stub/Utf7imap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* Copyright 2014 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @category Horde
* @copyright 2014 Horde LLC
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Imap_Client
* @subpackage UnitTests
*/

/**
* Stub for testing the IMAP UTF7-IMAP conversion library.
* Needed to change protected static member variables.
*
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
* @copyright 2014 Horde LLC
* @ignore
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Imap_Client
* @subpackage UnitTests
*/
class Horde_Imap_Client_Stub_Utf7imap extends Horde_Imap_Client_Utf7imap
{
static public function setMbstring($val)
{
self::$_mbstring = (bool)$val;
}

}
32 changes: 29 additions & 3 deletions framework/Imap_Client/test/Horde/Imap/Client/Utf7ConvertTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,38 @@
*/
class Horde_Imap_Client_Utf7ConvertTest extends PHPUnit_Framework_TestCase
{
static public function setUpBeforeClass()
{
require_once __DIR__ . '/Stub/Utf7imap.php';
}

/**
* @dataProvider conversionProvider
*/
public function testConversionWithMbstring($orig, $expected = null)
{
if (!extension_loaded('mbstring')) {
$this->markTestSkipped('mbstring extension not loaded');
}

Horde_Imap_Client_Stub_Utf7imap::setMbstring(true);

$this->_testConversion($orig, $expected);
}

/**
* @dataProvider conversionProvider
*/
public function testConversion($orig, $expected = null)
public function testConversionWithoutMbstring($orig, $expected = null)
{
Horde_Imap_Client_Stub_Utf7imap::setMbstring(false);

$this->_testConversion($orig, $expected);
}

protected function _testConversion($orig, $expected)
{
$utf7_imap = Horde_Imap_Client_Utf7imap::Utf8ToUtf7Imap(
$utf7_imap = Horde_Imap_Client_Stub_Utf7imap::Utf8ToUtf7Imap(
$orig,
!is_null($expected)
);
Expand All @@ -41,7 +67,7 @@ public function testConversion($orig, $expected = null)
);

if ($expected) {
$utf8 = Horde_Imap_Client_Utf7imap::Utf7ImapToUtf8($utf7_imap);
$utf8 = Horde_Imap_Client_Stub_Utf7imap::Utf7ImapToUtf8($utf7_imap);
$this->assertEquals(
$orig,
$utf8
Expand Down

0 comments on commit 4e112a1

Please sign in to comment.