TYPO3 CMS  TYPO3_6-2
StringLengthValidatorTest.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 
28 
29  protected $validatorClassName = 'TYPO3\\CMS\\Extbase\\Validation\\Validator\\StringLengthValidator';
30 
31  public function setup() {
32  $this->validator = $this->getMock($this->validatorClassName, array('translateErrorMessage'));
33  }
34 
38  protected $validator;
39 
44  $this->assertFalse($this->validator->validate(NULL)->hasErrors());
45  }
46 
51  $this->assertFalse($this->validator->validate('')->hasErrors());
52  }
53 
58  $options = array('minimum' => 0, 'maximum' => 50);
59  $validator = $this->getMock($this->validatorClassName, array('dummy'), array($options));
60  $this->assertFalse($validator->validate('this is a very simple string')->hasErrors());
61  }
62 
67  $options = array('minimum' => 50, 'maximum' => 100);
68  $validator = $this->getMock($this->validatorClassName, array('translateErrorMessage'), array($options));
69  $this->assertTrue($validator->validate('this is a very short string')->hasErrors());
70  }
71 
76  $options = array('minimum' => 5, 'maximum' => 10);
77  $validator = $this->getMock($this->validatorClassName, array('translateErrorMessage'), array($options));
78  $this->assertTrue($validator->validate('this is a very short string')->hasErrors());
79  }
80 
85  $options = array('minimum' => 5);
86  $validator = $this->getMock($this->validatorClassName, array('dummy'), array($options));
87  $this->assertFalse($validator->validate('this is a very short string')->hasErrors());
88  }
89 
94  $options = array('maximum' => 100);
95  $validator = $this->getMock($this->validatorClassName, array('dummy'), array($options));
96  $this->assertFalse($validator->validate('this is a very short string')->hasErrors());
97  }
98 
103  $options = array('maximum' => 10);
104  $validator = $this->getMock($this->validatorClassName, array('dummy'), array($options));
105  $this->assertFalse($validator->validate('1234567890')->hasErrors());
106  }
107 
112  $options = array('minimum' => 10);
113  $validator = $this->getMock($this->validatorClassName, array('dummy'), array($options));
114  $this->assertFalse($validator->validate('1234567890')->hasErrors());
115  }
116 
121  $options = array('minimum' => 10, 'maximum' => 10);
122  $validator = $this->getMock($this->validatorClassName, array('dummy'), array($options));
123  $this->assertFalse($validator->validate('1234567890')->hasErrors());
124  }
125 
130  $options = array('minimum' => 1, 'maximum' => 10);
131  $validator = $this->getMock($this->validatorClassName, array('dummy'), array($options));
132  $this->assertFalse($validator->validate('1234567890')->hasErrors());
133  }
134 
139  $options = array('minimum' => 10, 'maximum' => 100);
140  $validator = $this->getMock($this->validatorClassName, array('dummy'), array($options));
141  $this->assertFalse($validator->validate('1234567890')->hasErrors());
142  }
143 
149  $options = array('minimum' => 101, 'maximum' => 100);
150  $validator = $this->getMock($this->validatorClassName, array('addError', 'translateErrorMessage'), array($options));
151  $validator->validate('1234567890');
152  }
153 
158  $options = array('minimum' => 50, 'maximum' => 100);
159  $validator = $this->getMock($this->validatorClassName, array('translateErrorMessage'), array($options));
160  $this->assertEquals(1, count($validator->validate('this is a very short string')->getErrors()));
161  }
162 
167  $options = array('minimum' => 5, 'maximum' => 100);
168  $validator = $this->getMock($this->validatorClassName, array('addError', 'translateErrorMessage'), array($options));
169 
170  $className = $this->getUniqueId('TestClass');
171 
172  eval('
173  class ' . $className . ' {
174  public function __toString() {
175  return \'some string\';
176  }
177  }
178  ');
179 
180  $object = new $className();
181  $this->assertFalse($validator->validate($object)->hasErrors());
182  }
183 
188  $options = array('minimum' => 5, 'maximum' => 100);
189  $validator = $this->getMock($this->validatorClassName, array('translateErrorMessage'), array($options));
190 
191  $className = $this->getUniqueId('TestClass');
192 
193  eval('
194  class ' . $className . ' {
195  protected $someProperty;
196  }
197  ');
198 
199  $object = new $className();
200  $this->assertTrue($validator->validate($object)->hasErrors());
201  }
202 
207 // $this->validatorOptions(array('maximum' => 8));
208 // $this->assertFalse($this->validator->validate('überlang')->hasErrors());
209  $this->markTestSkipped('Validator needs to be adjusted regarding multibyte char lengths.');
210  }
211 }