loaders = spl_autoload_functions(); if (!is_array($this->loaders)) { // spl_autoload_functions does not return empty array when no // autoloaders registered... $this->loaders = array(); } Zend_Loader_Autoloader::resetInstance(); $this->autoloader = Zend_Loader_Autoloader::getInstance(); $this->application = new Zend_Application('testing'); $this->bootstrap = new Zend_Application_Bootstrap_Bootstrap($this->application); Zend_Controller_Front::getInstance()->resetInstance(); } public function tearDown() { Zend_Mail::clearDefaultTransport(); // Restore original autoloaders $loaders = spl_autoload_functions(); foreach ($loaders as $loader) { spl_autoload_unregister($loader); } foreach ($this->loaders as $loader) { spl_autoload_register($loader); } // Reset autoloader instance so it doesn't affect other tests Zend_Loader_Autoloader::resetInstance(); } public function testInitializationInitializesMailObject() { $resource = new Zend_Application_Resource_Mail(array()); $resource->setBootstrap($this->bootstrap); $resource->setOptions(array('transport' => array('type' => 'sendmail'))); $resource->init(); $this->assertTrue($resource->getMail() instanceof Zend_Mail_Transport_Abstract); $this->assertTrue($resource->getMail() instanceof Zend_Mail_Transport_Sendmail); } public function testInitializationReturnsMailObject() { $resource = new Zend_Application_Resource_Mail(array()); $resource->setBootstrap($this->bootstrap); $resource->setOptions(array('transport' => array('type' => 'sendmail'))); $resource->init(); $this->assertTrue($resource->init() instanceof Zend_Mail_Transport_Abstract); $this->assertTrue(Zend_Mail::getDefaultTransport() instanceof Zend_Mail_Transport_Sendmail); } public function testOptionsPassedToResourceAreUsedToInitializeMailTransportSmtp() { // If host option isn't passed on, an exception is thrown, making this text effective $options = array('transport' => array('type' => 'smtp', 'host' => 'example.com', 'register' => true)); $resource = new Zend_Application_Resource_Mail(array()); $resource->setBootstrap($this->bootstrap); $resource->setOptions($options); $resource->init(); $this->assertTrue(Zend_Mail::getDefaultTransport() instanceof Zend_Mail_Transport_Smtp); } public function testNotRegisteringTransport() { // If host option isn't passed on, an exception is thrown, making this test effective $options = array('transport' => array('type' => 'sendmail', 'register' => false)); $resource = new Zend_Application_Resource_Mail(array()); $resource->setBootstrap($this->bootstrap); $resource->setOptions($options); $resource->init(); $this->assertNull(Zend_Mail::getDefaultTransport()); } public function testDefaultFromAndReplyTo() { $options = array('defaultfrom' => array('email' => 'foo@example.com', 'name' => 'Foo Bar'), 'defaultreplyto' => array('email' => 'john@example.com', 'name' => 'John Doe')); $resource = new Zend_Application_Resource_Mail(array()); $resource->setBootstrap($this->bootstrap); $resource->setOptions($options); $resource->init(); $this->assertNull(Zend_Mail::getDefaultTransport()); $this->assertEquals($options['defaultfrom'], Zend_Mail::getDefaultFrom()); $this->assertEquals($options['defaultreplyto'], Zend_Mail::getDefaultReplyTo()); } } if (PHPUnit_MAIN_METHOD == 'Zend_Application_Resource_LogTest::main') { Zend_Application_Resource_LogTest::main(); }