|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 2009 Christopher Hlubek <hlubek@networkteam.com> 00006 * (c) 2010 Bastian Waidelich <bastian@typo3.org> 00007 * All rights reserved 00008 * 00009 * This script is part of the TYPO3 project. The TYPO3 project is 00010 * free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * The GNU General Public License can be found at 00016 * http://www.gnu.org/copyleft/gpl.html. 00017 * 00018 * This script is distributed in the hope that it will be useful, 00019 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00021 * GNU General Public License for more details. 00022 * 00023 * This copyright notice MUST APPEAR in all copies of the script! 00024 ***************************************************************/ 00025 00026 class Tx_Extbase_Tests_Unit_Persistence_QueryTest extends Tx_Extbase_Tests_Unit_BaseTestCase { 00027 00028 /** 00029 * @var Tx_Extbase_Persistence_Query 00030 */ 00031 protected $query; 00032 00033 /** 00034 * @var Tx_Extbase_Persistence_QuerySettingsInterface 00035 */ 00036 protected $querySettings; 00037 00038 /** 00039 * @var Tx_Extbase_Object_ObjectManagerInterface 00040 */ 00041 protected $objectManager; 00042 00043 /** 00044 * @var Tx_Extbase_Persistence_ManagerInterface 00045 */ 00046 protected $persistenceManager; 00047 00048 /** 00049 * @var Tx_Extbase_Persistence_BackendInterface 00050 */ 00051 protected $backend; 00052 00053 /** 00054 * @var Tx_Extbase_Persistence_DataMapper 00055 */ 00056 protected $dataMapper; 00057 00058 /** 00059 * Sets up this test case 00060 * @return void 00061 */ 00062 public function setUp() { 00063 $this->objectManager = $this->getMock('Tx_Extbase_Object_ObjectManagerInterface'); 00064 $this->query = new Tx_Extbase_Persistence_Query('someType'); 00065 $this->query->injectObjectManager($this->objectManager); 00066 $this->querySettings = $this->getMock('Tx_Extbase_Persistence_QuerySettingsInterface'); 00067 $this->query->setQuerySettings($this->querySettings); 00068 $this->persistenceManager = $this->getMock('Tx_Extbase_Persistence_ManagerInterface'); 00069 $this->backend = $this->getMock('Tx_Extbase_Persistence_BackendInterface'); 00070 $this->backend->expects($this->any())->method('getQomFactory')->will($this->returnValue(NULL)); 00071 $this->persistenceManager->expects($this->any())->method('getBackend')->will($this->returnValue($this->backend)); 00072 $this->query->injectPersistenceManager($this->persistenceManager); 00073 $this->dataMapper = $this->getMock('Tx_Extbase_Persistence_Mapper_DataMapper'); 00074 $this->query->injectDataMapper($this->dataMapper); 00075 } 00076 00077 /** 00078 * @test 00079 */ 00080 public function executeReturnsQueryResultInstanceAndInjectsItself() { 00081 $queryResult = $this->getMock('Tx_Extbase_Persistence_QueryResult', array(), array(), '', FALSE); 00082 $this->objectManager->expects($this->once())->method('create')->with('Tx_Extbase_Persistence_QueryResultInterface', $this->query)->will($this->returnValue($queryResult)); 00083 $actualResult = $this->query->execute(); 00084 $this->assertSame($queryResult, $actualResult); 00085 } 00086 00087 /** 00088 * @test 00089 */ 00090 public function executeReturnsRawObjectDataIfRawQueryResultSettingIsTrue() { 00091 $this->querySettings->expects($this->once())->method('getReturnRawQueryResult')->will($this->returnValue(TRUE)); 00092 $this->persistenceManager->expects($this->once())->method('getObjectDataByQuery')->with($this->query)->will($this->returnValue('rawQueryResult')); 00093 $expectedResult = 'rawQueryResult'; 00094 $actualResult = $this->query->execute(); 00095 $this->assertEquals($expectedResult, $actualResult); 00096 } 00097 00098 /** 00099 * @test 00100 * @expectedException InvalidArgumentException 00101 */ 00102 public function setLimitAcceptsOnlyIntegers() { 00103 $this->query->setLimit(1.5); 00104 } 00105 00106 /** 00107 * @test 00108 * @expectedException InvalidArgumentException 00109 */ 00110 public function setLimitRejectsIntegersLessThanOne() { 00111 $this->query->setLimit(0); 00112 } 00113 00114 /** 00115 * @test 00116 * @expectedException InvalidArgumentException 00117 */ 00118 public function setOffsetAcceptsOnlyIntegers() { 00119 $this->query->setOffset(1.5); 00120 } 00121 00122 /** 00123 * @test 00124 * @expectedException InvalidArgumentException 00125 */ 00126 public function setOffsetRejectsIntegersLessThanZero() { 00127 $this->query->setOffset(-1); 00128 } 00129 00130 } 00131 ?>
1.8.0