|
|
@@ -59,6 +59,13 @@ require_once 'Zend/View/Exception.php';
|
|
|
class Zend_Log_Writer_MailTest extends PHPUnit_Framework_TestCase
|
|
|
{
|
|
|
/**
|
|
|
+ * Mock Transport for Zend_Mail
|
|
|
+ *
|
|
|
+ * @var Zend_Mail_Transport_Abstract
|
|
|
+ */
|
|
|
+ protected $_transport;
|
|
|
+
|
|
|
+ /**
|
|
|
* Runs the test methods of this class.
|
|
|
*
|
|
|
* @return void
|
|
|
@@ -70,6 +77,20 @@ class Zend_Log_Writer_MailTest extends PHPUnit_Framework_TestCase
|
|
|
$result = PHPUnit_TextUI_TestRunner::run($suite);
|
|
|
}
|
|
|
|
|
|
+ protected function setUp()
|
|
|
+ {
|
|
|
+ $this->_transport = $this->getMockForAbstractClass(
|
|
|
+ 'Zend_Mail_Transport_Abstract',
|
|
|
+ array()
|
|
|
+ );
|
|
|
+ Zend_Mail::setDefaultTransport($this->_transport);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function tearDown()
|
|
|
+ {
|
|
|
+ Zend_Mail::clearDefaultTransport();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Tests normal logging, but with multiple messages for a level.
|
|
|
*
|
|
|
@@ -287,6 +308,162 @@ class Zend_Log_Writer_MailTest extends PHPUnit_Framework_TestCase
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * @group ZF-9990
|
|
|
+ */
|
|
|
+ public function testFactory()
|
|
|
+ {
|
|
|
+ $config = array(
|
|
|
+ 'from' => array(
|
|
|
+ 'email' => 'log@test.framework.zend.com'
|
|
|
+ ),
|
|
|
+ 'to' => 'admin@domain.com',
|
|
|
+ 'subject' => '[error] exceptions on my application'
|
|
|
+ );
|
|
|
+
|
|
|
+ $writer = Zend_Log_Writer_Mail::factory($config);
|
|
|
+ $this->assertType('Zend_Log_Writer_Mail', $writer);
|
|
|
+
|
|
|
+ $writer->write($this->_getEvent());
|
|
|
+ $writer->shutdown();
|
|
|
+
|
|
|
+ $this->assertEquals('admin@domain.com', $this->_transport->recipients);
|
|
|
+ $this->assertContains('an info message', $this->_transport->body);
|
|
|
+ $this->assertContains('From: log@test.framework.zend.com', $this->_transport->header);
|
|
|
+ $this->assertContains('To: admin@domain.com', $this->_transport->header);
|
|
|
+ $this->assertContains('Subject: [error] exceptions on my application', $this->_transport->header);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @group ZF-9990
|
|
|
+ */
|
|
|
+ public function testFactoryShouldSetSubjectPrependText()
|
|
|
+ {
|
|
|
+ $config = array(
|
|
|
+ 'subjectPrependText' => '[error] exceptions on my application'
|
|
|
+ );
|
|
|
+
|
|
|
+ $writer = Zend_Log_Writer_Mail::factory($config);
|
|
|
+ $writer->write($this->_getEvent());
|
|
|
+ $writer->shutdown();
|
|
|
+
|
|
|
+ $this->assertContains('Subject: [error] exceptions on my application (INFO=1)', $this->_transport->header);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @group ZF-9990
|
|
|
+ */
|
|
|
+ public function testFactoryShouldAcceptCustomMailClass()
|
|
|
+ {
|
|
|
+ $this->getMock('Zend_Mail', array(), array(), 'Zend_Stub_Mail_Custom');
|
|
|
+ $config = array(
|
|
|
+ 'class' => 'Zend_Stub_Mail_Custom'
|
|
|
+ );
|
|
|
+
|
|
|
+ $writer = Zend_Log_Writer_Mail::factory($config);
|
|
|
+ $this->assertType('Zend_Log_Writer_Mail', $writer);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @group ZF-9990
|
|
|
+ */
|
|
|
+ public function testFactoryShouldSetCharsetForMail()
|
|
|
+ {
|
|
|
+ $config = array(
|
|
|
+ 'charset' => 'UTF-8'
|
|
|
+ );
|
|
|
+
|
|
|
+ $writer = Zend_Log_Writer_Mail::factory($config);
|
|
|
+ $writer->write($this->_getEvent());
|
|
|
+ $writer->shutdown();
|
|
|
+
|
|
|
+ $this->assertContains('Content-Type: text/plain; charset=UTF-8', $this->_transport->header);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @group ZF-9990
|
|
|
+ */
|
|
|
+ public function testFactoryShouldAllowToSetMultipleRecipientsInArray()
|
|
|
+ {
|
|
|
+ $config = array(
|
|
|
+ 'to' => array(
|
|
|
+ 'John Doe' => 'admin1@domain.com',
|
|
|
+ 'admin2@domain.com'
|
|
|
+ ),
|
|
|
+ 'cc' => array(
|
|
|
+ 'bug@domain.com',
|
|
|
+ 'project' => 'projectname@domain.com'
|
|
|
+ )
|
|
|
+ );
|
|
|
+
|
|
|
+ $writer = Zend_Log_Writer_Mail::factory($config);
|
|
|
+ $writer->write($this->_getEvent());
|
|
|
+ $writer->shutdown();
|
|
|
+
|
|
|
+ $this->assertContains('admin1@domain.com', $this->_transport->recipients);
|
|
|
+ $this->assertContains('admin2@domain.com', $this->_transport->recipients);
|
|
|
+ $this->assertContains('bug@domain.com', $this->_transport->recipients);
|
|
|
+ $this->assertContains('projectname@domain.com', $this->_transport->recipients);
|
|
|
+ $this->assertContains('To: John Doe <admin1@domain.com>', $this->_transport->header);
|
|
|
+ $this->assertContains('admin2@domain.com', $this->_transport->header);
|
|
|
+ $this->assertContains('Cc: bug@domain.com', $this->_transport->header);
|
|
|
+ $this->assertContains('project <projectname@domain.com>', $this->_transport->header);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @group ZF-9990
|
|
|
+ */
|
|
|
+ public function testFactoryWithLayout()
|
|
|
+ {
|
|
|
+ $config = array(
|
|
|
+ 'layoutOptions' => array(
|
|
|
+ 'layoutPath' => dirname(__FILE__) . '/_files'
|
|
|
+ )
|
|
|
+ );
|
|
|
+
|
|
|
+ $writer = Zend_Log_Writer_Mail::factory($config);
|
|
|
+ $writer->write($this->_getEvent());
|
|
|
+ $writer->shutdown();
|
|
|
+
|
|
|
+ $this->assertFalse(empty($this->_transport->boundary));
|
|
|
+ $this->assertContains('Content-Type: multipart/', $this->_transport->header);
|
|
|
+ $this->assertContains('boundary=', $this->_transport->header);
|
|
|
+ $this->assertContains('Content-Type: text/plain', $this->_transport->body);
|
|
|
+ $this->assertContains('Content-Type: text/html', $this->_transport->body);
|
|
|
+ $this->assertContains($this->_transport->boundary, $this->_transport->body);
|
|
|
+ $this->assertEquals(2, substr_count($this->_transport->body, 'an info message'));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @group ZF-9990
|
|
|
+ */
|
|
|
+ public function testFactoryShouldSetLayoutFormatter()
|
|
|
+ {
|
|
|
+ $config = array(
|
|
|
+ 'layoutOptions' => array(
|
|
|
+ 'layoutPath' => '/path/to/layout/scripts'
|
|
|
+ ),
|
|
|
+ 'layoutFormatter' => 'Zend_Log_Formatter_Simple'
|
|
|
+ );
|
|
|
+
|
|
|
+ $writer = Zend_Log_Writer_Mail::factory($config);
|
|
|
+ $this->assertType('Zend_Log_Formatter_Simple', $writer->getLayoutFormatter());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @group ZF-9990
|
|
|
+ */
|
|
|
+ public function testFactoryWithCustomLayoutClass()
|
|
|
+ {
|
|
|
+ $this->getMock('Zend_Layout', null, array(), 'Zend_Stub_Layout_Custom');
|
|
|
+ $config = array(
|
|
|
+ 'layout' => 'Zend_Stub_Layout_Custom'
|
|
|
+ );
|
|
|
+
|
|
|
+ $writer = Zend_Log_Writer_Mail::factory($config);
|
|
|
+ $this->assertType('Zend_Log_Writer_Mail', $writer);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* Returns an array of the Zend_Mail mock object, Zend_Log_Writer_Mail
|
|
|
* object, and Zend_Log objects.
|
|
|
*
|
|
|
@@ -324,9 +501,24 @@ class Zend_Log_Writer_MailTest extends PHPUnit_Framework_TestCase
|
|
|
|
|
|
return array($mail, $writer, $log, $layout);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Returns a sample of an event
|
|
|
+ *
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ protected function _getEvent()
|
|
|
+ {
|
|
|
+ return array(
|
|
|
+ 'timestamp' => date('c'),
|
|
|
+ 'message' => 'an info message',
|
|
|
+ 'priority' => 6,
|
|
|
+ 'priorityName' => 'INFO'
|
|
|
+ );
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// Call Zend_Log_Writer_MailTest::main() if this source file is executed directly.
|
|
|
if (PHPUnit_MAIN_METHOD == "Zend_Log_Writer_MailTest::main") {
|
|
|
Zend_Log_Writer_MailTest::main();
|
|
|
-}
|
|
|
+}
|