1
|
|
|
<?php |
2
|
|
|
namespace Azine\EmailBundle\Tests\Controller; |
3
|
|
|
|
4
|
|
|
use Azine\EmailBundle\DependencyInjection\AzineEmailExtension; |
5
|
|
|
use Azine\EmailBundle\Tests\FindInFileUtil; |
6
|
|
|
use Azine\EmailBundle\Services\AzineTemplateProvider; |
7
|
|
|
use Azine\EmailBundle\Entity\SentEmail; |
8
|
|
|
use Azine\EmailBundle\Controller\AzineEmailTemplateController; |
9
|
|
|
|
10
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
11
|
|
|
use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException; |
12
|
|
|
use Symfony\Component\HttpFoundation\ParameterBag; |
13
|
|
|
use Symfony\Component\HttpFoundation\Request; |
14
|
|
|
use Symfony\Component\HttpFoundation\Response; |
15
|
|
|
use Symfony\Component\Routing\RequestContext; |
16
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; |
17
|
|
|
|
18
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* |
22
|
|
|
* @author d.businger |
23
|
|
|
* |
24
|
|
|
*/ |
25
|
|
|
class AzineEmailTemplateControllerTest extends WebTestCase |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* delete all files from spool-folder |
29
|
|
|
*/ |
30
|
|
|
protected function setUp() |
31
|
|
|
{ |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function renderResponseCallback($template, $params) |
35
|
|
|
{ |
36
|
|
|
if ($template == "AzineEmailBundle:Webview:index.html.twig") { |
37
|
|
|
return new Response("indexPage-html :".print_r($params, true)); |
38
|
|
|
|
39
|
|
|
} elseif ($template == "AzineEmailBundle:Webview:mail.not.available.html.twig") { |
40
|
|
|
return new Response("mail.not.available.html.twig :".print_r($params, true)); |
41
|
|
|
|
42
|
|
|
} elseif ($template == AzineTemplateProvider::NEWSLETTER_TEMPLATE.".html.twig") { |
43
|
|
|
return new Response("newsletter-html <a href='http://testurl.com/'>bla</a> <a href='http://testurl.com/with/?param=1'>with param</a>:".print_r($params, true)); |
44
|
|
|
|
45
|
|
|
} elseif ($template == AzineTemplateProvider::NEWSLETTER_TEMPLATE.".txt.twig") { |
46
|
|
|
return new Response("newsletter-text bla\n\n some url with param http://testurl.com/with/?param=1 in plain-text:".print_r($params, true)); |
47
|
|
|
|
48
|
|
|
} else if($template == "A") |
49
|
|
|
throw new \Exception("unexpected template $template"); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function testIndexAction() |
53
|
|
|
{ |
54
|
|
|
$requestMock = $this->getMockBuilder("Symfony\Component\HttpFoundation\Request")->disableOriginalConstructor()->setMethods(array('get'))->getMock(); |
55
|
|
|
$requestMock->expects($this->once())->method('get')->will($this->returnValue("[email protected]")); |
56
|
|
|
|
57
|
|
|
$webViewServiceMock = $this->getMockBuilder("Azine\EmailBundle\Services\AzineWebViewService")->disableOriginalConstructor()->getMock(); |
58
|
|
|
$webViewServiceMock->expects($this->once())->method("getTemplatesForWebPreView")->will($this->returnValue(array( |
59
|
|
|
array( 'url' => "azine_email_web_preview/newsletter", |
60
|
|
|
'description' => "Newsletter Template", |
61
|
|
|
'formats' => array('html','txt'), |
62
|
|
|
'templateId' => AzineTemplateProvider::NEWSLETTER_TEMPLATE, |
63
|
|
|
), |
64
|
|
|
array( 'url' => "azine_email_web_preview/notifications", |
65
|
|
|
'description' => "Notifications Template", |
66
|
|
|
'formats' => array('html','txt'), |
67
|
|
|
'templateId' => AzineTemplateProvider::NOTIFICATIONS_TEMPLATE, |
68
|
|
|
), |
69
|
|
|
))); |
70
|
|
|
$webViewServiceMock->expects($this->once())->method("getTestMailAccounts")->will($this->returnValue(array( |
71
|
|
|
array('accountDescription' => "Gmail", 'accountEmail' => "[email protected]" ), |
72
|
|
|
array('accountDescription' => "GMX", 'accountEmail' => "[email protected]" ), |
73
|
|
|
))); |
74
|
|
|
|
75
|
|
|
$twigMock = $this->getMockBuilder("Symfony\Bundle\TwigBundle\TwigEngine")->disableOriginalConstructor()->getMock(); |
76
|
|
|
$twigMock->expects($this->once())->method("renderResponse")->will($this->returnCallback(array($this, 'renderResponseCallback'))); |
77
|
|
|
|
78
|
|
|
$containerMock = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")->disableOriginalConstructor()->getMock(); |
79
|
|
|
$containerMock->expects($this->exactly(4))->method("get")->will($this->returnValueMap(array( |
80
|
|
|
array('request', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $requestMock), |
81
|
|
|
array('azine_email_web_view_service', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $webViewServiceMock), |
82
|
|
|
array('templating', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $twigMock) |
83
|
|
|
))); |
84
|
|
|
|
85
|
|
|
$controller = new AzineEmailTemplateController(); |
86
|
|
|
$controller->setContainer($containerMock); |
87
|
|
|
$response = $controller->indexAction(); |
|
|
|
|
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function testWebPreViewAction() |
91
|
|
|
{ |
92
|
|
|
$requestMock = $this->getMockBuilder("Symfony\Component\HttpFoundation\Request")->disableOriginalConstructor()->setMethods(array('getLocale'))->getMock(); |
93
|
|
|
$requestMock->expects($this->exactly(6))->method("getLocale")->will($this->returnValue("en")); |
94
|
|
|
$requestMock->query = new ParameterBag(); |
95
|
|
|
|
96
|
|
|
$webViewServiceMock = $this->getMockBuilder("Azine\EmailBundle\Services\AzineWebViewService")->disableOriginalConstructor()->getMock(); |
97
|
|
|
$webViewServiceMock->expects($this->exactly(3))->method("getDummyVarsFor")->will($this->returnValue(array())); |
98
|
|
|
|
99
|
|
|
$twigMock = $this->getMockBuilder("Symfony\Bundle\TwigBundle\TwigEngine")->disableOriginalConstructor()->getMock(); |
100
|
|
|
$twigMock->expects($this->exactly(3))->method("renderResponse")->will($this->returnCallback(array($this, 'renderResponseCallback'))); |
101
|
|
|
|
102
|
|
|
$emailVars = array(); |
103
|
|
|
|
104
|
|
|
$templateProviderMock = $this->getMockBuilder("Azine\EmailBundle\Services\AzineTemplateProvider")->disableOriginalConstructor()->getMock(); |
105
|
|
|
$templateProviderMock->expects($this->exactly(3))->method('addTemplateVariablesFor')->will($this->returnValue($emailVars)); |
106
|
|
|
$templateProviderMock->expects($this->exactly(3))->method('makeImagePathsWebRelative')->will($this->returnValue($emailVars)); |
107
|
|
|
$templateProviderMock->expects($this->exactly(3))->method('addTemplateSnippetsWithImagesFor')->will($this->returnValue($emailVars)); |
108
|
|
|
$templateProviderMock->expects($this->exactly(3))->method('getCampaignParamsFor')->will($this->returnValue(array("utm_campaign" => "name", "utm_medium" => "medium"))); |
109
|
|
|
|
110
|
|
|
|
111
|
|
|
$trackingCodeBuilderMock = $this->getMockBuilder("Azine\EmailBundle\Services\AzineEmailOpenTrackingCodeBuilder")->setConstructorArgs(array("http://www.google-analytics.com/?", array( |
112
|
|
|
AzineEmailExtension::TRACKING_PARAM_CAMPAIGN_NAME=> "utm_campaign", |
113
|
|
|
AzineEmailExtension::TRACKING_PARAM_CAMPAIGN_TERM => "utm_term", |
114
|
|
|
AzineEmailExtension::TRACKING_PARAM_CAMPAIGN_SOURCE => "utm_source", |
115
|
|
|
AzineEmailExtension::TRACKING_PARAM_CAMPAIGN_MEDIUM => "utm_medium", |
116
|
|
|
AzineEmailExtension::TRACKING_PARAM_CAMPAIGN_CONTENT => "utm_content", |
117
|
|
|
)))->getMock(); |
118
|
|
|
$trackingCodeBuilderMock->expects($this->exactly(3))->method('getTrackingImgCode')->will($this->returnValue("http://www.google-analytics.com/?")); |
119
|
|
|
|
120
|
|
|
|
121
|
|
|
$containerMock = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")->disableOriginalConstructor()->getMock(); |
122
|
|
|
$containerMock->expects($this->exactly(27))->method("get")->will($this->returnValueMap(array( |
123
|
|
|
array('request', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $requestMock), |
124
|
|
|
array('azine_email_web_view_service', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $webViewServiceMock), |
125
|
|
|
array('templating', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $twigMock), |
126
|
|
|
array('azine_email_template_provider', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $templateProviderMock), |
127
|
|
|
array('azine_email_email_open_tracking_code_builder', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $trackingCodeBuilderMock), |
128
|
|
|
|
129
|
|
|
))); |
130
|
|
|
$containerMock->expects($this->exactly(3))->method("getParameter")->with("azine_email_no_reply")->will($this->returnValue(array('email' => "[email protected]", 'name' => 'no-reply-name'))); |
131
|
|
|
|
132
|
|
|
$controller = new AzineEmailTemplateController(); |
133
|
|
|
$controller->setContainer($containerMock); |
134
|
|
|
|
135
|
|
|
$response = $controller->webPreViewAction(AzineTemplateProvider::NEWSLETTER_TEMPLATE); |
|
|
|
|
136
|
|
|
|
137
|
|
|
$response = $controller->webPreViewAction(AzineTemplateProvider::NEWSLETTER_TEMPLATE, "html"); |
|
|
|
|
138
|
|
|
|
139
|
|
|
$response = $controller->webPreViewAction(AzineTemplateProvider::NEWSLETTER_TEMPLATE, "txt"); |
140
|
|
|
$this->assertEquals("text/plain", $response->headers->get("Content-Type")); |
141
|
|
|
$this->assertNotContains("<!doctype", $response->getContent()); |
142
|
|
|
|
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
public function testWebViewAction_User_access_allowed() |
146
|
|
|
{ |
147
|
|
|
$token = "fdasdfasfafsadf"; |
148
|
|
|
|
149
|
|
|
$twigMock = $this->getMockBuilder("Symfony\Bundle\TwigBundle\TwigEngine")->disableOriginalConstructor()->getMock(); |
150
|
|
|
$twigMock->expects($this->once())->method("renderResponse")->will($this->returnCallback(array($this, 'renderResponseCallback'))); |
151
|
|
|
|
152
|
|
|
$userMail = "[email protected]"; |
153
|
|
|
$userMock = $this->getMockBuilder('FOS\UserBundle\Model\User')->getMock(); |
154
|
|
|
$userMock->expects($this->once())->method("getEmail")->will($this->returnValue($userMail)); |
155
|
|
|
|
156
|
|
|
$sentEmail = new SentEmail(); |
157
|
|
|
$sentEmail->setRecipients(array($userMail)); |
158
|
|
|
$sentEmail->setSent(new \DateTime("2 weeks ago")); |
159
|
|
|
$sentEmail->setTemplate(AzineTemplateProvider::NEWSLETTER_TEMPLATE); |
160
|
|
|
$sentEmail->setVariables(array()); |
161
|
|
|
$sentEmail->setToken($token); |
162
|
|
|
|
163
|
|
|
$repositoryMock = $this->getMockBuilder("Azine\EmailBundle\Entity\Repositories\SentEmailRepository")->disableOriginalConstructor()->setMethods(array('findOneByToken'))->getMock(); |
164
|
|
|
$repositoryMock->expects($this->once())->method("findOneByToken")->will($this->returnValue($sentEmail)); |
165
|
|
|
|
166
|
|
|
$doctrineManagerMock = $this->getMockBuilder("Doctrine\ORM\EntityManager")->disableOriginalConstructor()->getMock(); |
167
|
|
|
|
168
|
|
|
$doctrineManagerRegistryMock = $this->getMockBuilder("Doctrine\Common\Persistence\ManagerRegistry")->disableOriginalConstructor()->getMock(); |
169
|
|
|
$doctrineManagerRegistryMock->expects($this->once())->method('getRepository')->with('AzineEmailBundle:SentEmail')->will($this->returnValue($repositoryMock)); |
170
|
|
|
$doctrineManagerRegistryMock->expects($this->once())->method('getManager')->will($this->returnValue($this->returnValue($doctrineManagerMock))); |
171
|
|
|
|
172
|
|
|
$securityTokenMock = $this->getMockBuilder("Symfony\Component\Security\Core\Authentication\Token\TokenInterface")->disableOriginalConstructor()->getMock(); |
173
|
|
|
$securityTokenMock->expects($this->exactly(2))->method('getUser')->will($this->returnValue($userMock)); |
174
|
|
|
|
175
|
|
|
$securityContextMock = $this->getMockBuilder("Symfony\Component\Security\Core\SecurityContext")->disableOriginalConstructor()->getMock(); |
176
|
|
|
$securityContextMock->expects($this->once())->method('getToken')->will($this->returnValue($securityTokenMock)); |
177
|
|
|
|
178
|
|
|
$templateProviderMock = $this->getMockBuilder("Azine\EmailBundle\Services\AzineTemplateProvider")->disableOriginalConstructor()->getMock(); |
179
|
|
|
$templateProviderMock->expects($this->once())->method('getWebViewTokenId')->will($this->returnValue("tokenId")); |
180
|
|
|
|
181
|
|
|
$containerMock = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")->disableOriginalConstructor()->getMock(); |
182
|
|
|
$containerMock->expects($this->exactly(5))->method("get")->will($this->returnValueMap(array( |
183
|
|
|
array('azine_email_template_provider', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $templateProviderMock), |
184
|
|
|
array('templating', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $twigMock), |
185
|
|
|
array('doctrine', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $doctrineManagerRegistryMock), |
186
|
|
|
array('security.context', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $securityContextMock), |
187
|
|
|
))); |
188
|
|
|
$containerMock->expects($this->once())->method("has")->with('security.context')->will($this->returnValue(true)); |
189
|
|
|
|
190
|
|
|
$controller = new AzineEmailTemplateController(); |
191
|
|
|
$controller->setContainer($containerMock); |
192
|
|
|
$response = $controller->webViewAction($token); |
|
|
|
|
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
public function testWebViewAction_Anonymous_access_allowed() |
196
|
|
|
{ |
197
|
|
|
$token = "fdasdfasfafsadf"; |
198
|
|
|
|
199
|
|
|
$twigMock = $this->getMockBuilder("Symfony\Bundle\TwigBundle\TwigEngine")->disableOriginalConstructor()->getMock(); |
200
|
|
|
$twigMock->expects($this->once())->method("renderResponse")->will($this->returnCallback(array($this, 'renderResponseCallback'))); |
201
|
|
|
|
202
|
|
|
$sentEmail = new SentEmail(); |
203
|
|
|
$sentEmail->setSent(new \DateTime("2 weeks ago")); |
204
|
|
|
$sentEmail->setTemplate(AzineTemplateProvider::NEWSLETTER_TEMPLATE); |
205
|
|
|
$sentEmail->setVariables(array()); |
206
|
|
|
$sentEmail->setToken($token); |
207
|
|
|
|
208
|
|
|
$repositoryMock = $this->getMockBuilder("Azine\EmailBundle\Entity\Repositories\SentEmailRepository")->disableOriginalConstructor()->setMethods(array('findOneByToken'))->getMock(); |
209
|
|
|
$repositoryMock->expects($this->once())->method("findOneByToken")->will($this->returnValue($sentEmail)); |
210
|
|
|
|
211
|
|
|
$doctrineManagerMock = $this->getMockBuilder("Doctrine\ORM\EntityManager")->disableOriginalConstructor()->getMock(); |
212
|
|
|
|
213
|
|
|
$doctrineManagerRegistryMock = $this->getMockBuilder("Doctrine\Common\Persistence\ManagerRegistry")->disableOriginalConstructor()->getMock(); |
214
|
|
|
$doctrineManagerRegistryMock->expects($this->once())->method('getRepository')->with('AzineEmailBundle:SentEmail')->will($this->returnValue($repositoryMock)); |
215
|
|
|
$doctrineManagerRegistryMock->expects($this->once())->method('getManager')->will($this->returnValue($this->returnValue($doctrineManagerMock))); |
216
|
|
|
|
217
|
|
|
$securityTokenMock = $this->getMockBuilder("Symfony\Component\Security\Core\Authentication\Token\TokenInterface")->disableOriginalConstructor()->getMock(); |
218
|
|
|
$securityTokenMock->expects($this->never())->method('getUser'); |
219
|
|
|
|
220
|
|
|
$securityContextMock = $this->getMockBuilder("Symfony\Component\Security\Core\SecurityContext")->disableOriginalConstructor()->getMock(); |
221
|
|
|
$securityContextMock->expects($this->never())->method('getToken'); |
222
|
|
|
|
223
|
|
|
$templateProviderMock = $this->getMockBuilder("Azine\EmailBundle\Services\AzineTemplateProvider")->disableOriginalConstructor()->getMock(); |
224
|
|
|
$templateProviderMock->expects($this->once())->method('getWebViewTokenId')->will($this->returnValue("tokenId")); |
225
|
|
|
|
226
|
|
|
$containerMock = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")->disableOriginalConstructor()->getMock(); |
227
|
|
|
$containerMock->expects($this->exactly(4))->method("get")->will($this->returnValueMap(array( |
228
|
|
|
array('azine_email_template_provider', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $templateProviderMock), |
229
|
|
|
array('templating', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $twigMock), |
230
|
|
|
array('doctrine', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $doctrineManagerRegistryMock), |
231
|
|
|
array('security.context', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $securityContextMock), |
232
|
|
|
))); |
233
|
|
|
$containerMock->expects($this->never())->method("has"); |
234
|
|
|
|
235
|
|
|
$controller = new AzineEmailTemplateController(); |
236
|
|
|
$controller->setContainer($containerMock); |
237
|
|
|
$response = $controller->webViewAction($token); |
|
|
|
|
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* @expectedException Symfony\Component\Security\Core\Exception\AccessDeniedException |
242
|
|
|
*/ |
243
|
|
|
public function testWebViewAction_User_access_denied() |
244
|
|
|
{ |
245
|
|
|
$token = "fdasdfasfafsadf"; |
246
|
|
|
|
247
|
|
|
$userMail = "[email protected]"; |
248
|
|
|
$userMock = $this->getMockBuilder('FOS\UserBundle\Model\User')->getMock(); |
249
|
|
|
$userMock->expects($this->once())->method("getEmail")->will($this->returnValue($userMail)); |
250
|
|
|
|
251
|
|
|
$sentEmail = new SentEmail(); |
252
|
|
|
$sentEmail->setRecipients(array("[email protected]")); |
253
|
|
|
$sentEmail->setSent(new \DateTime("2 weeks ago")); |
254
|
|
|
$sentEmail->setTemplate(AzineTemplateProvider::NEWSLETTER_TEMPLATE); |
255
|
|
|
$sentEmail->setVariables(array()); |
256
|
|
|
$sentEmail->setToken($token); |
257
|
|
|
|
258
|
|
|
$repositoryMock = $this->getMockBuilder("Azine\EmailBundle\Entity\Repositories\SentEmailRepository")->disableOriginalConstructor()->setMethods(array('findOneByToken'))->getMock(); |
259
|
|
|
$repositoryMock->expects($this->once())->method("findOneByToken")->will($this->returnValue($sentEmail)); |
260
|
|
|
|
261
|
|
|
$doctrineManagerMock = $this->getMockBuilder("Doctrine\ORM\EntityManager")->disableOriginalConstructor()->getMock(); |
|
|
|
|
262
|
|
|
|
263
|
|
|
$doctrineManagerRegistryMock = $this->getMockBuilder("Doctrine\Common\Persistence\ManagerRegistry")->disableOriginalConstructor()->getMock(); |
264
|
|
|
$doctrineManagerRegistryMock->expects($this->once())->method('getRepository')->with('AzineEmailBundle:SentEmail')->will($this->returnValue($repositoryMock)); |
265
|
|
|
|
266
|
|
|
$securityTokenMock = $this->getMockBuilder("Symfony\Component\Security\Core\Authentication\Token\TokenInterface")->disableOriginalConstructor()->getMock(); |
267
|
|
|
$securityTokenMock->expects($this->exactly(2))->method('getUser')->will($this->returnValue($userMock)); |
268
|
|
|
|
269
|
|
|
$securityContextMock = $this->getMockBuilder("Symfony\Component\Security\Core\SecurityContext")->disableOriginalConstructor()->getMock(); |
270
|
|
|
$securityContextMock->expects($this->once())->method('getToken')->will($this->returnValue($securityTokenMock)); |
271
|
|
|
|
272
|
|
|
$translatorMock = $this->getMockBuilder("Symfony\Bundle\FrameworkBundle\Translation\Translator")->disableOriginalConstructor()->setMethods(array('trans'))->getMock(); |
273
|
|
|
$translatorMock->expects($this->once())->method("trans")->will($this->returnValue("translation")); |
274
|
|
|
|
275
|
|
|
$containerMock = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")->disableOriginalConstructor()->getMock(); |
276
|
|
|
$containerMock->expects($this->exactly(3))->method("get")->will($this->returnValueMap(array( |
277
|
|
|
array('doctrine', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $doctrineManagerRegistryMock), |
278
|
|
|
array('security.context', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $securityContextMock), |
279
|
|
|
array('translator', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $translatorMock), |
280
|
|
|
))); |
281
|
|
|
$containerMock->expects($this->once())->method("has")->with('security.context')->will($this->returnValue(true)); |
282
|
|
|
|
283
|
|
|
$controller = new AzineEmailTemplateController(); |
284
|
|
|
$controller->setContainer($containerMock); |
285
|
|
|
$controller->webViewAction($token); |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
/** |
289
|
|
|
* @expectedException Symfony\Component\Security\Core\Exception\AccessDeniedException |
290
|
|
|
*/ |
291
|
|
|
public function testWebViewAction_Anonymous_Access_denied() |
292
|
|
|
{ |
293
|
|
|
$token = "fdasdfasfafsadf"; |
294
|
|
|
|
295
|
|
|
$sentEmail = new SentEmail(); |
296
|
|
|
$sentEmail->setRecipients(array("[email protected]")); |
297
|
|
|
$sentEmail->setSent(new \DateTime("2 weeks ago")); |
298
|
|
|
$sentEmail->setTemplate(AzineTemplateProvider::NEWSLETTER_TEMPLATE); |
299
|
|
|
$sentEmail->setVariables(array()); |
300
|
|
|
$sentEmail->setToken($token); |
301
|
|
|
|
302
|
|
|
$repositoryMock = $this->getMockBuilder("Azine\EmailBundle\Entity\Repositories\SentEmailRepository")->disableOriginalConstructor()->setMethods(array('findOneByToken'))->getMock(); |
303
|
|
|
$repositoryMock->expects($this->once())->method("findOneByToken")->will($this->returnValue($sentEmail)); |
304
|
|
|
|
305
|
|
|
$doctrineManagerMock = $this->getMockBuilder("Doctrine\ORM\EntityManager")->disableOriginalConstructor()->getMock(); |
|
|
|
|
306
|
|
|
|
307
|
|
|
$doctrineManagerRegistryMock = $this->getMockBuilder("Doctrine\Common\Persistence\ManagerRegistry")->disableOriginalConstructor()->getMock(); |
308
|
|
|
$doctrineManagerRegistryMock->expects($this->once())->method('getRepository')->with('AzineEmailBundle:SentEmail')->will($this->returnValue($repositoryMock)); |
309
|
|
|
|
310
|
|
|
$securityTokenMock = $this->getMockBuilder("Symfony\Component\Security\Core\Authentication\Token\TokenInterface")->disableOriginalConstructor()->getMock(); |
311
|
|
|
$securityTokenMock->expects($this->once())->method('getUser')->will($this->returnValue(null)); |
312
|
|
|
|
313
|
|
|
$securityContextMock = $this->getMockBuilder("Symfony\Component\Security\Core\SecurityContext")->disableOriginalConstructor()->getMock(); |
314
|
|
|
$securityContextMock->expects($this->once())->method('getToken')->will($this->returnValue($securityTokenMock)); |
315
|
|
|
|
316
|
|
|
$translatorMock = $this->getMockBuilder("Symfony\Bundle\FrameworkBundle\Translation\Translator")->disableOriginalConstructor()->setMethods(array('trans'))->getMock(); |
317
|
|
|
$translatorMock->expects($this->once())->method("trans")->will($this->returnValue("translation")); |
318
|
|
|
|
319
|
|
|
$containerMock = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")->disableOriginalConstructor()->getMock(); |
320
|
|
|
$containerMock->expects($this->exactly(3))->method("get")->will($this->returnValueMap(array( |
321
|
|
|
array('doctrine', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $doctrineManagerRegistryMock), |
322
|
|
|
array('security.context', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $securityContextMock), |
323
|
|
|
array('translator', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $translatorMock), |
324
|
|
|
))); |
325
|
|
|
$containerMock->expects($this->once())->method("has")->with('security.context')->will($this->returnValue(true)); |
326
|
|
|
|
327
|
|
|
$controller = new AzineEmailTemplateController(); |
328
|
|
|
$controller->setContainer($containerMock); |
329
|
|
|
$response = $controller->webViewAction($token); |
|
|
|
|
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
public function testWebViewAction_Admin_with_CampaignParams() |
333
|
|
|
{ |
334
|
|
|
$token = "fdasdfasfafsadf"; |
335
|
|
|
|
336
|
|
|
$twigMock = $this->getMockBuilder("Symfony\Bundle\TwigBundle\TwigEngine")->disableOriginalConstructor()->getMock(); |
337
|
|
|
$twigMock->expects($this->once())->method("renderResponse")->will($this->returnCallback(array($this, 'renderResponseCallback'))); |
338
|
|
|
|
339
|
|
|
$userMock = $this->getMockBuilder('FOS\UserBundle\Model\User')->getMock(); |
340
|
|
|
$userMock->expects($this->once())->method("getEmail")->will($this->returnValue("[email protected]")); |
341
|
|
|
$userMock->expects($this->once())->method("hasRole")->with("ROLE_ADMIN")->will($this->returnValue(true)); |
342
|
|
|
|
343
|
|
|
$sentEmail = new SentEmail(); |
344
|
|
|
$sentEmail->setRecipients(array("[email protected]")); |
345
|
|
|
$sentEmail->setSent(new \DateTime("2 weeks ago")); |
346
|
|
|
$sentEmail->setTemplate(AzineTemplateProvider::NEWSLETTER_TEMPLATE); |
347
|
|
|
$sentEmail->setVariables(array()); |
348
|
|
|
$sentEmail->setToken($token); |
349
|
|
|
|
350
|
|
|
$repositoryMock = $this->getMockBuilder("Azine\EmailBundle\Entity\Repositories\SentEmailRepository")->disableOriginalConstructor()->setMethods(array('findOneByToken'))->getMock(); |
351
|
|
|
$repositoryMock->expects($this->once())->method("findOneByToken")->will($this->returnValue($sentEmail)); |
352
|
|
|
|
353
|
|
|
$doctrineManagerMock = $this->getMockBuilder("Doctrine\ORM\EntityManager")->disableOriginalConstructor()->getMock(); |
354
|
|
|
|
355
|
|
|
$doctrineManagerRegistryMock = $this->getMockBuilder("Doctrine\Common\Persistence\ManagerRegistry")->disableOriginalConstructor()->getMock(); |
356
|
|
|
$doctrineManagerRegistryMock->expects($this->once())->method('getRepository')->with('AzineEmailBundle:SentEmail')->will($this->returnValue($repositoryMock)); |
357
|
|
|
$doctrineManagerRegistryMock->expects($this->once())->method('getManager')->will($this->returnValue($this->returnValue($doctrineManagerMock))); |
358
|
|
|
|
359
|
|
|
$securityTokenMock = $this->getMockBuilder("Symfony\Component\Security\Core\Authentication\Token\TokenInterface")->disableOriginalConstructor()->getMock(); |
360
|
|
|
$securityTokenMock->expects($this->exactly(2))->method('getUser')->will($this->returnValue($userMock)); |
361
|
|
|
|
362
|
|
|
$securityContextMock = $this->getMockBuilder("Symfony\Component\Security\Core\SecurityContext")->disableOriginalConstructor()->getMock(); |
363
|
|
|
$securityContextMock->expects($this->once())->method('getToken')->will($this->returnValue($securityTokenMock)); |
364
|
|
|
|
365
|
|
|
$templateProviderMock = $this->getMockBuilder("Azine\EmailBundle\Services\AzineTemplateProvider")->disableOriginalConstructor()->getMock(); |
366
|
|
|
$templateProviderMock->expects($this->once())->method('getWebViewTokenId')->will($this->returnValue("tokenId")); |
367
|
|
|
$templateProviderMock->expects($this->once())->method('getCampaignParamsFor')->will($this->returnValue(array("campaign" => "newsletter","keyword" => "2013-11-19"))); |
368
|
|
|
|
369
|
|
|
$containerMock = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")->disableOriginalConstructor()->getMock(); |
370
|
|
|
$containerMock->expects($this->exactly(5))->method("get")->will($this->returnValueMap(array( |
371
|
|
|
array('azine_email_template_provider', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $templateProviderMock), |
372
|
|
|
array('templating', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $twigMock), |
373
|
|
|
array('doctrine', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $doctrineManagerRegistryMock), |
374
|
|
|
array('security.context', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $securityContextMock), |
375
|
|
|
))); |
376
|
|
|
$containerMock->expects($this->once())->method("has")->with('security.context')->will($this->returnValue(true)); |
377
|
|
|
|
378
|
|
|
$controller = new AzineEmailTemplateController(); |
379
|
|
|
$controller->setContainer($containerMock); |
380
|
|
|
$response = $controller->webViewAction($token); |
381
|
|
|
|
382
|
|
|
$this->assertContains("http://testurl.com/?campaign=newsletter&keyword=2013-11-19", $response->getContent()); |
383
|
|
|
$this->assertContains('http://testurl.com/with/?param=1&campaign=newsletter&keyword=2013-11-19', $response->getContent()); |
384
|
|
|
} |
385
|
|
|
|
386
|
|
|
public function testWebViewAction_MailNotFound() |
387
|
|
|
{ |
388
|
|
|
$token = "fdasdfasfafsadf-not-found"; |
389
|
|
|
|
390
|
|
|
$twigMock = $this->getMockBuilder("Symfony\Bundle\TwigBundle\TwigEngine")->disableOriginalConstructor()->getMock(); |
391
|
|
|
$twigMock->expects($this->once())->method("renderResponse")->will($this->returnCallback(array($this, 'renderResponseCallback'))); |
392
|
|
|
|
393
|
|
|
$repositoryMock = $this->getMockBuilder("Azine\EmailBundle\Entity\Repositories\SentEmailRepository")->disableOriginalConstructor()->setMethods(array('findOneByToken'))->getMock(); |
394
|
|
|
$repositoryMock->expects($this->once())->method("findOneByToken")->will($this->returnValue(null)); |
395
|
|
|
|
396
|
|
|
$doctrineManagerRegistryMock = $this->getMockBuilder("Doctrine\Common\Persistence\ManagerRegistry")->disableOriginalConstructor()->getMock(); |
397
|
|
|
$doctrineManagerRegistryMock->expects($this->once())->method('getRepository')->with('AzineEmailBundle:SentEmail')->will($this->returnValue($repositoryMock)); |
398
|
|
|
|
399
|
|
|
$containerMock = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")->disableOriginalConstructor()->getMock(); |
400
|
|
|
$containerMock->expects($this->once())->method("getParameter")->with("azine_email_web_view_retention")->will($this->returnValue(123)); |
401
|
|
|
$containerMock->expects($this->exactly(2))->method("get")->will($this->returnValueMap(array( |
402
|
|
|
array('templating', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $twigMock), |
403
|
|
|
array('doctrine', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $doctrineManagerRegistryMock), |
404
|
|
|
))); |
405
|
|
|
|
406
|
|
|
$controller = new AzineEmailTemplateController(); |
407
|
|
|
$controller->setContainer($containerMock); |
408
|
|
|
$response = $controller->webViewAction($token); |
|
|
|
|
409
|
|
|
} |
410
|
|
|
|
411
|
|
|
public function testServeImageAction() |
412
|
|
|
{ |
413
|
|
|
$folderKey = "asdfadfasfasfd"; |
414
|
|
|
$filename = "testImage.png"; |
415
|
|
|
|
416
|
|
|
$templateProviderMock = $this->getMockBuilder("Azine\EmailBundle\Services\AzineTemplateProvider")->disableOriginalConstructor()->getMock(); |
417
|
|
|
$templateProviderMock->expects($this->exactly(1))->method('getFolderFrom')->with($folderKey)->will($this->returnValue(__DIR__."/")); |
418
|
|
|
|
419
|
|
|
$containerMock = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")->disableOriginalConstructor()->getMock(); |
420
|
|
|
$containerMock->expects($this->exactly(1))->method("get")->will($this->returnValueMap(array( |
421
|
|
|
array('azine_email_template_provider', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $templateProviderMock) |
422
|
|
|
))); |
423
|
|
|
|
424
|
|
|
$controller = new AzineEmailTemplateController(); |
425
|
|
|
$controller->setContainer($containerMock); |
426
|
|
|
$response = $controller->serveImageAction($folderKey, $filename); |
427
|
|
|
|
428
|
|
|
$this->assertEquals("image", $response->headers->get("Content-Type")); |
429
|
|
|
$this->assertEquals('inline; filename="'.$filename.'"', $response->headers->get('Content-Disposition')); |
430
|
|
|
|
431
|
|
|
} |
432
|
|
|
|
433
|
|
|
/** |
434
|
|
|
* @expectedException Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException |
435
|
|
|
*/ |
436
|
|
|
public function testServeImageAction_404() |
437
|
|
|
{ |
438
|
|
|
$folderKey = "asdfadfasfasfd"; |
439
|
|
|
$filename = "testImage.not.found.png"; |
440
|
|
|
|
441
|
|
|
$templateProviderMock = $this->getMockBuilder("Azine\EmailBundle\Services\AzineTemplateProvider")->disableOriginalConstructor()->getMock(); |
442
|
|
|
$templateProviderMock->expects($this->exactly(1))->method('getFolderFrom')->with($folderKey)->will($this->returnValue(false)); |
443
|
|
|
|
444
|
|
|
$containerMock = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")->disableOriginalConstructor()->getMock(); |
445
|
|
|
$containerMock->expects($this->exactly(1))->method("get")->will($this->returnValueMap(array( |
446
|
|
|
array('azine_email_template_provider', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $templateProviderMock) |
447
|
|
|
))); |
448
|
|
|
|
449
|
|
|
$controller = new AzineEmailTemplateController(); |
450
|
|
|
$controller->setContainer($containerMock); |
451
|
|
|
$response = $controller->serveImageAction($folderKey, $filename); |
|
|
|
|
452
|
|
|
} |
453
|
|
|
|
454
|
|
|
public function testSendTestEmailAction() |
455
|
|
|
{ |
456
|
|
|
if (null !== static::$kernel) { |
457
|
|
|
static::$kernel->shutdown(); |
458
|
|
|
} |
459
|
|
|
|
460
|
|
|
try { |
461
|
|
|
static::$kernel = static::createKernel(array()); |
462
|
|
|
} catch (\RuntimeException $ex) { |
463
|
|
|
$this->markTestSkipped("There does not seem to be a full application available (e.g. running tests on travis.org). So this test is skipped."); |
464
|
|
|
|
465
|
|
|
return; |
466
|
|
|
} |
467
|
|
|
|
468
|
|
|
static::$kernel->boot(); |
469
|
|
|
$container = static::$kernel->getContainer(); |
470
|
|
|
|
471
|
|
|
$spoolDir = $container->getParameter('swiftmailer.spool.defaultMailer.file.path'); |
472
|
|
|
|
473
|
|
|
// delete all spooled mails from other tests |
474
|
|
|
array_map('unlink', glob($spoolDir."/*.messag*")); |
475
|
|
|
array_map('unlink', glob($spoolDir."/.*.messag*")); |
476
|
|
|
|
477
|
|
|
$context = new RequestContext('/app.php'); |
478
|
|
|
$context->setParameter('_locale', 'en'); |
479
|
|
|
$router = $container->get('router'); |
480
|
|
|
$router->setContext($context); |
481
|
|
|
$to = md5(time()."to").'@email.non-existent.to.mail.domain.com'; |
482
|
|
|
$uri = $router->generate("azine_email_send_test_email", array('template' => AzineTemplateProvider::NEWSLETTER_TEMPLATE, 'email' => $to)); |
483
|
|
|
$container->set('request', Request::create($uri, "GET")); |
484
|
|
|
|
485
|
|
|
// "login" a user |
486
|
|
|
$token = new UsernamePasswordToken("username", "password", "main"); |
487
|
|
|
$recipientProvider = $container->get('azine_email_recipient_provider'); |
488
|
|
|
$users = $recipientProvider->getNewsletterRecipientIDs(); |
489
|
|
|
$token->setUser($recipientProvider->getRecipient($users[0])); |
490
|
|
|
$container->get('security.context')->setToken($token); |
491
|
|
|
|
492
|
|
|
// instantiate the controller and try to send the email |
493
|
|
|
$controller = new AzineEmailTemplateController(); |
494
|
|
|
$controller->setContainer($container); |
495
|
|
|
$response = $controller->sendTestEmailAction(AzineTemplateProvider::NEWSLETTER_TEMPLATE, $to); |
496
|
|
|
|
497
|
|
|
$this->assertEquals(302, $response->getStatusCode(), "Status-Code 302 expected."); |
498
|
|
|
$uri = $router->generate("azine_email_template_index"); |
499
|
|
|
$this->assertContains("Redirecting to $uri", $response->getContent(), "Redirect expected."); |
500
|
|
|
|
501
|
|
|
$findInFile = new FindInFileUtil(); |
502
|
|
|
$findInFile->excludeMode = false; |
503
|
|
|
$findInFile->formats = array(".message"); |
504
|
|
|
$this->assertEquals(1, sizeof($findInFile->find($spoolDir, "This is just the default content-block."))); |
505
|
|
|
$this->assertEquals(1, sizeof($findInFile->find($spoolDir, "Add some html content here"))); |
506
|
|
|
} |
507
|
|
|
|
508
|
|
|
public function testGetSpamIndexReportForSwiftMessage() |
509
|
|
|
{ |
510
|
|
|
$swiftMessage = new \Swift_Message(); |
511
|
|
|
$swiftMessage->setFrom("[email protected]"); |
512
|
|
|
$swiftMessage->setTo("[email protected]"); |
513
|
|
|
$swiftMessage->setSubject("a subject."); |
514
|
|
|
|
515
|
|
|
$swiftMessage->addPart("Hello dude, |
516
|
|
|
================================================================================ |
517
|
|
|
|
518
|
|
|
Add some content here |
519
|
|
|
|
520
|
|
|
This is just the default content-block. |
521
|
|
|
|
522
|
|
|
Best regards, |
523
|
|
|
the azine team |
524
|
|
|
|
525
|
|
|
________________________________________________________________________________ |
526
|
|
|
azine ist ein Service von Azine IT Services AG |
527
|
|
|
© 2013 by Azine IT Services AG |
528
|
|
|
|
529
|
|
|
Füge \"[email protected]\" zu deinem Adressbuch hinzu, um den Empfang von azine Mails sicherzustellen. |
530
|
|
|
|
531
|
|
|
|
532
|
|
|
- Help / FAQs : https://some.host.com/app_dev.php/de/help |
533
|
|
|
- AGB : https://some.host.com/app_dev.php/de/terms |
534
|
|
|
- Über azine: https://some.host.com/app_dev.php/de/about |
535
|
|
|
- Kontakt : https://some.host.com/app_dev.php/de/contact |
536
|
|
|
|
537
|
|
|
", 'text/plain'); |
538
|
|
|
$swiftMessage->setBody("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title>azine – </title><meta name=\"description\" content=\"azine – \" /><meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" /></head><body style=\" color: #484B4C; margin:0; font: normal 12px/18px Arial, Helvetica, sans-serif; background-color: #fdfbfa;\"><table summary=\"header and logo\" width=\"640\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" style=\"font: normal 12px/18px Arial, Helvetica, sans-serif;\"><tr><td> </td><td bgcolor=\"#f2f1f0\"> </td><td> </td></tr><tr><td width=\"10\"> </td><td width=\"620\" bgcolor=\"#f2f1f0\" style=\"padding: 0px 20px;\"><a href=\"http://azine\" target=\"_blank\" style=\"color: #9fb400; font-size: 55px; font-weight: bold; text-decoration: none;\"><img src=\"/app_dev.php/de/email/image/08f69bba117e6f02d40f07a5d84071e3/logo.png\" height=\"35\" width=\"169\" alt=\"azine\" /></a> |
539
|
|
|
<br /><span style='font-size: 16px; color:#484B4C; margin: 0px; padding: 0px;'>IT-Rekrutierung von morgen... weil du die beste Besetzung verdienst.</span></td><td width=\"10\"> </td></tr></table><table summary='box with shadows' width='640' border='0' align='center' cellpadding='0' cellspacing='0' style='font: normal 14px/18px Arial, Helvetica, sans-serif;'><tr><td colspan='3' width='640'><img width='640' height='10' src='/app_dev.php/de/email/image/08f69bba117e6f02d40f07a5d84071e3/topshadow.png' alt='' style='vertical-align: bottom;'/></td></tr><tr><td width='10' style='border-right: 1px solid #EEEEEE; background-image: url(\"/app_dev.php/de/email/image/08f69bba117e6f02d40f07a5d84071e3/left-shadow.png\");'> </td><td width=\"620\" bgcolor=\"white\" style=\"padding:10px 20px 20px 20px; border-top: 1px solid #EEEEEE;\"><a name=\"top\" ></a><span style='color:#024d84; font:bold 16px Arial;'>Hallo dude,</span><p> |
540
|
|
|
Add some content here |
541
|
|
|
</p><p> |
542
|
|
|
This is just the default content-block. |
543
|
|
|
</p><p> |
544
|
|
|
Freundliche Grüsse und bis bald, |
545
|
|
|
<br/><span style=\"color:#024d84;\">dein azine Team</span></p></td><td width='10' style='border-left: 1px solid #EEEEEE; background-image: url(\"/app_dev.php/de/email/image/08f69bba117e6f02d40f07a5d84071e3/right-shadow.png\");'> </td></tr><tr><td width='10' style='border-right: 1px solid #EEEEEE; background-image: url(\"/app_dev.php/de/email/image/08f69bba117e6f02d40f07a5d84071e3/left-shadow.png\");'> </td><td width=\"620\" bgcolor=\"white\" style=\"text-align:center;\"><a href=\"http://azine\" target=\"_blank\" style=\"color: #9fb400; font-size: 32px; font-weight: bold; text-decoration: none; position:relative; top:1px;\"><img height=\"24\" width=\"116\" src=\"/app_dev.php/de/email/image/08f69bba117e6f02d40f07a5d84071e3/logo.png\" alt=\"azine\" /></a></td><td width='10' style='border-left: 1px solid #EEEEEE; background-image: url(\"/app_dev.php/de/email/image/08f69bba117e6f02d40f07a5d84071e3/right-shadow.png\");'> </td></tr><tr><td width='10' style='border-right: 1px solid #EEEEEE; background-image: url(\"/app_dev.php/de/email/image/08f69bba117e6f02d40f07a5d84071e3/left-shadow.png\");'> </td><td width=\"620\" align=\"center\" valign=\"top\" bgcolor=\"#434343\" style=\"font: normal 12px/18px Arial, Helvetica, sans-serif; padding:10px 30px 30px 30px; border-top:3px solid #b1c800; text-align:center;\" ><p style=\"color:white;\"><a href='https://some.host.com/app_dev.php/de/' style='text-decoration:none;'><span style='color: #9fb400; font-size:110%;'>azine</span></a> ist ein Service angeboten von Azine IT Services AG. |
546
|
|
|
</p><p style=\"color:white;\"> |
547
|
|
|
Füge \"<a style=\"color:#FFFFFF;\" href=\"mailto:azine <[email protected]>\"><span style=\"color:#FFFFFF;\">[email protected]</span></a>\" zu deinem Adressbuch hinzu, um den Empfang von <a href=\"http://azine\" style=\"color:white; text-decoration:none;\">azine</a> Mails sicherzustellen. |
548
|
|
|
</p><p style=\"color:#9fb400;\"> |
549
|
|
|
© 2013 by Azine IT Services AG |
550
|
|
|
</p><p style=\"color:#acacac;\"><a style=\"color:#acacac; text-decoration:none;\" href=\"https://some.host.com/app_dev.php/de/help\">Hilfe / FAQs</a> | |
551
|
|
|
<a style=\"color:#acacac; text-decoration:none;\" href=\"https://some.host.com/app_dev.php/de/terms\">AGB</a> | |
552
|
|
|
<a style=\"color:#acacac; text-decoration:none;\" href=\"https://some.host.com/app_dev.php/de/about\">Über azine</a> | |
553
|
|
|
<a style=\"color:#acacac; text-decoration:none;\" href=\"https://some.host.com/app_dev.php/de/contact\">Kontakt</a></p></td><td width='10' style='border-left: 1px solid #EEEEEE; background-image: url(\"/app_dev.php/de/email/image/08f69bba117e6f02d40f07a5d84071e3/right-shadow.png\");'> </td></tr></table> |
554
|
|
|
<div id=\"sfwdt016a7f\" class=\"sf-toolbar\" style=\"display: none\"></div><script>/*<![CDATA[*/ Sfjs = (function () { \"use strict\"; var noop = function () {}, profilerStorageKey = 'sf2/profiler/', request = function (url, onSuccess, onError, payload, options) { var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP'); options = options || {}; xhr.open(options.method || 'GET', url, true); xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); xhr.onreadystatechange = function (state) { if (4 === xhr.readyState && 200 === xhr.status) { (onSuccess || noop)(xhr); } elseif (4 === xhr.readyState && xhr.status != 200) { (onError || noop)(xhr); } }; xhr.send(payload || ''); }, hasClass = function (el, klass) { return el.className.match(new RegExp('\\b' + klass + '\\b')); }, removeClass = function (el, klass) { el.className = el.className.replace(new RegExp('\\b' + klass + '\\b'), ' '); }, addClass = function (el, klass) { if (!hasClass(el, klass)) { el.className += \" \" + klass; } }, getPreference = function (name) { if (!window.localStorage) { return null; } return localStorage.getItem(profilerStorageKey + name); }, setPreference = function (name, value) { if (!window.localStorage) { return null; } localStorage.setItem(profilerStorageKey + name, value); }; return { hasClass: hasClass, removeClass: removeClass, addClass: addClass, getPreference: getPreference, setPreference: setPreference, request: request, load: function (selector, url, onSuccess, onError, options) { var el = document.getElementById(selector); if (el && el.getAttribute('data-sfurl') !== url) { request( url, function (xhr) { el.innerHTML = xhr.responseText; el.setAttribute('data-sfurl', url); removeClass(el, 'loading'); (onSuccess || noop)(xhr, el); }, function (xhr) { (onError || noop)(xhr, el); }, options ); } return this; }, toggle: function (selector, elOn, elOff) { var i, style, tmp = elOn.style.display, el = document.getElementById(selector); elOn.style.display = elOff.style.display; elOff.style.display = tmp; if (el) { el.style.display = 'none' === tmp ? 'none' : 'block'; } return this; } } })();/*]]>*/</script><script>/*<![CDATA[*/ (function () { Sfjs.load( 'sfwdt016a7f', '/app_dev.php/_wdt/016a7f', function (xhr, el) { el.style.display = -1 !== xhr.responseText.indexOf('sf-toolbarreset') ? 'block' : 'none'; if (el.style.display == 'none') { return; } if (Sfjs.getPreference('toolbar/displayState') == 'none') { document.getElementById('sfToolbarMainContent-016a7f').style.display = 'none'; document.getElementById('sfToolbarClearer-016a7f').style.display = 'none'; document.getElementById('sfMiniToolbar-016a7f').style.display = 'block'; } else { document.getElementById('sfToolbarMainContent-016a7f').style.display = 'block'; document.getElementById('sfToolbarClearer-016a7f').style.display = 'block'; document.getElementById('sfMiniToolbar-016a7f').style.display = 'none'; } }, function (xhr) { if (xhr.status !== 0) { confirm('An error occurred while loading the web debug toolbar (' + xhr.status + ': ' + xhr.statusText + ').\n\nDo you want to open the profiler?') && (window.location = '/app_dev.php/_profiler/016a7f'); } } ); })();/*]]>*/</script> |
555
|
|
|
</body></html>", 'text/html'); |
556
|
|
|
|
557
|
|
|
$controller = new AzineEmailTemplateController(); |
558
|
|
|
$report = $controller->getSpamIndexReportForSwiftMessage($swiftMessage); |
559
|
|
|
|
560
|
|
|
if (array_key_exists('curlError', $report)) { |
561
|
|
|
$this->markTestIncomplete("It seems postmarks spam-check-service is unresponsive.\n\n".print_r($report, true)); |
562
|
|
|
} |
563
|
|
|
|
564
|
|
|
$this->assertArrayHasKey("success", $report, "success was expected in report.\n\n".print_r($report, true)); |
565
|
|
|
$this->assertArrayNotHasKey("curlError", $report, "curlError was not expected in report.\n\n".print_r($report, true)); |
566
|
|
|
$this->assertArrayHasKey("message", $report, "message was expected in report.\n\n".print_r($report, true)); |
567
|
|
|
|
568
|
|
|
} |
569
|
|
|
|
570
|
|
|
public function testCheckSpamScoreOfSentEmailAction() |
571
|
|
|
{ |
572
|
|
|
$emailSource = file_get_contents(__DIR__."/sentEmail.txt"); |
573
|
|
|
|
574
|
|
|
$requestMock = $this->getMockBuilder("Symfony\Component\HttpFoundation\Request")->disableOriginalConstructor()->setMethods(array('get'))->getMock(); |
575
|
|
|
$requestMock->expects($this->once())->method('get')->will($this->returnValue($emailSource)); |
576
|
|
|
|
577
|
|
|
$containerMock = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")->disableOriginalConstructor()->getMock(); |
578
|
|
|
$containerMock->expects($this->once())->method("get")->will($this->returnValueMap(array( |
579
|
|
|
array('request', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $requestMock)))); |
580
|
|
|
|
581
|
|
|
$controller = new AzineEmailTemplateController(); |
582
|
|
|
$controller->setContainer($containerMock); |
583
|
|
|
$jsonResponse = $controller->checkSpamScoreOfSentEmailAction(); |
584
|
|
|
|
585
|
|
|
$json = $jsonResponse->getContent(); |
586
|
|
|
if (strpos($json, "Getting the spam-info failed") !== false) { |
587
|
|
|
$this->markTestIncomplete("It seems postmarks spam-check-service is unresponsive.\n\n$json"); |
588
|
|
|
} |
589
|
|
|
|
590
|
|
|
$this->assertNotContains("Getting the spam-info failed.", $jsonResponse->getContent(), "Spamcheck returned:\n".$jsonResponse->getContent()); |
591
|
|
|
$this->assertContains("SpamScore", $jsonResponse->getContent()); |
592
|
|
|
|
593
|
|
|
} |
594
|
|
|
} |
595
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.