/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

  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-2011 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /**
  22. * @namespace
  23. */
  24. namespace ZendTest\Mail;
  25. use Zend\Mail\Storage;
  26. /**
  27. * Maildir class, which uses old message class
  28. */
  29. class MboxOldMessage extends Storage\Mbox
  30. {
  31. /**
  32. * used message class
  33. * @var string
  34. */
  35. protected $_messageClass = '\Zend\Mail\Message';
  36. }
  37. /**
  38. * @category Zend
  39. * @package Zend_Mail
  40. * @subpackage UnitTests
  41. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  42. * @license http://framework.zend.com/license/new-bsd New BSD License
  43. * @group Zend_Mail
  44. */
  45. class MboxMessageOldTest extends \PHPUnit_Framework_TestCase
  46. {
  47. protected $_mboxOriginalFile;
  48. protected $_mboxFile;
  49. protected $_tmpdir;
  50. public function setUp()
  51. {
  52. if ($this->_tmpdir == null) {
  53. if (TESTS_ZEND_MAIL_TEMPDIR != null) {
  54. $this->_tmpdir = TESTS_ZEND_MAIL_TEMPDIR;
  55. } else {
  56. $this->_tmpdir = __DIR__ . '/_files/test.tmp/';
  57. }
  58. if (!file_exists($this->_tmpdir)) {
  59. mkdir($this->_tmpdir);
  60. }
  61. $count = 0;
  62. $dh = opendir($this->_tmpdir);
  63. while (readdir($dh) !== false) {
  64. ++$count;
  65. }
  66. closedir($dh);
  67. if ($count != 2) {
  68. $this->markTestSkipped('Are you sure your tmp dir is a valid empty dir?');
  69. return;
  70. }
  71. }
  72. $this->_mboxOriginalFile = __DIR__ . '/_files/test.mbox/INBOX';
  73. $this->_mboxFile = $this->_tmpdir . 'INBOX';
  74. copy($this->_mboxOriginalFile, $this->_mboxFile);
  75. }
  76. public function tearDown()
  77. {
  78. unlink($this->_mboxFile);
  79. }
  80. public function testFetchHeader()
  81. {
  82. $mail = new MboxOldMessage(array('filename' => $this->_mboxFile));
  83. $subject = $mail->getMessage(1)->subject;
  84. $this->assertEquals('Simple Message', $subject);
  85. }
  86. /*
  87. public function testFetchTopBody()
  88. {
  89. $mail = new MboxOldMessage(array('filename' => $this->_mboxFile));
  90. $content = $mail->getHeader(3, 1)->getContent();
  91. $this->assertEquals('Fair river! in thy bright, clear flow', trim($content));
  92. }
  93. */
  94. public function testFetchMessageHeader()
  95. {
  96. $mail = new MboxOldMessage(array('filename' => $this->_mboxFile));
  97. $subject = $mail->getMessage(1)->subject;
  98. $this->assertEquals('Simple Message', $subject);
  99. }
  100. public function testFetchMessageBody()
  101. {
  102. $mail = new MboxOldMessage(array('filename' => $this->_mboxFile));
  103. $content = $mail->getMessage(3)->getContent();
  104. list($content, ) = explode("\n", $content, 2);
  105. $this->assertEquals('Fair river! in thy bright, clear flow', trim($content));
  106. }
  107. public function testShortMbox()
  108. {
  109. $fh = fopen($this->_mboxFile, 'w');
  110. fputs($fh, "From \r\nSubject: test\r\nFrom \r\nSubject: test2\r\n");
  111. fclose($fh);
  112. $mail = new MboxOldMessage(array('filename' => $this->_mboxFile));
  113. $this->assertEquals($mail->countMessages(), 2);
  114. $this->assertEquals($mail->getMessage(1)->subject, 'test');
  115. $this->assertEquals($mail->getMessage(1)->getContent(), '');
  116. $this->assertEquals($mail->getMessage(2)->subject, 'test2');
  117. $this->assertEquals($mail->getMessage(2)->getContent(), '');
  118. }
  119. }