2
0

InterfaceTest.php 5.1 KB

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