2
0

MboxMessageOldTest.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Mail
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * Zend_Mail_Storage_Mbox
  24. */
  25. require_once 'Zend/Mail/Storage/Mbox.php';
  26. /**
  27. * Zend_Config
  28. */
  29. require_once 'Zend/Config.php';
  30. /**
  31. * PHPUnit test case
  32. */
  33. require_once 'PHPUnit/Framework/TestCase.php';
  34. /**
  35. * Maildir class, which uses old message class
  36. *
  37. * @category Zend
  38. * @package Zend_Mail
  39. * @subpackage UnitTests
  40. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  41. * @license http://framework.zend.com/license/new-bsd New BSD License
  42. */
  43. class Zend_Mail_Storage_Mbox_OldMessage extends Zend_Mail_Storage_Mbox
  44. {
  45. /**
  46. * used message class
  47. * @var string
  48. */
  49. protected $_messageClass = 'Zend_Mail_Message';
  50. }
  51. /**
  52. * @category Zend
  53. * @package Zend_Mail
  54. * @subpackage UnitTests
  55. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  56. * @license http://framework.zend.com/license/new-bsd New BSD License
  57. * @group Zend_Mail
  58. */
  59. class Zend_Mail_MboxMessageOldTest extends PHPUnit_Framework_TestCase
  60. {
  61. protected $_mboxOriginalFile;
  62. protected $_mboxFile;
  63. protected $_tmpdir;
  64. public function setUp()
  65. {
  66. if ($this->_tmpdir == null) {
  67. if (TESTS_ZEND_MAIL_TEMPDIR != null) {
  68. $this->_tmpdir = TESTS_ZEND_MAIL_TEMPDIR;
  69. } else {
  70. $this->_tmpdir = dirname(__FILE__) . '/_files/test.tmp/';
  71. }
  72. if (!file_exists($this->_tmpdir)) {
  73. mkdir($this->_tmpdir);
  74. }
  75. $count = 0;
  76. $dh = opendir($this->_tmpdir);
  77. while (readdir($dh) !== false) {
  78. ++$count;
  79. }
  80. closedir($dh);
  81. if ($count != 2) {
  82. $this->markTestSkipped('Are you sure your tmp dir is a valid empty dir?');
  83. return;
  84. }
  85. }
  86. $this->_mboxOriginalFile = dirname(__FILE__) . '/_files/test.mbox/INBOX';
  87. $this->_mboxFile = $this->_tmpdir . 'INBOX';
  88. copy($this->_mboxOriginalFile, $this->_mboxFile);
  89. }
  90. public function tearDown()
  91. {
  92. unlink($this->_mboxFile);
  93. }
  94. public function testFetchHeader()
  95. {
  96. $mail = new Zend_Mail_Storage_Mbox_OldMessage(array('filename' => $this->_mboxFile));
  97. $subject = $mail->getMessage(1)->subject;
  98. $this->assertEquals('Simple Message', $subject);
  99. }
  100. /*
  101. public function testFetchTopBody()
  102. {
  103. $mail = new Zend_Mail_Storage_Mbox_OldMessage(array('filename' => $this->_mboxFile));
  104. $content = $mail->getHeader(3, 1)->getContent();
  105. $this->assertEquals('Fair river! in thy bright, clear flow', trim($content));
  106. }
  107. */
  108. public function testFetchMessageHeader()
  109. {
  110. $mail = new Zend_Mail_Storage_Mbox_OldMessage(array('filename' => $this->_mboxFile));
  111. $subject = $mail->getMessage(1)->subject;
  112. $this->assertEquals('Simple Message', $subject);
  113. }
  114. public function testFetchMessageBody()
  115. {
  116. $mail = new Zend_Mail_Storage_Mbox_OldMessage(array('filename' => $this->_mboxFile));
  117. $content = $mail->getMessage(3)->getContent();
  118. list($content, ) = explode("\n", $content, 2);
  119. $this->assertEquals('Fair river! in thy bright, clear flow', trim($content));
  120. }
  121. public function testShortMbox()
  122. {
  123. $fh = fopen($this->_mboxFile, 'w');
  124. fputs($fh, "From \r\nSubject: test\r\nFrom \r\nSubject: test2\r\n");
  125. fclose($fh);
  126. $mail = new Zend_Mail_Storage_Mbox_OldMessage(array('filename' => $this->_mboxFile));
  127. $this->assertEquals($mail->countMessages(), 2);
  128. $this->assertEquals($mail->getMessage(1)->subject, 'test');
  129. $this->assertEquals($mail->getMessage(1)->getContent(), '');
  130. $this->assertEquals($mail->getMessage(2)->subject, 'test2');
  131. $this->assertEquals($mail->getMessage(2)->getContent(), '');
  132. }
  133. }