Extbase:
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Persistence / Tests / Repository_testcase.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 Christopher Hlubek <hlubek@networkteam.com>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 require_once('Base_testcase.php');
26
27 class Tx_Extbase_Persistence_Repository_testcase extends Tx_Extbase_Base_testcase {
28
29 public function __construct() {
30 require_once(t3lib_extMgm::extPath('blog_example') . 'Classes/Domain/BlogRepository.php');
31 }
32
33 public function setUp() {
34 $GLOBALS['TSFE'] = $this->getMock('tslib_fe', array('includeTCA'));
35 $GLOBALS['TSFE']->expects($this->any())
36 ->method('includeTCA')
37 ->will($this->returnValue(NULL));
38
39 $GLOBALS['TYPO3_DB'] = $this->getMock('tslib_DB', array('fullQuoteStr'));
40 }
41
42 public function test_FindByConditionWithPlaceholders() {
43 $repository = new Tx_BlogExample_Domain_Model_BlogRepository();
44 $repository->dataMapper = $this->getMock('Tx_Extbase_Persistence_Mapper_ObjectRelationalMapper', array('fetch'));
45 $repository->dataMapper->expects($this->once())
46 ->method('fetch')
47 ->with($this->equalTo('Tx_BlogExample_Domain_Model_Blog'), $this->equalTo('(name LIKE "foo" OR name LIKE "bar") AND (hidden = 0)'));
48
49 $GLOBALS['TYPO3_DB']->expects($this->at(0))
50 ->method('fullQuoteStr')
51 ->with($this->equalTo('foo'))
52 ->will($this->returnValue('"foo"'));
53
54 $GLOBALS['TYPO3_DB']->expects($this->at(1))
55 ->method('fullQuoteStr')
56 ->with($this->equalTo('bar'))
57 ->will($this->returnValue('"bar"'));
58
59 $GLOBALS['TYPO3_DB']->expects($this->at(2))
60 ->method('fullQuoteStr')
61 ->with($this->equalTo('0'))
62 ->will($this->returnValue('0'));
63
64 $repository->find(array(
65 array('name LIKE ? OR name LIKE ?', 'foo', 'bar'),
66 array('hidden = ?', FALSE)
67 ));
68 }
69
70 public function test_FindByConditionWithExample() {
71 $repository = new Tx_BlogExample_Domain_Model_BlogRepository();
72 $repository->dataMapper = $this->getMock('Tx_Extbase_Persistence_Mapper_ObjectRelationalMapper', array('fetch'));
73 $repository->dataMapper->expects($this->once())
74 ->method('fetch')
75 ->with($this->equalTo('Tx_BlogExample_Domain_Model_Blog'), $this->equalTo('(blog_name = "foo") AND (hidden = 0)'));
76
77 $GLOBALS['TYPO3_DB']->expects($this->at(0))
78 ->method('fullQuoteStr')
79 ->with($this->equalTo('foo'))
80 ->will($this->returnValue('"foo"'));
81
82 $GLOBALS['TYPO3_DB']->expects($this->at(1))
83 ->method('fullQuoteStr')
84 ->with($this->equalTo('0'))
85 ->will($this->returnValue('0'));
86
87 $repository->find(array(
88 'blogName' => 'foo',
89 'hidden' => FALSE
90 ));
91 }
92
93 public function test_MagicFindByPropertyUsesGenericFind() {
94 $repository = $this->getMock('Tx_BlogExample_Domain_Model_BlogRepository', array('find'), array('Tx_BlogExample_Domain_Model_Blog'));
95 $repository->expects($this->once())
96 ->method('find')
97 ->with($this->equalTo(array('name' => 'foo')))
98 ->will($this->returnValue(array()));
99
100 $repository->findByName('foo');
101 }
102 }
103 ?>
104 <?php
105 /***************************************************************
106 * Copyright notice
107 *
108 * (c) 2009 Christopher Hlubek <hlubek@networkteam.com>
109 * All rights reserved
110 *
111 * This script is part of the TYPO3 project. The TYPO3 project is
112 * free software; you can redistribute it and/or modify
113 * it under the terms of the GNU General Public License as published by
114 * the Free Software Foundation; either version 2 of the License, or
115 * (at your option) any later version.
116 *
117 * The GNU General Public License can be found at
118 * http://www.gnu.org/copyleft/gpl.html.
119 *
120 * This script is distributed in the hope that it will be useful,
121 * but WITHOUT ANY WARRANTY; without even the implied warranty of
122 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
123 * GNU General Public License for more details.
124 *
125 * This copyright notice MUST APPEAR in all copies of the script!
126 ***************************************************************/
127
128 require_once('Base_testcase.php');
129
130 class Tx_Extbase_Persistence_Repository_testcase extends Tx_Extbase_Base_testcase {
131
132 public function __construct() {
133 require_once(t3lib_extMgm::extPath('blog_example') . 'Classes/Domain/BlogRepository.php');
134 }
135
136 public function setUp() {
137 $GLOBALS['TSFE'] = $this->getMock('tslib_fe', array('includeTCA'));
138 $GLOBALS['TSFE']->expects($this->any())
139 ->method('includeTCA')
140 ->will($this->returnValue(NULL));
141
142 $GLOBALS['TYPO3_DB'] = $this->getMock('tslib_DB', array('fullQuoteStr'));
143 }
144
145 public function test_FindByConditionWithPlaceholders() {
146 $repository = new Tx_BlogExample_Domain_Model_BlogRepository();
147 $repository->dataMapper = $this->getMock('Tx_Extbase_Persistence_Mapper_ObjectRelationalMapper', array('fetch'));
148 $repository->dataMapper->expects($this->once())
149 ->method('fetch')
150 ->with($this->equalTo('Tx_BlogExample_Domain_Model_Blog'), $this->equalTo('(name LIKE "foo" OR name LIKE "bar") AND (hidden = 0)'));
151
152 $GLOBALS['TYPO3_DB']->expects($this->at(0))
153 ->method('fullQuoteStr')
154 ->with($this->equalTo('foo'))
155 ->will($this->returnValue('"foo"'));
156
157 $GLOBALS['TYPO3_DB']->expects($this->at(1))
158 ->method('fullQuoteStr')
159 ->with($this->equalTo('bar'))
160 ->will($this->returnValue('"bar"'));
161
162 $GLOBALS['TYPO3_DB']->expects($this->at(2))
163 ->method('fullQuoteStr')
164 ->with($this->equalTo('0'))
165 ->will($this->returnValue('0'));
166
167 $repository->find(array(
168 array('name LIKE ? OR name LIKE ?', 'foo', 'bar'),
169 array('hidden = ?', FALSE)
170 ));
171 }
172
173 public function test_FindByConditionWithExample() {
174 $repository = new Tx_BlogExample_Domain_Model_BlogRepository();
175 $repository->dataMapper = $this->getMock('Tx_Extbase_Persistence_Mapper_ObjectRelationalMapper', array('fetch'));
176 $repository->dataMapper->expects($this->once())
177 ->method('fetch')
178 ->with($this->equalTo('Tx_BlogExample_Domain_Model_Blog'), $this->equalTo('(blog_name = "foo") AND (hidden = 0)'));
179
180 $GLOBALS['TYPO3_DB']->expects($this->at(0))
181 ->method('fullQuoteStr')
182 ->with($this->equalTo('foo'))
183 ->will($this->returnValue('"foo"'));
184
185 $GLOBALS['TYPO3_DB']->expects($this->at(1))
186 ->method('fullQuoteStr')
187 ->with($this->equalTo('0'))
188 ->will($this->returnValue('0'));
189
190 $repository->find(array(
191 'blogName' => 'foo',
192 'hidden' => FALSE
193 ));
194 }
195
196 public function test_MagicFindByPropertyUsesGenericFind() {
197 $repository = $this->getMock('Tx_BlogExample_Domain_Model_BlogRepository', array('find'), array('Tx_BlogExample_Domain_Model_Blog'));
198 $repository->expects($this->once())
199 ->method('find')
200 ->with($this->equalTo(array('name' => 'foo')))
201 ->will($this->returnValue(array()));
202
203 $repository->findByName('foo');
204 }
205 }
206 ?>
207 <?php
208 /***************************************************************
209 * Copyright notice
210 *
211 * (c) 2009 Christopher Hlubek <hlubek@networkteam.com>
212 * All rights reserved
213 *
214 * This script is part of the TYPO3 project. The TYPO3 project is
215 * free software; you can redistribute it and/or modify
216 * it under the terms of the GNU General Public License as published by
217 * the Free Software Foundation; either version 2 of the License, or
218 * (at your option) any later version.
219 *
220 * The GNU General Public License can be found at
221 * http://www.gnu.org/copyleft/gpl.html.
222 *
223 * This script is distributed in the hope that it will be useful,
224 * but WITHOUT ANY WARRANTY; without even the implied warranty of
225 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
226 * GNU General Public License for more details.
227 *
228 * This copyright notice MUST APPEAR in all copies of the script!
229 ***************************************************************/
230
231 require_once('Base_testcase.php');
232
233 class Tx_Extbase_Persistence_Repository_testcase extends Tx_Extbase_Base_testcase {
234
235 public function __construct() {
236 require_once(t3lib_extMgm::extPath('blog_example') . 'Classes/Domain/BlogRepository.php');
237 }
238
239 public function setUp() {
240 $GLOBALS['TSFE'] = $this->getMock('tslib_fe', array('includeTCA'));
241 $GLOBALS['TSFE']->expects($this->any())
242 ->method('includeTCA')
243 ->will($this->returnValue(NULL));
244
245 $GLOBALS['TYPO3_DB'] = $this->getMock('tslib_DB', array('fullQuoteStr'));
246 }
247
248 public function test_FindByConditionWithPlaceholders() {
249 $repository = new Tx_BlogExample_Domain_Model_BlogRepository();
250 $repository->dataMapper = $this->getMock('Tx_Extbase_Persistence_Mapper_ObjectRelationalMapper', array('fetch'));
251 $repository->dataMapper->expects($this->once())
252 ->method('fetch')
253 ->with($this->equalTo('Tx_BlogExample_Domain_Model_Blog'), $this->equalTo('(name LIKE "foo" OR name LIKE "bar") AND (hidden = 0)'));
254
255 $GLOBALS['TYPO3_DB']->expects($this->at(0))
256 ->method('fullQuoteStr')
257 ->with($this->equalTo('foo'))
258 ->will($this->returnValue('"foo"'));
259
260 $GLOBALS['TYPO3_DB']->expects($this->at(1))
261 ->method('fullQuoteStr')
262 ->with($this->equalTo('bar'))
263 ->will($this->returnValue('"bar"'));
264
265 $GLOBALS['TYPO3_DB']->expects($this->at(2))
266 ->method('fullQuoteStr')
267 ->with($this->equalTo('0'))
268 ->will($this->returnValue('0'));
269
270 $repository->find(array(
271 array('name LIKE ? OR name LIKE ?', 'foo', 'bar'),
272 array('hidden = ?', FALSE)
273 ));
274 }
275
276 public function test_FindByConditionWithExample() {
277 $repository = new Tx_BlogExample_Domain_Model_BlogRepository();
278 $repository->dataMapper = $this->getMock('Tx_Extbase_Persistence_Mapper_ObjectRelationalMapper', array('fetch'));
279 $repository->dataMapper->expects($this->once())
280 ->method('fetch')
281 ->with($this->equalTo('Tx_BlogExample_Domain_Model_Blog'), $this->equalTo('(blog_name = "foo") AND (hidden = 0)'));
282
283 $GLOBALS['TYPO3_DB']->expects($this->at(0))
284 ->method('fullQuoteStr')
285 ->with($this->equalTo('foo'))
286 ->will($this->returnValue('"foo"'));
287
288 $GLOBALS['TYPO3_DB']->expects($this->at(1))
289 ->method('fullQuoteStr')
290 ->with($this->equalTo('0'))
291 ->will($this->returnValue('0'));
292
293 $repository->find(array(
294 'blogName' => 'foo',
295 'hidden' => FALSE
296 ));
297 }
298
299 public function test_MagicFindByPropertyUsesGenericFind() {
300 $repository = $this->getMock('Tx_BlogExample_Domain_Model_BlogRepository', array('find'), array('Tx_BlogExample_Domain_Model_Blog'));
301 $repository->expects($this->once())
302 ->method('find')
303 ->with($this->equalTo(array('name' => 'foo')))
304 ->will($this->returnValue(array()));
305
306 $repository->findByName('foo');
307 }
308 }
309 ?>