Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix handling setlocale in unit tests
Need to put in setUp/tearDown, since we need to guarantee that the locale will be reset after a failed test.
- Loading branch information
Showing
3 changed files
with
128 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
framework/Mime/test/Horde/Mime/Mdn/NonTranslatedTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
<?php | ||
/** | ||
* Copyright 2014 Horde LLC (http://www.horde.org/) | ||
* | ||
* @category Horde | ||
* @copyright 2014 Horde LLC | ||
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 | ||
* @package Mime | ||
* @subpackage UnitTests | ||
*/ | ||
|
||
/** | ||
* Tests for the Horde_Mime_Mdn object that require translations to not occur. | ||
* | ||
* @author Michael Slusarz <slusarz@horde.org> | ||
* @category Horde | ||
* @copyright 2014 Horde LLC | ||
* @internal | ||
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 | ||
* @package Mime | ||
* @subpackage UnitTests | ||
*/ | ||
class Horde_Mime_Mdn_NonTranslatedTest extends PHPUnit_Framework_TestCase | ||
{ | ||
private $oldlocale; | ||
|
||
public function setUp() | ||
{ | ||
$this->oldlocale = setlocale(LC_MESSAGES, 0); | ||
setlocale(LC_MESSAGES, 'C'); | ||
} | ||
|
||
public function tearDown() | ||
{ | ||
setlocale(LC_MESSAGES, $this->oldlocale); | ||
} | ||
|
||
public function testGenerate() | ||
{ | ||
$h = new Horde_Mime_Headers(); | ||
$ob = new Horde_Mime_Mdn($h); | ||
|
||
try { | ||
$ob->generate(true, true, 'deleted', 'foo', null); | ||
$this->fail('Expected Exception'); | ||
} catch (RuntimeException $e) {} | ||
|
||
$date = 'Tue, 18 Nov 2014 20:14:17 -0700'; | ||
$mdn_addr = 'Aäb <foo@example.com>'; | ||
|
||
$h->addHeader('Date', $date); | ||
$h->addHeader('Subject', 'Test'); | ||
$h->addHeader('To', '"BAR" <bar@example.com>'); | ||
|
||
$ob->addMdnRequestHeaders($mdn_addr); | ||
|
||
$mailer = new Horde_Mail_Transport_Mock(); | ||
|
||
$ob->generate( | ||
true, | ||
true, | ||
'displayed', | ||
'test.example.com', | ||
$mailer, | ||
array( | ||
'from_addr' => 'bar@example.com' | ||
), | ||
array('error'), | ||
array('error' => 'Foo') | ||
); | ||
|
||
$sent = str_replace("\r\n", "\n", $mailer->sentMessages[0]); | ||
|
||
$this->assertEquals( | ||
'auto-replied', | ||
$sent['headers']['Auto-Submitted'] | ||
); | ||
$this->assertEquals( | ||
'bar@example.com', | ||
$sent['headers']['From'] | ||
); | ||
$this->assertEquals( | ||
$mdn_addr, | ||
Horde_Mime::decode($sent['headers']['To']) | ||
); | ||
$this->assertEquals( | ||
'Disposition Notification', | ||
$sent['headers']['Subject'] | ||
); | ||
|
||
$this->assertStringMatchesFormat( | ||
'This message is in MIME format. | ||
--=%s | ||
Content-Type: text/plain; format=flowed; DelSp=Yes | ||
The message sent on Tue, 18 Nov 2014 20:14:17 -0700 to BAR | ||
<bar@example.com> with subject "Test" has been displayed. | ||
This is no guarantee that the message has been read or understood. | ||
--=%s | ||
Content-Type: message/disposition-notification | ||
Reporting-UA: test.example.com; Horde Application Framework 5 | ||
Final-Recipient: rfc822;bar@example.com | ||
Disposition: manual-action/MDN-sent-manually; displayed/error | ||
Error: Foo | ||
--=%s | ||
Content-Type: message/rfc822 | ||
Date: Tue, 18 Nov 2014 20:14:17 -0700 | ||
Subject: Test | ||
To: BAR <bar@example.com> | ||
Disposition-Notification-To: =?utf-8?b?QcOkYg==?= <foo@example.com> | ||
--=%s | ||
', | ||
$sent['body'] | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters