e34d3e9881a7fc6280b839fb666e9b5a780cd652
[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 protected function setUp()
28 {
29 $this->markTestSkipped('Erros found in specific implementation, see @todo remarks there');
30 }
31
32 /**
33 * @return array
34 */
35 public function validTypesProvider()
36 {
37 return array(
38 'pdf in (pdf)' => array(array('application/pdf', 'application/pdf')),
39 'pdf in (pdf, json)' => array(array('application/pdf, application/json', 'application/pdf'))
40
41 );
42 }
43
44 /**
45 * @return array
46 */
47 public function invalidTypesProvider()
48 {
49 return array(
50 'xml in (pdf, json)' => array(array('application/pdf, application/json', 'application/xml')),
51 'xml in (pdf)' => array(array('application/pdf, application/json', 'application/xml'))
52 );
53 }
54
55 /**
56 * @test
57 * @dataProvider validTypesProvider
58 */
59 public function validateForValidInputHasEmptyErrorResult($input)
60 {
61 $options = array('element' => uniqid('test'), 'errorMessage' => uniqid('error'));
62 $options['types'] = $input[0];
63 $subject = $this->createSubject($options);
64
65 $this->assertEmpty(
66 $subject->validate($input[1])->getErrors()
67 );
68 }
69
70 /**
71 * @test
72 * @dataProvider invalidTypesProvider
73 */
74 public function validateForInvalidInputHasNotEmptyErrorResult($input)
75 {
76 $options = array('element' => uniqid('test'), 'errorMessage' => uniqid('error'));
77 $options['types'] = $input[0];
78 $subject = $this->createSubject($options);
79
80 $this->assertNotEmpty(
81 $subject->validate($input[1])->getErrors()
82 );
83 }
84 }