76573bc3ce9b793466b83fcd901bb65a8ea71e3a
[Packages/TYPO3.CMS.git] / tests / t3lib / class.t3lib_autoloaderTest.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2011 Andreas Wolf <andreas.wolf@ikt-werk.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
25 /**
26 * Testcase for the t3lib_autoloader class in the TYPO3 Core.
27 *
28 * @package TYPO3
29 * @subpackage t3lib
30 *
31 * @author Andreas Wolf <andreas.wolf@ikt-werk.de>
32 */
33 class t3lib_autoloaderTest extends Tx_Phpunit_TestCase {
34
35 /**
36 * @var array Register of temporary extensions in typo3temp
37 */
38 protected $fakedExtensions = array();
39
40 /**
41 * Clean up
42 */
43 public function tearDown() {
44 foreach ($this->fakedExtensions as $extension) {
45 t3lib_div::rmdir(PATH_site . 'typo3temp/' . $extension, TRUE);
46 }
47 }
48
49 /**
50 * Creates a fake extension inside typo3temp/. No configuration is created,
51 * just the folder, plus the extension is registered in $TYPO3_LOADED_EXT
52 *
53 * @return string The extension key
54 */
55 protected function createFakeExtension() {
56 $extKey = uniqid('testing');
57 $absExtPath = PATH_site . "typo3temp/$extKey/";
58 $relPath = "typo3temp/$extKey/";
59 t3lib_div::mkdir($absExtPath);
60
61 $GLOBALS['TYPO3_LOADED_EXT'][$extKey] = array(
62 'siteRelPath' => $relPath
63 );
64
65 $this->fakedExtensions[] = $extKey;
66 t3lib_extMgm::clearExtensionKeyMap();
67
68 return $extKey;
69 }
70
71 /**
72 * @test
73 */
74 public function extensionAutoloadFileIsIncludedIfAvailable() {
75 $extKey = $this->createFakeExtension();
76 $extPath = PATH_site . "typo3temp/$extKey/";
77 $autoloaderFile = $extPath . "ext_autoload.php";
78
79 $class = strtolower("tx_${extKey}_" . uniqid(''));
80 $file = $extPath . uniqid('') . '.php';
81
82 file_put_contents($file, "<?php\n\nthrow new RuntimeException('', 1310203812);\n\n?>");
83 file_put_contents($autoloaderFile, "<?php\n\nreturn array('$class' => '$file');\n\n?>");
84
85 // Expect the exception of the file to be thrown
86 $this->setExpectedException('RuntimeException', '', 1310203812);
87 t3lib_autoloader::autoload($class);
88 }
89 }
90
91
92 ?>