InterfaceTest.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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-2015 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. * @category Zend
  28. * @package Zend_Mail
  29. * @subpackage UnitTests
  30. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. * @group Zend_Mail
  33. */
  34. class Zend_Mail_InterfaceTest extends PHPUnit_Framework_TestCase
  35. {
  36. protected $_mboxFile;
  37. public function setUp()
  38. {
  39. $this->_mboxFile = dirname(__FILE__) . '/_files/test.mbox/INBOX';
  40. }
  41. public function testCount()
  42. {
  43. $list = new Zend_Mail_Storage_Mbox(array('filename' => $this->_mboxFile));
  44. $count = count($list);
  45. $this->assertEquals(7, $count);
  46. }
  47. public function testIsset()
  48. {
  49. $list = new Zend_Mail_Storage_Mbox(array('filename' => $this->_mboxFile));
  50. $this->assertTrue(isset($list[1]));
  51. }
  52. public function testNotIsset()
  53. {
  54. $list = new Zend_Mail_Storage_Mbox(array('filename' => $this->_mboxFile));
  55. $this->assertFalse(isset($list[10]));
  56. }
  57. public function testArrayGet()
  58. {
  59. $list = new Zend_Mail_Storage_Mbox(array('filename' => $this->_mboxFile));
  60. $subject = $list[1]->subject;
  61. $this->assertEquals('Simple Message', $subject);
  62. }
  63. public function testArraySetFail()
  64. {
  65. $list = new Zend_Mail_Storage_Mbox(array('filename' => $this->_mboxFile));
  66. try {
  67. $list[1] = 'test';
  68. } catch (Exception $e) {
  69. return; // test ok
  70. }
  71. $this->fail('no exception thrown while writing to array access');
  72. }
  73. public function testIterationKey()
  74. {
  75. $list = new Zend_Mail_Storage_Mbox(array('filename' => $this->_mboxFile));
  76. $pos = 1;
  77. foreach ($list as $key => $message) {
  78. $this->assertEquals($key, $pos, "wrong key in iteration $pos");
  79. ++$pos;
  80. }
  81. }
  82. public function testIterationIsMessage()
  83. {
  84. $list = new Zend_Mail_Storage_Mbox(array('filename' => $this->_mboxFile));
  85. foreach ($list as $key => $message) {
  86. $this->assertTrue($message instanceof Zend_Mail_Message_Interface, 'value in iteration is not a mail message');
  87. }
  88. }
  89. public function testIterationRounds()
  90. {
  91. $list = new Zend_Mail_Storage_Mbox(array('filename' => $this->_mboxFile));
  92. $count = 0;
  93. foreach ($list as $key => $message) {
  94. ++$count;
  95. }
  96. $this->assertEquals(7, $count);
  97. }
  98. public function testIterationWithSeek()
  99. {
  100. $list = new Zend_Mail_Storage_Mbox(array('filename' => $this->_mboxFile));
  101. $count = 0;
  102. foreach (new LimitIterator($list, 1, 3) as $key => $message) {
  103. ++$count;
  104. }
  105. $this->assertEquals(3, $count);
  106. }
  107. public function testIterationWithSeekCapped()
  108. {
  109. $list = new Zend_Mail_Storage_Mbox(array('filename' => $this->_mboxFile));
  110. $count = 0;
  111. foreach (new LimitIterator($list, 3, 7) as $key => $message) {
  112. ++$count;
  113. }
  114. $this->assertEquals(5, $count);
  115. }
  116. public function testFallback()
  117. {
  118. $list = new Zend_Mail_Storage_Mbox(array('filename' => $this->_mboxFile));
  119. try {
  120. $result = $list->noop();
  121. $this->assertTrue($result);
  122. } catch (Exception $e) {
  123. $this->fail('exception raised while calling noop thru fallback');
  124. }
  125. }
  126. public function testWrongVariable()
  127. {
  128. $list = new Zend_Mail_Storage_Mbox(array('filename' => $this->_mboxFile));
  129. try {
  130. $list->thisdoesnotexist;
  131. } catch (Exception $e) {
  132. return; // test ok
  133. }
  134. $this->fail('no exception thrown while reading wrong variable (via __get())');
  135. }
  136. public function testGetHeaders()
  137. {
  138. $list = new Zend_Mail_Storage_Mbox(array('filename' => $this->_mboxFile));
  139. $headers = $list[1]->getHeaders();
  140. $this->assertTrue(count($headers) > 0);
  141. }
  142. public function testWrongHeader()
  143. {
  144. $list = new Zend_Mail_Storage_Mbox(array('filename' => $this->_mboxFile));
  145. try {
  146. $list[1]->thisdoesnotexist;
  147. } catch (Exception $e) {
  148. return; // test ok
  149. }
  150. $this->fail('no exception thrown while reading wrong header');
  151. }
  152. }