‪TYPO3CMS  10.4
InTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
24 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
25 
26 class ‪InTest extends FunctionalTestCase
27 {
31  protected ‪$blogRepository;
32 
36  protected ‪$postRepository;
37 
41  protected ‪$testExtensionsToLoad = ['typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example'];
42 
46  protected ‪$coreExtensionsToLoad = ['extbase', 'fluid'];
47 
51  protected ‪$objectManager;
52 
56  protected function ‪setUp(): void
57  {
58  parent::setUp();
59 
60  $this->importDataSet('PACKAGE:typo3/testing-framework/Resources/Core/Functional/Fixtures/pages.xml');
61  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/blogs.xml');
62  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/posts.xml');
63  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/tags.xml');
64  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/post-tag-mm.xml');
65 
66  $this->objectManager = GeneralUtility::makeInstance(ObjectManager::class);
67  $this->blogRepository = $this->objectManager->get(BlogRepository::class);
68  $this->postRepository = $this->objectManager->get(PostRepository::class);
69  }
70 
75  {
76  $blog1 = $this->blogRepository->findByUid(1);
77  $blog2 = $this->blogRepository->findByUid(2);
78 
79  $inQuery = $this->postRepository->createQuery();
80 
81  $inQuery->matching(
82  $inQuery->in('blog', [$blog1, $blog2])
83  );
84 
85  self::assertSame(11, $inQuery->count());
86  }
87 
92  {
93  $blog1 = $this->blogRepository->findByUid(1);
94  $blog2 = $this->blogRepository->findByUid(2);
95 
96  $inQuery = $this->postRepository->createQuery();
97 
98  $inQuery->matching(
99  $inQuery->in('blog', [$blog1, $blog2])
100  );
101 
102  self::assertSame(11, $inQuery->count());
103 
104  $newInQuery = $this->postRepository->createQuery();
105 
106  $newInQuery->matching(
107  $newInQuery->in('blog', [$blog1])
108  );
109 
110  self::assertSame(10, $newInQuery->count());
111  }
112 
116  public function ‪inConditionWorksWithObjectStorage()
117  {
118  $blog1 = $this->blogRepository->findByUid(1);
119  $blog2 = $this->blogRepository->findByUid(2);
120 
121  $objectStorage = $this->objectManager->get(ObjectStorage::class);
122  $objectStorage->attach($blog1);
123  $objectStorage->attach($blog2);
124 
125  $inQuery = $this->postRepository->createQuery();
126 
127  $inQuery->matching(
128  $inQuery->in('blog', $objectStorage)
129  );
130 
131  self::assertSame(11, $inQuery->count());
132  }
133 
138  {
139  $blog1 = $this->blogRepository->findByUid(1);
140  $blog2 = $this->blogRepository->findByUid(2);
141 
142  $objectStorage = $this->objectManager->get(ObjectStorage::class);
143  $objectStorage->attach($blog1);
144  $objectStorage->attach($blog2);
145 
146  $inQuery = $this->postRepository->createQuery();
147 
148  $inQuery->matching(
149  $inQuery->in('blog', $objectStorage)
150  );
151 
152  self::assertSame(11, $inQuery->count());
153 
154  $newObjectStorage = $this->objectManager->get(ObjectStorage::class);
155  $newObjectStorage->attach($blog1);
156 
157  $newInQuery = $this->postRepository->createQuery();
158 
159  $newInQuery->matching(
160  $newInQuery->in('blog', $newObjectStorage)
161  );
162 
163  self::assertSame(10, $newInQuery->count());
164  }
165 
169  public function ‪inConditionWorksWithQueryResult()
170  {
171  $query = $this->blogRepository->createQuery();
172  $query->matching($query->in('uid', [1, 2]));
173  $queryResult = $query->execute();
174 
175  $inQuery = $this->postRepository->createQuery();
176 
177  $inQuery->matching(
178  $inQuery->in('blog', $queryResult)
179  );
180 
181  self::assertSame(11, $inQuery->count());
182  }
183 
188  {
189  $query = $this->blogRepository->createQuery();
190  $query->matching($query->in('uid', [1, 2]));
191  $queryResult = $query->execute();
192 
193  $inQuery = $this->postRepository->createQuery();
194 
195  $inQuery->matching(
196  $inQuery->in('blog', $queryResult)
197  );
198 
199  self::assertSame(11, $inQuery->count());
200 
201  $newInQuery = $this->postRepository->createQuery();
202 
203  $newInQuery->matching(
204  $newInQuery->in('blog', $queryResult)
205  );
206 
207  self::assertSame(11, $newInQuery->count());
208  }
209 
214  {
215  $blog = $this->blogRepository->findByUid(1);
216 
217  self::assertInstanceOf(
218  LazyObjectStorage::class,
219  $blog->getPosts()
220  );
221 
222  $inQuery = $this->postRepository->createQuery();
223 
224  $inQuery->matching(
225  $inQuery->in('uid', $blog->getPosts())
226  );
227 
228  self::assertSame(10, $inQuery->count());
229  }
230 
235  {
236  $blog = $this->blogRepository->findByUid(1);
237 
238  self::assertInstanceOf(
239  LazyObjectStorage::class,
240  $blog->getPosts()
241  );
242 
243  $inQuery = $this->postRepository->createQuery();
244 
245  $inQuery->matching(
246  $inQuery->in('uid', $blog->getPosts())
247  );
248 
249  self::assertSame(10, $inQuery->count());
250 
251  $newInQuery = $this->postRepository->createQuery();
252 
253  $newInQuery->matching(
254  $newInQuery->in('uid', $blog->getPosts())
255  );
256 
257  self::assertSame(10, $newInQuery->count());
258  }
259 }
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\InTest\inConditionWorksWithQueryResult
‪inConditionWorksWithQueryResult()
Definition: InTest.php:164
‪ExtbaseTeam\BlogExample\Domain\Repository\BlogRepository
Definition: BlogRepository.php:25
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\InTest\inConditionWorksWithObjectStorage
‪inConditionWorksWithObjectStorage()
Definition: InTest.php:111
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\InTest\$coreExtensionsToLoad
‪array $coreExtensionsToLoad
Definition: InTest.php:42
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\InTest\inConditionWorksWithArrayOfObjects
‪inConditionWorksWithArrayOfObjects()
Definition: InTest.php:69
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\InTest\$testExtensionsToLoad
‪array $testExtensionsToLoad
Definition: InTest.php:38
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\InTest\setUp
‪setUp()
Definition: InTest.php:51
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\InTest\$blogRepository
‪ExtbaseTeam BlogExample Domain Repository BlogRepository $blogRepository
Definition: InTest.php:30
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\InTest\inConditionWorksWithLazyObjectStorage
‪inConditionWorksWithLazyObjectStorage()
Definition: InTest.php:208
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\InTest
Definition: InTest.php:27
‪TYPO3\CMS\Extbase\Persistence\ObjectStorage
Definition: ObjectStorage.php:28
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\InTest\inConditionWorksWithArrayOfObjectsOnSecondCall
‪inConditionWorksWithArrayOfObjectsOnSecondCall()
Definition: InTest.php:86
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\InTest\$postRepository
‪ExtbaseTeam BlogExample Domain Repository PostRepository $postRepository
Definition: InTest.php:34
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence
Definition: AddTest.php:16
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\InTest\inConditionWorksWithLazyObjectStorageOnSecondCall
‪inConditionWorksWithLazyObjectStorageOnSecondCall()
Definition: InTest.php:229
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\InTest\inConditionWorksWithQueryResultOnSecondCall
‪inConditionWorksWithQueryResultOnSecondCall()
Definition: InTest.php:182
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\InTest\$objectManager
‪TYPO3 CMS Extbase Object ObjectManagerInterface $objectManager
Definition: InTest.php:46
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\InTest\inConditionWorksWithObjectStorageOnSecondCall
‪inConditionWorksWithObjectStorageOnSecondCall()
Definition: InTest.php:132
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪ExtbaseTeam\BlogExample\Domain\Repository\PostRepository
Definition: PostRepository.php:30
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyObjectStorage
Definition: LazyObjectStorage.php:30
‪TYPO3\CMS\Extbase\Object\ObjectManager
Definition: ObjectManager.php:28