[BUGFIX] TypeHandlingService throws Exception for StorageObjects
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Service / TypeHandlingServiceTest.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Tests\Unit\Service;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2011 Extbase Team
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26 /**
27 * Testcase for class Tx_Extbase_Service_TypeHandling
28 *
29 * @package Extbase
30 * @subpackage extbase
31 */
32 class TypeHandlingServiceTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
33
34 /**
35 * @var \TYPO3\CMS\Extbase\Service\TypeHandlingService
36 */
37 protected $typeHandlingService;
38
39 public function setUp() {
40 $this->typeHandlingService = new \TYPO3\CMS\Extbase\Service\TypeHandlingService();
41 }
42
43 /**
44 * @test
45 * @expectedException \InvalidArgumentException
46 */
47 public function parseTypeThrowsExceptionOnInvalidType() {
48 $this->typeHandlingService->parseType('something not a type');
49 }
50
51 /**
52 * @test
53 * @expectedException \InvalidArgumentException
54 * @author Karsten Dambekalns <karsten@typo3.org>
55 */
56 public function parseTypeThrowsExceptionOnInvalidElementTypeHint() {
57 $this->typeHandlingService->parseType('string<integer>');
58 }
59
60 /**
61 * data provider for parseTypeReturnsArrayWithInformation
62 *
63 * @author Karsten Dambekalns <karsten@typo3.org>
64 * @return array
65 */
66 public function types() {
67 return array(
68 array('int', array('type' => 'integer', 'elementType' => NULL)),
69 array('string', array('type' => 'string', 'elementType' => NULL)),
70 array('DateTime', array('type' => 'DateTime', 'elementType' => NULL)),
71 array('Tx_Extbase_Bar', array('type' => 'Tx_Extbase_Bar', 'elementType' => NULL)),
72 array('Tx_Extbase_Bar', array('type' => 'Tx_Extbase_Bar', 'elementType' => NULL)),
73 array('array<integer>', array('type' => 'array', 'elementType' => 'integer')),
74 array('ArrayObject<string>', array('type' => 'ArrayObject', 'elementType' => 'string')),
75 array('SplObjectStorage<Tx_Extbase_Bar>', array('type' => 'SplObjectStorage', 'elementType' => 'Tx_Extbase_Bar')),
76 array('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\ObjectStorage<Tx_Extbase_Bar>', array('type' => 'TYPO3\\CMS\\Extbase\\Persistence\\Generic\\ObjectStorage', 'elementType' => 'Tx_Extbase_Bar')),
77 array('Tx_Extbase_Persistence_ObjectStorage<Tx_Extbase_Bar>', array('type' => 'Tx_Extbase_Persistence_ObjectStorage', 'elementType' => 'Tx_Extbase_Bar'))
78 );
79 }
80
81 /**
82 * @test
83 * @dataProvider types
84 * @author Karsten Dambekalns <karsten@typo3.org>
85 * @param mixed $type
86 * @param mixed $expectedResult
87 */
88 public function parseTypeReturnsArrayWithInformation($type, $expectedResult) {
89 $this->assertEquals($this->typeHandlingService->parseType($type), $expectedResult);
90 }
91
92 /**
93 * data provider for normalizeTypesReturnsNormalizedType
94 *
95 * @author Karsten Dambekalns <karsten@typo3.org>
96 * @return array
97 */
98 public function normalizeTypes() {
99 return array(
100 array('int', 'integer'),
101 array('double', 'float'),
102 array('bool', 'boolean'),
103 array('string', 'string')
104 );
105 }
106
107 /**
108 * @test
109 * @dataProvider normalizeTypes
110 * @author Karsten Dambekalns <karsten@typo3.org>
111 * @param mixed $type
112 * @param mixed $normalized
113 */
114 public function normalizeTypesReturnsNormalizedType($type, $normalized) {
115 $this->assertEquals($this->typeHandlingService->normalizeType($type), $normalized);
116 }
117
118 /**
119 * data provider for isLiteralReturnsFalseForNonLiteralTypes
120 *
121 * @author Karsten Dambekalns <karsten@typo3.org>
122 * @return array
123 */
124 public function nonLiteralTypes() {
125 return array(
126 array('DateTime'),
127 array('\\Foo\\Bar'),
128 array('array'),
129 array('ArrayObject'),
130 array('stdClass')
131 );
132 }
133
134 /**
135 * @test
136 * @dataProvider nonliteralTypes
137 * @author Karsten Dambekalns <karsten@typo3.org>
138 * @param mixed $type
139 */
140 public function isLiteralReturnsFalseForNonLiteralTypes($type) {
141 $this->assertFalse($this->typeHandlingService->isLiteral($type));
142 }
143
144 /**
145 * data provider for isLiteralReturnsTrueForLiteralType
146 *
147 * @author Karsten Dambekalns <karsten@typo3.org>
148 * @return array
149 */
150 public function literalTypes() {
151 return array(
152 array('integer'),
153 array('int'),
154 array('float'),
155 array('double'),
156 array('boolean'),
157 array('bool'),
158 array('string')
159 );
160 }
161
162 /**
163 * @test
164 * @dataProvider literalTypes
165 * @author Karsten Dambekalns <karsten@typo3.org>
166 * @param mixed $type
167 */
168 public function isLiteralReturnsTrueForLiteralType($type) {
169 $this->assertTrue($this->typeHandlingService->isLiteral($type));
170 }
171
172 }
173
174
175 ?>