[TASK] Removes eval() in core data handler unit tests 50/40450/3
authorPierrick Caillon <pierrick.caillon@plan-net.fr>
Thu, 18 Jun 2015 13:48:45 +0000 (15:48 +0200)
committerMarkus Klein <markus.klein@typo3.org>
Thu, 18 Jun 2015 21:16:32 +0000 (23:16 +0200)
Adds fixtures for InvalidHook and AllowAccessHook and removes the ugly
usage of eval() from DataHandlerTest in unit tests.

Resolves: #67606
Related: #67468
Releases: master
Change-Id: Ibf14efcc966659ff813ac9d8a3a00c6ccbc47da6
Reviewed-on: http://review.typo3.org/40450
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/core/Tests/Unit/DataHandling/DataHandlerTest.php
typo3/sysext/core/Tests/Unit/DataHandling/Fixtures/AllowAccessHookFixture.php [new file with mode: 0644]
typo3/sysext/core/Tests/Unit/DataHandling/Fixtures/InvalidHookFixture.php [new file with mode: 0644]

index c45d4b0..cd8122e 100644 (file)
@@ -16,6 +16,8 @@ namespace TYPO3\CMS\Core\Tests\Unit\DataHandler;
 
 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
 use TYPO3\CMS\Core\DataHandling\DataHandler;
+use TYPO3\CMS\Core\Tests\Unit\DataHandling\Fixtures\AllowAccessHookFixture;
+use TYPO3\CMS\Core\Tests\Unit\DataHandling\Fixtures\InvalidHookFixture;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Database\DatabaseConnection;
 
@@ -267,9 +269,7 @@ class DataHandlerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @expectedException \UnexpectedValueException
         */
        public function doesCheckModifyAccessListThrowExceptionOnWrongHookInterface() {
-               $hookClass = $this->getUniqueId('tx_coretest');
-               eval('class ' . $hookClass . ' {}');
-               $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkModifyAccessList'][] = $hookClass;
+               $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkModifyAccessList'][] = InvalidHookFixture::class;
                $this->subject->checkModifyAccessList('tt_content');
        }
 
@@ -293,13 +293,7 @@ class DataHandlerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function doesCheckModifyAccessListHookModifyAccessAllowed() {
-               $hookClass = $this->getUniqueId('tx_coretest');
-               eval('
-                       class ' . $hookClass . ' implements \\TYPO3\\CMS\\Core\\DataHandling\\DataHandlerCheckModifyAccessListHookInterface {
-                               public function checkModifyAccessList(&$accessAllowed, $table, \\TYPO3\\CMS\\Core\\DataHandling\\DataHandler $parent) { $accessAllowed = TRUE; }
-                       }
-               ');
-               $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkModifyAccessList'][] = $hookClass;
+               $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkModifyAccessList'][] = AllowAccessHookFixture::class;
                $this->assertTrue($this->subject->checkModifyAccessList('tt_content'));
        }
 
diff --git a/typo3/sysext/core/Tests/Unit/DataHandling/Fixtures/AllowAccessHookFixture.php b/typo3/sysext/core/Tests/Unit/DataHandling/Fixtures/AllowAccessHookFixture.php
new file mode 100644 (file)
index 0000000..8c1860d
--- /dev/null
@@ -0,0 +1,35 @@
+<?php
+namespace TYPO3\CMS\Core\Tests\Unit\DataHandling\Fixtures;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use TYPO3\CMS\Core\DataHandling\DataHandler;
+use TYPO3\CMS\Core\DataHandling\DataHandlerCheckModifyAccessListHookInterface;
+
+/**
+ * Fixture hook allow access
+ */
+class AllowAccessHookFixture implements DataHandlerCheckModifyAccessListHookInterface {
+
+       /**
+        *  Check modify access list
+        *
+        * @param bool &$accessAllowed
+        * @param string $table
+        * @param DataHandler $parent
+        */
+       public function checkModifyAccessList(&$accessAllowed, $table, DataHandler $parent) {
+               $accessAllowed = TRUE;
+       }
+}
diff --git a/typo3/sysext/core/Tests/Unit/DataHandling/Fixtures/InvalidHookFixture.php b/typo3/sysext/core/Tests/Unit/DataHandling/Fixtures/InvalidHookFixture.php
new file mode 100644 (file)
index 0000000..b3218e4
--- /dev/null
@@ -0,0 +1,21 @@
+<?php
+namespace TYPO3\CMS\Core\Tests\Unit\DataHandling\Fixtures;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+/**
+ * Fixture invalid hook
+ */
+class InvalidHookFixture {
+}