[TASK] Re-work/simplify copyright header in PHP files - Part 8
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Functional / Persistence / InTest.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Tests\Functional\Persistence;
3
4 /**
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Utility\GeneralUtility;
18 use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
19
20 class InTest extends \TYPO3\CMS\Core\Tests\FunctionalTestCase {
21
22 /**
23 * @var \ExtbaseTeam\BlogExample\Domain\Repository\BlogRepository
24 */
25 protected $blogRepository;
26
27 /**
28 * @var \ExtbaseTeam\BlogExample\Domain\Repository\PostRepository
29 */
30 protected $postRepository;
31
32 /**
33 * @var array
34 */
35 protected $testExtensionsToLoad = array('typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example');
36
37 /**
38 * @var array
39 */
40 protected $coreExtensionsToLoad = array('extbase', 'fluid');
41
42 /**
43 * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface The object manager
44 */
45 protected $objectManager;
46
47 /**
48 * Sets up this test suite.
49 */
50 public function setUp() {
51 parent::setUp();
52
53 $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/core/Tests/Functional/Fixtures/pages.xml');
54 $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/blogs.xml');
55 $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/posts.xml');
56 $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/tags.xml');
57 $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/post-tag-mm.xml');
58
59 $this->objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
60 $this->blogRepository = $this->objectManager->get('ExtbaseTeam\\BlogExample\\Domain\\Repository\\BlogRepository');
61 $this->postRepository = $this->objectManager->get('ExtbaseTeam\\BlogExample\\Domain\\Repository\\PostRepository');
62
63 }
64
65 /**
66 * @test
67 */
68 public function inConditionWorksWithArrayOfObjects() {
69 $blog1 = $this->blogRepository->findByUid(1);
70 $blog2 = $this->blogRepository->findByUid(2);
71
72 $inQuery = $this->postRepository->createQuery();
73
74 $inQuery->matching(
75 $inQuery->in('blog', array($blog1, $blog2))
76 );
77
78 $this->assertSame(11, $inQuery->count());
79 }
80
81 /**
82 * @test
83 */
84 public function inConditionWorksWithArrayOfObjectsOnSecondCall() {
85 $blog1 = $this->blogRepository->findByUid(1);
86 $blog2 = $this->blogRepository->findByUid(2);
87
88 $inQuery = $this->postRepository->createQuery();
89
90 $inQuery->matching(
91 $inQuery->in('blog', array($blog1, $blog2))
92 );
93
94 $this->assertSame(11, $inQuery->count());
95
96 $newInQuery = $this->postRepository->createQuery();
97
98 $newInQuery->matching(
99 $newInQuery->in('blog', array($blog1))
100 );
101
102 $this->assertSame(10, $newInQuery->count());
103 }
104
105 /**
106 * @test
107 */
108 public function inConditionWorksWithObjectStorage() {
109 $blog1 = $this->blogRepository->findByUid(1);
110 $blog2 = $this->blogRepository->findByUid(2);
111
112 $objectStorage = $this->objectManager->create('TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage');
113 $objectStorage->attach($blog1);
114 $objectStorage->attach($blog2);
115
116 $inQuery = $this->postRepository->createQuery();
117
118 $inQuery->matching(
119 $inQuery->in('blog', $objectStorage)
120 );
121
122 $this->assertSame(11, $inQuery->count());
123 }
124
125 /**
126 * @test
127 */
128 public function inConditionWorksWithObjectStorageOnSecondCall() {
129 $blog1 = $this->blogRepository->findByUid(1);
130 $blog2 = $this->blogRepository->findByUid(2);
131
132 $objectStorage = $this->objectManager->create('TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage');
133 $objectStorage->attach($blog1);
134 $objectStorage->attach($blog2);
135
136 $inQuery = $this->postRepository->createQuery();
137
138 $inQuery->matching(
139 $inQuery->in('blog', $objectStorage)
140 );
141
142 $this->assertSame(11, $inQuery->count());
143
144 $newObjectStorage = $this->objectManager->create('TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage');
145 $newObjectStorage->attach($blog1);
146
147 $newInQuery = $this->postRepository->createQuery();
148
149 $newInQuery->matching(
150 $newInQuery->in('blog', $newObjectStorage)
151 );
152
153 $this->assertSame(10, $newInQuery->count());
154 }
155
156 /**
157 * @test
158 */
159 public function inConditionWorksWithQueryResult() {
160 $queryResult = $this->blogRepository->findAll();
161
162 $inQuery = $this->postRepository->createQuery();
163
164 $inQuery->matching(
165 $inQuery->in('blog', $queryResult)
166 );
167
168 $this->assertSame(11, $inQuery->count());
169 }
170
171
172 /**
173 * @test
174 */
175 public function inConditionWorksWithQueryResultOnSecondCall() {
176 $queryResult = $this->blogRepository->findAll();
177
178 $inQuery = $this->postRepository->createQuery();
179
180 $inQuery->matching(
181 $inQuery->in('blog', $queryResult)
182 );
183
184 $this->assertSame(11, $inQuery->count());
185
186 $newInQuery = $this->postRepository->createQuery();
187
188 $newInQuery->matching(
189 $newInQuery->in('blog', $queryResult)
190 );
191
192 $this->assertSame(11, $newInQuery->count());
193 }
194
195 /**
196 * @test
197 */
198 public function inConditionWorksWithLazyObjectStorage() {
199 $blog = $this->blogRepository->findByUid(1);
200
201 $this->assertInstanceOf(
202 '\TYPO3\CMS\Extbase\Persistence\Generic\LazyObjectStorage',
203 $blog->getPosts()
204 );
205
206 $inQuery = $this->postRepository->createQuery();
207
208 $inQuery->matching(
209 $inQuery->in('uid', $blog->getPosts())
210 );
211
212 $this->assertSame(10, $inQuery->count());
213 }
214
215 /**
216 * @test
217 */
218 public function inConditionWorksWithLazyObjectStorageOnSecondCall() {
219 $blog = $this->blogRepository->findByUid(1);
220
221 $this->assertInstanceOf(
222 '\TYPO3\CMS\Extbase\Persistence\Generic\LazyObjectStorage',
223 $blog->getPosts()
224 );
225
226 $inQuery = $this->postRepository->createQuery();
227
228 $inQuery->matching(
229 $inQuery->in('uid', $blog->getPosts())
230 );
231
232 $this->assertSame(10, $inQuery->count());
233
234
235 $newInQuery = $this->postRepository->createQuery();
236
237 $newInQuery->matching(
238 $newInQuery->in('uid', $blog->getPosts())
239 );
240
241 $this->assertSame(10, $newInQuery->count());
242 }
243 }