1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace Hautzi\SystemMailBundle\Tests\SystemMailer\MailDefinition; |
5
|
|
|
|
6
|
|
|
use Hautzi\SystemMailBundle\SystemMailer\MailDefinition\MailDefinitionParserXml; |
7
|
|
|
use Hautzi\SystemMailBundle\SystemMailer\XML\XsdValidator; |
8
|
|
|
|
9
|
|
|
class MailDefinitionParserXmlTest extends \PHPUnit_Framework_TestCase |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var MailDefinitionParserXml |
13
|
|
|
*/ |
14
|
|
|
protected $fixture; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var XsdValidator |
18
|
|
|
*/ |
19
|
|
|
protected $xsdValidator; |
20
|
|
|
|
21
|
|
|
protected function setUp() |
22
|
|
|
{ |
23
|
|
|
$this->xsdValidator = $this->prophesize(XsdValidator::class); |
|
|
|
|
24
|
|
|
|
25
|
|
|
$this->fixture = new MailDefinitionParserXml($this->xsdValidator->reveal(), 'pathtoxsd.xsd'); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testParseXmlWithAllValidValuesNotLocalized() |
29
|
|
|
{ |
30
|
|
|
$xml = <<<XML |
31
|
|
|
<email> |
32
|
|
|
<from name="from_name">[email protected]</from> |
33
|
|
|
<replyTo>[email protected]</replyTo> |
34
|
|
|
<to name="to_name1">[email protected]</to> |
35
|
|
|
<to name="to_name2">[email protected]</to> |
36
|
|
|
<to>[email protected]</to> |
37
|
|
|
<cc name="cc_name1">[email protected]</cc> |
38
|
|
|
<cc name="cc_name2">[email protected]</cc> |
39
|
|
|
<cc>[email protected]</cc> |
40
|
|
|
<bcc name="bcc_name1">[email protected]</bcc> |
41
|
|
|
<bcc name="bcc_name2">[email protected]</bcc> |
42
|
|
|
<bcc>[email protected]</bcc> |
43
|
|
|
<subject>_subject</subject> |
44
|
|
|
<messageText>_text_message</messageText> |
45
|
|
|
<messageHtml><![CDATA[<p>_html_message</p>]]></messageHtml> |
46
|
|
|
</email> |
47
|
|
|
XML; |
48
|
|
|
$this->xsdValidator->validate($xml, 'pathtoxsd.xsd')->shouldBeCalled(); |
|
|
|
|
49
|
|
|
|
50
|
|
|
$parsedMessage = $this->fixture->parseMailDefinition($xml); |
51
|
|
|
|
52
|
|
|
// from |
53
|
|
|
$this->assertEquals(['[email protected]' => 'from_name'], $parsedMessage->getFrom()); |
54
|
|
|
// reply-to |
55
|
|
|
$this->assertEquals('[email protected]', $parsedMessage->getReplyTo()); |
56
|
|
|
// to |
57
|
|
|
$this->assertEquals([ |
58
|
|
|
'[email protected]' => 'to_name1', |
59
|
|
|
'[email protected]' => 'to_name2', |
60
|
|
|
'[email protected]', |
61
|
|
|
], $parsedMessage->getTo()); |
62
|
|
|
// cc |
63
|
|
|
$this->assertEquals([ |
64
|
|
|
'[email protected]' => 'cc_name1', |
65
|
|
|
'[email protected]' => 'cc_name2', |
66
|
|
|
'[email protected]', |
67
|
|
|
], $parsedMessage->getCc()); |
68
|
|
|
// bcc |
69
|
|
|
$this->assertEquals([ |
70
|
|
|
'[email protected]' => 'bcc_name1', |
71
|
|
|
'[email protected]' => 'bcc_name2', |
72
|
|
|
'[email protected]', |
73
|
|
|
], $parsedMessage->getBcc()); |
74
|
|
|
|
75
|
|
|
$this->assertEquals('_subject', $parsedMessage->getSubject()); |
76
|
|
|
$this->assertEquals('_text_message', $parsedMessage->getMessageText()); |
77
|
|
|
$this->assertEquals('<p>_html_message</p>', $parsedMessage->getMessageHtml()); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @dataProvider localizedSubjectMessageTextProvider() |
82
|
|
|
* |
83
|
|
|
* @param $_locale |
84
|
|
|
* @param $_subject |
85
|
|
|
* @param $_messageText |
86
|
|
|
* @param $_messageHtml |
87
|
|
|
*/ |
88
|
|
|
public function testParseXmlLocalizedFields($_locale, $_subject, $_messageText, $_messageHtml) |
89
|
|
|
{ |
90
|
|
|
$xml = <<<XML |
91
|
|
|
<email> |
92
|
|
|
<from name="from_name">[email protected]</from> |
93
|
|
|
<to name="to_name1">[email protected]</to> |
94
|
|
|
<subject locale="de">_subject_de</subject> |
95
|
|
|
<subject locale="en">_subject_en</subject> |
96
|
|
|
<messageText locale="de">_text_message_de</messageText> |
97
|
|
|
<messageText locale="en">_text_message_en</messageText> |
98
|
|
|
<messageHtml locale="de"><![CDATA[<p>_html_message_de</p>]]></messageHtml> |
99
|
|
|
<messageHtml locale="en"><![CDATA[<p>_html_message_en</p>]]></messageHtml> |
100
|
|
|
</email> |
101
|
|
|
XML; |
102
|
|
|
$this->xsdValidator->validate($xml, 'pathtoxsd.xsd')->shouldBeCalled(); |
|
|
|
|
103
|
|
|
|
104
|
|
|
$parsedMessage = $this->fixture->parseMailDefinition($xml, $_locale); |
105
|
|
|
|
106
|
|
|
$this->assertEquals($_subject, $parsedMessage->getSubject()); |
107
|
|
|
$this->assertEquals($_messageText, $parsedMessage->getMessageText()); |
108
|
|
|
$this->assertEquals($_messageHtml, $parsedMessage->getMessageHtml()); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function localizedSubjectMessageTextProvider() |
112
|
|
|
{ |
113
|
|
|
return [ |
114
|
|
|
['de', '_subject_de', '_text_message_de', '<p>_html_message_de</p>'], |
115
|
|
|
['en', '_subject_en', '_text_message_en', '<p>_html_message_en</p>'], |
116
|
|
|
]; |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..