TYPO3 API  SVNRelease
t3lib_pageselectTest.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 2009-2011 Christian Kuhn <lolli@schwarzbu.ch>
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *
00017 *  This script is distributed in the hope that it will be useful,
00018 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 *  GNU General Public License for more details.
00021 *
00022 *  This copyright notice MUST APPEAR in all copies of the script!
00023 ***************************************************************/
00024 
00025 
00026 /**
00027  * Testcase for class t3lib_page
00028  *
00029  * @author Christian Kuhn <lolli@schwarzbu.ch>
00030  * @author Oliver Klee <typo3-coding@oliverklee.de>
00031  *
00032  * @package TYPO3
00033  * @subpackage t3lib
00034  */
00035 class t3lib_pageselectTest extends tx_phpunit_testcase {
00036 
00037     /**
00038      * @var t3lib_DB
00039      */
00040     protected $typo3DbBackup;
00041 
00042     /**
00043      * @var t3lib_pageSelect
00044      */
00045     protected $pageSelectObject;
00046 
00047     /**
00048      * Sets up this testcase
00049      */
00050     public function setUp() {
00051         $this->typo3DbBackup = $GLOBALS['TYPO3_DB'];
00052         $GLOBALS['TYPO3_DB'] = $this->getMock('t3lib_DB', array('exec_SELECTquery', 'sql_fetch_assoc', 'sql_free_result'));
00053 
00054         $this->pageSelectObject = new t3lib_pageSelect();
00055     }
00056 
00057     /**
00058      * Tears down this testcase
00059      */
00060     public function tearDown() {
00061         $GLOBALS['TYPO3_DB'] = $this->typo3DbBackup;
00062     }
00063 
00064     /**
00065      * Tests whether the getPage Hook is called correctly.
00066      *
00067      * @test
00068      */
00069     public function isGetPageHookCalled() {
00070             // Create a hook mock object
00071         $className = uniqid('tx_coretest');
00072         $getPageHookMock = $this->getMock(
00073             't3lib_pageSelect_getPageHook',
00074             array('getPage_preProcess'),
00075             array(),
00076             $className
00077         );
00078 
00079             // Register hook mock object
00080         $GLOBALS['T3_VAR']['getUserObj'][$className] = $getPageHookMock;
00081         $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_page.php']['getPage'][] = $className;
00082 
00083             // Test if hook is called and register a callback method to check given arguments
00084         $getPageHookMock->expects($this->once())->method('getPage_preProcess')
00085             ->will($this->returnCallback(array($this, 'isGetPagePreProcessCalledCallback')));
00086 
00087         $this->pageSelectObject->getPage(42, FALSE);
00088     }
00089 
00090     /**
00091      * Handles the arguments that have been sent to the getPage_preProcess hook
00092      */
00093     public function isGetPagePreProcessCalledCallback() {
00094         list($uid, $disableGroupAccessCheck, $parent) = func_get_args();
00095 
00096         $this->assertEquals(42, $uid);
00097         $this->assertFalse($disableGroupAccessCheck);
00098         $this->assertTrue($parent instanceof t3lib_pageSelect);
00099     }
00100 
00101 
00102     /////////////////////////////////////////
00103     // Tests concerning getPathFromRootline
00104     /////////////////////////////////////////
00105 
00106     /**
00107      * @test
00108      */
00109     public function getPathFromRootLineForEmptyRootLineReturnsEmptyString() {
00110         $this->assertEquals(
00111             '',
00112             $this->pageSelectObject->getPathFromRootline(array())
00113         );
00114     }
00115 
00116 
00117     ///////////////////////////////
00118     // Tests concerning getExtURL
00119     ///////////////////////////////
00120 
00121     /**
00122      * @test
00123      */
00124     public function getExtUrlForDokType2ReturnsFalse() {
00125         $this->assertEquals(
00126             FALSE,
00127             $this->pageSelectObject->getExtURL(array('doktype' => t3lib_pageSelect::DOKTYPE_ADVANCED))
00128         );
00129     }
00130 
00131     /**
00132      * @test
00133      */
00134     public function getExtUrlForDokType3AndUrlType1AddsHttpSchemeToUrl() {
00135         $this->assertEquals(
00136             'http://www.example.com',
00137             $this->pageSelectObject->getExtURL(
00138                 array(
00139                     'doktype' => t3lib_pageSelect::DOKTYPE_LINK,
00140                     'urltype' => 1,
00141                     'url' => 'www.example.com',
00142                 )
00143             )
00144         );
00145     }
00146 
00147     /**
00148      * @test
00149      */
00150     public function getExtUrlForDokType3AndUrlType0PrependsSiteUrl() {
00151         $this->assertEquals(
00152             t3lib_div::getIndpEnv('TYPO3_SITE_URL') . 'hello/world/',
00153             $this->pageSelectObject->getExtURL(
00154                 array(
00155                     'doktype' => t3lib_pageSelect::DOKTYPE_LINK,
00156                     'urltype' => 0,
00157                     'url' => 'hello/world/',
00158                 )
00159             )
00160         );
00161     }
00162 }
00163 ?>