TYPO3 CMS  TYPO3_6-2
QueryTest.php
Go to the documentation of this file.
1 <?php
3 
21 
25  protected $query;
26 
30  protected $querySettings;
31 
36 
40  protected $backend;
41 
45  protected $dataMapper;
46 
52  public function setUp() {
53  $this->query = $this->getAccessibleMock('TYPO3\CMS\Extbase\Persistence\Generic\Query', array('dummy'), array('someType'));
54  $this->querySettings = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QuerySettingsInterface');
55  $this->query->_set('querySettings', $this->querySettings);
56  $this->persistenceManager = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\PersistenceManagerInterface');
57  $this->backend = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\BackendInterface');
58  $this->backend->expects($this->any())->method('getQomFactory')->will($this->returnValue(NULL));
59  $this->persistenceManager->expects($this->any())->method('getBackend')->will($this->returnValue($this->backend));
60  $this->query->_set('persistenceManager', $this->persistenceManager);
61  $this->dataMapper = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapper');
62  $this->query->_set('dataMapper', $this->dataMapper);
63  }
64 
68  public function executeReturnsQueryResultInstanceAndInjectsItself() {
70  $objectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
71  $this->query->_set('objectManager', $objectManager);
72  $queryResult = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QueryResult', array(), array(), '', FALSE);
73  $objectManager->expects($this->once())->method('get')->with('TYPO3\\CMS\\Extbase\\Persistence\\QueryResultInterface', $this->query)->will($this->returnValue($queryResult));
74  $actualResult = $this->query->execute();
75  $this->assertSame($queryResult, $actualResult);
76  }
77 
82  $this->querySettings->expects($this->once())->method('getReturnRawQueryResult')->will($this->returnValue(TRUE));
83  $this->persistenceManager->expects($this->once())->method('getObjectDataByQuery')->with($this->query)->will($this->returnValue('rawQueryResult'));
84  $expectedResult = 'rawQueryResult';
85  $actualResult = $this->query->execute();
86  $this->assertEquals($expectedResult, $actualResult);
87  }
88 
93  $this->persistenceManager->expects($this->once())->method('getObjectDataByQuery')->with($this->query)->will($this->returnValue('rawQueryResult'));
94  $expectedResult = 'rawQueryResult';
95  $actualResult = $this->query->execute(TRUE);
96  $this->assertEquals($expectedResult, $actualResult);
97  }
98 
103  public function setLimitAcceptsOnlyIntegers() {
104  $this->query->setLimit(1.5);
105  }
106 
112  $this->query->setLimit(0);
113  }
114 
119  public function setOffsetAcceptsOnlyIntegers() {
120  $this->query->setOffset(1.5);
121  }
122 
128  $this->query->setOffset(-1);
129  }
130 
135  return array(
136  'Polish alphabet' => array('name', 'ĄĆĘŁŃÓŚŹŻABCDEFGHIJKLMNOPRSTUWYZQXVąćęłńóśźżabcdefghijklmnoprstuwyzqxv', 'ąćęłńóśźżabcdefghijklmnoprstuwyzqxvąćęłńóśźżabcdefghijklmnoprstuwyzqxv'),
137  'German alphabet' => array('name', 'ßÜÖÄüöä', 'ßüöäüöä'),
138  'Greek alphabet' => array('name', 'Τάχιστη αλώπηξ βαφής ψημένη γη', 'τάχιστη αλώπηξ βαφής ψημένη γη'),
139  'Russian alphabet' => array('name', 'АВСТРАЛИЯавстралия', 'австралияавстралия')
140  );
141  }
142 
152  public function equalsForCaseSensitiveFalseLowercasesOperand($propertyName, $operand, $expectedOperand) {
154  $objectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
156  $dynamicOperand = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Qom\\PropertyValueInterface');
157  $objectManager->expects($this->any())->method('get')->will($this->returnValue($dynamicOperand));
159  $qomFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Qom\\QueryObjectModelFactory', array('comparison'));
160  $qomFactory->_set('objectManager', $objectManager);
161  $qomFactory->expects($this->once())->method('comparison')->with($this->anything(), $this->anything(), $expectedOperand);
162  $this->query->_set('qomFactory', $qomFactory);
163  $this->query->equals($propertyName, $operand, FALSE);
164  }
165 }
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)