TYPO3 CMS  TYPO3_6-2
EnumerationTest.php
Go to the documentation of this file.
1 <?php
3 
19 
24 
30  new Enumeration\MissingConstantsEnumeration();
31  }
32 
38  new Enumeration\CompleteEnumeration('bar');
39  }
40 
46  new Enumeration\MissingConstantsEnumeration(2);
47  }
48 
54  new Enumeration\InvalidConstantEnumeration(1);
55  }
56 
62  new Enumeration\MissingDefaultEnumeration();
63  }
64 
70  new Enumeration\DuplicateConstantValueEnumeration(1);
71  }
72 
77  $enumeration = $this->getAccessibleMock(
78  'TYPO3\\CMS\\Core\\Tests\\Unit\\Type\\Fixture\\Enumeration\\CompleteEnumeration',
79  array('dummy')
80  );
81 
82  $enumClassName = get_class($enumeration);
83 
84  $expectedValue = array(
85  'INTEGER_VALUE' => 1,
86  'STRING_VALUE' => 'foo',
87  '__default' => 1
88  );
89 
90  $result = $enumeration->_getStatic('enumConstants');
91  $this->assertArrayHasKey($enumClassName, $result);
92  $this->assertSame($expectedValue, $result[$enumClassName]);
93  }
94 
98  public function constructorSetsValue() {
99  $enumeration = $this->getAccessibleMock(
100  'TYPO3\\CMS\\Core\\Tests\\Unit\\Type\\Fixture\\Enumeration\\CompleteEnumeration',
101  array('dummy'),
102  array(1)
103  );
104  $this->assertEquals(1, $enumeration->_get('value'));
105  }
106 
110  public function setValueSetsValue() {
111  $enumeration = $this->getAccessibleMock(
112  'TYPO3\\CMS\\Core\\Tests\\Unit\\Type\\Fixture\\Enumeration\\CompleteEnumeration',
113  array('dummy'),
114  array(1)
115  );
116  $enumeration->_call('setValue', 'foo');
117  $this->assertEquals('foo', $enumeration->_get('value'));
118  }
119 
125  $enumeration = $this->getAccessibleMock(
126  'TYPO3\\CMS\\Core\\Tests\\Unit\\Type\\Fixture\\Enumeration\\CompleteEnumeration',
127  array('dummy'),
128  array(1)
129  );
130  $enumeration->_call('setValue', 2);
131  $this->assertEquals(2, $enumeration->_get('value'));
132  }
133 
137  public function isValidComparisonExpectations() {
138  return array(
139  array(
140  1,
141  1,
142  TRUE
143  ),
144  array(
145  1,
146  '1',
147  TRUE
148  ),
149  array(
150  '1',
151  1,
152  TRUE
153  ),
154  array(
155  'a1',
156  1,
157  FALSE
158  ),
159  array(
160  1,
161  'a1',
162  FALSE
163  ),
164  array(
165  '1a',
166  1,
167  FALSE
168  ),
169  array(
170  1,
171  '1a',
172  FALSE
173  ),
174  array(
175  'foo',
176  'foo',
177  TRUE
178  ),
179  array(
180  'foo',
181  'bar',
182  FALSE
183  ),
184  array(
185  'foo',
186  'foobar',
187  FALSE
188  )
189  );
190  }
191 
196  public function isValidDoesTypeLooseComparison($enumerationValue, $testValue, $expectation) {
197  $mockName = $this->getUniqueId('CompleteEnumerationMock');
198  $enumeration = $this->getAccessibleMock(
199  'TYPO3\\CMS\\Core\\Tests\\Unit\\Type\\Fixture\\Enumeration\\CompleteEnumeration',
200  array('dummy'),
201  array(),
202  $mockName,
203  FALSE
204  );
205  $enumeration->_setStatic('enumConstants', array($mockName => array('CONSTANT_NAME' => $enumerationValue)));
206  $enumeration->_set('value', $enumerationValue);
207  $this->assertSame($expectation, $enumeration->_call('isValid', $testValue));
208  }
209 
214  $this->assertEquals(array('INTEGER_VALUE' => 1, 'STRING_VALUE' => 'foo'), Enumeration\CompleteEnumeration::getConstants());
215  }
216 
221  $this->assertEquals(array('INTEGER_VALUE' => 1, 'STRING_VALUE' => 'foo', '__default' => 1), Enumeration\CompleteEnumeration::getConstants(TRUE));
222  }
223 
228  $enumeration = new Enumeration\CompleteEnumeration();
229  $this->assertEquals(array('INTEGER_VALUE' => 1, 'STRING_VALUE' => 'foo'), $enumeration->getConstants());
230  }
231 
235  public function toStringReturnsValueAsString() {
236  $enumeration = new Enumeration\CompleteEnumeration();
237  $this->assertSame('1', $enumeration->__toString());
238  }
239 
244  $enumeration = Enumeration\CompleteEnumeration::cast(1);
245  $this->assertInstanceOf('TYPO3\\CMS\\Core\\Tests\\Unit\\Type\\Fixture\\Enumeration\\CompleteEnumeration', $enumeration);
246  }
247 
252  $initialEnumeration = new Enumeration\MissingDefaultEnumeration(1);
253  $enumeration = Enumeration\CompleteEnumeration::cast($initialEnumeration);
254  $this->assertInstanceOf('TYPO3\\CMS\\Core\\Tests\\Unit\\Type\\Fixture\\Enumeration\\CompleteEnumeration', $enumeration);
255  }
256 
261  $initialEnumeration = new Enumeration\CompleteEnumeration(1);
262  $enumeration = Enumeration\CompleteEnumeration::cast($initialEnumeration);
263  $this->assertSame($initialEnumeration, $enumeration);
264  }
265 
270  $enumeration = $this->getAccessibleMock(
271  'TYPO3\\CMS\\Core\\Tests\\Unit\\Type\\Fixture\\Enumeration\\CompleteEnumeration',
272  array('dummy'),
273  array('1')
274  );
275  $this->assertSame(1, $enumeration->_get('value'));
276  }
277 
282  $enumeration = $this->getAccessibleMock(
283  'TYPO3\\CMS\\Core\\Tests\\Unit\\Type\\Fixture\\Enumeration\\CompleteEnumeration',
284  array('dummy'),
285  array(1)
286  );
287  $this->assertSame(1, $enumeration->_get('value'));
288  }
289 
294  $enumeration = new Enumeration\CompleteEnumeration(1);
295  $this->assertTrue($enumeration->equals(1));
296  }
297 
302  $enumeration = new Enumeration\CompleteEnumeration(1);
303  $this->assertTrue($enumeration->equals('1'));
304  }
305 
310  $enumerationFoo = new Enumeration\CompleteEnumeration(1);
311  $enumerationBar = new Enumeration\CompleteEnumeration(1);
312  $this->assertTrue($enumerationFoo->equals($enumerationBar));
313  }
314 
319  $enumerationFoo = new Enumeration\CompleteEnumeration(1);
320  $enumerationBar = new Enumeration\MissingDefaultEnumeration(1);
321  $this->assertTrue($enumerationFoo->equals($enumerationBar));
322  }
323 
328  $enumerationFoo = new Enumeration\CompleteEnumeration('foo');
329  $enumerationBar = new Enumeration\MissingDefaultEnumeration(1);
330  $this->assertFalse($enumerationFoo->equals($enumerationBar));
331  }
332 
337  $enumerationFoo = new Enumeration\CompleteEnumeration(1);
338  $enumerationBar = new Enumeration\CompleteEnumeration('foo');
339  $this->assertFalse($enumerationFoo->equals($enumerationBar));
340  }
341 
342 }
static getConstants($include_default=FALSE)
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren&#39;t numeric.
isValidDoesTypeLooseComparison($enumerationValue, $testValue, $expectation)