2 /***************************************************************
5 * (c) 2009-2011 Christian Kuhn <lolli@schwarzbu.ch>
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
27 * Testcase for class t3lib_page
29 * @author Christian Kuhn <lolli@schwarzbu.ch>
30 * @author Oliver Klee <typo3-coding@oliverklee.de>
35 class t3lib_pageselectTest
extends tx_phpunit_testcase
{
40 protected $typo3DbBackup;
43 * @var t3lib_pageSelect
45 protected $pageSelectObject;
48 * Sets up this testcase
50 public function setUp() {
51 $this->typo3DbBackup
= $GLOBALS['TYPO3_DB'];
52 $GLOBALS['TYPO3_DB'] = $this->getMock('t3lib_DB', array('exec_SELECTquery', 'sql_fetch_assoc', 'sql_free_result'));
54 $this->pageSelectObject
= new t3lib_pageSelect();
58 * Tears down this testcase
60 public function tearDown() {
61 $GLOBALS['TYPO3_DB'] = $this->typo3DbBackup
;
65 * Tests whether the getPage Hook is called correctly.
69 public function isGetPageHookCalled() {
70 // Create a hook mock object
71 $className = uniqid('tx_coretest');
72 $getPageHookMock = $this->getMock(
73 't3lib_pageSelect_getPageHook',
74 array('getPage_preProcess'),
79 // Register hook mock object
80 $GLOBALS['T3_VAR']['getUserObj'][$className] = $getPageHookMock;
81 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_page.php']['getPage'][] = $className;
83 // Test if hook is called and register a callback method to check given arguments
84 $getPageHookMock->expects($this->once())->method('getPage_preProcess')
85 ->will($this->returnCallback(array($this, 'isGetPagePreProcessCalledCallback')));
87 $this->pageSelectObject
->getPage(42, FALSE);
91 * Handles the arguments that have been sent to the getPage_preProcess hook
93 public function isGetPagePreProcessCalledCallback() {
94 list($uid, $disableGroupAccessCheck, $parent) = func_get_args();
96 $this->assertEquals(42, $uid);
97 $this->assertFalse($disableGroupAccessCheck);
98 $this->assertTrue($parent instanceof t3lib_pageSelect
);
102 /////////////////////////////////////////
103 // Tests concerning getPathFromRootline
104 /////////////////////////////////////////
109 public function getPathFromRootLineForEmptyRootLineReturnsEmptyString() {
112 $this->pageSelectObject
->getPathFromRootline(array())
117 ///////////////////////////////
118 // Tests concerning getExtURL
119 ///////////////////////////////
124 public function getExtUrlForDokType2ReturnsFalse() {
127 $this->pageSelectObject
->getExtURL(array('doktype' => t3lib_pageSelect
::DOKTYPE_ADVANCED
))
134 public function getExtUrlForDokType3AndUrlType1AddsHttpSchemeToUrl() {
136 'http://www.example.com',
137 $this->pageSelectObject
->getExtURL(
139 'doktype' => t3lib_pageSelect
::DOKTYPE_LINK
,
141 'url' => 'www.example.com',
150 public function getExtUrlForDokType3AndUrlType0PrependsSiteUrl() {
152 t3lib_div
::getIndpEnv('TYPO3_SITE_URL') . 'hello/world/',
153 $this->pageSelectObject
->getExtURL(
155 'doktype' => t3lib_pageSelect
::DOKTYPE_LINK
,
157 'url' => 'hello/world/',