1 | <?php |
||||
2 | |||||
3 | namespace Azine\EmailBundle\Tests\Controller; |
||||
4 | |||||
5 | use Azine\EmailBundle\Controller\AzineEmailTemplateController; |
||||
6 | use Azine\EmailBundle\DependencyInjection\AzineEmailExtension; |
||||
7 | use Azine\EmailBundle\Entity\SentEmail; |
||||
8 | use Azine\EmailBundle\Services\AzineEmailTwigExtension; |
||||
9 | use Azine\EmailBundle\Services\AzineTemplateProvider; |
||||
10 | use Azine\EmailBundle\Tests\FindInFileUtil; |
||||
11 | use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
||||
12 | use Symfony\Component\DependencyInjection\ContainerInterface; |
||||
13 | use Symfony\Component\HttpFoundation\ParameterBag; |
||||
14 | use Symfony\Component\HttpFoundation\Request; |
||||
15 | use Symfony\Component\HttpFoundation\Response; |
||||
16 | use Symfony\Component\HttpFoundation\Session\Session; |
||||
17 | use Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage; |
||||
18 | use Symfony\Component\HttpKernel\Kernel; |
||||
19 | use Symfony\Component\Routing\RequestContext; |
||||
20 | use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; |
||||
21 | |||||
22 | /** |
||||
23 | * @author d.businger |
||||
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 ('AzineEmailBundle:Webview:index.html.twig' == $template) { |
||||
37 | return new Response('indexPage-html :'.print_r($params, true)); |
||||
38 | } elseif ('AzineEmailBundle:Webview:mail.not.available.html.twig' == $template) { |
||||
39 | return new Response('mail.not.available.html.twig :'.print_r($params, true)); |
||||
40 | } elseif ($template == AzineTemplateProvider::NEWSLETTER_TEMPLATE.'.html.twig') { |
||||
41 | 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)); |
||||
42 | } elseif ($template == AzineTemplateProvider::NEWSLETTER_TEMPLATE.'.txt.twig') { |
||||
43 | 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)); |
||||
44 | } elseif ('A' == $template) { |
||||
45 | throw new \Exception("unexpected template $template"); |
||||
46 | } |
||||
47 | } |
||||
48 | |||||
49 | public function testIndexAction() |
||||
50 | { |
||||
51 | $requestMock = $this->getMockBuilder("Symfony\Component\HttpFoundation\Request")->disableOriginalConstructor()->setMethods(array('get'))->getMock(); |
||||
52 | $requestMock->expects($this->once())->method('get')->will($this->returnValue('[email protected]')); |
||||
53 | $webViewServiceMock = $this->getMockBuilder("Azine\EmailBundle\Services\AzineWebViewService")->disableOriginalConstructor()->getMock(); |
||||
54 | $webViewServiceMock->expects($this->once())->method('getTemplatesForWebPreView')->will($this->returnValue(array( |
||||
55 | array('url' => 'azine_email_web_preview/newsletter', |
||||
56 | 'description' => 'Newsletter Template', |
||||
57 | 'formats' => array('html', 'txt'), |
||||
58 | 'templateId' => AzineTemplateProvider::NEWSLETTER_TEMPLATE, |
||||
59 | ), |
||||
60 | array('url' => 'azine_email_web_preview/notifications', |
||||
61 | 'description' => 'Notifications Template', |
||||
62 | 'formats' => array('html', 'txt'), |
||||
63 | 'templateId' => AzineTemplateProvider::NOTIFICATIONS_TEMPLATE, |
||||
64 | ), |
||||
65 | ))); |
||||
66 | $webViewServiceMock->expects($this->once())->method('getTestMailAccounts')->will($this->returnValue(array( |
||||
67 | array('accountDescription' => 'Gmail', 'accountEmail' => '[email protected]'), |
||||
68 | array('accountDescription' => 'GMX', 'accountEmail' => '[email protected]'), |
||||
69 | ))); |
||||
70 | $twigMock = $this->getMockBuilder("Symfony\Bundle\TwigBundle\TwigEngine")->disableOriginalConstructor()->getMock(); |
||||
71 | $twigMock->expects($this->once())->method('renderResponse')->will($this->returnCallback(array($this, 'renderResponseCallback'))); |
||||
72 | $containerMock = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")->disableOriginalConstructor()->getMock(); |
||||
73 | $containerMock->expects($this->exactly(3))->method('get')->will($this->returnValueMap(array( |
||||
74 | array('request', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $requestMock), |
||||
75 | array('azine_email_web_view_service', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $webViewServiceMock), |
||||
76 | array('templating', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $twigMock), |
||||
77 | ))); |
||||
78 | $controller = new AzineEmailTemplateController(); |
||||
79 | $controller->setContainer($containerMock); |
||||
80 | $controller->indexAction($requestMock); |
||||
81 | } |
||||
82 | |||||
83 | public function testWebPreViewAction() |
||||
84 | { |
||||
85 | $requestMock = $this->getMockBuilder("Symfony\Component\HttpFoundation\Request")->disableOriginalConstructor()->setMethods(array('getLocale'))->getMock(); |
||||
86 | $requestMock->expects($this->exactly(3))->method('getLocale')->will($this->returnValue('en')); |
||||
87 | $requestMock->query = new ParameterBag(); |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
88 | $webViewServiceMock = $this->getMockBuilder("Azine\EmailBundle\Services\AzineWebViewService")->disableOriginalConstructor()->getMock(); |
||||
89 | $webViewServiceMock->expects($this->exactly(3))->method('getDummyVarsFor')->will($this->returnValue(array())); |
||||
90 | $twigMock = $this->getMockBuilder("Symfony\Bundle\TwigBundle\TwigEngine")->disableOriginalConstructor()->getMock(); |
||||
91 | $twigMock->expects($this->exactly(3))->method('renderResponse')->will($this->returnCallback(array($this, 'renderResponseCallback'))); |
||||
92 | $emailVars = array(); |
||||
93 | $templateProviderMock = $this->getMockBuilder("Azine\EmailBundle\Services\AzineTemplateProvider")->disableOriginalConstructor()->getMock(); |
||||
94 | $templateProviderMock->expects($this->exactly(3))->method('addTemplateVariablesFor')->will($this->returnValue($emailVars)); |
||||
95 | $templateProviderMock->expects($this->exactly(3))->method('makeImagePathsWebRelative')->will($this->returnValue($emailVars)); |
||||
96 | $templateProviderMock->expects($this->exactly(3))->method('addTemplateSnippetsWithImagesFor')->will($this->returnValue($emailVars)); |
||||
97 | $templateProviderMock->expects($this->exactly(3))->method('getCampaignParamsFor')->will($this->returnValue(array('utm_campaign' => 'name', 'utm_medium' => 'medium'))); |
||||
98 | $trackingCodeBuilderMock = $this->getMockBuilder("Azine\EmailBundle\Services\AzineEmailOpenTrackingCodeBuilder")->setConstructorArgs(array('http://www.google-analytics.com/?', array( |
||||
99 | AzineEmailExtension::TRACKING_PARAM_CAMPAIGN_NAME => 'utm_campaign', |
||||
100 | AzineEmailExtension::TRACKING_PARAM_CAMPAIGN_TERM => 'utm_term', |
||||
101 | AzineEmailExtension::TRACKING_PARAM_CAMPAIGN_SOURCE => 'utm_source', |
||||
102 | AzineEmailExtension::TRACKING_PARAM_CAMPAIGN_MEDIUM => 'utm_medium', |
||||
103 | AzineEmailExtension::TRACKING_PARAM_CAMPAIGN_CONTENT => 'utm_content', |
||||
104 | )))->getMock(); |
||||
105 | $trackingCodeBuilderMock->expects($this->exactly(3))->method('getTrackingImgCode')->will($this->returnValue('http://www.google-analytics.com/?')); |
||||
106 | $azineEmailTwigExtension = $this->getMockBuilder("Azine\EmailBundle\Services\AzineEmailTwigExtension")->disableOriginalConstructor()->getMock(); |
||||
107 | $azineEmailTwigExtension->expects($this->exactly(3))->method('addCampaignParamsToAllUrls')->will($this->returnArgument(0)); |
||||
108 | $containerMock = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")->disableOriginalConstructor()->getMock(); |
||||
109 | $containerMock->expects($this->exactly(24))->method('get')->will($this->returnValueMap(array( |
||||
110 | array('request', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $requestMock), |
||||
111 | array('azine_email_web_view_service', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $webViewServiceMock), |
||||
112 | array('templating', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $twigMock), |
||||
113 | array('azine_email_template_provider', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $templateProviderMock), |
||||
114 | array('azine_email_email_open_tracking_code_builder', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $trackingCodeBuilderMock), |
||||
115 | array('azine.email.bundle.twig.filters', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $azineEmailTwigExtension), |
||||
116 | ))); |
||||
117 | $containerMock->expects($this->exactly(3))->method('getParameter')->with('azine_email_no_reply')->will($this->returnValue(array('email' => '[email protected]', 'name' => 'no-reply-name'))); |
||||
118 | $controller = new AzineEmailTemplateController(); |
||||
119 | $controller->setContainer($containerMock); |
||||
120 | $controller->webPreViewAction($requestMock, AzineTemplateProvider::NEWSLETTER_TEMPLATE); |
||||
121 | $controller->webPreViewAction($requestMock, AzineTemplateProvider::NEWSLETTER_TEMPLATE, 'html'); |
||||
122 | $response = $controller->webPreViewAction($requestMock, AzineTemplateProvider::NEWSLETTER_TEMPLATE, 'txt'); |
||||
123 | $this->assertSame('text/plain', $response->headers->get('Content-Type')); |
||||
124 | $this->assertNotContains('<!doctype', $response->getContent()); |
||||
125 | } |
||||
126 | |||||
127 | public function testWebViewAction_User_access_allowed() |
||||
128 | { |
||||
129 | $token = 'fdasdfasfafsadf'; |
||||
130 | $twigMock = $this->getMockBuilder("Symfony\Bundle\TwigBundle\TwigEngine")->disableOriginalConstructor()->getMock(); |
||||
131 | $twigMock->expects($this->once())->method('renderResponse')->will($this->returnCallback(array($this, 'renderResponseCallback'))); |
||||
132 | $userMail = '[email protected]'; |
||||
133 | $userMock = $this->getMockBuilder('FOS\UserBundle\Model\User')->getMock(); |
||||
134 | $userMock->expects($this->once())->method('getEmail')->will($this->returnValue($userMail)); |
||||
135 | $sentEmail = new SentEmail(); |
||||
136 | $sentEmail->setRecipients(array($userMail)); |
||||
137 | $sentEmail->setSent(new \DateTime('2 weeks ago')); |
||||
138 | $sentEmail->setTemplate(AzineTemplateProvider::NEWSLETTER_TEMPLATE); |
||||
139 | $sentEmail->setVariables(array()); |
||||
140 | $sentEmail->setToken($token); |
||||
141 | $repositoryMock = $this->getMockBuilder("Azine\EmailBundle\Entity\Repositories\SentEmailRepository")->disableOriginalConstructor()->setMethods(array('findOneByToken'))->getMock(); |
||||
142 | $repositoryMock->expects($this->once())->method('findOneByToken')->will($this->returnValue($sentEmail)); |
||||
143 | $doctrineManagerMock = $this->getMockBuilder("Doctrine\ORM\EntityManagerMock")->disableOriginalConstructor()->getMock(); |
||||
144 | $doctrineManagerRegistryMock = $this->getMockBuilder("Doctrine\Common\Persistence\ManagerRegistry")->disableOriginalConstructor()->getMock(); |
||||
145 | $doctrineManagerRegistryMock->expects($this->once())->method('getRepository')->with('AzineEmailBundle:SentEmail')->will($this->returnValue($repositoryMock)); |
||||
146 | $doctrineManagerRegistryMock->expects($this->once())->method('getManager')->will($this->returnValue($this->returnValue($doctrineManagerMock))); |
||||
147 | $securityTokenMock = $this->getMockBuilder("Symfony\Component\Security\Core\Authentication\Token\TokenInterface")->disableOriginalConstructor()->getMock(); |
||||
148 | $securityTokenMock->expects($this->exactly(2))->method('getUser')->will($this->returnValue($userMock)); |
||||
149 | $tokenStorageMock = $this->getMockBuilder("Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage")->disableOriginalConstructor()->getMock(); |
||||
150 | $tokenStorageMock->expects($this->once())->method('getToken')->will($this->returnValue($securityTokenMock)); |
||||
151 | $templateProviderMock = $this->getMockBuilder("Azine\EmailBundle\Services\AzineTemplateProvider")->disableOriginalConstructor()->getMock(); |
||||
152 | $templateProviderMock->expects($this->once())->method('getWebViewTokenId')->will($this->returnValue('tokenId')); |
||||
153 | $containerMock = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")->disableOriginalConstructor()->getMock(); |
||||
154 | $containerMock->expects($this->exactly(5))->method('get')->will($this->returnValueMap(array( |
||||
155 | array('azine_email_template_provider', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $templateProviderMock), |
||||
156 | array('templating', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $twigMock), |
||||
157 | array('doctrine', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $doctrineManagerRegistryMock), |
||||
158 | array('security.token_storage', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $tokenStorageMock), |
||||
159 | ))); |
||||
160 | $containerMock->expects($this->once())->method('has')->with('security.token_storage')->will($this->returnValue(true)); |
||||
161 | $requestMock = $this->getMockBuilder("Symfony\Component\HttpFoundation\Request")->disableOriginalConstructor()->getMock(); |
||||
162 | $controller = new AzineEmailTemplateController(); |
||||
163 | $controller->setContainer($containerMock); |
||||
164 | $controller->webViewAction($requestMock, $token); |
||||
165 | } |
||||
166 | |||||
167 | public function testWebViewAction_Anonymous_access_allowed() |
||||
168 | { |
||||
169 | $token = 'fdasdfasfafsadf'; |
||||
170 | $twigMock = $this->getMockBuilder("Symfony\Bundle\TwigBundle\TwigEngine")->disableOriginalConstructor()->getMock(); |
||||
171 | $twigMock->expects($this->once())->method('renderResponse')->will($this->returnCallback(array($this, 'renderResponseCallback'))); |
||||
172 | $sentEmail = new SentEmail(); |
||||
173 | $sentEmail->setSent(new \DateTime('2 weeks ago')); |
||||
174 | $sentEmail->setTemplate(AzineTemplateProvider::NEWSLETTER_TEMPLATE); |
||||
175 | $sentEmail->setVariables(array()); |
||||
176 | $sentEmail->setToken($token); |
||||
177 | $repositoryMock = $this->getMockBuilder("Azine\EmailBundle\Entity\Repositories\SentEmailRepository")->disableOriginalConstructor()->setMethods(array('findOneByToken'))->getMock(); |
||||
178 | $repositoryMock->expects($this->once())->method('findOneByToken')->will($this->returnValue($sentEmail)); |
||||
179 | $doctrineManagerMock = $this->getMockBuilder("Doctrine\ORM\EntityManagerMock")->disableOriginalConstructor()->getMock(); |
||||
180 | $doctrineManagerRegistryMock = $this->getMockBuilder("Doctrine\Common\Persistence\ManagerRegistry")->disableOriginalConstructor()->getMock(); |
||||
181 | $doctrineManagerRegistryMock->expects($this->once())->method('getRepository')->with('AzineEmailBundle:SentEmail')->will($this->returnValue($repositoryMock)); |
||||
182 | $doctrineManagerRegistryMock->expects($this->once())->method('getManager')->will($this->returnValue($this->returnValue($doctrineManagerMock))); |
||||
183 | $securityTokenMock = $this->getMockBuilder("Symfony\Component\Security\Core\Authentication\Token\TokenInterface")->disableOriginalConstructor()->getMock(); |
||||
184 | $securityTokenMock->expects($this->never())->method('getUser'); |
||||
185 | $tokenStorageMock = $this->getMockBuilder("Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage")->disableOriginalConstructor()->getMock(); |
||||
186 | $tokenStorageMock->expects($this->never())->method('getToken'); |
||||
187 | $templateProviderMock = $this->getMockBuilder("Azine\EmailBundle\Services\AzineTemplateProvider")->disableOriginalConstructor()->getMock(); |
||||
188 | $templateProviderMock->expects($this->once())->method('getWebViewTokenId')->will($this->returnValue('tokenId')); |
||||
189 | $containerMock = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")->disableOriginalConstructor()->getMock(); |
||||
190 | $containerMock->expects($this->exactly(4))->method('get')->will($this->returnValueMap(array( |
||||
191 | array('azine_email_template_provider', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $templateProviderMock), |
||||
192 | array('templating', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $twigMock), |
||||
193 | array('doctrine', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $doctrineManagerRegistryMock), |
||||
194 | array('security.token_storage', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $tokenStorageMock), |
||||
195 | ))); |
||||
196 | $containerMock->expects($this->never())->method('has'); |
||||
197 | $requestMock = $this->getMockBuilder("Symfony\Component\HttpFoundation\Request")->disableOriginalConstructor()->getMock(); |
||||
198 | $controller = new AzineEmailTemplateController(); |
||||
199 | $controller->setContainer($containerMock); |
||||
200 | $controller->webViewAction($requestMock, $token); |
||||
201 | } |
||||
202 | |||||
203 | /** |
||||
204 | * @expectedException \Symfony\Component\Security\Core\Exception\AccessDeniedException |
||||
205 | */ |
||||
206 | public function testWebViewAction_User_access_denied() |
||||
207 | { |
||||
208 | $token = 'fdasdfasfafsadf'; |
||||
209 | $userMail = '[email protected]'; |
||||
210 | $userMock = $this->getMockBuilder('FOS\UserBundle\Model\User')->getMock(); |
||||
211 | $userMock->expects($this->once())->method('getEmail')->will($this->returnValue($userMail)); |
||||
212 | $sentEmail = new SentEmail(); |
||||
213 | $sentEmail->setRecipients(array('[email protected]')); |
||||
214 | $sentEmail->setSent(new \DateTime('2 weeks ago')); |
||||
215 | $sentEmail->setTemplate(AzineTemplateProvider::NEWSLETTER_TEMPLATE); |
||||
216 | $sentEmail->setVariables(array()); |
||||
217 | $sentEmail->setToken($token); |
||||
218 | $repositoryMock = $this->getMockBuilder("Azine\EmailBundle\Entity\Repositories\SentEmailRepository")->disableOriginalConstructor()->setMethods(array('findOneByToken'))->getMock(); |
||||
219 | $repositoryMock->expects($this->once())->method('findOneByToken')->will($this->returnValue($sentEmail)); |
||||
220 | $doctrineManagerMock = $this->getMockBuilder("Doctrine\ORM\EntityManagerMock")->disableOriginalConstructor()->getMock(); |
||||
0 ignored issues
–
show
|
|||||
221 | $doctrineManagerRegistryMock = $this->getMockBuilder("Doctrine\Common\Persistence\ManagerRegistry")->disableOriginalConstructor()->getMock(); |
||||
222 | $doctrineManagerRegistryMock->expects($this->once())->method('getRepository')->with('AzineEmailBundle:SentEmail')->will($this->returnValue($repositoryMock)); |
||||
223 | $securityTokenMock = $this->getMockBuilder("Symfony\Component\Security\Core\Authentication\Token\TokenInterface")->disableOriginalConstructor()->getMock(); |
||||
224 | $securityTokenMock->expects($this->exactly(2))->method('getUser')->will($this->returnValue($userMock)); |
||||
225 | $tokenStorageMock = $this->getMockBuilder("Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage")->disableOriginalConstructor()->getMock(); |
||||
226 | $tokenStorageMock->expects($this->once())->method('getToken')->will($this->returnValue($securityTokenMock)); |
||||
227 | $translatorMock = $this->getMockBuilder("Symfony\Bundle\FrameworkBundle\Translation\Translator")->disableOriginalConstructor()->setMethods(array('trans'))->getMock(); |
||||
228 | $translatorMock->expects($this->once())->method('trans')->will($this->returnValue('translation')); |
||||
229 | $containerMock = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")->disableOriginalConstructor()->getMock(); |
||||
230 | $containerMock->expects($this->exactly(3))->method('get')->will($this->returnValueMap(array( |
||||
231 | array('doctrine', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $doctrineManagerRegistryMock), |
||||
232 | array('security.token_storage', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $tokenStorageMock), |
||||
233 | array('translator', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $translatorMock), |
||||
234 | ))); |
||||
235 | $containerMock->expects($this->once())->method('has')->with('security.token_storage')->will($this->returnValue(true)); |
||||
236 | $requestMock = $this->getMockBuilder("Symfony\Component\HttpFoundation\Request")->disableOriginalConstructor()->getMock(); |
||||
237 | $controller = new AzineEmailTemplateController(); |
||||
238 | $controller->setContainer($containerMock); |
||||
239 | $controller->webViewAction($requestMock, $token); |
||||
240 | } |
||||
241 | |||||
242 | /** |
||||
243 | * @expectedException \Symfony\Component\Security\Core\Exception\AccessDeniedException |
||||
244 | */ |
||||
245 | public function testWebViewAction_Anonymous_Access_denied() |
||||
246 | { |
||||
247 | $token = 'fdasdfasfafsadf'; |
||||
248 | $sentEmail = new SentEmail(); |
||||
249 | $sentEmail->setRecipients(array('[email protected]')); |
||||
250 | $sentEmail->setSent(new \DateTime('2 weeks ago')); |
||||
251 | $sentEmail->setTemplate(AzineTemplateProvider::NEWSLETTER_TEMPLATE); |
||||
252 | $sentEmail->setVariables(array()); |
||||
253 | $sentEmail->setToken($token); |
||||
254 | $repositoryMock = $this->getMockBuilder("Azine\EmailBundle\Entity\Repositories\SentEmailRepository")->disableOriginalConstructor()->setMethods(array('findOneByToken'))->getMock(); |
||||
255 | $repositoryMock->expects($this->once())->method('findOneByToken')->will($this->returnValue($sentEmail)); |
||||
256 | $doctrineManagerMock = $this->getMockBuilder("Doctrine\ORM\EntityManagerMock")->disableOriginalConstructor()->getMock(); |
||||
0 ignored issues
–
show
|
|||||
257 | $doctrineManagerRegistryMock = $this->getMockBuilder("Doctrine\Common\Persistence\ManagerRegistry")->disableOriginalConstructor()->getMock(); |
||||
258 | $doctrineManagerRegistryMock->expects($this->once())->method('getRepository')->with('AzineEmailBundle:SentEmail')->will($this->returnValue($repositoryMock)); |
||||
259 | $securityTokenMock = $this->getMockBuilder("Symfony\Component\Security\Core\Authentication\Token\TokenInterface")->disableOriginalConstructor()->getMock(); |
||||
260 | $securityTokenMock->expects($this->once())->method('getUser')->will($this->returnValue(null)); |
||||
261 | $tokenStorageMock = $this->getMockBuilder("Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage")->disableOriginalConstructor()->getMock(); |
||||
262 | $tokenStorageMock->expects($this->once())->method('getToken')->will($this->returnValue($securityTokenMock)); |
||||
263 | $translatorMock = $this->getMockBuilder("Symfony\Bundle\FrameworkBundle\Translation\Translator")->disableOriginalConstructor()->setMethods(array('trans'))->getMock(); |
||||
264 | $translatorMock->expects($this->once())->method('trans')->will($this->returnValue('translation')); |
||||
265 | $containerMock = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")->disableOriginalConstructor()->getMock(); |
||||
266 | $containerMock->expects($this->exactly(3))->method('get')->will($this->returnValueMap(array( |
||||
267 | array('doctrine', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $doctrineManagerRegistryMock), |
||||
268 | array('security.token_storage', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $tokenStorageMock), |
||||
269 | array('translator', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $translatorMock), |
||||
270 | ))); |
||||
271 | $containerMock->expects($this->once())->method('has')->with('security.token_storage')->will($this->returnValue(true)); |
||||
272 | $requestMock = $this->getMockBuilder("Symfony\Component\HttpFoundation\Request")->disableOriginalConstructor()->getMock(); |
||||
273 | $controller = new AzineEmailTemplateController(); |
||||
274 | $controller->setContainer($containerMock); |
||||
275 | $controller->webViewAction($requestMock, $token); |
||||
276 | } |
||||
277 | |||||
278 | public function testWebViewAction_Admin_with_CampaignParams() |
||||
279 | { |
||||
280 | $token = 'fdasdfasfafsadf'; |
||||
281 | $twigMock = $this->getMockBuilder("Symfony\Bundle\TwigBundle\TwigEngine")->disableOriginalConstructor()->getMock(); |
||||
282 | $twigMock->expects($this->once())->method('renderResponse')->will($this->returnCallback(array($this, 'renderResponseCallback'))); |
||||
283 | $userMock = $this->getMockBuilder('FOS\UserBundle\Model\User')->getMock(); |
||||
284 | $userMock->expects($this->once())->method('getEmail')->will($this->returnValue('[email protected]')); |
||||
285 | $userMock->expects($this->once())->method('hasRole')->with('ROLE_ADMIN')->will($this->returnValue(true)); |
||||
286 | $sentEmail = new SentEmail(); |
||||
287 | $sentEmail->setRecipients(array('[email protected]')); |
||||
288 | $sentEmail->setSent(new \DateTime('2 weeks ago')); |
||||
289 | $sentEmail->setTemplate(AzineTemplateProvider::NEWSLETTER_TEMPLATE); |
||||
290 | $sentEmail->setVariables(array()); |
||||
291 | $sentEmail->setToken($token); |
||||
292 | $repositoryMock = $this->getMockBuilder("Azine\EmailBundle\Entity\Repositories\SentEmailRepository")->disableOriginalConstructor()->setMethods(array('findOneByToken'))->getMock(); |
||||
293 | $repositoryMock->expects($this->once())->method('findOneByToken')->will($this->returnValue($sentEmail)); |
||||
294 | $doctrineManagerMock = $this->getMockBuilder("Doctrine\ORM\EntityManagerMock")->disableOriginalConstructor()->getMock(); |
||||
295 | $doctrineManagerRegistryMock = $this->getMockBuilder("Doctrine\Common\Persistence\ManagerRegistry")->disableOriginalConstructor()->getMock(); |
||||
296 | $doctrineManagerRegistryMock->expects($this->once())->method('getRepository')->with('AzineEmailBundle:SentEmail')->will($this->returnValue($repositoryMock)); |
||||
297 | $doctrineManagerRegistryMock->expects($this->once())->method('getManager')->will($this->returnValue($this->returnValue($doctrineManagerMock))); |
||||
298 | $securityTokenMock = $this->getMockBuilder("Symfony\Component\Security\Core\Authentication\Token\TokenInterface")->disableOriginalConstructor()->getMock(); |
||||
299 | $securityTokenMock->expects($this->exactly(2))->method('getUser')->will($this->returnValue($userMock)); |
||||
300 | $tokenStorageMock = $this->getMockBuilder("Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage")->disableOriginalConstructor()->getMock(); |
||||
301 | $tokenStorageMock->expects($this->once())->method('getToken')->will($this->returnValue($securityTokenMock)); |
||||
302 | $translatorMock = $this->getMockBuilder("Symfony\Bundle\FrameworkBundle\Translation\Translator")->disableOriginalConstructor()->getMock(); |
||||
303 | $translatorMock->expects($this->any())->method('trans')->will($this->returnArgument(0)); |
||||
304 | $templateProviderMock = $this->getMockBuilder("Azine\EmailBundle\Services\AzineTemplateProvider")->disableOriginalConstructor()->getMock(); |
||||
305 | $templateProviderMock->expects($this->once())->method('getWebViewTokenId')->will($this->returnValue('tokenId')); |
||||
306 | $templateProviderMock->expects($this->once())->method('getCampaignParamsFor')->will($this->returnValue(array('campaign' => 'newsletter', 'keyword' => '2013-11-19'))); |
||||
307 | $emailTwigExtension = new AzineEmailTwigExtension($templateProviderMock, $translatorMock, array('testurl.com')); |
||||
308 | $containerMock = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")->disableOriginalConstructor()->getMock(); |
||||
309 | $containerMock->expects($this->exactly(6))->method('get')->will($this->returnValueMap(array( |
||||
310 | array('azine_email_template_provider', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $templateProviderMock), |
||||
311 | array('templating', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $twigMock), |
||||
312 | array('doctrine', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $doctrineManagerRegistryMock), |
||||
313 | array('security.token_storage', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $tokenStorageMock), |
||||
314 | array('azine.email.bundle.twig.filters', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $emailTwigExtension), |
||||
315 | ))); |
||||
316 | $containerMock->expects($this->once())->method('has')->with('security.token_storage')->will($this->returnValue(true)); |
||||
317 | $requestMock = $this->getMockBuilder("Symfony\Component\HttpFoundation\Request")->disableOriginalConstructor()->getMock(); |
||||
318 | $controller = new AzineEmailTemplateController(); |
||||
319 | $controller->setContainer($containerMock); |
||||
320 | $response = $controller->webViewAction($requestMock, $token); |
||||
321 | $this->assertContains('http://testurl.com/?campaign=newsletter&keyword=2013-11-19', $response->getContent()); |
||||
322 | $this->assertContains('http://testurl.com/with/?param=1&campaign=newsletter&keyword=2013-11-19', $response->getContent()); |
||||
323 | } |
||||
324 | |||||
325 | public function testWebViewAction_MailNotFound() |
||||
326 | { |
||||
327 | $token = 'fdasdfasfafsadf-not-found'; |
||||
328 | $twigMock = $this->getMockBuilder("Symfony\Bundle\TwigBundle\TwigEngine")->disableOriginalConstructor()->getMock(); |
||||
329 | $twigMock->expects($this->once())->method('renderResponse')->will($this->returnCallback(array($this, 'renderResponseCallback'))); |
||||
330 | $repositoryMock = $this->getMockBuilder("Azine\EmailBundle\Entity\Repositories\SentEmailRepository")->disableOriginalConstructor()->setMethods(array('findOneByToken'))->getMock(); |
||||
331 | $repositoryMock->expects($this->once())->method('findOneByToken')->will($this->returnValue(null)); |
||||
332 | $doctrineManagerRegistryMock = $this->getMockBuilder("Doctrine\Common\Persistence\ManagerRegistry")->disableOriginalConstructor()->getMock(); |
||||
333 | $doctrineManagerRegistryMock->expects($this->once())->method('getRepository')->with('AzineEmailBundle:SentEmail')->will($this->returnValue($repositoryMock)); |
||||
334 | $containerMock = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")->disableOriginalConstructor()->getMock(); |
||||
335 | $containerMock->expects($this->once())->method('getParameter')->with('azine_email_web_view_retention')->will($this->returnValue(123)); |
||||
336 | $containerMock->expects($this->exactly(2))->method('get')->will($this->returnValueMap(array( |
||||
337 | array('templating', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $twigMock), |
||||
338 | array('doctrine', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $doctrineManagerRegistryMock), |
||||
339 | ))); |
||||
340 | $requestMock = $this->getMockBuilder("Symfony\Component\HttpFoundation\Request")->disableOriginalConstructor()->getMock(); |
||||
341 | $controller = new AzineEmailTemplateController(); |
||||
342 | $controller->setContainer($containerMock); |
||||
343 | $controller->webViewAction($requestMock, $token); |
||||
344 | } |
||||
345 | |||||
346 | public function testServeImageAction() |
||||
347 | { |
||||
348 | $folderKey = 'asdfadfasfasfd'; |
||||
349 | $filename = 'testImage.png'; |
||||
350 | $templateProviderMock = $this->getMockBuilder("Azine\EmailBundle\Services\AzineTemplateProvider")->disableOriginalConstructor()->getMock(); |
||||
351 | $templateProviderMock->expects($this->exactly(1))->method('getFolderFrom')->with($folderKey)->will($this->returnValue(__DIR__.'/')); |
||||
352 | $containerMock = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")->disableOriginalConstructor()->getMock(); |
||||
353 | $containerMock->expects($this->exactly(1))->method('get')->will($this->returnValueMap(array( |
||||
354 | array('azine_email_template_provider', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $templateProviderMock), |
||||
355 | ))); |
||||
356 | $requestMock = $this->getMockBuilder("Symfony\Component\HttpFoundation\Request")->disableOriginalConstructor()->getMock(); |
||||
357 | $controller = new AzineEmailTemplateController(); |
||||
358 | $controller->setContainer($containerMock); |
||||
359 | $response = $controller->serveImageAction($requestMock, $folderKey, $filename); |
||||
360 | $this->assertSame('image', $response->headers->get('Content-Type')); |
||||
361 | |||||
362 | if (Kernel::VERSION_ID < 40102) { |
||||
363 | $this->assertSame('inline; filename="'.$filename.'"', $response->headers->get('Content-Disposition')); |
||||
364 | } else { |
||||
365 | $this->assertSame('inline; filename='.$filename, $response->headers->get('Content-Disposition')); |
||||
366 | } |
||||
367 | } |
||||
368 | |||||
369 | /** |
||||
370 | * @expectedException \Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException |
||||
371 | */ |
||||
372 | public function testServeImageAction_404() |
||||
373 | { |
||||
374 | $folderKey = 'asdfadfasfasfd'; |
||||
375 | $filename = 'testImage.not.found.png'; |
||||
376 | $templateProviderMock = $this->getMockBuilder("Azine\EmailBundle\Services\AzineTemplateProvider")->disableOriginalConstructor()->getMock(); |
||||
377 | $templateProviderMock->expects($this->exactly(1))->method('getFolderFrom')->with($folderKey)->will($this->returnValue(false)); |
||||
378 | $containerMock = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")->disableOriginalConstructor()->getMock(); |
||||
379 | $containerMock->expects($this->exactly(1))->method('get')->will($this->returnValueMap(array( |
||||
380 | array('azine_email_template_provider', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $templateProviderMock), |
||||
381 | ))); |
||||
382 | $requestMock = $this->getMockBuilder("Symfony\Component\HttpFoundation\Request")->disableOriginalConstructor()->getMock(); |
||||
383 | $controller = new AzineEmailTemplateController(); |
||||
384 | $controller->setContainer($containerMock); |
||||
385 | $controller->serveImageAction($requestMock, $folderKey, $filename); |
||||
386 | } |
||||
387 | |||||
388 | public function testSendTestEmailAction() |
||||
389 | { |
||||
390 | if (null !== static::$kernel) { |
||||
391 | static::$kernel->shutdown(); |
||||
392 | } |
||||
393 | try { |
||||
394 | static::$kernel = static::createKernel(array()); |
||||
395 | } catch (\RuntimeException $ex) { |
||||
396 | $this->markTestSkipped('There does not seem to be a full application available (e.g. running tests on travis.org). So this test is skipped.'); |
||||
397 | |||||
398 | return; |
||||
399 | } |
||||
400 | static::$kernel->boot(); |
||||
401 | $container = static::$kernel->getContainer(); |
||||
402 | $spoolDir = $container->getParameter('swiftmailer.spool.defaultMailer.file.path'); |
||||
403 | // delete all spooled mails from other tests |
||||
404 | array_map('unlink', glob($spoolDir.'/*.messag*')); |
||||
0 ignored issues
–
show
It seems like
glob($spoolDir . '/*.messag*') can also be of type false ; however, parameter $arr1 of array_map() does only seem to accept array , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
405 | array_map('unlink', glob($spoolDir.'/.*.messag*')); |
||||
406 | $context = new RequestContext('/app.php'); |
||||
407 | $context->setParameter('_locale', 'en'); |
||||
408 | $router = $container->get('router'); |
||||
409 | $router->setContext($context); |
||||
410 | $to = md5(time().'to').'@email.non-existent.to.mail.domain.com'; |
||||
411 | $uri = $router->generate('azine_email_send_test_email', array('template' => AzineTemplateProvider::NEWSLETTER_TEMPLATE, 'email' => $to)); |
||||
412 | $container->set('request', Request::create($uri, 'GET')); |
||||
413 | // "login" a user |
||||
414 | $token = new UsernamePasswordToken('username', 'password', 'main'); |
||||
415 | $recipientProvider = $container->get('azine_email_recipient_provider'); |
||||
416 | $users = $recipientProvider->getNewsletterRecipientIDs(); |
||||
417 | $token->setUser($recipientProvider->getRecipient($users[0])); |
||||
418 | $container->get('security.token_storage')->setToken($token); |
||||
419 | $container->get('request')->setSession(new Session(new MockFileSessionStorage())); |
||||
420 | // instantiate the controller and try to send the email |
||||
421 | $controller = new AzineEmailTemplateController(); |
||||
422 | $controller->setContainer($container); |
||||
423 | $response = $controller->sendTestEmailAction($container->get('request'), AzineTemplateProvider::NEWSLETTER_TEMPLATE, $to); |
||||
424 | $this->assertSame(302, $response->getStatusCode(), 'Status-Code 302 expected.'); |
||||
425 | $uri = $router->generate('azine_email_template_index'); |
||||
426 | $this->assertContains("Redirecting to $uri", $response->getContent(), 'Redirect expected.'); |
||||
427 | $findInFile = new FindInFileUtil(); |
||||
428 | $findInFile->excludeMode = false; |
||||
429 | $findInFile->formats = array('.message'); |
||||
430 | $this->assertSame(1, sizeof($findInFile->find($spoolDir, 'This is just the default content-block.'))); |
||||
431 | $this->assertSame(1, sizeof($findInFile->find($spoolDir, 'Add some html content here'))); |
||||
432 | } |
||||
433 | |||||
434 | public function testGetSpamIndexReportForSwiftMessage() |
||||
435 | { |
||||
436 | $swiftMessage = new \Swift_Message(); |
||||
437 | $swiftMessage->setFrom('[email protected]'); |
||||
438 | $swiftMessage->setTo('[email protected]'); |
||||
439 | $swiftMessage->setSubject('a subject.'); |
||||
440 | $swiftMessage->addPart('Hello dude, |
||||
441 | ================================================================================ |
||||
442 | Add some content here |
||||
443 | This is just the default content-block. |
||||
444 | Best regards, |
||||
445 | the azine team |
||||
446 | ________________________________________________________________________________ |
||||
447 | azine ist ein Service von Azine IT Services AG |
||||
448 | © 2013 by Azine IT Services AG |
||||
449 | Füge "[email protected]" zu deinem Adressbuch hinzu, um den Empfang von azine Mails sicherzustellen. |
||||
450 | - Help / FAQs : https://some.host.com/app_dev.php/de/help |
||||
451 | - AGB : https://some.host.com/app_dev.php/de/terms |
||||
452 | - Über azine: https://some.host.com/app_dev.php/de/about |
||||
453 | - Kontakt : https://some.host.com/app_dev.php/de/contact |
||||
454 | ', 'text/plain'); |
||||
455 | $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> |
||||
456 | <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> |
||||
457 | Add some content here |
||||
458 | </p><p> |
||||
459 | This is just the default content-block. |
||||
460 | </p><p> |
||||
461 | Freundliche Grüsse und bis bald, |
||||
462 | <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. |
||||
463 | </p><p style=\"color:white;\"> |
||||
464 | 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. |
||||
465 | </p><p style=\"color:#9fb400;\"> |
||||
466 | © 2013 by Azine IT Services AG |
||||
467 | </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> | |
||||
468 | <a style=\"color:#acacac; text-decoration:none;\" href=\"https://some.host.com/app_dev.php/de/terms\">AGB</a> | |
||||
469 | <a style=\"color:#acacac; text-decoration:none;\" href=\"https://some.host.com/app_dev.php/de/about\">Über azine</a> | |
||||
470 | <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> |
||||
471 | </body></html>", 'text/html'); |
||||
472 | $controller = new AzineEmailTemplateController(); |
||||
473 | $report = $controller->getSpamIndexReportForSwiftMessage($swiftMessage); |
||||
474 | if (array_key_exists('curlError', $report)) { |
||||
475 | $this->markTestIncomplete("It seems postmarks spam-check-service is unresponsive.\n\n".print_r($report, true)); |
||||
476 | } |
||||
477 | $this->assertArrayHasKey('success', $report, "success was expected in report.\n\n".print_r($report, true)); |
||||
478 | $this->assertArrayNotHasKey('curlError', $report, "curlError was not expected in report.\n\n".print_r($report, true)); |
||||
479 | $this->assertArrayHasKey('message', $report, "message was expected in report.\n\n".print_r($report, true)); |
||||
480 | } |
||||
481 | |||||
482 | public function testCheckSpamScoreOfSentEmailAction() |
||||
483 | { |
||||
484 | $requestMock = $this->getMockBuilder("Symfony\Component\HttpFoundation\Request")->disableOriginalConstructor()->setMethods(array('get'))->getMock(); |
||||
485 | $containerMock = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")->disableOriginalConstructor()->getMock(); |
||||
486 | $containerMock->expects($this->once())->method('get')->will($this->returnValueMap(array( |
||||
487 | array('request', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $requestMock), ))); |
||||
488 | $controller = new AzineEmailTemplateController(); |
||||
489 | $controller->setContainer($containerMock); |
||||
490 | $jsonResponse = $controller->checkSpamScoreOfSentEmailAction($requestMock); |
||||
491 | $json = $jsonResponse->getContent(); |
||||
492 | if (false !== strpos($json, 'Getting the spam-info failed')) { |
||||
493 | $this->markTestIncomplete("It seems postmarks spam-check-service is unresponsive.\n\n$json"); |
||||
494 | } |
||||
495 | $this->assertNotContains('Getting the spam-info failed.', $jsonResponse->getContent(), "Spamcheck returned:\n".$jsonResponse->getContent()); |
||||
496 | $this->assertContains('SpamScore', $jsonResponse->getContent()); |
||||
497 | } |
||||
498 | } |
||||
499 |