TYPO3 CMS  TYPO3_7-6
LengthValidatorTest.php
Go to the documentation of this file.
1 <?php
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 
20 
25 {
29  protected $subjectClassName = \TYPO3\CMS\Form\Domain\Validator\LengthValidator::class;
30 
35 
39  protected function setUp()
40  {
41  parent::setUp();
42  $this->charsetConverterProphecy = $this->prophesize(CharsetConverter::class);
43  $this->charsetConverterProphecy
44  ->strlen(Argument::cetera())
45  ->will(function ($arguments) {
46  return mb_strlen($arguments[1], $arguments[0]);
47  });
48  }
49 
50  protected function tearDown()
51  {
52  parent::tearDown();
53  unset($this->charsetConverterProphecy);
54  }
55 
59  public function validLengthProvider()
60  {
61  return [
62  '4 ≤ length(myString) ≤ 8' => [
63  [4, 8, 'mäString']
64  ],
65  '8 ≤ length(myString) ≤ 8' => [
66  [8, 8, 'möString']
67  ],
68  '4 ≤ length(myString)' => [
69  [4, null, 'myString']
70  ],
71  '4 ≤ length(asdf) ≤ 4' => [
72  [4, 4, 'asdf']
73  ],
74  ];
75  }
76 
81  public function validateForValidInputHasEmptyErrorResult($input)
82  {
83  $options = ['element' => uniqid('test'), 'errorMessage' => uniqid('error')];
84  $options['minimum'] = $input[0];
85  $options['maximum'] = $input[1];
87  $subject = $this->createSubject($options);
88  $subject->injectCharsetConverter($this->charsetConverterProphecy->reveal());
89 
90  $this->assertEmpty(
91  $subject->validate($input[2])->getErrors()
92  );
93  }
94 
98  public function invalidLengthProvider()
99  {
100  return [
101  '4 ≤ length(my) ≤ 12' => [
102  [4, 12, 'my']
103  ],
104  '4 ≤ length(my long string) ≤ 12' => [
105  [4, 12, 'my long string']
106  ],
107  ];
108  }
109 
114  public function validateForInvalidInputHasNotEmptyErrorResult($input)
115  {
116  $options = ['element' => uniqid('test'), 'errorMessage' => uniqid('error')];
117  $options['minimum'] = $input[0];
118  $options['maximum'] = $input[1];
120  $subject = $this->createSubject($options);
121  $subject->injectCharsetConverter($this->charsetConverterProphecy->reveal());
122 
123  $this->assertNotEmpty(
124  $subject->validate($input[2])->getErrors()
125  );
126  }
127 }