Follow-up to feature #2278: Added unit tests for the new checkModifyAccessList hook
authorOliver Hader <oliver.hader@typo3.org>
Thu, 17 Sep 2009 19:26:30 +0000 (19:26 +0000)
committerOliver Hader <oliver.hader@typo3.org>
Thu, 17 Sep 2009 19:26:30 +0000 (19:26 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@5959 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
tests/t3lib/t3lib_tcemain_testcase.php

index 4a0584e..4aa18da 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -13,6 +13,7 @@
        * Fixed bug #11985: Optimize disposal of t3lib_PageRenderer (thanks to Steffen Kamper)
        * Added feature #11669: Provide a reason for why $TSFE->set_no_cache() has been triggered (thanks to Michael Stucki)
        * Added feature #2278: Add hook to t3lib_TCEmain::checkModifyAccessList() (thanks to Michael Stucki)
+       * Follow-up to feature #2278: Added unit tests for the new checkModifyAccessList hook
 
 2009-09-17  Sebastian Kurfuerst  <sebastian@typo3.org>
 
index 7c534b4..9f8b82b 100644 (file)
@@ -36,6 +36,11 @@ require_once(PATH_t3lib . 'class.t3lib_tcemain.php');
  */
 class t3lib_tcemain_testcase extends tx_phpunit_testcase {
        /**
+        * @var boolean
+        */
+       protected $backupGlobals = true;
+
+       /**
         * @var t3lib_TCEmain
         */
        private $fixture;
@@ -197,5 +202,58 @@ class t3lib_tcemain_testcase extends tx_phpunit_testcase {
                }
        }
 
+       /**
+        * Tests whether a wrong interface on the 'checkModifyAccessList' hook throws an exception.
+        * @test
+        * @expectedException UnexpectedValueException
+        * @see t3lib_TCEmain::checkModifyAccessList()
+        */
+       public function doesCheckModifyAccessListThrowExceptionOnWrongHookInterface() {
+               $hookClass = uniqid('tx_coretest');
+               eval('class ' . $hookClass . ' {}');
+
+               $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkModifyAccessList'][] = $hookClass;
+
+               $this->fixture->checkModifyAccessList('tt_content');
+       }
+
+       /**
+        * Tests whether the 'checkModifyAccessList' hook is called correctly.
+        * @test
+        * @see t3lib_TCEmain::checkModifyAccessList()
+        */
+       public function doesCheckModifyAccessListHookGetsCalled() {
+               $hookClass = uniqid('tx_coretest');
+               $hookMock = $this->getMock(
+                       't3lib_TCEmain_checkModifyAccessListHook',
+                       array('checkModifyAccessList'),
+                       array(),
+                       $hookClass
+               );
+               $hookMock->expects($this->once())->method('checkModifyAccessList');
+
+               $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkModifyAccessList'][] = $hookClass;
+               $GLOBALS['T3_VAR']['getUserObj'][$hookClass] = $hookMock;
+
+               $this->fixture->checkModifyAccessList('tt_content');
+       }
+
+       /**
+        * Tests whether the 'checkModifyAccessList' hook modifies the $accessAllowed variable.
+        * @test
+        * @see t3lib_TCEmain::checkModifyAccessList()
+        */
+       public function doesCheckModifyAccessListHookModifyAccessAllowed() {
+               $hookClass = uniqid('tx_coretest');
+               eval('
+                       class ' . $hookClass . ' implements t3lib_TCEmain_checkModifyAccessListHook {
+                               public function checkModifyAccessList(&$accessAllowed, $table, t3lib_TCEmain $parent) { $accessAllowed = true; }
+                       }
+               ');
+
+               $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkModifyAccessList'][] = $hookClass;
+
+               $this->assertTrue($this->fixture->checkModifyAccessList('tt_content'));
+       }
 }
 ?>