TYPO3 CMS  TYPO3_7-6
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 
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(ORIGINAL_ROOT . 'typo3/sysext/core/Tests/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 
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  $this->assertSame(10, $query->count());
201  }
202 
206  public function queryWithAndConditionsToTheSameTableReturnExpectedCount()
207  {
209  $personRepository = $this->objectManager->get(\ExtbaseTeam\BlogExample\Domain\Repository\PersonRepository::class);
210  $query = $personRepository->createQuery();
211  $query->matching(
212  $query->logicalAnd(
213  $query->equals('tags.name', 'TagForAuthor1'),
214  $query->equals('tagsSpecial.name', 'SpecialTagForAuthor1')
215  )
216  );
217  $this->assertSame(1, $query->count());
218  }
219 
223  public function queryWithOrConditionsToTheSameTableReturnExpectedCount()
224  {
226  $personRepository = $this->objectManager->get(\ExtbaseTeam\BlogExample\Domain\Repository\PersonRepository::class);
227  $query = $personRepository->createQuery();
228  $query->matching(
229  $query->logicalOr(
230  $query->equals('tags.name', 'TagForAuthor1'),
231  $query->equals('tagsSpecial.name', 'SpecialTagForAuthor1')
232  )
233  );
234  $this->assertSame(3, $query->count());
235  }
236 }