[BUGFIX] FOLLOWUP Queries with NULL don't work
[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 * Copyright notice
6 *
7 * (c) 2014 Felix Oertel <typo3@foertel.com>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 use TYPO3\CMS\Core\Utility\GeneralUtility;
28 use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
29
30 class QueryParserTest extends \TYPO3\CMS\Core\Tests\FunctionalTestCase {
31
32 /**
33 * @var \TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo3DbQueryParser
34 */
35 protected $queryParser;
36
37 /**
38 * @var array
39 */
40 protected $testExtensionsToLoad = array('typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example');
41
42 /**
43 * @var array
44 */
45 protected $coreExtensionsToLoad = array('extbase', 'fluid');
46
47 /**
48 * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface The object manager
49 */
50 protected $objectManager;
51
52 /**
53 * Sets up this test suite.
54 */
55 public function setUp() {
56 parent::setUp();
57
58 $this->objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
59 $this->queryParser = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbQueryParser');
60 $this->blogRepository = $this->objectManager->get('ExtbaseTeam\\BlogExample\\Domain\\Repository\\BlogRepository');
61 }
62
63 /**
64 * @test
65 */
66 public function preparseQueryTakesOperatorsIntoHash() {
67 $queryWithEquals = $this->blogRepository->createQuery();
68
69 $queryWithEquals->matching(
70 $queryWithEquals->equals('uid', 1)
71 );
72
73 list($hashWithEquals) = $this->queryParser->preparseQuery($queryWithEquals);
74
75 $queryWithIn = $this->blogRepository->createQuery();
76
77 $queryWithIn->matching(
78 $queryWithIn->in('uid', array(1))
79 );
80
81 list($hashWithIn) = $this->queryParser->preparseQuery($queryWithIn);
82
83 $this->assertNotSame($hashWithEquals, $hashWithIn);
84 }
85
86 /**
87 * @test
88 */
89 public function preparseQueryHasDiffersForIsNullOperator() {
90 $queryWithIsNull = $this->blogRepository->createQuery();
91
92 $queryWithIsNull->matching(
93 $queryWithIsNull->equals('title', NULL)
94 );
95
96 list($hashWithIsNull) = $this->queryParser->preparseQuery($queryWithIsNull);
97
98 $queryWithoutIsNull = $this->blogRepository->createQuery();
99
100 $queryWithoutIsNull->matching(
101 $queryWithoutIsNull->equals('title', '')
102 );
103
104 list($hashWithoutIsNull) = $this->queryParser->preparseQuery($queryWithoutIsNull);
105
106 $this->assertNotSame($hashWithIsNull, $hashWithoutIsNull);
107 }
108 }