PageRenderTime 39ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/t3lib/t3lib_tcemainTest.php

https://github.com/foxsoft/typo3v4core
PHP | 233 lines | 108 code | 37 blank | 88 comment | 0 complexity | 10272cedde2ca7e81862c5a829d882c0 MD5 | raw file
Possible License(s): Apache-2.0
  1. <?php
  2. /***************************************************************
  3. * Copyright notice
  4. *
  5. * (c) 2009-2010 Oliver Klee (typo3-coding@oliverklee.de)
  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. require_once(PATH_t3lib . 'class.t3lib_beuserauth.php');
  25. require_once(PATH_t3lib . 'class.t3lib_tcemain.php');
  26. /**
  27. * Testcase for the t3lib_TCEmain class in the TYPO3 core.
  28. *
  29. * @package TYPO3
  30. * @subpackage t3lib
  31. *
  32. * @author Oliver Klee <typo3-coding@oliverklee.de>
  33. */
  34. class t3lib_tcemainTest extends tx_phpunit_testcase {
  35. /**
  36. * @var boolean
  37. */
  38. protected $backupGlobals = true;
  39. /**
  40. * @var t3lib_TCEmain
  41. */
  42. private $fixture;
  43. /**
  44. * @var t3lib_beUserAuth a mock logged-in back-end user
  45. */
  46. private $backEndUser;
  47. public function setUp() {
  48. $this->backEndUser = $this->getMock('t3lib_beUserAuth');
  49. $this->fixture = new t3lib_TCEmain();
  50. $this->fixture->start(array(), '', $this->backEndUser);
  51. }
  52. public function tearDown() {
  53. unset(
  54. $this->fixture->BE_USER, $this->fixture, $this->backEndUser
  55. );
  56. }
  57. //////////////////////////////////////
  58. // Tests for the basic functionality
  59. //////////////////////////////////////
  60. /**
  61. * @test
  62. */
  63. public function fixtureCanBeCreated() {
  64. $this->assertTrue(
  65. $this->fixture instanceof t3lib_TCEmain
  66. );
  67. }
  68. //////////////////////////////////////////
  69. // Test concerning checkModifyAccessList
  70. //////////////////////////////////////////
  71. /**
  72. * @test
  73. */
  74. public function adminIsAllowedToModifyNonAdminTable() {
  75. $this->fixture->admin = true;
  76. $this->assertTrue(
  77. $this->fixture->checkModifyAccessList('tt_content')
  78. );
  79. }
  80. /**
  81. * @test
  82. */
  83. public function nonAdminIsNorAllowedToModifyNonAdminTable() {
  84. $this->fixture->admin = false;
  85. $this->assertFalse(
  86. $this->fixture->checkModifyAccessList('tt_content')
  87. );
  88. }
  89. /**
  90. * @test
  91. */
  92. public function nonAdminWithTableModifyAccessIsAllowedToModifyNonAdminTable() {
  93. $this->fixture->admin = false;
  94. $this->backEndUser->groupData['tables_modify'] = 'tt_content';
  95. $this->assertTrue(
  96. $this->fixture->checkModifyAccessList('tt_content')
  97. );
  98. }
  99. /**
  100. * @test
  101. */
  102. public function adminIsAllowedToModifyAdminTable() {
  103. $this->fixture->admin = true;
  104. $this->assertTrue(
  105. $this->fixture->checkModifyAccessList('be_users')
  106. );
  107. }
  108. /**
  109. * @test
  110. */
  111. public function nonAdminIsNotAllowedToModifyAdminTable() {
  112. $this->fixture->admin = false;
  113. $this->assertFalse(
  114. $this->fixture->checkModifyAccessList('be_users')
  115. );
  116. }
  117. /**
  118. * @test
  119. */
  120. public function nonAdminWithTableModifyAccessIsNotAllowedToModifyAdminTable() {
  121. $this->fixture->admin = false;
  122. $this->backEndUser->groupData['tables_modify'] = 'be_users';
  123. $this->assertFalse(
  124. $this->fixture->checkModifyAccessList('be_users')
  125. );
  126. }
  127. /**
  128. * @test
  129. */
  130. public function evalCheckValueDouble2() {
  131. $testData = array (
  132. '-0,5' => '-0.50',
  133. '1000' => '1000.00',
  134. '1000,10' => '1000.10',
  135. '1000,0' => '1000.00',
  136. '600.000.000,00' => '600000000.00',
  137. '60aaa00' => '6000.00',
  138. );
  139. foreach ($testData as $value => $expectedReturnValue){
  140. $returnValue = $this->fixture->checkValue_input_Eval($value, array('double2'), '');
  141. $this->assertSame(
  142. $returnValue['value'],
  143. $expectedReturnValue
  144. );
  145. }
  146. }
  147. ///////////////////////////////////////////
  148. // Tests concerning checkModifyAccessList
  149. ///////////////////////////////////////////
  150. /**
  151. * Tests whether a wrong interface on the 'checkModifyAccessList' hook throws an exception.
  152. * @test
  153. * @expectedException UnexpectedValueException
  154. * @see t3lib_TCEmain::checkModifyAccessList()
  155. */
  156. public function doesCheckModifyAccessListThrowExceptionOnWrongHookInterface() {
  157. $hookClass = uniqid('tx_coretest');
  158. eval('class ' . $hookClass . ' {}');
  159. $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkModifyAccessList'][] = $hookClass;
  160. $this->fixture->checkModifyAccessList('tt_content');
  161. }
  162. /**
  163. * Tests whether the 'checkModifyAccessList' hook is called correctly.
  164. * @test
  165. * @see t3lib_TCEmain::checkModifyAccessList()
  166. */
  167. public function doesCheckModifyAccessListHookGetsCalled() {
  168. $hookClass = uniqid('tx_coretest');
  169. $hookMock = $this->getMock(
  170. 't3lib_TCEmain_checkModifyAccessListHook',
  171. array('checkModifyAccessList'),
  172. array(),
  173. $hookClass
  174. );
  175. $hookMock->expects($this->once())->method('checkModifyAccessList');
  176. $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkModifyAccessList'][] = $hookClass;
  177. $GLOBALS['T3_VAR']['getUserObj'][$hookClass] = $hookMock;
  178. $this->fixture->checkModifyAccessList('tt_content');
  179. }
  180. /**
  181. * Tests whether the 'checkModifyAccessList' hook modifies the $accessAllowed variable.
  182. * @test
  183. * @see t3lib_TCEmain::checkModifyAccessList()
  184. */
  185. public function doesCheckModifyAccessListHookModifyAccessAllowed() {
  186. $hookClass = uniqid('tx_coretest');
  187. eval('
  188. class ' . $hookClass . ' implements t3lib_TCEmain_checkModifyAccessListHook {
  189. public function checkModifyAccessList(&$accessAllowed, $table, t3lib_TCEmain $parent) { $accessAllowed = true; }
  190. }
  191. ');
  192. $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkModifyAccessList'][] = $hookClass;
  193. $this->assertTrue($this->fixture->checkModifyAccessList('tt_content'));
  194. }
  195. }
  196. ?>