[TASK] Use fully qualified name resolution in PHP 5.5
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Functional / Persistence / CountTest.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
19 class CountTest extends \TYPO3\CMS\Core\Tests\FunctionalTestCase {
20
21 /**
22 * @var int number of all records
23 */
24 protected $numberOfRecordsInFixture = 11;
25
26 /**
27 * @var \TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager
28 */
29 protected $persistentManager;
30
31 /**
32 * @var array
33 */
34 protected $testExtensionsToLoad = array('typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example');
35
36 /**
37 * @var array
38 */
39 protected $coreExtensionsToLoad = array('extbase', 'fluid');
40
41 /**
42 * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface The object manager
43 */
44 protected $objectManager;
45
46 /**
47 * @var \TYPO3\CMS\Extbase\Persistence\Repository
48 */
49 protected $blogRepository;
50
51 /**
52 * Sets up this test suite.
53 */
54 public function setUp() {
55 parent::setUp();
56
57 $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/core/Tests/Functional/Fixtures/pages.xml');
58 $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/blogs.xml');
59 $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/posts.xml');
60 $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/tags.xml');
61 $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/post-tag-mm.xml');
62
63 $this->objectManager = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
64 $this->persistentManager = $this->objectManager->get(\TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager::class);
65 $this->postRepository = $this->objectManager->get(\ExtbaseTeam\BlogExample\Domain\Repository\PostRepository::class);
66 }
67
68 /**
69 * @test
70 */
71 public function simpleCountTest() {
72 $query = $this->postRepository->createQuery();
73 $this->assertSame($this->numberOfRecordsInFixture, $query->count());
74 }
75
76 /**
77 * @test
78 */
79 public function offsetCountTest() {
80 $query = $this->postRepository->createQuery();
81
82 $query->setOffset(6);
83
84 $this->assertSame(($this->numberOfRecordsInFixture - 6), $query->count());
85 }
86
87 /**
88 * @test
89 */
90 public function exceedingOffsetCountTest() {
91 $query = $this->postRepository->createQuery();
92
93 $query->setOffset(($this->numberOfRecordsInFixture + 5));
94
95 $this->assertSame(0, $query->count());
96 }
97
98 /**
99 * @test
100 */
101 public function limitCountTest() {
102 $query = $this->postRepository->createQuery();
103
104 $query->setLimit(4);
105
106 $this->assertSame(4, $query->count());
107 }
108
109 /**
110 * @test
111 */
112 public function limitAndOffsetCountTest() {
113 $query = $this->postRepository->createQuery();
114
115 $query
116 ->setOffset(($this->numberOfRecordsInFixture - 3))
117 ->setLimit(4);
118
119 $this->assertSame(3, $query->count());
120 }
121
122 /**
123 * @test
124 */
125 public function inConstraintCountTest() {
126 $query = $this->postRepository->createQuery();
127
128 $query->matching(
129 $query->in('uid', array(1,2,3))
130 );
131
132 $this->assertSame(3, $query->count());
133 }
134
135 /**
136 * Test if count works with subproperties in subselects.
137 *
138 * @test
139 */
140 public function subpropertyJoinCountTest() {
141 $query = $this->postRepository->createQuery();
142
143 $query->matching(
144 $query->equals('blog.title', 'Blog1')
145 );
146
147 $this->assertSame(10, $query->count());
148 }
149
150 /**
151 * Test if count works with subproperties in multiple left join.
152 *
153 * @test
154 */
155 public function subpropertyInMultipleLeftJoinCountTest() {
156 $query = $this->postRepository->createQuery();
157
158 $query->matching(
159 $query->logicalOr(
160 $query->equals('tags.uid', 1),
161 $query->equals('tags.uid', 2)
162 )
163 );
164
165 $this->assertSame(10, $query->count());
166 }
167 }