Skip to content

Commit 48da66d

Browse files
committed
Fixes e-mail capture for Magento CE 1.7 and Magento EE 1.12 #75
1 parent f72edf6 commit 48da66d

File tree

2 files changed

+64
-11
lines changed

2 files changed

+64
-11
lines changed

code/Debug/Model/Core/Email/Template.php

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,33 @@ public function getContent(Zend_Mail $mail)
9999
return $queue->getMessageBody();
100100
}
101101

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

105-
return $content ? $content->getRawContent() : '';
105+
return $this->getPartDecodedContent($mimePart);
106+
}
107+
108+
109+
/**
110+
* Returns raw content of e-mail message. Abstract Zend_Mime_Part interface changes between 1.11.0 and 1.12.0
111+
*
112+
* @param Zend_Mime_Part $mimePart
113+
* @return String
114+
*/
115+
public function getPartDecodedContent(Zend_Mime_Part $mimePart)
116+
{
117+
118+
// getRawContent is not available in Zend 1.11 (Magento CE 1.7)
119+
if (method_exists($mimePart, 'getRawContent')) {
120+
return $mimePart->getRawContent();
121+
}
122+
123+
$encoding = $mimePart->encoding;
124+
$mimePart->encoding = 'none';
125+
$content = $mimePart->getContent();
126+
$mimePart->encoding = $encoding;
127+
128+
return $content;
106129
}
107130

108131

code/Debug/Test/Model/Core/Email/Template.php

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,15 @@ public function testAddEmailToProfile()
121121
*/
122122
public function testGetContentForPlain()
123123
{
124-
$content = $this->getMock('Zend_Mime_Part', array('getRawContent'), array(), '', false);;
125-
$content->expects($this->once())->method('getRawContent')->willReturn('raw content');
124+
$mimePart = $this->getMock('Zend_Mime_Part', null, array(), '', false);;
126125

127126
$mail = $this->getMock('Zend_Mail', array('getBodyText', 'getBodyHtml'));
128-
$mail->expects($this->once())->method('getBodyText')->willReturn($content);
127+
$mail->expects($this->once())->method('getBodyText')->willReturn($mimePart);
129128
$mail->expects($this->never())->method('getBodyHtml');
130129

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

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

147146
$mail = $this->getMock('Zend_Mail', array('getBodyText', 'getBodyHtml'));
148147
$mail->expects($this->never())->method('getBodyText');
149-
$mail->expects($this->once())->method('getBodyHtml')->willReturn($content);
148+
$mail->expects($this->once())->method('getBodyHtml')->willReturn($mimePart);
150149

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

154154
$actual = $model->getContent($mail);
155155
$this->assertEquals('raw html content', $actual);
@@ -178,6 +178,33 @@ public function testGetContentForQueue()
178178
}
179179

180180

181+
/**
182+
* @covers Sheep_Debug_Model_Core_Email_Template_Capture::getPartDecodedContent
183+
*/
184+
public function testGetPartDecodedContent()
185+
{
186+
// this condition doesn't seem right to live in a test
187+
$zendWithGetRawContent = Zend_Version::compareVersion('1.12.0') <= 0;
188+
189+
$mimePart = $this->getMock('Zend_Mime_Part', array(), array(), '', false);
190+
if ($zendWithGetRawContent) {
191+
$mimePart->expects($this->any())->method('getRawContent')->willReturn('raw content');
192+
} else {
193+
$mimePart->expects($this->any())->method('getContent')->willReturn('content');
194+
}
195+
196+
$model = $this->getModelMock('core/email_template', array('isPlain'));
197+
$actual = $model->getPartDecodedContent($mimePart);
198+
199+
if ($zendWithGetRawContent) {
200+
$this->assertEquals('raw content', $actual);
201+
} else {
202+
$this->assertEquals('content', $actual);
203+
204+
}
205+
}
206+
207+
181208
/**
182209
* @covers Sheep_Debug_Model_Core_Email_Template_Capture::decodeSubject
183210
*/
@@ -188,6 +215,9 @@ public function testDecodeSubject()
188215
}
189216

190217

218+
/**
219+
* @covers Sheep_Debug_Model_Core_Email_Template_Capture::decodeSubject
220+
*/
191221
public function testDecodeSubjectForQueue()
192222
{
193223
$queue = $this->getModelMock('core/email_queue', array('getMessageParameters'));

0 commit comments

Comments
 (0)