TYPO3 CMS  TYPO3_7-6
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 
21 {
25  protected $query;
26 
30  protected $querySettings;
31 
36 
40  protected $backend;
41 
45  protected $dataMapper;
46 
52  protected function setUp()
53  {
54  $this->query = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Query::class, ['dummy'], ['someType']);
55  $this->querySettings = $this->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface::class);
56  $this->query->_set('querySettings', $this->querySettings);
57  $this->persistenceManager = $this->getMock(\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface::class);
58  $this->backend = $this->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface::class);
59  $this->backend->expects($this->any())->method('getQomFactory')->will($this->returnValue(null));
60  $this->persistenceManager->expects($this->any())->method('getBackend')->will($this->returnValue($this->backend));
61  $this->query->_set('persistenceManager', $this->persistenceManager);
62  $this->dataMapper = $this->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper::class);
63  $this->query->_set('dataMapper', $this->dataMapper);
64  }
65 
69  public function executeReturnsQueryResultInstanceAndInjectsItself()
70  {
72  $objectManager = $this->getMock(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
73  $this->query->_set('objectManager', $objectManager);
74  $queryResult = $this->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\QueryResult::class, [], [], '', false);
75  $objectManager->expects($this->once())->method('get')->with(\TYPO3\CMS\Extbase\Persistence\QueryResultInterface::class, $this->query)->will($this->returnValue($queryResult));
76  $actualResult = $this->query->execute();
77  $this->assertSame($queryResult, $actualResult);
78  }
79 
84  {
85  $this->persistenceManager->expects($this->once())->method('getObjectDataByQuery')->with($this->query)->will($this->returnValue('rawQueryResult'));
86  $expectedResult = 'rawQueryResult';
87  $actualResult = $this->query->execute(true);
88  $this->assertEquals($expectedResult, $actualResult);
89  }
90 
95  public function setLimitAcceptsOnlyIntegers()
96  {
97  $this->query->setLimit(1.5);
98  }
99 
105  {
106  $this->query->setLimit(0);
107  }
108 
114  {
115  $this->query->setOffset(1.5);
116  }
117 
123  {
124  $this->query->setOffset(-1);
125  }
126 
131  {
132  return [
133  'Polish alphabet' => ['name', 'ĄĆĘŁŃÓŚŹŻABCDEFGHIJKLMNOPRSTUWYZQXVąćęłńóśźżabcdefghijklmnoprstuwyzqxv', 'ąćęłńóśźżabcdefghijklmnoprstuwyzqxvąćęłńóśźżabcdefghijklmnoprstuwyzqxv'],
134  'German alphabet' => ['name', 'ßÜÖÄüöä', 'ßüöäüöä'],
135  'Greek alphabet' => ['name', 'Τάχιστη αλώπηξ βαφής ψημένη γη', 'τάχιστη αλώπηξ βαφής ψημένη γη'],
136  'Russian alphabet' => ['name', 'АВСТРАЛИЯавстралия', 'австралияавстралия']
137  ];
138  }
139 
149  public function equalsForCaseSensitiveFalseLowercasesOperand($propertyName, $operand, $expectedOperand)
150  {
152  $objectManager = $this->getMock(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
154  $dynamicOperand = $this->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\PropertyValueInterface::class);
155  $objectManager->expects($this->any())->method('get')->will($this->returnValue($dynamicOperand));
157  $qomFactory = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory::class, ['comparison']);
158  $qomFactory->_set('objectManager', $objectManager);
159  $qomFactory->expects($this->once())->method('comparison')->with($this->anything(), $this->anything(), $expectedOperand);
160  $this->query->_set('qomFactory', $qomFactory);
161  $this->query->equals($propertyName, $operand, false);
162  }
163 }
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)