/sbw/ZendFramework-1.11.4/tests/Zend/Application/Resource/MailTest.php

https://github.com/nbcutech/o3drupal · PHP · 220 lines · 136 code · 31 blank · 53 comment · 4 complexity · 0ac3eb8803a3d77a63a0e18b23d7bf67 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_Application
  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. * @version $Id$
  21. */
  22. if (!defined('PHPUnit_MAIN_METHOD')) {
  23. define('PHPUnit_MAIN_METHOD', 'Zend_Application_Resource_MailTest::main');
  24. }
  25. /**
  26. * Zend_Loader_Autoloader
  27. */
  28. require_once 'Zend/Loader/Autoloader.php';
  29. /**
  30. * @category Zend
  31. * @package Zend_Application
  32. * @subpackage UnitTests
  33. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  34. * @license http://framework.zend.com/license/new-bsd New BSD License
  35. * @group Zend_Application
  36. */
  37. class Zend_Application_Resource_MailTest extends PHPUnit_Framework_TestCase
  38. {
  39. public static function main()
  40. {
  41. $suite = new PHPUnit_Framework_TestSuite(__CLASS__);
  42. $result = PHPUnit_TextUI_TestRunner::run($suite);
  43. }
  44. public function setUp()
  45. {
  46. // Store original autoloaders
  47. $this->loaders = spl_autoload_functions();
  48. if (!is_array($this->loaders)) {
  49. // spl_autoload_functions does not return empty array when no
  50. // autoloaders registered...
  51. $this->loaders = array();
  52. }
  53. Zend_Loader_Autoloader::resetInstance();
  54. $this->autoloader = Zend_Loader_Autoloader::getInstance();
  55. $this->application = new Zend_Application('testing');
  56. $this->bootstrap = new Zend_Application_Bootstrap_Bootstrap($this->application);
  57. Zend_Controller_Front::getInstance()->resetInstance();
  58. }
  59. public function tearDown()
  60. {
  61. Zend_Mail::clearDefaultTransport();
  62. // Restore original autoloaders
  63. $loaders = spl_autoload_functions();
  64. foreach ($loaders as $loader) {
  65. spl_autoload_unregister($loader);
  66. }
  67. foreach ($this->loaders as $loader) {
  68. spl_autoload_register($loader);
  69. }
  70. // Reset autoloader instance so it doesn't affect other tests
  71. Zend_Loader_Autoloader::resetInstance();
  72. }
  73. public function testInitializationInitializesMailObject()
  74. {
  75. $resource = new Zend_Application_Resource_Mail(array());
  76. $resource->setBootstrap($this->bootstrap);
  77. $resource->setOptions(array('transport' => array('type' => 'sendmail')));
  78. $resource->init();
  79. $this->assertTrue($resource->getMail() instanceof Zend_Mail_Transport_Abstract);
  80. $this->assertTrue($resource->getMail() instanceof Zend_Mail_Transport_Sendmail);
  81. }
  82. public function testInitializationReturnsMailObject()
  83. {
  84. $resource = new Zend_Application_Resource_Mail(array());
  85. $resource->setBootstrap($this->bootstrap);
  86. $resource->setOptions(array('transport' => array('type' => 'sendmail')));
  87. $resource->init();
  88. $this->assertTrue($resource->init() instanceof Zend_Mail_Transport_Abstract);
  89. $this->assertTrue(Zend_Mail::getDefaultTransport() instanceof Zend_Mail_Transport_Sendmail);
  90. }
  91. public function testOptionsPassedToResourceAreUsedToInitializeMailTransportSmtp()
  92. {
  93. // If host option isn't passed on, an exception is thrown, making this text effective
  94. $options = array('transport' => array('type' => 'smtp',
  95. 'host' => 'example.com',
  96. 'register' => true));
  97. $resource = new Zend_Application_Resource_Mail(array());
  98. $resource->setBootstrap($this->bootstrap);
  99. $resource->setOptions($options);
  100. $resource->init();
  101. $this->assertTrue(Zend_Mail::getDefaultTransport() instanceof Zend_Mail_Transport_Smtp);
  102. }
  103. public function testNotRegisteringTransport()
  104. {
  105. // If host option isn't passed on, an exception is thrown, making this test effective
  106. $options = array('transport' => array('type' => 'sendmail',
  107. 'register' => false));
  108. $resource = new Zend_Application_Resource_Mail(array());
  109. $resource->setBootstrap($this->bootstrap);
  110. $resource->setOptions($options);
  111. $resource->init();
  112. $this->assertNull(Zend_Mail::getDefaultTransport());
  113. }
  114. public function testDefaultFromAndReplyTo()
  115. {
  116. $options = array('defaultfrom' => array('email' => 'foo@example.com',
  117. 'name' => 'Foo Bar'),
  118. 'defaultreplyto' => array('email' => 'john@example.com',
  119. 'name' => 'John Doe'));
  120. $resource = new Zend_Application_Resource_Mail(array());
  121. $resource->setBootstrap($this->bootstrap);
  122. $resource->setOptions($options);
  123. $resource->init();
  124. $this->assertNull(Zend_Mail::getDefaultTransport());
  125. $this->assertEquals($options['defaultfrom'], Zend_Mail::getDefaultFrom());
  126. $this->assertEquals($options['defaultreplyto'], Zend_Mail::getDefaultReplyTo());
  127. }
  128. /**
  129. * Got notice: Undefined index: type
  130. */
  131. public function testDefaultTransport() {
  132. $options = array('transport' => array(//'type' => 'sendmail', // dont define type
  133. 'register' => true));
  134. $resource = new Zend_Application_Resource_Mail(array());
  135. $resource->setBootstrap($this->bootstrap);
  136. $resource->setOptions($options);
  137. $resource->init();
  138. $this->assertTrue(Zend_Mail::getDefaultTransport() instanceof Zend_Mail_Transport_Sendmail);
  139. }
  140. /**
  141. * @group ZF-8811
  142. */
  143. public function testDefaultsCaseSensivity() {
  144. $options = array('defaultFroM' => array('email' => 'f00@example.com', 'name' => null),
  145. 'defAultReplyTo' => array('email' => 'j0hn@example.com', 'name' => null));
  146. $resource = new Zend_Application_Resource_Mail(array());
  147. $resource->setBootstrap($this->bootstrap);
  148. $resource->setOptions($options);
  149. $resource->init();
  150. $this->assertNull(Zend_Mail::getDefaultTransport());
  151. $this->assertEquals($options['defaultFroM'], Zend_Mail::getDefaultFrom());
  152. $this->assertEquals($options['defAultReplyTo'], Zend_Mail::getDefaultReplyTo());
  153. }
  154. /**
  155. * @group ZF-8981
  156. */
  157. public function testNumericRegisterDirectiveIsPassedOnCorrectly() {
  158. $options = array('transport' => array('type' => 'sendmail',
  159. 'register' => '1')); // Culprit
  160. $resource = new Zend_Application_Resource_Mail(array());
  161. $resource->setBootstrap($this->bootstrap);
  162. $resource->setOptions($options);
  163. $resource->init();
  164. $this->assertTrue(Zend_Mail::getDefaultTransport() instanceof Zend_Mail_Transport_Sendmail);
  165. }
  166. /**
  167. * @group ZF-9136
  168. */
  169. public function testCustomMailTransportWithFQName() {
  170. $options = array('transport' => array('type' => 'Zend_Mail_Transport_Sendmail'));
  171. $resource = new Zend_Application_Resource_Mail(array());
  172. $resource->setBootstrap($this->bootstrap);
  173. $resource->setOptions($options);
  174. $this->assertTrue($resource->init() instanceof Zend_Mail_Transport_Sendmail);
  175. }
  176. /**
  177. * @group ZF-9136
  178. */
  179. public function testCustomMailTransportWithWrontCasesAsShouldBe() {
  180. $options = array('transport' => array('type' => 'Zend_Application_Resource_mailTestCAsE'));
  181. $resource = new Zend_Application_Resource_Mail(array());
  182. $resource->setBootstrap($this->bootstrap);
  183. $resource->setOptions($options);
  184. $this->assertTrue($resource->init() instanceof Zend_Application_Resource_mailTestCAsE);
  185. }
  186. }
  187. if (PHPUnit_MAIN_METHOD == 'Zend_Application_Resource_MailTest::main') {
  188. Zend_Application_Resource_MailTest::main();
  189. }