[BUGFIX] Solves PHP warning in FileAllowedTypesValidator
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Tests / Unit / Validator / FileAllowedTypesValidatorTest.php
1 <?php
2 namespace TYPO3\CMS\Form\Tests\Unit\Validator;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * Test case
19 */
20 class FileAllowedTypesValidatorTest extends AbstractValidatorTest
21 {
22 /**
23 * @var string
24 */
25 protected $subjectClassName = \TYPO3\CMS\Form\Domain\Validator\FileAllowedTypesValidator::class;
26
27 /**
28 * @return array
29 */
30 public function validTypesProvider()
31 {
32 return array(
33 'pdf in (pdf)' => [
34 'application/pdf',
35 [
36 'type' => 'application/pdf',
37 ],
38 ],
39 'pdf in (pdf, json)' => [
40 'application/pdf, application/json',
41 [
42 'type' => 'application/pdf',
43 ],
44 ],
45 );
46 }
47
48 /**
49 * @return array
50 */
51 public function invalidTypesProvider()
52 {
53 return array(
54 'xml in (pdf, json)' => [
55 'application/pdf, application/json',
56 [
57 'type' => 'application/xml',
58 ],
59 ],
60 'xml in (pdf)' => [
61 'application/pdf',
62 [
63 'type' => 'application/xml',
64 ],
65 ],
66 'empty mimetype' => [
67 'application/pdf, application/json',
68 [
69 'type' => '',
70 ],
71 ],
72 'empty value' => [
73 'application/pdf, application/json',
74 '',
75 ],
76 );
77 }
78
79 /**
80 * @test
81 * @param string $types
82 * @param array $value
83 * @dataProvider validTypesProvider
84 */
85 public function validateForValidInputHasEmptyErrorResult($types, $value)
86 {
87 $options = [
88 'element' => uniqid('test'),
89 'errorMessage' => uniqid('error'),
90 'types' => $types,
91 ];
92 $subject = $this->createSubject($options);
93
94 $this->assertEmpty($subject->validate($value)->getErrors());
95 }
96
97 /**
98 * @test
99 * @param string $types
100 * @param array $value
101 * @dataProvider invalidTypesProvider
102 */
103 public function validateForInvalidInputHasNotEmptyErrorResult($types, $value)
104 {
105 $options = [
106 'element' => uniqid('test'),
107 'errorMessage' => uniqid('error'),
108 'types' => $types,
109 ];
110 $subject = $this->createSubject($options);
111
112 $this->assertNotEmpty($subject->validate($value)->getErrors());
113 }
114 }