‪TYPO3CMS  9.5
CountTest.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 ‪CountTest extends \TYPO3\TestingFramework\Core\Functional\FunctionalTestCase
20 {
24  protected ‪$numberOfRecordsInFixture = 14;
25 
29  protected ‪$persistentManager;
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 ‪$blogRepository;
50 
54  protected ‪$postRepository;
55 
59  protected function ‪setUp()
60  {
61  parent::setUp();
62 
63  $this->importDataSet('PACKAGE:typo3/testing-framework/Resources/Core/Functional/Fixtures/pages.xml');
64  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/blogs.xml');
65  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/posts.xml');
66  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/post-post-mm.xml');
67  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/tags.xml');
68  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/tags-mm.xml');
69  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/post-tag-mm.xml');
70  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/persons.xml');
71 
72  $this->objectManager = GeneralUtility::makeInstance(\‪TYPO3\CMS\‪Extbase\Object\ObjectManager::class);
73  $this->persistentManager = $this->objectManager->get(\‪TYPO3\CMS\‪Extbase\Persistence\Generic\PersistenceManager::class);
74  $this->postRepository = $this->objectManager->get(\‪ExtbaseTeam\BlogExample\Domain\Repository\PostRepository::class);
75  }
76 
80  public function ‪simpleCountTest()
81  {
82  $query = $this->postRepository->createQuery();
83  $this->assertSame($this->numberOfRecordsInFixture, $query->count());
84  }
85 
89  public function ‪offsetCountTest()
90  {
91  $query = $this->postRepository->createQuery();
92 
93  $query->setLimit($this->numberOfRecordsInFixture+1);
94  $query->setOffset(6);
95 
96  $this->assertSame($this->numberOfRecordsInFixture - 6, $query->count());
97  }
98 
102  public function ‪exceedingOffsetCountTest()
103  {
104  $query = $this->postRepository->createQuery();
105 
106  $query->setLimit($this->numberOfRecordsInFixture+1);
107  $query->setOffset($this->numberOfRecordsInFixture + 5);
108 
109  $this->assertSame(0, $query->count());
110  }
111 
115  public function ‪limitCountTest()
116  {
117  $query = $this->postRepository->createQuery();
118 
119  $query->setLimit(4);
120 
121  $this->assertSame(4, $query->count());
122  }
123 
127  public function ‪limitAndOffsetCountTest()
128  {
129  $query = $this->postRepository->createQuery();
130 
131  $query
132  ->setOffset($this->numberOfRecordsInFixture - 3)
133  ->setLimit(4);
134 
135  $this->assertSame(3, $query->count());
136  }
137 
141  public function ‪inConstraintCountTest()
142  {
143  $query = $this->postRepository->createQuery();
144 
145  $query->matching(
146  $query->in('uid', [1, 2, 3])
147  );
148 
149  $this->assertSame(3, $query->count());
150  }
151 
157  public function ‪subpropertyJoinCountTest()
158  {
159  $query = $this->postRepository->createQuery();
160 
161  $query->matching(
162  $query->equals('blog.title', 'Blog1')
163  );
164 
165  $this->assertSame(10, $query->count());
166  }
167 
173  public function ‪subpropertyJoinSameTableCountTest()
174  {
175  $query = $this->postRepository->createQuery();
176 
177  $query->matching(
178  $query->equals('relatedPosts.title', 'Post2')
179  );
180 
181  $this->assertSame(1, $query->count());
182  }
183 
190  {
191  $query = $this->postRepository->createQuery();
192 
193  $query->matching(
194  $query->logicalOr(
195  $query->equals('tags.uid', 1),
196  $query->equals('tags.uid', 2)
197  )
198  );
199 
200  // QueryResult is lazy, so we have to run valid method to initialize
201  $result = $query->execute();
202  $result->valid();
203 
204  $this->assertSame(10, $result->count());
205  }
206 
211  {
213  $personRepository = $this->objectManager->get(\‪ExtbaseTeam\BlogExample\Domain\Repository\PersonRepository::class);
214  $query = $personRepository->createQuery();
215  $query->matching(
216  $query->logicalAnd(
217  $query->equals('tags.name', 'TagForAuthor1'),
218  $query->equals('tagsSpecial.name', 'SpecialTagForAuthor1')
219  )
220  );
221  $this->assertSame(1, $query->count());
222  }
223 
228  {
230  $personRepository = $this->objectManager->get(\‪ExtbaseTeam\BlogExample\Domain\Repository\PersonRepository::class);
231  $query = $personRepository->createQuery();
232  $query->matching(
233  $query->logicalOr(
234  $query->equals('tags.name', 'TagForAuthor1'),
235  $query->equals('tagsSpecial.name', 'SpecialTagForAuthor1')
236  )
237  );
238  $this->assertSame(4, $query->count());
239  }
240 }
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\CountTest\subpropertyJoinCountTest
‪subpropertyJoinCountTest()
Definition: CountTest.php:150
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\CountTest\offsetCountTest
‪offsetCountTest()
Definition: CountTest.php:82
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\CountTest\limitCountTest
‪limitCountTest()
Definition: CountTest.php:108
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\CountTest\$blogRepository
‪TYPO3 CMS Extbase Persistence Repository $blogRepository
Definition: CountTest.php:43
‪TYPO3\CMS\Extbase\Annotation
Definition: IgnoreValidation.php:4
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\CountTest\simpleCountTest
‪simpleCountTest()
Definition: CountTest.php:73
‪TYPO3
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\CountTest\limitAndOffsetCountTest
‪limitAndOffsetCountTest()
Definition: CountTest.php:120
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\CountTest\exceedingOffsetCountTest
‪exceedingOffsetCountTest()
Definition: CountTest.php:95
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\CountTest\$testExtensionsToLoad
‪array $testExtensionsToLoad
Definition: CountTest.php:31
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\CountTest\queryWithAndConditionsToTheSameTableReturnExpectedCount
‪queryWithAndConditionsToTheSameTableReturnExpectedCount()
Definition: CountTest.php:203
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence
Definition: AddTest.php:2
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\CountTest\$postRepository
‪ExtbaseTeam BlogExample Domain Repository PostRepository $postRepository
Definition: CountTest.php:47
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\CountTest\$numberOfRecordsInFixture
‪int $numberOfRecordsInFixture
Definition: CountTest.php:23
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\CountTest\$objectManager
‪TYPO3 CMS Extbase Object ObjectManagerInterface $objectManager
Definition: CountTest.php:39
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\CountTest\subpropertyJoinSameTableCountTest
‪subpropertyJoinSameTableCountTest()
Definition: CountTest.php:166
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\CountTest\$coreExtensionsToLoad
‪array $coreExtensionsToLoad
Definition: CountTest.php:35
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\CountTest\setUp
‪setUp()
Definition: CountTest.php:52
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\CountTest\inConstraintCountTest
‪inConstraintCountTest()
Definition: CountTest.php:134
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\CountTest\$persistentManager
‪TYPO3 CMS Extbase Persistence Generic PersistenceManager $persistentManager
Definition: CountTest.php:27
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\CountTest\subpropertyInMultipleLeftJoinCountTest
‪subpropertyInMultipleLeftJoinCountTest()
Definition: CountTest.php:182
‪ExtbaseTeam
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\CountTest\queryWithOrConditionsToTheSameTableReturnExpectedCount
‪queryWithOrConditionsToTheSameTableReturnExpectedCount()
Definition: CountTest.php:220
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\CountTest
Definition: CountTest.php:20