Skip to content

Commit

Permalink
Fix activesync tests
Browse files Browse the repository at this point in the history
Make header array comparisons not depend on order/case of headers output
by Horde_Mime_Headers, since neither of those is guaranteed.
  • Loading branch information
slusarz committed Nov 4, 2014
1 parent 1b58912 commit 88fbae9
Showing 1 changed file with 43 additions and 33 deletions.
76 changes: 43 additions & 33 deletions framework/ActiveSync/test/Horde/ActiveSync/Rfc822Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,55 @@
*/
class Horde_ActiveSync_Rfc822Test extends Horde_Test_Case
{
public function testHeadersMultipartAlternativeAsString()
/**
* @dataProvider headersMultipartAlternativeProvider
*/
public function testHeadersMultipartAlternative($fixture, $expected)
{
$fixture = file_get_contents(__DIR__ . '/fixtures/iOSMultipartAlternative.eml');
$rfc822 = new Horde_ActiveSync_Rfc822($fixture);
$test = $rfc822->getHeaders();
$expected = array(
'Subject' => 'Testing',
'From' => 'mrubinsk@horde.org',
'Content-Type' => 'multipart/alternative;
boundary=Apple-Mail-B1C01B47-00D8-4AFB-8B65-DF81C4E4B47D',
'Message-Id' => '<D492BB4F-6A2E-4E58-B607-4E8849A72919@horde.org>',
'Date' => 'Tue, 1 Jan 2013 18:10:37 -0500',
'To' => 'Michael Rubinsky <mike@theupstairsroom.com>',
'Content-Transfer-Encoding' => '7bit',
'Mime-Version' => '1.0 (1.0)',
'User-Agent' => 'Horde Application Framework 5');

$this->assertEquals($expected, $rfc822->getHeaders()->toArray());
}
$test = array_change_key_case(
$rfc822->getHeaders()->toArray(),
CASE_LOWER
);
ksort($test);

public function testHeadersMultipartAlternativeAsStream()
$this->assertEquals(
$expected,
$test
);

if (is_resource($fixture)) {
fclose($fixture);
}
}

public function headersMultipartAlternativeProvider()
{
$fixture = fopen(__DIR__ . '/fixtures/iOSMultipartAlternative.eml', 'r');
$rfc822 = new Horde_ActiveSync_Rfc822($fixture);
$test = $rfc822->getHeaders();
$expected = array(
'Subject' => 'Testing',
'From' => 'mrubinsk@horde.org',
'Content-Type' => 'multipart/alternative;
$expected = array_change_key_case(array(
'Subject' => 'Testing',
'From' => 'mrubinsk@horde.org',
'Content-Type' => 'multipart/alternative;
boundary=Apple-Mail-B1C01B47-00D8-4AFB-8B65-DF81C4E4B47D',
'Message-Id' => '<D492BB4F-6A2E-4E58-B607-4E8849A72919@horde.org>',
'Date' => 'Tue, 1 Jan 2013 18:10:37 -0500',
'To' => 'Michael Rubinsky <mike@theupstairsroom.com>',
'Content-Transfer-Encoding' => '7bit',
'Mime-Version' => '1.0 (1.0)',
'User-Agent' => 'Horde Application Framework 5');
'Message-Id' => '<D492BB4F-6A2E-4E58-B607-4E8849A72919@horde.org>',
'Date' => 'Tue, 1 Jan 2013 18:10:37 -0500',
'To' => 'Michael Rubinsky <mike@theupstairsroom.com>',
'Content-Transfer-Encoding' => '7bit',
'Mime-Version' => '1.0 (1.0)',
'User-Agent' => 'Horde Application Framework 5'
), CASE_LOWER);
ksort($expected);

$this->assertEquals($expected, $rfc822->getHeaders()->toArray());
fclose($fixture);
return array(
array(
file_get_contents(__DIR__ . '/fixtures/iOSMultipartAlternative.eml'),
$expected
),
array(
fopen(__DIR__ . '/fixtures/iOSMultipartAlternative.eml', 'r'),
$expected
)
);
}

public function testBaseMimePart()
Expand Down Expand Up @@ -78,4 +88,4 @@ public function testMIMEEncodingWhenStandardHeadersAreAdded()
$this->assertEquals('=?utf-8?b?w4PDhMOjw6s=?=', $hdr_array['Subject']);
}

}
}

0 comments on commit 88fbae9

Please sign in to comment.