‪TYPO3CMS  9.5
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 
17 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
18 
22 class ‪QueryTest extends UnitTestCase
23 {
27  protected ‪$query;
28 
32  protected ‪$querySettings;
33 
37  protected ‪$persistenceManager;
38 
42  protected ‪$dataMapFactory;
43 
47  protected function ‪setUp()
48  {
49  $this->query = $this->getAccessibleMock(\‪TYPO3\CMS\‪Extbase\Persistence\Generic\Query::class, ['getSelectorName'], ['someType']);
50  $this->querySettings = $this->createMock(\‪TYPO3\CMS\‪Extbase\Persistence\Generic\QuerySettingsInterface::class);
51  $this->query->_set('querySettings', $this->querySettings);
52  $this->persistenceManager = $this->createMock(\‪TYPO3\CMS\‪Extbase\Persistence\PersistenceManagerInterface::class);
53  $this->query->_set('persistenceManager', $this->persistenceManager);
54  $this->dataMapFactory = $this->createMock(\‪TYPO3\CMS\‪Extbase\Persistence\Generic\Mapper\DataMapFactory::class);
55  $this->query->_set('dataMapFactory', $this->dataMapFactory);
56  }
57 
62  {
64  $objectManager = $this->createMock(\‪TYPO3\CMS\‪Extbase\Object\ObjectManager::class);
65  $this->query->_set('objectManager', $objectManager);
66  $queryResult = $this->createMock(\‪TYPO3\CMS\‪Extbase\Persistence\Generic\QueryResult::class);
67  $objectManager->expects($this->once())->method('get')->with(\‪TYPO3\CMS\‪Extbase\Persistence\QueryResultInterface::class, $this->query)->will($this->returnValue($queryResult));
68  $actualResult = $this->query->execute();
69  $this->assertSame($queryResult, $actualResult);
70  }
71 
76  {
77  $this->persistenceManager->expects($this->once())->method('getObjectDataByQuery')->with($this->query)->will($this->returnValue('rawQueryResult'));
78  $expectedResult = 'rawQueryResult';
79  $actualResult = $this->query->execute(true);
80  $this->assertEquals($expectedResult, $actualResult);
81  }
82 
86  public function ‪setLimitAcceptsOnlyIntegers()
87  {
88  $this->expectException(\InvalidArgumentException::class);
89  $this->expectExceptionCode(1245071870);
90  $this->query->setLimit(1.5);
91  }
92 
97  {
98  $this->expectException(\InvalidArgumentException::class);
99  $this->expectExceptionCode(1245071870);
100  $this->query->setLimit(0);
101  }
102 
106  public function ‪setOffsetAcceptsOnlyIntegers()
107  {
108  $this->expectException(\InvalidArgumentException::class);
109  $this->expectExceptionCode(1245071872);
110  $this->query->setOffset(1.5);
111  }
112 
117  {
118  $this->expectException(\InvalidArgumentException::class);
119  $this->expectExceptionCode(1245071872);
120  $this->query->setOffset(-1);
121  }
122 
127  {
128  return [
129  'Polish alphabet' => ['name', 'ĄĆĘŁŃÓŚŹŻABCDEFGHIJKLMNOPRSTUWYZQXVąćęłńóśźżabcdefghijklmnoprstuwyzqxv', 'ąćęłńóśźżabcdefghijklmnoprstuwyzqxvąćęłńóśźżabcdefghijklmnoprstuwyzqxv'],
130  'German alphabet' => ['name', 'ßÜÖÄüöä', 'ßüöäüöä'],
131  'Greek alphabet' => ['name', 'Τάχιστη αλώπηξ βαφής ψημένη γη', 'τάχιστη αλώπηξ βαφής ψημένη γη'],
132  'Russian alphabet' => ['name', 'АВСТРАЛИЯавстралия', 'австралияавстралия']
133  ];
134  }
135 
145  public function ‪equalsForCaseSensitiveFalseLowercasesOperand($propertyName, $operand, $expectedOperand)
146  {
148  $objectManager = $this->createMock(\‪TYPO3\CMS\‪Extbase\Object\ObjectManager::class);
150  $dynamicOperand = $this->createMock(\‪TYPO3\CMS\‪Extbase\Persistence\Generic\Qom\PropertyValueInterface::class);
151  $objectManager->expects($this->any())->method('get')->will($this->returnValue($dynamicOperand));
153  $qomFactory = $this->getAccessibleMock(\‪TYPO3\CMS\‪Extbase\Persistence\Generic\Qom\QueryObjectModelFactory::class, ['comparison']);
154  $qomFactory->_set('objectManager', $objectManager);
155  $qomFactory->expects($this->once())->method('comparison')->with($this->anything(), $this->anything(), $expectedOperand);
156  $this->query->expects($this->any())->method('getSelectorName')->will($this->returnValue('someSelector'));
157  $this->query->_set('qomFactory', $qomFactory);
158  $this->query->equals($propertyName, $operand, false);
159  }
160 }
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\QueryTest\setOffsetAcceptsOnlyIntegers
‪setOffsetAcceptsOnlyIntegers()
Definition: QueryTest.php:102
‪TYPO3\CMS\Extbase\Annotation
Definition: IgnoreValidation.php:4
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\QueryTest\$query
‪TYPO3 CMS Extbase Persistence Generic Query PHPUnit_Framework_MockObject_MockObject TYPO3 TestingFramework Core AccessibleObjectInterface $query
Definition: QueryTest.php:26
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\QueryTest\equalsForCaseSensitiveFalseLowercasesOperand
‪equalsForCaseSensitiveFalseLowercasesOperand($propertyName, $operand, $expectedOperand)
Definition: QueryTest.php:141
‪TYPO3
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\QueryTest\setLimitAcceptsOnlyIntegers
‪setLimitAcceptsOnlyIntegers()
Definition: QueryTest.php:82
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\QueryTest\$persistenceManager
‪TYPO3 CMS Extbase Persistence PersistenceManagerInterface $persistenceManager
Definition: QueryTest.php:34
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\QueryTest\setLimitRejectsIntegersLessThanOne
‪setLimitRejectsIntegersLessThanOne()
Definition: QueryTest.php:92
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic
Definition: BackendTest.php:3
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\QueryTest\executeReturnsRawObjectDataIfReturnRawQueryResultIsSet
‪executeReturnsRawObjectDataIfReturnRawQueryResultIsSet()
Definition: QueryTest.php:71
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\QueryTest
Definition: QueryTest.php:23
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\QueryTest\executeReturnsQueryResultInstanceAndInjectsItself
‪executeReturnsQueryResultInstanceAndInjectsItself()
Definition: QueryTest.php:57
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\QueryTest\$querySettings
‪TYPO3 CMS Extbase Persistence Generic QuerySettingsInterface $querySettings
Definition: QueryTest.php:30
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\QueryTest\equalsForCaseSensitiveFalseLowercasesOperandProvider
‪array equalsForCaseSensitiveFalseLowercasesOperandProvider()
Definition: QueryTest.php:122
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\QueryTest\$dataMapFactory
‪TYPO3 CMS Extbase Persistence Generic Mapper DataMapFactory $dataMapFactory
Definition: QueryTest.php:38
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\QueryTest\setOffsetRejectsIntegersLessThanZero
‪setOffsetRejectsIntegersLessThanZero()
Definition: QueryTest.php:112
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\QueryTest\setUp
‪setUp()
Definition: QueryTest.php:43