e08c50054127caed30dc4ae9ebb643ac93671a7b
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Tests / Unit / Validator / RequiredValidatorTest.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 RequiredValidatorTest extends AbstractValidatorTest
21 {
22 /**
23 * @var string
24 */
25 protected $subjectClassName = \TYPO3\CMS\Form\Domain\Validator\RequiredValidator::class;
26
27 /**
28 * @return array
29 */
30 public function validDataProvider()
31 {
32 return array(
33 'string "a"' => array('a'),
34 'string "a b"' => array('a b'),
35 'string "0"' => array('0'),
36 'value 0' => array(0),
37 'array with string "a"' => array(array('a')),
38 'array with string "a b"' => array(array('a b')),
39 'array with string "0"' => array(array('0')),
40 'array with value 0' => array(array(0)),
41 'array with strings "a" and "b"' => array(array('a', 'b')),
42 'array with empty string and "a"' => array(array('', 'a')),
43 'array with empty string and "0"' => array(array('', "0")),
44 'array with empty string and 0' => array(array('', 0)),
45 );
46 }
47
48 /**
49 * @return array
50 */
51 public function invalidDataProvider()
52 {
53 return array(
54 'empty string' => array(''),
55 'array with empty string' => array(array('')),
56 'array with empty strings' => array(array('', ''))
57 );
58 }
59
60 /**
61 * @test
62 * @dataProvider validDataProvider
63 */
64 public function validateForValidDataHasEmptyErrorResult($input)
65 {
66 $options = array('element' => uniqid('test'), 'errorMessage' => uniqid('error'));
67 $subject = $this->createSubject($options);
68
69 $this->assertEmpty(
70 $subject->validate($input)->getErrors()
71 );
72 }
73
74 /**
75 * @test
76 * @dataProvider invalidDataProvider
77 */
78 public function validateForInvalidDataHasNotEmptyErrorResult($input)
79 {
80 $options = array('element' => uniqid('test'), 'errorMessage' => uniqid('error'));
81 $subject = $this->createSubject($options);
82
83 $this->assertNotEmpty(
84 $subject->validate($input)->getErrors()
85 );
86 }
87 }