Skip to content

Commit

Permalink
Fixes e-mail capture for Magento CE 1.7 and Magento EE 1.12 #75
Browse files Browse the repository at this point in the history
  • Loading branch information
madalinoprea committed Mar 16, 2016
1 parent f72edf6 commit 48da66d
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 11 deletions.
29 changes: 26 additions & 3 deletions code/Debug/Model/Core/Email/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,33 @@ public function getContent(Zend_Mail $mail)
return $queue->getMessageBody();
}

/** @var Zend_Mime_Part $content */
$content = $this->isPlain() ? $mail->getBodyText() : $mail->getBodyHtml();
/** @var Zend_Mime_Part $mimePart */
$mimePart = $this->isPlain() ? $mail->getBodyText() : $mail->getBodyHtml();

return $content ? $content->getRawContent() : '';
return $this->getPartDecodedContent($mimePart);
}


/**
* Returns raw content of e-mail message. Abstract Zend_Mime_Part interface changes between 1.11.0 and 1.12.0
*
* @param Zend_Mime_Part $mimePart
* @return String
*/
public function getPartDecodedContent(Zend_Mime_Part $mimePart)
{

// getRawContent is not available in Zend 1.11 (Magento CE 1.7)
if (method_exists($mimePart, 'getRawContent')) {
return $mimePart->getRawContent();
}

$encoding = $mimePart->encoding;
$mimePart->encoding = 'none';
$content = $mimePart->getContent();
$mimePart->encoding = $encoding;

return $content;
}


Expand Down
46 changes: 38 additions & 8 deletions code/Debug/Test/Model/Core/Email/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@ public function testAddEmailToProfile()
*/
public function testGetContentForPlain()
{
$content = $this->getMock('Zend_Mime_Part', array('getRawContent'), array(), '', false);;
$content->expects($this->once())->method('getRawContent')->willReturn('raw content');
$mimePart = $this->getMock('Zend_Mime_Part', null, array(), '', false);;

$mail = $this->getMock('Zend_Mail', array('getBodyText', 'getBodyHtml'));
$mail->expects($this->once())->method('getBodyText')->willReturn($content);
$mail->expects($this->once())->method('getBodyText')->willReturn($mimePart);
$mail->expects($this->never())->method('getBodyHtml');

$model = $this->getModelMock('core/email_template', array('isPlain'));
$model = $this->getModelMock('core/email_template', array('isPlain', 'getPartDecodedContent'));
$model->expects($this->any())->method('isPlain')->willReturn(true);
$model->expects($this->once())->method('getPartDecodedContent')->with($mimePart)->willReturn('raw content');

$actual = $model->getContent($mail);
$this->assertEquals('raw content', $actual);
Expand All @@ -141,15 +141,15 @@ public function testGetContentForPlain()
*/
public function testGetContentForNonPlain()
{
$content = $this->getMock('Zend_Mime_Part', array('getRawContent'), array(), '', false);;
$content->expects($this->once())->method('getRawContent')->willReturn('raw html content');
$mimePart = $this->getMock('Zend_Mime_Part', null, array(), '', false);;

$mail = $this->getMock('Zend_Mail', array('getBodyText', 'getBodyHtml'));
$mail->expects($this->never())->method('getBodyText');
$mail->expects($this->once())->method('getBodyHtml')->willReturn($content);
$mail->expects($this->once())->method('getBodyHtml')->willReturn($mimePart);

$model = $this->getModelMock('core/email_template', array('isPlain'));
$model = $this->getModelMock('core/email_template', array('isPlain', 'getPartDecodedContent'));
$model->expects($this->any())->method('isPlain')->willReturn(false);
$model->expects($this->once())->method('getPartDecodedContent')->with($mimePart)->willReturn('raw html content');

$actual = $model->getContent($mail);
$this->assertEquals('raw html content', $actual);
Expand Down Expand Up @@ -178,6 +178,33 @@ public function testGetContentForQueue()
}


/**
* @covers Sheep_Debug_Model_Core_Email_Template_Capture::getPartDecodedContent
*/
public function testGetPartDecodedContent()
{
// this condition doesn't seem right to live in a test
$zendWithGetRawContent = Zend_Version::compareVersion('1.12.0') <= 0;

$mimePart = $this->getMock('Zend_Mime_Part', array(), array(), '', false);
if ($zendWithGetRawContent) {
$mimePart->expects($this->any())->method('getRawContent')->willReturn('raw content');
} else {
$mimePart->expects($this->any())->method('getContent')->willReturn('content');
}

$model = $this->getModelMock('core/email_template', array('isPlain'));
$actual = $model->getPartDecodedContent($mimePart);

if ($zendWithGetRawContent) {
$this->assertEquals('raw content', $actual);
} else {
$this->assertEquals('content', $actual);

}
}


/**
* @covers Sheep_Debug_Model_Core_Email_Template_Capture::decodeSubject
*/
Expand All @@ -188,6 +215,9 @@ public function testDecodeSubject()
}


/**
* @covers Sheep_Debug_Model_Core_Email_Template_Capture::decodeSubject
*/
public function testDecodeSubjectForQueue()
{
$queue = $this->getModelMock('core/email_queue', array('getMessageParameters'));
Expand Down

0 comments on commit 48da66d

Please sign in to comment.