[TASK] Add prefix "class." to all unit test files which contain classes.
[Packages/TYPO3.CMS.git] / tests / t3lib / class.t3lib_pageselectTest.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009-2011 Christian Kuhn <lolli@schwarzbu.ch>
6 * All rights reserved
7 *
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.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
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.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25
26 /**
27 * Testcase for class t3lib_page
28 *
29 * @author Christian Kuhn <lolli@schwarzbu.ch>
30 * @author Oliver Klee <typo3-coding@oliverklee.de>
31 *
32 * @package TYPO3
33 * @subpackage t3lib
34 */
35 class t3lib_pageselectTest extends tx_phpunit_testcase {
36
37 /**
38 * @var t3lib_DB
39 */
40 protected $typo3DbBackup;
41
42 /**
43 * @var t3lib_pageSelect
44 */
45 protected $pageSelectObject;
46
47 /**
48 * Sets up this testcase
49 */
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'));
53
54 $this->pageSelectObject = new t3lib_pageSelect();
55 }
56
57 /**
58 * Tears down this testcase
59 */
60 public function tearDown() {
61 $GLOBALS['TYPO3_DB'] = $this->typo3DbBackup;
62 }
63
64 /**
65 * Tests whether the getPage Hook is called correctly.
66 *
67 * @test
68 */
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'),
75 array(),
76 $className
77 );
78
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;
82
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')));
86
87 $this->pageSelectObject->getPage(42, FALSE);
88 }
89
90 /**
91 * Handles the arguments that have been sent to the getPage_preProcess hook
92 */
93 public function isGetPagePreProcessCalledCallback() {
94 list($uid, $disableGroupAccessCheck, $parent) = func_get_args();
95
96 $this->assertEquals(42, $uid);
97 $this->assertFalse($disableGroupAccessCheck);
98 $this->assertTrue($parent instanceof t3lib_pageSelect);
99 }
100
101
102 /////////////////////////////////////////
103 // Tests concerning getPathFromRootline
104 /////////////////////////////////////////
105
106 /**
107 * @test
108 */
109 public function getPathFromRootLineForEmptyRootLineReturnsEmptyString() {
110 $this->assertEquals(
111 '',
112 $this->pageSelectObject->getPathFromRootline(array())
113 );
114 }
115
116
117 ///////////////////////////////
118 // Tests concerning getExtURL
119 ///////////////////////////////
120
121 /**
122 * @test
123 */
124 public function getExtUrlForDokType2ReturnsFalse() {
125 $this->assertEquals(
126 FALSE,
127 $this->pageSelectObject->getExtURL(array('doktype' => t3lib_pageSelect::DOKTYPE_ADVANCED))
128 );
129 }
130
131 /**
132 * @test
133 */
134 public function getExtUrlForDokType3AndUrlType1AddsHttpSchemeToUrl() {
135 $this->assertEquals(
136 'http://www.example.com',
137 $this->pageSelectObject->getExtURL(
138 array(
139 'doktype' => t3lib_pageSelect::DOKTYPE_LINK,
140 'urltype' => 1,
141 'url' => 'www.example.com',
142 )
143 )
144 );
145 }
146
147 /**
148 * @test
149 */
150 public function getExtUrlForDokType3AndUrlType0PrependsSiteUrl() {
151 $this->assertEquals(
152 t3lib_div::getIndpEnv('TYPO3_SITE_URL') . 'hello/world/',
153 $this->pageSelectObject->getExtURL(
154 array(
155 'doktype' => t3lib_pageSelect::DOKTYPE_LINK,
156 'urltype' => 0,
157 'url' => 'hello/world/',
158 )
159 )
160 );
161 }
162 }
163 ?>