/tests/Zend/Mail/MboxMessageOldTest.php
https://github.com/sidealice/zf2 · PHP · 138 lines · 74 code · 18 blank · 46 comment · 9 complexity · 01eed0bdc7cc69c8590f6be13ff34c7a MD5 · raw file
- <?php
- /**
- * Zend Framework
- *
- * LICENSE
- *
- * This source file is subject to the new BSD license that is bundled
- * with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://framework.zend.com/license/new-bsd
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@zend.com so we can send you a copy immediately.
- *
- * @category Zend
- * @package Zend_Mail
- * @subpackage UnitTests
- * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- */
- /**
- * @namespace
- */
- namespace ZendTest\Mail;
- use Zend\Mail\Storage;
- /**
- * Maildir class, which uses old message class
- */
- class MboxOldMessage extends Storage\Mbox
- {
- /**
- * used message class
- * @var string
- */
- protected $_messageClass = '\Zend\Mail\Message';
- }
- /**
- * @category Zend
- * @package Zend_Mail
- * @subpackage UnitTests
- * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @group Zend_Mail
- */
- class MboxMessageOldTest extends \PHPUnit_Framework_TestCase
- {
- protected $_mboxOriginalFile;
- protected $_mboxFile;
- protected $_tmpdir;
- public function setUp()
- {
- if ($this->_tmpdir == null) {
- if (TESTS_ZEND_MAIL_TEMPDIR != null) {
- $this->_tmpdir = TESTS_ZEND_MAIL_TEMPDIR;
- } else {
- $this->_tmpdir = __DIR__ . '/_files/test.tmp/';
- }
- if (!file_exists($this->_tmpdir)) {
- mkdir($this->_tmpdir);
- }
- $count = 0;
- $dh = opendir($this->_tmpdir);
- while (readdir($dh) !== false) {
- ++$count;
- }
- closedir($dh);
- if ($count != 2) {
- $this->markTestSkipped('Are you sure your tmp dir is a valid empty dir?');
- return;
- }
- }
- $this->_mboxOriginalFile = __DIR__ . '/_files/test.mbox/INBOX';
- $this->_mboxFile = $this->_tmpdir . 'INBOX';
- copy($this->_mboxOriginalFile, $this->_mboxFile);
- }
- public function tearDown()
- {
- unlink($this->_mboxFile);
- }
- public function testFetchHeader()
- {
- $mail = new MboxOldMessage(array('filename' => $this->_mboxFile));
- $subject = $mail->getMessage(1)->subject;
- $this->assertEquals('Simple Message', $subject);
- }
- /*
- public function testFetchTopBody()
- {
- $mail = new MboxOldMessage(array('filename' => $this->_mboxFile));
- $content = $mail->getHeader(3, 1)->getContent();
- $this->assertEquals('Fair river! in thy bright, clear flow', trim($content));
- }
- */
- public function testFetchMessageHeader()
- {
- $mail = new MboxOldMessage(array('filename' => $this->_mboxFile));
- $subject = $mail->getMessage(1)->subject;
- $this->assertEquals('Simple Message', $subject);
- }
- public function testFetchMessageBody()
- {
- $mail = new MboxOldMessage(array('filename' => $this->_mboxFile));
- $content = $mail->getMessage(3)->getContent();
- list($content, ) = explode("\n", $content, 2);
- $this->assertEquals('Fair river! in thy bright, clear flow', trim($content));
- }
- public function testShortMbox()
- {
- $fh = fopen($this->_mboxFile, 'w');
- fputs($fh, "From \r\nSubject: test\r\nFrom \r\nSubject: test2\r\n");
- fclose($fh);
- $mail = new MboxOldMessage(array('filename' => $this->_mboxFile));
- $this->assertEquals($mail->countMessages(), 2);
- $this->assertEquals($mail->getMessage(1)->subject, 'test');
- $this->assertEquals($mail->getMessage(1)->getContent(), '');
- $this->assertEquals($mail->getMessage(2)->subject, 'test2');
- $this->assertEquals($mail->getMessage(2)->getContent(), '');
- }
- }