This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Oro\Bundle\EmailBundle\Tests\Unit\Form\Type; |
||
4 | |||
5 | use Doctrine\Common\Collections\ArrayCollection; |
||
6 | |||
7 | use Genemu\Bundle\FormBundle\Form\JQuery\Type\Select2Type; |
||
8 | |||
9 | use Symfony\Component\Form\FormEvent; |
||
10 | use Symfony\Component\Form\Test\TypeTestCase; |
||
11 | use Symfony\Component\Form\PreloadedExtension; |
||
12 | use Symfony\Component\PropertyAccess\PropertyAccess; |
||
13 | |||
14 | use Oro\Bundle\FormBundle\Form\Type\OroRichTextType; |
||
15 | use Oro\Bundle\FormBundle\Form\Type\OroResizeableRichTextType; |
||
16 | use Oro\Bundle\EmailBundle\Entity\EmailTemplate; |
||
17 | use Oro\Bundle\TranslationBundle\Form\Type\TranslatableEntityType; |
||
18 | use Oro\Bundle\ActivityBundle\Form\Type\ContextsSelectType; |
||
19 | use Oro\Bundle\EmailBundle\Form\Type\EmailType; |
||
20 | use Oro\Bundle\EmailBundle\Form\Model\Email; |
||
21 | use Oro\Bundle\EmailBundle\Form\Type\EmailAddressType; |
||
22 | use Oro\Bundle\EmailBundle\Form\Type\EmailAttachmentsType; |
||
23 | use Oro\Bundle\EmailBundle\Form\Type\EmailTemplateSelectType; |
||
24 | use Oro\Bundle\EmailBundle\Form\Type\EmailAddressFromType; |
||
25 | use Oro\Bundle\EmailBundle\Form\Type\EmailAddressRecipientsType; |
||
26 | use Oro\Bundle\UserBundle\Entity\User; |
||
27 | |||
28 | class EmailTypeTest extends TypeTestCase |
||
29 | { |
||
30 | /** |
||
31 | * @var \Symfony\Component\Security\Core\SecurityContextInterface|\PHPUnit_Framework_MockObject_MockObject |
||
32 | */ |
||
33 | protected $securityContext; |
||
34 | |||
35 | /** |
||
36 | * @var \Oro\Bundle\EmailBundle\Provider\EmailRenderer|\PHPUnit_Framework_MockObject_MockObject |
||
37 | */ |
||
38 | protected $emailRenderer; |
||
39 | |||
40 | /** |
||
41 | * @var \Oro\Bundle\EmailBundle\Builder\Helper\EmailModelBuilderHelper|\PHPUnit_Framework_MockObject_MockObject |
||
42 | */ |
||
43 | protected $emailModelBuilderHelper; |
||
44 | |||
45 | /** |
||
46 | * @var EmailTemplate |
||
47 | */ |
||
48 | protected $emailTemplate; |
||
49 | |||
50 | protected function setUp() |
||
51 | { |
||
52 | parent::setUp(); |
||
53 | $this->securityContext = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface'); |
||
54 | $this->emailRenderer = $this->getMockBuilder('Oro\Bundle\EmailBundle\Provider\EmailRenderer') |
||
55 | ->disableOriginalConstructor()->getMock(); |
||
56 | $this->emailModelBuilderHelper = $this |
||
57 | ->getMockBuilder('Oro\Bundle\EmailBundle\Builder\Helper\EmailModelBuilderHelper') |
||
58 | ->disableOriginalConstructor()->getMock(); |
||
59 | $this->htmlTagProvider = $this->getMock('Oro\Bundle\FormBundle\Provider\HtmlTagProvider'); |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * @return EmailType |
||
64 | */ |
||
65 | protected function createEmailType() |
||
66 | { |
||
67 | return new EmailType($this->securityContext, $this->emailRenderer, $this->emailModelBuilderHelper); |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * @SuppressWarnings(PHPMD.ExcessiveMethodLength) |
||
72 | * @return array |
||
73 | */ |
||
74 | protected function getExtensions() |
||
75 | { |
||
76 | $emailAddressType = new EmailAddressType($this->securityContext); |
||
0 ignored issues
–
show
|
|||
77 | $translatableType = $this->getMockBuilder('Oro\Bundle\TranslationBundle\Form\Type\TranslatableEntityType') |
||
78 | ->disableOriginalConstructor() |
||
79 | ->getMock(); |
||
80 | $translatableType->expects($this->any()) |
||
81 | ->method('getName') |
||
82 | ->will($this->returnValue(TranslatableEntityType::NAME)); |
||
83 | |||
84 | // $translatableType = new \Oro\Component\Testing\Unit\Form\Type\Stub\EntityType( |
||
85 | // [ |
||
86 | // 'test_name' => (new EmailTemplate())->setName('test_name'), |
||
87 | // ], |
||
88 | // TranslatableEntityType::NAME |
||
89 | // ); |
||
90 | |||
91 | $user = new User(); |
||
92 | $securityFacade = $this->getMockBuilder('Oro\Bundle\SecurityBundle\SecurityFacade') |
||
93 | ->disableOriginalConstructor() |
||
94 | ->getMock(); |
||
95 | $securityFacade->expects($this->any()) |
||
96 | ->method('getLoggedUser') |
||
97 | ->will($this->returnValue($user)); |
||
98 | |||
99 | $relatedEmailsProvider = $this->getMockBuilder('Oro\Bundle\EmailBundle\Provider\RelatedEmailsProvider') |
||
100 | ->disableOriginalConstructor() |
||
101 | ->getMock(); |
||
102 | $relatedEmailsProvider->expects($this->any()) |
||
103 | ->method('getEmails') |
||
104 | ->with($user) |
||
105 | ->will($this->returnValue(['[email protected]' => 'John Smith <[email protected]>'])); |
||
106 | |||
107 | $mailboxManager = $this->getMockBuilder('Oro\Bundle\EmailBundle\Entity\Manager\MailboxManager') |
||
108 | ->disableOriginalConstructor() |
||
109 | ->getMock(); |
||
110 | $mailboxManager->expects($this->any()) |
||
111 | ->method('findAvailableMailboxEmails') |
||
112 | ->will($this->returnValue([])); |
||
113 | |||
114 | $configManager = $this->getMockBuilder('Oro\Bundle\ConfigBundle\Config\ConfigManager') |
||
115 | ->disableOriginalConstructor() |
||
116 | ->getMock(); |
||
117 | |||
118 | $select2ChoiceType = new Select2Type(TranslatableEntityType::NAME); |
||
119 | $genemuChoiceType = new Select2Type('choice'); |
||
120 | $emailTemplateList = new EmailTemplateSelectType(); |
||
121 | $attachmentsType = new EmailAttachmentsType(); |
||
122 | $emailAddressFromType = new EmailAddressFromType($securityFacade, $relatedEmailsProvider, $mailboxManager); |
||
123 | $emailAddressRecipientsType = new EmailAddressRecipientsType($configManager); |
||
124 | |||
125 | $configManager = $this->getMockBuilder('Oro\Bundle\ConfigBundle\Config\ConfigManager') |
||
126 | ->disableOriginalConstructor() |
||
127 | ->getMock(); |
||
128 | $htmlTagProvider = $this->getMock('Oro\Bundle\FormBundle\Provider\HtmlTagProvider'); |
||
129 | $htmlTagProvider->expects($this->any()) |
||
130 | ->method('getAllowedElements') |
||
131 | ->willReturn(['br', 'a']); |
||
132 | $richTextType = new OroRichTextType($configManager, $htmlTagProvider); |
||
133 | $resizableRichTextType = new OroResizeableRichTextType($configManager, $htmlTagProvider); |
||
134 | $em = $this->getMockBuilder('Doctrine\ORM\EntityManager') |
||
135 | ->disableOriginalConstructor() |
||
136 | ->getMock(); |
||
137 | $metadata = $this->getMockBuilder('Doctrine\ORM\Mapping\ClassMetadataInfo') |
||
138 | ->disableOriginalConstructor() |
||
139 | ->getMock(); |
||
140 | $metadata->expects($this->any()) |
||
141 | ->method('getName'); |
||
142 | $em->expects($this->any()) |
||
143 | ->method('getClassMetadata') |
||
144 | ->willReturn($metadata); |
||
145 | $repo = $this->getMockBuilder('\Doctrine\ORM\EntityRepository') |
||
146 | ->disableOriginalConstructor() |
||
147 | ->getMock(); |
||
148 | $repo->expects($this->any()) |
||
149 | ->method('find'); |
||
150 | $em->expects($this->any()) |
||
151 | ->method('getRepository') |
||
152 | ->willReturn($repo); |
||
153 | $configManager = $this->getMockBuilder('Oro\Bundle\EntityConfigBundle\Config\ConfigManager') |
||
154 | ->disableOriginalConstructor() |
||
155 | ->getMock(); |
||
156 | $translator = $this->getMockBuilder('Symfony\Component\Translation\DataCollectorTranslator') |
||
157 | ->disableOriginalConstructor() |
||
158 | ->getMock(); |
||
159 | $mapper = $this->getMockBuilder('Oro\Bundle\SearchBundle\Engine\ObjectMapper') |
||
160 | ->disableOriginalConstructor() |
||
161 | ->getMock(); |
||
162 | $securityTokenStorage = |
||
163 | $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface') |
||
164 | ->disableOriginalConstructor() |
||
165 | ->getMock(); |
||
166 | $eventDispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') |
||
167 | ->disableOriginalConstructor() |
||
168 | ->getMock(); |
||
169 | $contextsSelectType = new ContextsSelectType( |
||
170 | $em, |
||
171 | $configManager, |
||
172 | $translator, |
||
173 | $mapper, |
||
174 | $securityTokenStorage, |
||
175 | $eventDispatcher |
||
176 | ); |
||
177 | |||
178 | return [ |
||
179 | new PreloadedExtension( |
||
180 | [ |
||
181 | TranslatableEntityType::NAME => $translatableType, |
||
182 | $select2ChoiceType->getName() => $select2ChoiceType, |
||
183 | $emailTemplateList->getName() => $emailTemplateList, |
||
184 | $emailAddressType->getName() => $emailAddressType, |
||
185 | $richTextType->getName() => $richTextType, |
||
186 | $resizableRichTextType->getName() => $resizableRichTextType, |
||
187 | $attachmentsType->getName() => $attachmentsType, |
||
188 | ContextsSelectType::NAME => $contextsSelectType, |
||
189 | 'genemu_jqueryselect2_hidden' => new Select2Type('hidden'), |
||
190 | $genemuChoiceType->getName() => $genemuChoiceType, |
||
191 | $emailAddressFromType->getName() => $emailAddressFromType, |
||
192 | $emailAddressRecipientsType->getName() => $emailAddressRecipientsType, |
||
193 | ], |
||
194 | [] |
||
195 | ) |
||
196 | ]; |
||
197 | } |
||
198 | |||
199 | /** |
||
200 | * @dataProvider messageDataProvider |
||
201 | * @param array $formData |
||
202 | * @param array $to |
||
203 | * @param array $cc |
||
204 | * @param array $bcc |
||
205 | */ |
||
206 | public function testSubmitValidData($formData, $to, $cc, $bcc) |
||
207 | { |
||
208 | $body = ''; |
||
209 | if (isset($formData['body'])) { |
||
210 | $body = $formData['body']; |
||
211 | } |
||
212 | $type = $this->createEmailType(); |
||
213 | $form = $this->factory->create($type); |
||
214 | |||
215 | $form->submit($formData); |
||
216 | $this->assertTrue($form->isSynchronized()); |
||
217 | |||
218 | /** @var Email $result */ |
||
219 | $result = $form->getData(); |
||
220 | $this->assertInstanceOf('Oro\Bundle\EmailBundle\Form\Model\Email', $result); |
||
221 | $this->assertEquals('test_grid', $result->getGridName()); |
||
222 | $this->assertEquals($formData['from'], $result->getFrom()); |
||
223 | $this->assertEquals($to, $result->getTo()); |
||
224 | $this->assertEquals($cc, $result->getCc()); |
||
225 | $this->assertEquals($bcc, $result->getBcc()); |
||
226 | $this->assertEquals($formData['subject'], $result->getSubject()); |
||
227 | $this->assertEquals($body, $result->getBody()); |
||
228 | } |
||
229 | |||
230 | View Code Duplication | public function testSetDefaultOptions() |
|
231 | { |
||
232 | $resolver = $this->getMock('Symfony\Component\OptionsResolver\OptionsResolverInterface'); |
||
233 | $resolver->expects($this->once()) |
||
234 | ->method('setDefaults') |
||
235 | ->with( |
||
236 | [ |
||
237 | 'data_class' => 'Oro\Bundle\EmailBundle\Form\Model\Email', |
||
238 | 'intention' => 'email', |
||
239 | 'csrf_protection' => true, |
||
240 | 'cascade_validation' => true |
||
241 | ] |
||
242 | ); |
||
243 | |||
244 | $type = $this->createEmailType(); |
||
245 | $type->setDefaultOptions($resolver); |
||
246 | } |
||
247 | |||
248 | public function testGetName() |
||
249 | { |
||
250 | $type = $this->createEmailType(); |
||
251 | $this->assertEquals('oro_email_email', $type->getName()); |
||
252 | } |
||
253 | |||
254 | public function messageDataProvider() |
||
255 | { |
||
256 | return [ |
||
257 | [ |
||
258 | [ |
||
259 | 'gridName' => 'test_grid', |
||
260 | 'from' => 'John Smith <[email protected]>', |
||
261 | 'to' => [ |
||
262 | 'John Smith 1 <[email protected]>', |
||
263 | '"John Smith 2" <[email protected]>', |
||
264 | '[email protected]', |
||
265 | ], |
||
266 | 'subject' => 'Test subject', |
||
267 | 'type' => 'text', |
||
268 | 'attachments' => new ArrayCollection(), |
||
269 | 'template' => new EmailTemplate(), |
||
270 | ], |
||
271 | ['John Smith 1 <[email protected]>', '"John Smith 2" <[email protected]>', '[email protected]'], |
||
272 | [], |
||
273 | [], |
||
274 | ], |
||
275 | [ |
||
276 | [ |
||
277 | 'gridName' => 'test_grid', |
||
278 | 'from' => 'John Smith <[email protected]>', |
||
279 | 'to' => [ |
||
280 | 'John Smith 1 <[email protected]>', |
||
281 | '"John Smith 2" <[email protected]>', |
||
282 | '[email protected]', |
||
283 | ], |
||
284 | 'cc' => [ |
||
285 | 'John Smith 4 <[email protected]>', |
||
286 | '"John Smith 5" <[email protected]>', |
||
287 | '[email protected]', |
||
288 | ], |
||
289 | 'bcc' => [ |
||
290 | 'John Smith 7 <[email protected]>', |
||
291 | '"John Smith 8" <[email protected]>', |
||
292 | '[email protected]', |
||
293 | ], |
||
294 | 'subject' => 'Test subject', |
||
295 | 'body' => 'Test body', |
||
296 | 'type' => 'text', |
||
297 | 'template' => new EmailTemplate(), |
||
298 | ], |
||
299 | ['John Smith 1 <[email protected]>', '"John Smith 2" <[email protected]>', '[email protected]'], |
||
300 | ['John Smith 4 <[email protected]>', '"John Smith 5" <[email protected]>', '[email protected]'], |
||
301 | ['John Smith 7 <[email protected]>', '"John Smith 8" <[email protected]>', '[email protected]'], |
||
302 | ], |
||
303 | ]; |
||
304 | } |
||
305 | |||
306 | /** |
||
307 | * @param Email $inputData |
||
308 | * @param array $expectedData |
||
309 | * |
||
310 | * @dataProvider fillFormByTemplateProvider |
||
311 | */ |
||
312 | public function testFillFormByTemplate(Email $inputData = null, array $expectedData = []) |
||
313 | { |
||
314 | $this->markTestSkipped( |
||
315 | 'Test Skipped because of unresolved relation to \Oro\Component\Testing\Unit\Form\Type\Stub\EntityType' |
||
316 | ); |
||
317 | $emailTemplate = $this->createEmailTemplate(); |
||
318 | $this->emailRenderer |
||
319 | ->expects($this->any()) |
||
320 | ->method('compileMessage') |
||
321 | ->with($emailTemplate) |
||
322 | ->willReturn( |
||
323 | [ |
||
324 | $emailTemplate->getSubject(), |
||
325 | $emailTemplate->getContent() |
||
326 | ] |
||
327 | ); |
||
328 | |||
329 | $formType = $this->createEmailType(); |
||
330 | $form = $this->factory->create($formType, $inputData); |
||
331 | |||
332 | $formType->fillFormByTemplate(new FormEvent($form, $inputData)); |
||
333 | |||
334 | $formData = $form->getData(); |
||
335 | |||
336 | $propertyAccess = PropertyAccess::createPropertyAccessor(); |
||
337 | foreach ($expectedData as $propertyPath => $expectedValue) { |
||
338 | $value = $propertyAccess->getValue($formData, $propertyPath); |
||
339 | $this->assertEquals($expectedValue, $value); |
||
340 | } |
||
341 | } |
||
342 | |||
343 | /** |
||
344 | * @return array |
||
345 | */ |
||
346 | public function fillFormByTemplateProvider() |
||
347 | { |
||
348 | return [ |
||
349 | 'template is not empty' => [ |
||
350 | 'inputData' => (new Email())->setTemplate($this->createEmailTemplate()), |
||
351 | 'expectedData' => [ |
||
352 | 'subject' => 'Test Subject', |
||
353 | 'body' => 'Test Body', |
||
354 | ], |
||
355 | ], |
||
356 | 'template and subject is not empty' => [ |
||
357 | 'inputData' => (new Email()) |
||
358 | ->setTemplate($this->createEmailTemplate()) |
||
359 | ->setSubject('New Test Subject'), |
||
360 | 'expectedData' => [ |
||
361 | 'subject' => 'New Test Subject', |
||
362 | 'body' => 'Test Body', |
||
363 | ], |
||
364 | ], |
||
365 | 'template and body is not empty' => [ |
||
366 | 'inputData' => (new Email()) |
||
367 | ->setTemplate($this->createEmailTemplate()) |
||
368 | ->setBody('New Test Body'), |
||
369 | 'expectedData' => [ |
||
370 | 'subject' => 'Test Subject', |
||
371 | 'body' => 'New Test Body', |
||
372 | ], |
||
373 | ], |
||
374 | 'template, subject and body is not empty' => [ |
||
375 | 'inputData' => (new Email()) |
||
376 | ->setTemplate($this->createEmailTemplate()) |
||
377 | ->setSubject('New Test Subject') |
||
378 | ->setBody('New Test Body'), |
||
379 | 'expectedData' => [ |
||
380 | 'subject' => 'New Test Subject', |
||
381 | 'body' => 'New Test Body', |
||
382 | ], |
||
383 | ], |
||
384 | ]; |
||
385 | } |
||
386 | |||
387 | /** |
||
388 | * @return EmailTemplate |
||
389 | */ |
||
390 | protected function createEmailTemplate() |
||
391 | { |
||
392 | $template = new EmailTemplate(); |
||
393 | $template |
||
394 | ->setName('test_name') |
||
395 | ->setSubject('Test Subject') |
||
396 | ->setContent('Test Body'); |
||
397 | |||
398 | return $template; |
||
399 | } |
||
400 | } |
||
401 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.