TYPO3 CMS  TYPO3_8-7
QueryTest.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 
20 class QueryTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
21 {
25  protected $query;
26 
30  protected $querySettings;
31 
36 
40  protected $dataMapper;
41 
45  protected function setUp()
46  {
47  $this->query = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Query::class, ['dummy'], ['someType']);
48  $this->querySettings = $this->createMock(\TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface::class);
49  $this->query->_set('querySettings', $this->querySettings);
50  $this->persistenceManager = $this->createMock(\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface::class);
51  $this->query->_set('persistenceManager', $this->persistenceManager);
52  $this->dataMapper = $this->createMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper::class);
53  $this->query->_set('dataMapper', $this->dataMapper);
54  }
55 
59  public function executeReturnsQueryResultInstanceAndInjectsItself()
60  {
62  $objectManager = $this->createMock(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
63  $this->query->_set('objectManager', $objectManager);
64  $queryResult = $this->createMock(\TYPO3\CMS\Extbase\Persistence\Generic\QueryResult::class);
65  $objectManager->expects($this->once())->method('get')->with(\TYPO3\CMS\Extbase\Persistence\QueryResultInterface::class, $this->query)->will($this->returnValue($queryResult));
66  $actualResult = $this->query->execute();
67  $this->assertSame($queryResult, $actualResult);
68  }
69 
74  {
75  $this->persistenceManager->expects($this->once())->method('getObjectDataByQuery')->with($this->query)->will($this->returnValue('rawQueryResult'));
76  $expectedResult = 'rawQueryResult';
77  $actualResult = $this->query->execute(true);
78  $this->assertEquals($expectedResult, $actualResult);
79  }
80 
84  public function setLimitAcceptsOnlyIntegers()
85  {
86  $this->expectException(\InvalidArgumentException::class);
87  $this->expectExceptionCode(1245071870);
88  $this->query->setLimit(1.5);
89  }
90 
95  {
96  $this->expectException(\InvalidArgumentException::class);
97  $this->expectExceptionCode(1245071870);
98  $this->query->setLimit(0);
99  }
100 
105  {
106  $this->expectException(\InvalidArgumentException::class);
107  $this->expectExceptionCode(1245071872);
108  $this->query->setOffset(1.5);
109  }
110 
115  {
116  $this->expectException(\InvalidArgumentException::class);
117  $this->expectExceptionCode(1245071872);
118  $this->query->setOffset(-1);
119  }
120 
125  {
126  return [
127  'Polish alphabet' => ['name', 'ĄĆĘŁŃÓŚŹŻABCDEFGHIJKLMNOPRSTUWYZQXVąćęłńóśźżabcdefghijklmnoprstuwyzqxv', 'ąćęłńóśźżabcdefghijklmnoprstuwyzqxvąćęłńóśźżabcdefghijklmnoprstuwyzqxv'],
128  'German alphabet' => ['name', 'ßÜÖÄüöä', 'ßüöäüöä'],
129  'Greek alphabet' => ['name', 'Τάχιστη αλώπηξ βαφής ψημένη γη', 'τάχιστη αλώπηξ βαφής ψημένη γη'],
130  'Russian alphabet' => ['name', 'АВСТРАЛИЯавстралия', 'австралияавстралия']
131  ];
132  }
133 
143  public function equalsForCaseSensitiveFalseLowercasesOperand($propertyName, $operand, $expectedOperand)
144  {
146  $objectManager = $this->createMock(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
148  $dynamicOperand = $this->createMock(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\PropertyValueInterface::class);
149  $objectManager->expects($this->any())->method('get')->will($this->returnValue($dynamicOperand));
151  $qomFactory = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory::class, ['comparison']);
152  $qomFactory->_set('objectManager', $objectManager);
153  $qomFactory->expects($this->once())->method('comparison')->with($this->anything(), $this->anything(), $expectedOperand);
154  $this->query->_set('qomFactory', $qomFactory);
155  $this->query->equals($propertyName, $operand, false);
156  }
157 }