TYPO3 CMS  TYPO3_8-7
BooleanValidatorTest.php
Go to the documentation of this file.
1 <?php
3 
4 /* *
5  * This script belongs to the Extbase framework. *
6  * *
7  * It is free software; you can redistribute it and/or modify it under *
8  * the terms of the GNU Lesser General Public License as published by the *
9  * Free Software Foundation, either version 3 of the License, or (at your *
10  * option) any later version. *
11  * *
12  * This script is distributed in the hope that it will be useful, but *
13  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
14  * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
15  * General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU Lesser General Public *
18  * License along with the script. *
19  * If not, see http://www.gnu.org/licenses/lgpl.html *
20  * *
21  * The TYPO3 project - inspiring people to share! *
22  * */
23 
30 {
34  protected $validatorClassName = \TYPO3\CMS\Extbase\Validation\Validator\BooleanValidator::class;
35 
40  {
41  $options = ['is' => 'false'];
42  $validator = $this->getMockBuilder($this->validatorClassName)
43  ->setMethods(['translateErrorMessage'])
44  ->setConstructorArgs([$options])
45  ->getMock();
46  $this->assertFalse($validator->validate(false)->hasErrors());
47  }
48 
53  {
54  $options = ['is' => 'true'];
55  $validator = $this->getMockBuilder($this->validatorClassName)
56  ->setMethods(['translateErrorMessage'])
57  ->setConstructorArgs([$options])
58  ->getMock();
59  $this->assertFalse($validator->validate(true)->hasErrors());
60  }
61 
66  {
67  $options = ['is' => true];
68  $validator = $this->getMockBuilder($this->validatorClassName)
69  ->setMethods(['translateErrorMessage'])
70  ->setConstructorArgs([$options])
71  ->getMock();
72  $this->assertFalse($validator->validate(true)->hasErrors());
73  }
74 
79  {
80  $options = ['is' => false];
81  $validator = $this->getMockBuilder($this->validatorClassName)
82  ->setMethods(['translateErrorMessage'])
83  ->setConstructorArgs([$options])
84  ->getMock();
85  $this->assertFalse($validator->validate(false)->hasErrors());
86  }
87 
92  {
93  $options = ['is' => false];
94  $validator = $this->getMockBuilder($this->validatorClassName)
95  ->setMethods(['translateErrorMessage'])
96  ->setConstructorArgs([$options])
97  ->getMock();
98  $this->assertTrue($validator->validate(true)->hasErrors());
99  }
100 
105  {
106  $options = ['is' => true];
107  $validator = $this->getMockBuilder($this->validatorClassName)
108  ->setMethods(['translateErrorMessage'])
109  ->setConstructorArgs([$options])
110  ->getMock();
111  $this->assertTrue($validator->validate(false)->hasErrors());
112  }
113 
118  {
119  $options = ['is' => true];
120  $validator = $this->getMockBuilder($this->validatorClassName)
121  ->setMethods(['translateErrorMessage'])
122  ->setConstructorArgs([$options])
123  ->getMock();
124  $this->assertTrue($validator->validate('a string')->hasErrors());
125  }
126 
131  {
132  $options = [];
133  $validator = $this->getMockBuilder($this->validatorClassName)
134  ->setMethods(['translateErrorMessage'])
135  ->setConstructorArgs([$options])
136  ->getMock();
137  $this->assertFalse($validator->validate(true)->hasErrors());
138  }
139 }