PageRenderTime 51ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/Zend/Mail/MaildirMessageOldTest.php

http://github.com/zendframework/zf2
PHP | 187 lines | 114 code | 21 blank | 52 comment | 14 complexity | 12637ba2c03073151074d4612c7c0e6a MD5 | raw file
Possible License(s): BSD-3-Clause
  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. * @category Zend
  30. * @package Zend_Mail
  31. * @subpackage UnitTests
  32. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  33. * @license http://framework.zend.com/license/new-bsd New BSD License
  34. */
  35. class MaildirOldMessage extends Storage\Maildir
  36. {
  37. /**
  38. * used message class
  39. * @var string
  40. */
  41. protected $_messageClass = '\Zend\Mail\Message';
  42. }
  43. /**
  44. * @category Zend
  45. * @package Zend_Mail
  46. * @subpackage UnitTests
  47. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  48. * @license http://framework.zend.com/license/new-bsd New BSD License
  49. * @group Zend_Mail
  50. */
  51. class MaildirMessageOldTest extends \PHPUnit_Framework_TestCase
  52. {
  53. protected $_originalMaildir;
  54. protected $_maildir;
  55. protected $_tmpdir;
  56. public function setUp()
  57. {
  58. $this->_originalMaildir = __DIR__ . '/_files/test.maildir/';
  59. if (!is_dir($this->_originalMaildir . '/cur/')) {
  60. $this->markTestSkipped('You have to unpack maildir.tar in Zend/Mail/_files/test.maildir/ '
  61. . 'directory before enabling the maildir tests');
  62. return;
  63. }
  64. if ($this->_tmpdir == null) {
  65. if (TESTS_ZEND_MAIL_TEMPDIR != null) {
  66. $this->_tmpdir = TESTS_ZEND_MAIL_TEMPDIR;
  67. } else {
  68. $this->_tmpdir = __DIR__ . '/_files/test.tmp/';
  69. }
  70. if (!file_exists($this->_tmpdir)) {
  71. mkdir($this->_tmpdir);
  72. }
  73. $count = 0;
  74. $dh = opendir($this->_tmpdir);
  75. while (readdir($dh) !== false) {
  76. ++$count;
  77. }
  78. closedir($dh);
  79. if ($count != 2) {
  80. $this->markTestSkipped('Are you sure your tmp dir is a valid empty dir?');
  81. return;
  82. }
  83. }
  84. $this->_maildir = $this->_tmpdir;
  85. foreach (array('cur', 'new') as $dir) {
  86. mkdir($this->_tmpdir . $dir);
  87. $dh = opendir($this->_originalMaildir . $dir);
  88. while (($entry = readdir($dh)) !== false) {
  89. $entry = $dir . '/' . $entry;
  90. if (!is_file($this->_originalMaildir . $entry)) {
  91. continue;
  92. }
  93. copy($this->_originalMaildir . $entry, $this->_tmpdir . $entry);
  94. }
  95. closedir($dh);
  96. }
  97. }
  98. public function tearDown()
  99. {
  100. foreach (array('cur', 'new') as $dir) {
  101. $dh = opendir($this->_tmpdir . $dir);
  102. while (($entry = readdir($dh)) !== false) {
  103. $entry = $this->_tmpdir . $dir . '/' . $entry;
  104. if (!is_file($entry)) {
  105. continue;
  106. }
  107. unlink($entry);
  108. }
  109. closedir($dh);
  110. rmdir($this->_tmpdir . $dir);
  111. }
  112. }
  113. public function testFetchHeader()
  114. {
  115. $mail = new MaildirOldMessage(array('dirname' => $this->_maildir));
  116. $subject = $mail->getMessage(1)->subject;
  117. $this->assertEquals('Simple Message', $subject);
  118. }
  119. /*
  120. public function testFetchTopBody()
  121. {
  122. $mail = new MaildirOldMessage(array('dirname' => $this->_maildir));
  123. $content = $mail->getHeader(3, 1)->getContent();
  124. $this->assertEquals('Fair river! in thy bright, clear flow', trim($content));
  125. }
  126. */
  127. public function testFetchMessageHeader()
  128. {
  129. $mail = new MaildirOldMessage(array('dirname' => $this->_maildir));
  130. $subject = $mail->getMessage(1)->subject;
  131. $this->assertEquals('Simple Message', $subject);
  132. }
  133. public function testFetchMessageBody()
  134. {
  135. $mail = new MaildirOldMessage(array('dirname' => $this->_maildir));
  136. $content = $mail->getMessage(3)->getContent();
  137. list($content, ) = explode("\n", $content, 2);
  138. $this->assertEquals('Fair river! in thy bright, clear flow', trim($content));
  139. }
  140. public function testHasFlag()
  141. {
  142. $mail = new MaildirOldMessage(array('dirname' => $this->_maildir));
  143. $this->assertFalse($mail->getMessage(5)->hasFlag(Storage::FLAG_SEEN));
  144. $this->assertTrue($mail->getMessage(5)->hasFlag(Storage::FLAG_RECENT));
  145. $this->assertTrue($mail->getMessage(2)->hasFlag(Storage::FLAG_FLAGGED));
  146. $this->assertFalse($mail->getMessage(2)->hasFlag(Storage::FLAG_ANSWERED));
  147. }
  148. public function testGetFlags()
  149. {
  150. $mail = new MaildirOldMessage(array('dirname' => $this->_maildir));
  151. $flags = $mail->getMessage(1)->getFlags();
  152. $this->assertTrue(isset($flags[Storage::FLAG_SEEN]));
  153. $this->assertTrue(in_array(Storage::FLAG_SEEN, $flags));
  154. }
  155. public function testFetchPart()
  156. {
  157. $mail = new MaildirOldMessage(array('dirname' => $this->_maildir));
  158. $this->assertEquals($mail->getMessage(4)->getPart(2)->contentType, 'text/x-vertical');
  159. }
  160. public function testPartSize()
  161. {
  162. $mail = new MaildirOldMessage(array('dirname' => $this->_maildir));
  163. $this->assertEquals($mail->getMessage(4)->getPart(2)->getSize(), 80);
  164. }
  165. }