[!!!][TASK] Extbase: Remove preparsing of queries
[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 array
23 */
24 protected $testExtensionsToLoad = array('typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example');
25
26 /**
27 * @var array
28 */
29 protected $coreExtensionsToLoad = array('extbase', 'fluid');
30
31 /**
32 * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface The object manager
33 */
34 protected $objectManager;
35
36 /**
37 * @var \ExtbaseTeam\BlogExample\Domain\Repository\BlogRepository
38 */
39 protected $blogRepository;
40
41 /**
42 * Sets up this test suite.
43 */
44 protected function setUp()
45 {
46 parent::setUp();
47
48 $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/tags.xml');
49 $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/tags-mm.xml');
50 $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/persons.xml');
51 $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/posts.xml');
52 $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/post-tag-mm.xml');
53
54 $this->objectManager = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
55 $this->blogRepository = $this->objectManager->get(\ExtbaseTeam\BlogExample\Domain\Repository\BlogRepository::class);
56 }
57
58 /**
59 * @test
60 */
61 public function queryWithMultipleRelationsToIdenticalTablesReturnsExpectedResultForOrQuery()
62 {
63 /** @var \ExtbaseTeam\BlogExample\Domain\Repository\PostRepository $postRepository */
64 $postRepository = $this->objectManager->get('ExtbaseTeam\\BlogExample\\Domain\\Repository\\PostRepository');
65 $query = $postRepository->createQuery();
66 $query->matching(
67 $query->logicalAnd(
68 $query->equals('blog', 3),
69 $query->logicalOr(
70 $query->equals('tags.name', 'Tag12'),
71 $query->equals('author.tags.name', 'TagForAuthor1')
72 )
73 )
74 );
75 $result = $query->execute()->toArray();
76 $this->assertEquals(3, count($result));
77 }
78
79 /**
80 * @test
81 */
82 public function queryWithMultipleRelationsToIdenticalTablesReturnsExpectedResultForAndQuery()
83 {
84 /** @var \ExtbaseTeam\BlogExample\Domain\Repository\PostRepository $postRepository */
85 $postRepository = $this->objectManager->get('ExtbaseTeam\\BlogExample\\Domain\\Repository\\PostRepository');
86 $query = $postRepository->createQuery();
87 $query->matching(
88 $query->logicalAnd(
89 $query->equals('blog', 3),
90 $query->equals('tags.name', 'Tag12'),
91 $query->equals('author.tags.name', 'TagForAuthor1')
92 )
93 );
94 $result = $query->execute()->toArray();
95 $this->assertEquals(1, count($result));
96 }
97 }