TYPO3 API  SVNRelease
Typo3DbBackendTest.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003  *  Copyright notice
00004  *
00005  *  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
00006  *  All rights reserved
00007  *
00008  *  This class is a backport of the corresponding class of FLOW3.
00009  *  All credits go to the v5 team.
00010  *
00011  *  This script is part of the TYPO3 project. The TYPO3 project is
00012  *  free software; you can redistribute it and/or modify
00013  *  it under the terms of the GNU General Public License as published by
00014  *  the Free Software Foundation; either version 2 of the License, or
00015  *  (at your option) any later version.
00016  *
00017  *  The GNU General Public License can be found at
00018  *  http://www.gnu.org/copyleft/gpl.html.
00019  *
00020  *  This script is distributed in the hope that it will be useful,
00021  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023  *  GNU General Public License for more details.
00024  *
00025  *  This copyright notice MUST APPEAR in all copies of the script!
00026  ***************************************************************/
00027 
00028 class Tx_Extbase_Tests_Unit_Persistence_Storage_Typo3DbBackendTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
00029 
00030     /**
00031      * This is the data provider for the statement generation with a basic comparison
00032      *
00033      * @return array An array of data
00034      */
00035     public function providerForBasicComparison() {
00036         return array(
00037             'equal' => array(
00038                 Tx_Extbase_Persistence_QueryInterface::OPERATOR_EQUAL_TO,
00039                 "SELECT table_name_from_selector.* FROM table_name_from_selector WHERE table_name_from_property.foo = 'baz'"
00040                 ),
00041             'less' => array(
00042                 Tx_Extbase_Persistence_QueryInterface::OPERATOR_LESS_THAN,
00043                 "SELECT table_name_from_selector.* FROM table_name_from_selector WHERE table_name_from_property.foo < 'baz'"
00044                 ),
00045             'less or equal' => array(
00046                 Tx_Extbase_Persistence_QueryInterface::OPERATOR_LESS_THAN_OR_EQUAL_TO,
00047                 "SELECT table_name_from_selector.* FROM table_name_from_selector WHERE table_name_from_property.foo <= 'baz'"
00048                 ),
00049             'greater' => array(
00050                 Tx_Extbase_Persistence_QueryInterface::OPERATOR_GREATER_THAN,
00051                 "SELECT table_name_from_selector.* FROM table_name_from_selector WHERE table_name_from_property.foo > 'baz'"
00052                 ),
00053             'greater or equal' => array(
00054                 Tx_Extbase_Persistence_QueryInterface::OPERATOR_GREATER_THAN_OR_EQUAL_TO,
00055                 "SELECT table_name_from_selector.* FROM table_name_from_selector WHERE table_name_from_property.foo >= 'baz'"
00056                 ),
00057 
00058             );
00059     }
00060 
00061     /**
00062      * @test
00063      */
00064     public function getStatementWorksWithMinimalisticQueryObjectModel() {
00065         $this->markTestIncomplete();
00066     }
00067 
00068     /**
00069      * @test
00070      */
00071     public function getStatementWorksWithBasicEqualsCondition() {
00072         $this->markTestIncomplete();
00073     }
00074 
00075     /**
00076      * @test
00077      * @expectedException Tx_Extbase_Persistence_Storage_Exception_BadConstraint
00078      */
00079     public function countRowsWithStatementConstraintResultsInAnException() {
00080         $this->markTestIncomplete();
00081     }
00082 
00083     /**
00084      * @test
00085      */
00086     public function joinStatementGenerationWorks() {
00087         $this->markTestIncomplete();
00088     }
00089 
00090     /**
00091      * @test
00092      */
00093     public function orderStatementGenerationWorks() {
00094         $mockSource = $this->getMock('Tx_Extbase_Persistence_QOM_Selector', array('getNodeTypeName'), array(), '', FALSE);
00095         $mockSource->expects($this->any())->method('getNodeTypeName')->will($this->returnValue('Tx_MyExt_ClassName'));
00096 
00097         $mockDataMapper = $this->getMock('Tx_Extbase_Persistence_Mapper_DataMapper', array('convertPropertyNameToColumnName', 'convertClassNameToTableName'), array(), '', FALSE);
00098         $mockDataMapper->expects($this->once())->method('convertClassNameToTableName')->with('Tx_MyExt_ClassName')->will($this->returnValue('tx_myext_tablename'));
00099         $mockDataMapper->expects($this->once())->method('convertPropertyNameToColumnName')->with('fooProperty', 'Tx_MyExt_ClassName')->will($this->returnValue('converted_fieldname'));
00100 
00101         $sql = array();
00102         $orderings = array('fooProperty' => Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_ORDER_ASCENDING);
00103         $mockTypo3DbBackend = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_Storage_Typo3DbBackend'), array('parserOrderings'), array(), '', FALSE);
00104         $mockTypo3DbBackend->_set('dataMapper', $mockDataMapper);
00105         $mockTypo3DbBackend->_callRef('parseOrderings', $orderings, $mockSource, $sql);
00106 
00107         $expecedSql = array('orderings' => array('tx_myext_tablename.converted_fieldname ASC'));
00108         $this->assertSame($expecedSql, $sql);
00109     }
00110 
00111     /**
00112      * @test
00113      * @expectedException Tx_Extbase_Persistence_Exception_UnsupportedOrder
00114      */
00115     public function orderStatementGenerationThrowsExceptionOnUnsupportedOrder() {
00116         $mockSource = $this->getMock('Tx_Extbase_Persistence_QOM_Selector', array('getNodeTypeName'), array(), '', FALSE);
00117         $mockSource->expects($this->never())->method('getNodeTypeName');
00118 
00119         $mockDataMapper = $this->getMock('Tx_Extbase_Persistence_Mapper_DataMapper', array('convertPropertyNameToColumnName', 'convertClassNameToTableName'), array(), '', FALSE);
00120         $mockDataMapper->expects($this->never())->method('convertClassNameToTableName');
00121         $mockDataMapper->expects($this->never())->method('convertPropertyNameToColumnName');
00122 
00123         $sql = array();
00124         $orderings = array('fooProperty' => 'unsupported_order');
00125         $mockTypo3DbBackend = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_Storage_Typo3DbBackend'), array('parserOrderings'), array(), '', FALSE);
00126         $mockTypo3DbBackend->_set('dataMapper', $mockDataMapper);
00127         $mockTypo3DbBackend->_callRef('parseOrderings', $orderings, $mockSource, $sql);
00128     }
00129 
00130     /**
00131      * @test
00132      */
00133     public function orderStatementGenerationWorksWithMultipleOrderings() {
00134         $mockSource = $this->getMock('Tx_Extbase_Persistence_QOM_Selector', array('getNodeTypeName'), array(), '', FALSE);
00135         $mockSource->expects($this->any())->method('getNodeTypeName')->will($this->returnValue('Tx_MyExt_ClassName'));
00136 
00137         $mockDataMapper = $this->getMock('Tx_Extbase_Persistence_Mapper_DataMapper', array('convertPropertyNameToColumnName', 'convertClassNameToTableName'), array(), '', FALSE);
00138         $mockDataMapper->expects($this->any())->method('convertClassNameToTableName')->with('Tx_MyExt_ClassName')->will($this->returnValue('tx_myext_tablename'));
00139         $mockDataMapper->expects($this->any())->method('convertPropertyNameToColumnName')->will($this->returnValue('converted_fieldname'));
00140 
00141         $sql = array();
00142         $orderings = array(
00143             'fooProperty' => Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_ORDER_ASCENDING,
00144             'barProperty' => Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_ORDER_DESCENDING
00145             );
00146         $mockTypo3DbBackend = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_Storage_Typo3DbBackend'), array('parserOrderings'), array(), '', FALSE);
00147         $mockTypo3DbBackend->_set('dataMapper', $mockDataMapper);
00148         $mockTypo3DbBackend->_callRef('parseOrderings', $orderings, $mockSource, $sql);
00149 
00150         $expecedSql = array('orderings' => array('tx_myext_tablename.converted_fieldname ASC', 'tx_myext_tablename.converted_fieldname DESC'));
00151         $this->assertSame($expecedSql, $sql);
00152     }
00153 
00154 }
00155 ?>