[TASK] Removes extra empty lines
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Functional / Persistence / QueryParserTest.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 QueryParserTest extends \TYPO3\CMS\Core\Tests\FunctionalTestCase
20 {
21 /**
22 * @var \TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo3DbQueryParser
23 */
24 protected $queryParser;
25
26 /**
27 * @var array
28 */
29 protected $testExtensionsToLoad = array('typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example');
30
31 /**
32 * @var array
33 */
34 protected $coreExtensionsToLoad = array('extbase', 'fluid');
35
36 /**
37 * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface The object manager
38 */
39 protected $objectManager;
40
41 /**
42 * @var \ExtbaseTeam\BlogExample\Domain\Repository\BlogRepository
43 */
44 protected $blogRepository;
45
46 /**
47 * Sets up this test suite.
48 */
49 protected function setUp()
50 {
51 parent::setUp();
52
53 $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/tags.xml');
54 $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/tags-mm.xml');
55 $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/persons.xml');
56 $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/posts.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->queryParser = $this->objectManager->get(\TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo3DbQueryParser::class);
61 $this->blogRepository = $this->objectManager->get(\ExtbaseTeam\BlogExample\Domain\Repository\BlogRepository::class);
62 }
63
64 /**
65 * @test
66 */
67 public function preparseQueryTakesOperatorsIntoHash()
68 {
69 $queryWithEquals = $this->blogRepository->createQuery();
70
71 $queryWithEquals->matching(
72 $queryWithEquals->equals('uid', 1)
73 );
74
75 list($hashWithEquals) = $this->queryParser->preparseQuery($queryWithEquals);
76
77 $queryWithIn = $this->blogRepository->createQuery();
78
79 $queryWithIn->matching(
80 $queryWithIn->in('uid', array(1))
81 );
82
83 list($hashWithIn) = $this->queryParser->preparseQuery($queryWithIn);
84
85 $this->assertNotSame($hashWithEquals, $hashWithIn);
86 }
87
88 /**
89 * @test
90 */
91 public function preparseQueryHashDiffersForIsNullOperator()
92 {
93 $queryWithIsNull = $this->blogRepository->createQuery();
94
95 $queryWithIsNull->matching(
96 $queryWithIsNull->equals('title', null)
97 );
98
99 list($hashWithIsNull) = $this->queryParser->preparseQuery($queryWithIsNull);
100
101 $queryWithoutIsNull = $this->blogRepository->createQuery();
102
103 $queryWithoutIsNull->matching(
104 $queryWithoutIsNull->equals('title', '')
105 );
106
107 list($hashWithoutIsNull) = $this->queryParser->preparseQuery($queryWithoutIsNull);
108
109 $this->assertNotSame($hashWithIsNull, $hashWithoutIsNull);
110 }
111
112 /**
113 * @test
114 */
115 public function preparseQueryHashDiffersForEqualsCaseSensitiveArgument()
116 {
117 $queryCaseSensitiveFalse = $this->blogRepository->createQuery();
118
119 $queryCaseSensitiveFalse->matching(
120 $queryCaseSensitiveFalse->equals('title', 'PoSt1', false)
121 );
122
123 list($hashWithCaseSensitiveFalse) = $this->queryParser->preparseQuery($queryCaseSensitiveFalse);
124
125 $queryCaseSensitiveTrue = $this->blogRepository->createQuery();
126
127 $queryCaseSensitiveTrue->matching(
128 $queryCaseSensitiveTrue->equals('title', 'PoSt1', true)
129 );
130
131 list($hashWithCaseSensitiveTrue) = $this->queryParser->preparseQuery($queryCaseSensitiveTrue);
132
133 $this->assertNotSame($hashWithCaseSensitiveFalse, $hashWithCaseSensitiveTrue);
134 }
135
136 /**
137 * @test
138 */
139 public function queryWithMultipleRelationsToIdenticalTablesReturnsExpectedResultForOrQuery()
140 {
141 /** @var \ExtbaseTeam\BlogExample\Domain\Repository\PostRepository $postRepository */
142 $postRepository = $this->objectManager->get('ExtbaseTeam\\BlogExample\\Domain\\Repository\\PostRepository');
143 $query = $postRepository->createQuery();
144 $query->matching(
145 $query->logicalAnd(
146 $query->equals('blog', 3),
147 $query->logicalOr(
148 $query->equals('tags.name', 'Tag12'),
149 $query->equals('author.tags.name', 'TagForAuthor1')
150 )
151 )
152 );
153 $result = $query->execute()->toArray();
154 $this->assertEquals(3, count($result));
155 }
156
157 /**
158 * @test
159 */
160 public function queryWithMultipleRelationsToIdenticalTablesReturnsExpectedResultForAndQuery()
161 {
162 /** @var \ExtbaseTeam\BlogExample\Domain\Repository\PostRepository $postRepository */
163 $postRepository = $this->objectManager->get('ExtbaseTeam\\BlogExample\\Domain\\Repository\\PostRepository');
164 $query = $postRepository->createQuery();
165 $query->matching(
166 $query->logicalAnd(
167 $query->equals('blog', 3),
168 $query->equals('tags.name', 'Tag12'),
169 $query->equals('author.tags.name', 'TagForAuthor1')
170 )
171 );
172 $result = $query->execute()->toArray();
173 $this->assertEquals(1, count($result));
174 }
175 }