‪TYPO3CMS  9.5
InTest.php
Go to the documentation of this file.
1 <?php
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 
18 
19 class ‪InTest extends \TYPO3\TestingFramework\Core\Functional\FunctionalTestCase
20 {
24  protected ‪$blogRepository;
25 
29  protected ‪$postRepository;
30 
34  protected ‪$testExtensionsToLoad = ['typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example'];
35 
39  protected ‪$coreExtensionsToLoad = ['extbase', 'fluid'];
40 
44  protected ‪$objectManager;
45 
49  protected function ‪setUp()
50  {
51  parent::setUp();
52 
53  $this->importDataSet('PACKAGE:typo3/testing-framework/Resources/Core/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::class);
60  $this->blogRepository = $this->objectManager->get(\‪ExtbaseTeam\BlogExample\Domain\Repository\BlogRepository::class);
61  $this->postRepository = $this->objectManager->get(\‪ExtbaseTeam\BlogExample\Domain\Repository\PostRepository::class);
62  }
63 
68  {
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', [$blog1, $blog2])
76  );
77 
78  $this->assertSame(11, $inQuery->count());
79  }
80 
85  {
86  $blog1 = $this->blogRepository->findByUid(1);
87  $blog2 = $this->blogRepository->findByUid(2);
88 
89  $inQuery = $this->postRepository->createQuery();
90 
91  $inQuery->matching(
92  $inQuery->in('blog', [$blog1, $blog2])
93  );
94 
95  $this->assertSame(11, $inQuery->count());
96 
97  $newInQuery = $this->postRepository->createQuery();
98 
99  $newInQuery->matching(
100  $newInQuery->in('blog', [$blog1])
101  );
102 
103  $this->assertSame(10, $newInQuery->count());
104  }
105 
109  public function ‪inConditionWorksWithObjectStorage()
110  {
111  $blog1 = $this->blogRepository->findByUid(1);
112  $blog2 = $this->blogRepository->findByUid(2);
113 
114  $objectStorage = $this->objectManager->get(\‪TYPO3\CMS\‪Extbase\Persistence\ObjectStorage::class);
115  $objectStorage->attach($blog1);
116  $objectStorage->attach($blog2);
117 
118  $inQuery = $this->postRepository->createQuery();
119 
120  $inQuery->matching(
121  $inQuery->in('blog', $objectStorage)
122  );
123 
124  $this->assertSame(11, $inQuery->count());
125  }
126 
131  {
132  $blog1 = $this->blogRepository->findByUid(1);
133  $blog2 = $this->blogRepository->findByUid(2);
134 
135  $objectStorage = $this->objectManager->get(\‪TYPO3\CMS\‪Extbase\Persistence\ObjectStorage::class);
136  $objectStorage->attach($blog1);
137  $objectStorage->attach($blog2);
138 
139  $inQuery = $this->postRepository->createQuery();
140 
141  $inQuery->matching(
142  $inQuery->in('blog', $objectStorage)
143  );
144 
145  $this->assertSame(11, $inQuery->count());
146 
147  $newObjectStorage = $this->objectManager->get(\‪TYPO3\CMS\‪Extbase\Persistence\ObjectStorage::class);
148  $newObjectStorage->attach($blog1);
149 
150  $newInQuery = $this->postRepository->createQuery();
151 
152  $newInQuery->matching(
153  $newInQuery->in('blog', $newObjectStorage)
154  );
155 
156  $this->assertSame(10, $newInQuery->count());
157  }
158 
162  public function ‪inConditionWorksWithQueryResult()
163  {
164  $query = $this->blogRepository->createQuery();
165  $query->matching($query->in('uid', [1, 2]));
166  $queryResult = $query->execute();
167 
168  $inQuery = $this->postRepository->createQuery();
169 
170  $inQuery->matching(
171  $inQuery->in('blog', $queryResult)
172  );
173 
174  $this->assertSame(11, $inQuery->count());
175  }
176 
181  {
182  $query = $this->blogRepository->createQuery();
183  $query->matching($query->in('uid', [1, 2]));
184  $queryResult = $query->execute();
185 
186  $inQuery = $this->postRepository->createQuery();
187 
188  $inQuery->matching(
189  $inQuery->in('blog', $queryResult)
190  );
191 
192  $this->assertSame(11, $inQuery->count());
193 
194  $newInQuery = $this->postRepository->createQuery();
195 
196  $newInQuery->matching(
197  $newInQuery->in('blog', $queryResult)
198  );
199 
200  $this->assertSame(11, $newInQuery->count());
201  }
202 
207  {
208  $blog = $this->blogRepository->findByUid(1);
209 
210  $this->assertInstanceOf(
211  \‪TYPO3\CMS\‪Extbase\Persistence\Generic\LazyObjectStorage::class,
212  $blog->getPosts()
213  );
214 
215  $inQuery = $this->postRepository->createQuery();
216 
217  $inQuery->matching(
218  $inQuery->in('uid', $blog->getPosts())
219  );
220 
221  $this->assertSame(10, $inQuery->count());
222  }
223 
228  {
229  $blog = $this->blogRepository->findByUid(1);
230 
231  $this->assertInstanceOf(
232  \‪TYPO3\CMS\‪Extbase\Persistence\Generic\LazyObjectStorage::class,
233  $blog->getPosts()
234  );
235 
236  $inQuery = $this->postRepository->createQuery();
237 
238  $inQuery->matching(
239  $inQuery->in('uid', $blog->getPosts())
240  );
241 
242  $this->assertSame(10, $inQuery->count());
243 
244  $newInQuery = $this->postRepository->createQuery();
245 
246  $newInQuery->matching(
247  $newInQuery->in('uid', $blog->getPosts())
248  );
249 
250  $this->assertSame(10, $newInQuery->count());
251  }
252 }
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\InTest\inConditionWorksWithQueryResult
‪inConditionWorksWithQueryResult()
Definition: InTest.php:157
‪TYPO3\CMS\Extbase\Annotation
Definition: IgnoreValidation.php:4
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\InTest\inConditionWorksWithObjectStorage
‪inConditionWorksWithObjectStorage()
Definition: InTest.php:104
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\InTest\$coreExtensionsToLoad
‪array $coreExtensionsToLoad
Definition: InTest.php:35
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\InTest\inConditionWorksWithArrayOfObjects
‪inConditionWorksWithArrayOfObjects()
Definition: InTest.php:62
‪TYPO3
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\InTest\$testExtensionsToLoad
‪array $testExtensionsToLoad
Definition: InTest.php:31
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\InTest\setUp
‪setUp()
Definition: InTest.php:44
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\InTest\$blogRepository
‪ExtbaseTeam BlogExample Domain Repository BlogRepository $blogRepository
Definition: InTest.php:23
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\InTest\inConditionWorksWithLazyObjectStorage
‪inConditionWorksWithLazyObjectStorage()
Definition: InTest.php:201
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\InTest
Definition: InTest.php:20
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\InTest\inConditionWorksWithArrayOfObjectsOnSecondCall
‪inConditionWorksWithArrayOfObjectsOnSecondCall()
Definition: InTest.php:79
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\InTest\$postRepository
‪ExtbaseTeam BlogExample Domain Repository PostRepository $postRepository
Definition: InTest.php:27
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence
Definition: AddTest.php:2
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\InTest\inConditionWorksWithLazyObjectStorageOnSecondCall
‪inConditionWorksWithLazyObjectStorageOnSecondCall()
Definition: InTest.php:222
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\InTest\inConditionWorksWithQueryResultOnSecondCall
‪inConditionWorksWithQueryResultOnSecondCall()
Definition: InTest.php:175
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\InTest\$objectManager
‪TYPO3 CMS Extbase Object ObjectManagerInterface $objectManager
Definition: InTest.php:39
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\InTest\inConditionWorksWithObjectStorageOnSecondCall
‪inConditionWorksWithObjectStorageOnSecondCall()
Definition: InTest.php:125
‪ExtbaseTeam
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45