[TASK] Add unit test for t3lib_autoloader
authorAndreas Wolf <andreas.wolf@ikt-werk.de>
Sat, 9 Jul 2011 14:10:22 +0000 (16:10 +0200)
committerSusanne Moog <typo3@susannemoog.de>
Sat, 9 Jul 2011 20:56:42 +0000 (22:56 +0200)
Change-Id: Id8b4d1c50ab17bd0cd4278dd6e6e487937b1c66d
Resolves: #28037
Releases: 4.6
Reviewed-on: http://review.typo3.org/3196
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
Reviewed-by: Susanne Moog
Tested-by: Susanne Moog
tests/t3lib/class.t3lib_autoloaderTest.php [new file with mode: 0644]

diff --git a/tests/t3lib/class.t3lib_autoloaderTest.php b/tests/t3lib/class.t3lib_autoloaderTest.php
new file mode 100644 (file)
index 0000000..870a030
--- /dev/null
@@ -0,0 +1,92 @@
+<?php
+/***************************************************************
+ * Copyright notice
+ *
+ * (c) 2011 Andreas Wolf <andreas.wolf@ikt-werk.de>
+ * All rights reserved
+ *
+ * This script is part of the TYPO3 project. The TYPO3 project is
+ * free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * The GNU General Public License can be found at
+ * http://www.gnu.org/copyleft/gpl.html.
+ *
+ * This script is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * Testcase for the t3lib_autoloader class in the TYPO3 Core.
+ *
+ * @package TYPO3
+ * @subpackage t3lib
+ *
+ * @author Andreas Wolf <andreas.wolf@ikt-werk.de>
+ */
+class t3lib_autoloaderTest extends Tx_Phpunit_TestCase {
+
+       /**
+        * @var array Register of temporary extensions in typo3temp
+        */
+       protected $fakedExtensions = array();
+
+       /**
+        * Clean up
+        */
+       public function tearDown() {
+               foreach ($fakedExtensions as $extension) {
+                       t3lib_div::rmdir(PATH_site . 'typo3temp/' . $extension, TRUE);
+               }
+       }
+
+       /**
+        * Creates a fake extension inside typo3temp/. No configuration is created,
+        * just the folder, plus the extension is registered in $TYPO3_LOADED_EXT
+        *
+        * @return string The extension key
+        */
+       protected function createFakeExtension() {
+               $extKey = uniqid('testing');
+               $absExtPath = PATH_site . "typo3temp/$extKey/";
+               $relPath = "typo3temp/$extKey/";
+               t3lib_div::mkdir($absExtPath);
+
+               $GLOBALS['TYPO3_LOADED_EXT'][$extKey] = array(
+                       'siteRelPath' => $relPath
+               );
+
+               $this->fakedExtensions[] = $extKey;
+               t3lib_extMgm::clearExtensionKeyMap();
+
+               return $extKey;
+       }
+
+       /**
+        * @test
+        */
+       public function extensionAutoloadFileIsIncludedIfAvailable() {
+               $extKey = $this->createFakeExtension();
+               $extPath = PATH_site . "typo3temp/$extKey/";
+               $autoloaderFile = $extPath . "ext_autoload.php";
+
+               $class = strtolower("tx_${extKey}_" . uniqid(''));
+               $file = $extPath . uniqid('') . '.php';
+
+               file_put_contents($file, "<?php\n\nthrow new RuntimeException('', 1310203812);\n\n?>");
+               file_put_contents($autoloaderFile, "<?php\n\nreturn array('$class' => '$file');\n\n?>");
+
+                       // Expect the exception of the file to be thrown
+               $this->setExpectedException('RuntimeException', '', 1310203812);
+               t3lib_autoloader::autoload($class);
+       }
+}
+
+
+?>
\ No newline at end of file