PageRenderTime 48ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/t3lib/t3lib_pageselectTest.php

https://github.com/foxsoft/typo3v4core
PHP | 163 lines | 70 code | 21 blank | 72 comment | 0 complexity | 47a758489f0a918b1eb2418d1103d874 MD5 | raw file
Possible License(s): Apache-2.0
  1. <?php
  2. /***************************************************************
  3. * Copyright notice
  4. *
  5. * (c) 2009-2010 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. * Testcase for class t3lib_page
  26. *
  27. * @author Christian Kuhn <lolli@schwarzbu.ch>
  28. * @author Oliver Klee <typo3-coding@oliverklee.de>
  29. *
  30. * @package TYPO3
  31. * @subpackage t3lib
  32. */
  33. class t3lib_pageselectTest extends tx_phpunit_testcase {
  34. /**
  35. * @var t3lib_DB
  36. */
  37. protected $typo3DbBackup;
  38. /**
  39. * @var t3lib_pageSelect
  40. */
  41. protected $pageSelectObject;
  42. /**
  43. * Sets up this testcase
  44. */
  45. public function setUp() {
  46. $this->typo3DbBackup = $GLOBALS['TYPO3_DB'];
  47. $GLOBALS['TYPO3_DB'] = $this->getMock('t3lib_DB', array('exec_SELECTquery', 'sql_fetch_assoc', 'sql_free_result'));
  48. $this->pageSelectObject = new t3lib_pageSelect();
  49. }
  50. /**
  51. * Tears down this testcase
  52. */
  53. public function tearDown() {
  54. $GLOBALS['TYPO3_DB'] = $this->typo3DbBackup;
  55. }
  56. /**
  57. * Tests whether the getPage Hook is called correctly.
  58. *
  59. * @test
  60. */
  61. public function isGetPageHookCalled() {
  62. // Create a hook mock object
  63. $className = uniqid('tx_coretest');
  64. $getPageHookMock = $this->getMock(
  65. 't3lib_pageSelect_getPageHook',
  66. array('getPage_preProcess'),
  67. array(),
  68. $className
  69. );
  70. // Register hook mock object
  71. $GLOBALS['T3_VAR']['getUserObj'][$className] = $getPageHookMock;
  72. $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_page.php']['getPage'][] = $className;
  73. // Test if hook is called and register a callback method to check given arguments
  74. $getPageHookMock->expects($this->once())->method('getPage_preProcess')
  75. ->will($this->returnCallback(array($this, 'isGetPagePreProcessCalledCallback')));
  76. $this->pageSelectObject->getPage(42, FALSE);
  77. }
  78. /**
  79. * Handles the arguments that have been sent to the getPage_preProcess hook
  80. */
  81. public function isGetPagePreProcessCalledCallback() {
  82. list($uid, $disableGroupAccessCheck, $parent) = func_get_args();
  83. $this->assertEquals(42, $uid);
  84. $this->assertFalse($disableGroupAccessCheck);
  85. $this->assertTrue($parent instanceof t3lib_pageSelect);
  86. }
  87. /////////////////////////////////////////
  88. // Tests concerning getPathFromRootline
  89. /////////////////////////////////////////
  90. /**
  91. * @test
  92. */
  93. public function getPathFromRootLineForEmptyRootLineReturnsEmptyString() {
  94. $this->assertEquals(
  95. '',
  96. $this->pageSelectObject->getPathFromRootline(array())
  97. );
  98. }
  99. ///////////////////////////////
  100. // Tests concerning getExtURL
  101. ///////////////////////////////
  102. /**
  103. * @test
  104. */
  105. public function getExtUrlForDokType2ReturnsFalse() {
  106. $this->assertEquals(
  107. FALSE,
  108. $this->pageSelectObject->getExtURL(array('doktype' => 2))
  109. );
  110. }
  111. /**
  112. * @test
  113. */
  114. public function getExtUrlForDokType3AndUrlType1AddsHttpSchemeToUrl() {
  115. $this->assertEquals(
  116. 'http://www.example.com',
  117. $this->pageSelectObject->getExtURL(
  118. array(
  119. 'doktype' => 3,
  120. 'urltype' => 1,
  121. 'url' => 'www.example.com',
  122. )
  123. )
  124. );
  125. }
  126. /**
  127. * @test
  128. */
  129. public function getExtUrlForDokType3AndUrlType0PrependsSiteUrl() {
  130. $this->assertEquals(
  131. t3lib_div::getIndpEnv('TYPO3_SITE_URL') . 'hello/world/',
  132. $this->pageSelectObject->getExtURL(
  133. array(
  134. 'doktype' => 3,
  135. 'urltype' => 0,
  136. 'url' => 'hello/world/',
  137. )
  138. )
  139. );
  140. }
  141. }
  142. ?>