TYPO3 API  SVNRelease
TemplateViewTest.php
Go to the documentation of this file.
00001 <?php
00002 
00003 /*                                                                        *
00004  * This script belongs to the FLOW3 package "Fluid".                      *
00005  *                                                                        *
00006  * It is free software; you can redistribute it and/or modify it under    *
00007  * the terms of the GNU Lesser General Public License as published by the *
00008  * Free Software Foundation, either version 3 of the License, or (at your *
00009  * option) any later version.                                             *
00010  *                                                                        *
00011  * This script is distributed in the hope that it will be useful, but     *
00012  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-    *
00013  * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser       *
00014  * General Public License for more details.                               *
00015  *                                                                        *
00016  * You should have received a copy of the GNU Lesser General Public       *
00017  * License along with the script.                                         *
00018  * If not, see http://www.gnu.org/licenses/lgpl.html                      *
00019  *                                                                        *
00020  * The TYPO3 project - inspiring people to share!                         *
00021  *                                                                        */
00022 
00023 include_once(dirname(__FILE__) . '/Fixtures/TransparentSyntaxTreeNode.php');
00024 include_once(dirname(__FILE__) . '/Fixtures/TemplateViewFixture.php');
00025 
00026 /**
00027  * Testcase for the TemplateView
00028  *
00029  * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
00030  */
00031 class Tx_Fluid_Tests_Unit_View_TemplateViewTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
00032 
00033     /**
00034      * @test
00035      * @author Sebastian Kurfürst <sebastian@typo3.org>
00036      */
00037     public function expandGenericPathPatternWorksWithBubblingDisabledAndFormatNotOptional() {
00038         $mockControllerContext = $this->setupMockControllerContextForPathResolving('MyPackage', NULL, 'My', 'html');
00039 
00040         $templateView = $this->getAccessibleMock('Tx_Fluid_View_TemplateView', array('getTemplateRootPath', 'getPartialRootPath', 'getLayoutRootPath'), array(), '', FALSE);
00041         $templateView->_set('controllerContext', $mockControllerContext);
00042         $templateView->expects($this->any())->method('getTemplateRootPath')->will($this->returnValue('Resources/Private/'));
00043 
00044         $expected = array('Resources/Private/Templates/My/@action.html');
00045         $actual = $templateView->_call('expandGenericPathPattern', '@templateRoot/Templates/@subpackage/@controller/@action.@format', FALSE, FALSE);
00046         $this->assertEquals($expected, $actual);
00047     }
00048 
00049 
00050     /**
00051      * @test
00052      * @author Sebastian Kurfürst <sebastian@typo3.org>
00053      */
00054     public function expandGenericPathPatternWorksWithSubpackageAndBubblingDisabledAndFormatNotOptional() { $this->markTestIncomplete("Not implemented in v4");
00055         $mockControllerContext = $this->setupMockControllerContextForPathResolving('MyPackage', 'MySubPackage', 'My', 'html');
00056 
00057         $templateView = $this->getAccessibleMock('Tx_Fluid_View_TemplateView', array('getTemplateRootPath', 'getPartialRootPath', 'getLayoutRootPath'), array(), '', FALSE);
00058         $templateView->_set('controllerContext', $mockControllerContext);
00059         $templateView->expects($this->any())->method('getTemplateRootPath')->will($this->returnValue('Resources/Private/'));
00060         $actual = $templateView->_call('expandGenericPathPattern', '@templateRoot/Templates/@subpackage/@controller/@action.@format', FALSE, FALSE);
00061 
00062         $expected = array(
00063             'Resources/Private/Templates/MySubPackage/My/@action.html'
00064         );
00065         $this->assertEquals($expected, $actual);
00066     }
00067 
00068     /**
00069      * @test
00070      * @author Sebastian Kurfürst <sebastian@typo3.org>
00071      */
00072     public function expandGenericPathPatternWorksWithSubpackageAndBubblingDisabledAndFormatOptional() { $this->markTestIncomplete("Not implemented in v4");
00073         $mockControllerContext = $this->setupMockControllerContextForPathResolving('MyPackage', 'MySubPackage', 'My', 'html');
00074 
00075         $templateView = $this->getAccessibleMock('Tx_Fluid_View_TemplateView', array('getTemplateRootPath', 'getPartialRootPath', 'getLayoutRootPath'), array(), '', FALSE);
00076         $templateView->_set('controllerContext', $mockControllerContext);
00077         $templateView->expects($this->any())->method('getTemplateRootPath')->will($this->returnValue('Resources/Private/'));
00078         $actual = $templateView->_call('expandGenericPathPattern', '@templateRoot/Templates/@subpackage/@controller/@action.@format', FALSE, TRUE);
00079 
00080         $expected = array(
00081             'Resources/Private/Templates/MySubPackage/My/@action.html',
00082             'Resources/Private/Templates/MySubPackage/My/@action'
00083         );
00084         $this->assertEquals($expected, $actual);
00085     }
00086 
00087     /**
00088      * @test
00089      * @author Sebastian Kurfürst <sebastian@typo3.org>
00090      */
00091     public function expandGenericPathPatternWorksWithSubpackageAndBubblingEnabledAndFormatOptional() { $this->markTestIncomplete("Not implemented in v4");
00092         $mockControllerContext = $this->setupMockControllerContextForPathResolving('MyPackage', 'MySubPackage', 'My', 'html');
00093 
00094         $templateView = $this->getAccessibleMock('Tx_Fluid_View_TemplateView', array('getTemplateRootPath', 'getPartialRootPath', 'getLayoutRootPath'), array(), '', FALSE);
00095         $templateView->_set('controllerContext', $mockControllerContext);
00096         $templateView->expects($this->any())->method('getTemplateRootPath')->will($this->returnValue('Resources/Private/'));
00097         $actual = $templateView->_call('expandGenericPathPattern', '@templateRoot/Templates/@subpackage/@controller/@action.@format', TRUE, TRUE);
00098 
00099         $expected = array(
00100             'Resources/Private/Templates/MySubPackage/My/@action.html',
00101             'Resources/Private/Templates/MySubPackage/My/@action',
00102             'Resources/Private/Templates/MySubPackage/@action.html',
00103             'Resources/Private/Templates/MySubPackage/@action',
00104             'Resources/Private/Templates/@action.html',
00105             'Resources/Private/Templates/@action',
00106         );
00107         $this->assertEquals($expected, $actual);
00108     }
00109 
00110     /**
00111      * Helper to build mock controller context needed to test expandGenericPathPattern.
00112      *
00113      * @param $packageKey
00114      * @param $subPackageKey
00115      * @param $controllerClassName
00116      * @param $format
00117      *
00118      * @author Sebastian Kurfürst <sebastian@typo3.org>
00119      * @author Robert Lemke <robert@typo3.org>
00120      */
00121     protected function setupMockControllerContextForPathResolving($packageKey, $subPackageKey, $controllerName, $format) {
00122         $controllerObjectName = 'Tx_' . $packageKey . '_' . ($subPackageKey !== '' ? '_' . $subPackageKey . '_' : '') . 'Controller_' . $controllerName . 'Controller';
00123 
00124         $mockRequest = $this->getMock('Tx_Extbase_MVC_Request');
00125         $mockRequest->expects($this->any())->method('getControllerPackageKey')->will($this->returnValue($packageKey));
00126         $mockRequest->expects($this->any())->method('getControllerSubPackageKey')->will($this->returnValue($subPackageKey));
00127         $mockRequest->expects($this->any())->method('getControllerName')->will($this->returnValue($controllerName));
00128         $mockRequest->expects($this->any())->method('getControllerObjectName')->will($this->returnValue($controllerObjectName));
00129         $mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue($format));
00130 
00131         $mockControllerContext = $this->getMock('Tx_Extbase_MVC_Controller_ControllerContext', array('getRequest'), array(), '', FALSE);
00132         $mockControllerContext->expects($this->any())->method('getRequest')->will($this->returnValue($mockRequest));
00133 
00134         return $mockControllerContext;
00135     }
00136 
00137     /**
00138      * @test
00139      * @author Sebastian Kurfürst <sebastian@typo3.org>
00140      */
00141     public function getTemplateRootPathReturnsUserSpecifiedTemplatePath() {
00142         $templateView = $this->getAccessibleMock('Tx_Fluid_View_TemplateView', array('dummy'), array(), '', FALSE);
00143         $templateView->setTemplateRootPath('/foo/bar');
00144         $expected = '/foo/bar';
00145         $actual = $templateView->_call('getTemplateRootPath');
00146         $this->assertEquals($expected, $actual, 'A set template root path was not returned correctly.');
00147     }
00148 
00149     /**
00150      * @test
00151      * @author Bastian Waidelich <bastian@typo3.org>
00152      */
00153     public function getPartialRootPathReturnsUserSpecifiedPartialPath() {
00154         $templateView = $this->getAccessibleMock('Tx_Fluid_View_TemplateView', array('dummy'), array(), '', FALSE);
00155         $templateView->setPartialRootPath('/foo/bar');
00156         $expected = '/foo/bar';
00157         $actual = $templateView->_call('getPartialRootPath');
00158         $this->assertEquals($expected, $actual, 'A set partial root path was not returned correctly.');
00159     }
00160 
00161     /**
00162      * @test
00163      * @author Bastian Waidelich <bastian@typo3.org>
00164      */
00165     public function getLayoutRootPathReturnsUserSpecifiedPartialPath() {
00166         $templateView = $this->getAccessibleMock('Tx_Fluid_View_TemplateView', array('dummy'), array(), '', FALSE);
00167         $templateView->setLayoutRootPath('/foo/bar');
00168         $expected = '/foo/bar';
00169         $actual = $templateView->_call('getLayoutRootPath');
00170         $this->assertEquals($expected, $actual, 'A set partial root path was not returned correctly.');
00171     }
00172 
00173     /**
00174      * @test
00175      * @author Sebastian Kurfürst <sebastian@typo3.org>
00176      */
00177     public function pathToPartialIsResolvedCorrectly() {
00178         $this->markTestSkipped('Needs to be finished');
00179         vfsStreamWrapper::register();
00180         mkdir('vfs://MyTemplates');
00181         file_put_contents('vfs://MyTemplates/MyCoolAction.html', 'contentsOfMyCoolAction');
00182         $mockRootDirectory = vfsStreamDirectory::create('ExamplePackagePath/Resources/Private/Partials');
00183         $mockRootDirectory->getChild('Resources/Private/Partials')->addChild('Partials');
00184         vfsStreamWrapper::setRoot($mockRootDirectory);
00185 
00186         $this->getAccessibleMock('Tx_Fluid_Core_Parser_TemplateParser', array(''), array(), '', FALSE);
00187     }
00188 
00189     /**
00190      * @test
00191      * @author Robert Lemke <robert@typo3.org>
00192      */
00193     public function resolveTemplatePathAndFilenameChecksDifferentPathPatternsAndReturnsTheFirstPathWhichExists() { $this->markTestIncomplete("Not implemented in v4");
00194         vfsStreamWrapper::register();
00195         mkdir('vfs://MyTemplates');
00196         file_put_contents('vfs://MyTemplates/MyCoolAction.html', 'contentsOfMyCoolAction');
00197 
00198         $paths = array(
00199              'vfs://NonExistantDir/UnknowFile.html',
00200              'vfs://MyTemplates/@action.html'
00201         );
00202 
00203         $templateView = $this->getAccessibleMock('Tx_Fluid_View_TemplateView', array('expandGenericPathPattern'), array(), '', FALSE);
00204         $templateView->expects($this->once())->method('expandGenericPathPattern')->with('@templateRoot/@subpackage/@controller/@action.@format', FALSE, FALSE)->will($this->returnValue($paths));
00205 
00206         $templateView->setTemplateRootPath('MyTemplates');
00207         $templateView->setPartialRootPath('MyPartials');
00208         $templateView->setLayoutRootPath('MyLayouts');
00209 
00210         $this->assertSame('contentsOfMyCoolAction', $templateView->_call('getTemplateSource', 'myCoolAction'));
00211 
00212     }
00213 
00214     /**
00215      * @test
00216      * @author Robert Lemke <robert@typo3.org>
00217      */
00218     public function resolveTemplatePathAndFilenameReturnsTheExplicitlyConfiguredTemplatePathAndFilename() { $this->markTestIncomplete("Not implemented in v4");
00219         vfsStreamWrapper::register();
00220         mkdir('vfs://MyTemplates');
00221         file_put_contents('vfs://MyTemplates/MyCoolAction.html', 'contentsOfMyCoolAction');
00222 
00223         $templateView = $this->getAccessibleMock('Tx_Fluid_View_TemplateView', array('dummy'), array(), '', FALSE);
00224         $templateView->_set('templatePathAndFilename', 'vfs://MyTemplates/MyCoolAction.html');
00225 
00226         $this->assertSame('contentsOfMyCoolAction', $templateView->_call('getTemplateSource'));
00227     }
00228 }
00229 
00230 ?>