2 /***************************************************************
5 * (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
8 * This class is a backport of the corresponding class of FLOW3.
9 * All credits go to the v5 team.
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
28 class Tx_Extbase_Persistence_Storage_Typo3DbBackend_testcase
extends Tx_Extbase_Tests_Unit_BaseTestCase
{
31 * This is the data provider for the statement generation with a basic comparison
33 * @return array An array of data
35 public function providerForBasicComparison() {
38 Tx_Extbase_Persistence_QueryInterface
::OPERATOR_EQUAL_TO
,
39 "SELECT table_name_from_selector.* FROM table_name_from_selector WHERE table_name_from_property.foo = 'baz'"
42 Tx_Extbase_Persistence_QueryInterface
::OPERATOR_LESS_THAN
,
43 "SELECT table_name_from_selector.* FROM table_name_from_selector WHERE table_name_from_property.foo < 'baz'"
45 'less or equal' => array(
46 Tx_Extbase_Persistence_QueryInterface
::OPERATOR_LESS_THAN_OR_EQUAL_TO
,
47 "SELECT table_name_from_selector.* FROM table_name_from_selector WHERE table_name_from_property.foo <= 'baz'"
50 Tx_Extbase_Persistence_QueryInterface
::OPERATOR_GREATER_THAN
,
51 "SELECT table_name_from_selector.* FROM table_name_from_selector WHERE table_name_from_property.foo > 'baz'"
53 'greater or equal' => array(
54 Tx_Extbase_Persistence_QueryInterface
::OPERATOR_GREATER_THAN_OR_EQUAL_TO
,
55 "SELECT table_name_from_selector.* FROM table_name_from_selector WHERE table_name_from_property.foo >= 'baz'"
64 public function getStatementWorksWithMinimalisticQueryObjectModel() {
65 $this->markTestIncomplete();
71 public function getStatementWorksWithBasicEqualsCondition() {
72 $this->markTestIncomplete();
77 * @expectedException Tx_Extbase_Persistence_Storage_Exception_BadConstraint
79 public function countRowsWithStatementConstraintResultsInAnException() {
80 $this->markTestIncomplete();
86 public function joinStatementGenerationWorks() {
87 $this->markTestIncomplete();
93 public function orderStatementGenerationWorks() {
94 $mockSource = $this->getMock('Tx_Extbase_Persistence_QOM_Selector', array('getNodeTypeName'), array(), '', FALSE);
95 $mockSource->expects($this->any())->method('getNodeTypeName')->will($this->returnValue('Tx_MyExt_ClassName'));
97 $mockDataMapper = $this->getMock('Tx_Extbase_Persistence_Mapper_DataMapper', array('convertPropertyNameToColumnName', 'convertClassNameToTableName'), array(), '', FALSE);
98 $mockDataMapper->expects($this->once())->method('convertClassNameToTableName')->with('Tx_MyExt_ClassName')->will($this->returnValue('tx_myext_tablename'));
99 $mockDataMapper->expects($this->once())->method('convertPropertyNameToColumnName')->with('fooProperty', 'Tx_MyExt_ClassName')->will($this->returnValue('converted_fieldname'));
102 $orderings = array('fooProperty' => Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface
::JCR_ORDER_ASCENDING
);
103 $mockTypo3DbBackend = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_Storage_Typo3DbBackend'), array('parserOrderings'), array(), '', FALSE);
104 $mockTypo3DbBackend->_set('dataMapper', $mockDataMapper);
105 $mockTypo3DbBackend->_callRef('parseOrderings', $orderings, $mockSource, $sql);
107 $expecedSql = array('orderings' => array('tx_myext_tablename.converted_fieldname ASC'));
108 $this->assertSame($expecedSql, $sql);
113 * @expectedException Tx_Extbase_Persistence_Exception_UnsupportedOrder
115 public function orderStatementGenerationThrowsExceptionOnUnsupportedOrder() {
116 $mockSource = $this->getMock('Tx_Extbase_Persistence_QOM_Selector', array('getNodeTypeName'), array(), '', FALSE);
117 $mockSource->expects($this->never())->method('getNodeTypeName');
119 $mockDataMapper = $this->getMock('Tx_Extbase_Persistence_Mapper_DataMapper', array('convertPropertyNameToColumnName', 'convertClassNameToTableName'), array(), '', FALSE);
120 $mockDataMapper->expects($this->never())->method('convertClassNameToTableName');
121 $mockDataMapper->expects($this->never())->method('convertPropertyNameToColumnName');
124 $orderings = array('fooProperty' => 'unsupported_order');
125 $mockTypo3DbBackend = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_Storage_Typo3DbBackend'), array('parserOrderings'), array(), '', FALSE);
126 $mockTypo3DbBackend->_set('dataMapper', $mockDataMapper);
127 $mockTypo3DbBackend->_callRef('parseOrderings', $orderings, $mockSource, $sql);
133 public function orderStatementGenerationWorksWithMultipleOrderings() {
134 $mockSource = $this->getMock('Tx_Extbase_Persistence_QOM_Selector', array('getNodeTypeName'), array(), '', FALSE);
135 $mockSource->expects($this->any())->method('getNodeTypeName')->will($this->returnValue('Tx_MyExt_ClassName'));
137 $mockDataMapper = $this->getMock('Tx_Extbase_Persistence_Mapper_DataMapper', array('convertPropertyNameToColumnName', 'convertClassNameToTableName'), array(), '', FALSE);
138 $mockDataMapper->expects($this->any())->method('convertClassNameToTableName')->with('Tx_MyExt_ClassName')->will($this->returnValue('tx_myext_tablename'));
139 $mockDataMapper->expects($this->any())->method('convertPropertyNameToColumnName')->will($this->returnValue('converted_fieldname'));
143 'fooProperty' => Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface
::JCR_ORDER_ASCENDING
,
144 'barProperty' => Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface
::JCR_ORDER_DESCENDING
146 $mockTypo3DbBackend = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_Storage_Typo3DbBackend'), array('parserOrderings'), array(), '', FALSE);
147 $mockTypo3DbBackend->_set('dataMapper', $mockDataMapper);
148 $mockTypo3DbBackend->_callRef('parseOrderings', $orderings, $mockSource, $sql);
150 $expecedSql = array('orderings' => array('tx_myext_tablename.converted_fieldname ASC', 'tx_myext_tablename.converted_fieldname DESC'));
151 $this->assertSame($expecedSql, $sql);