TYPO3 CMS  TYPO3_6-2
ClassLoaderTest.php
Go to the documentation of this file.
1 <?php
3 
18 
25 
29  protected $typo3CacheManager = NULL;
30 
34  protected $fakedExtensions = array();
35 
39  protected $classLoader;
40 
45 
51  public static $testClassWasLoaded = FALSE;
52 
58  public function setUp() {
59  vfsStream::setup('Test');
60 
61  mkdir('vfs://Test/Packages/Application/Acme.MyApp/Classes/', 0770, TRUE);
62  file_put_contents('vfs://Test/Packages/Application/Acme.MyApp/composer.json', '{"name": "acme/myapp", "type": "flow-test"}');
63  $package1 = new \TYPO3\Flow\Package\Package($this->getMock('TYPO3\Flow\Package\PackageManager'), 'Acme.MyApp', 'vfs://Test/Packages/Application/Acme.MyApp/', 'Classes');
64 
65  mkdir('vfs://Test/Packages/Application/Acme.MyAppAddon/Classes/', 0770, TRUE);
66  file_put_contents('vfs://Test/Packages/Application/Acme.MyAppAddon/composer.json', '{"name": "acme/myappaddon", "type": "flow-test"}');
67  $package2 = new \TYPO3\Flow\Package\Package($this->getMock('TYPO3\Flow\Package\PackageManager'), 'Acme.MyAppAddon', 'vfs://Test/Packages/Application/Acme.MyAppAddon/', 'Classes');
68 
69  $mockClassAliasMap = $this->getMock('TYPO3\\CMS\\Core\\Core\\ClassAliasMap', array('setPackagesButDontBuildMappingFilesReturnClassNameToAliasMappingInstead', 'buildMappingFiles'), array(), '', FALSE);
70  $mockClassAliasMap->expects($this->any())->method('setPackagesButDontBuildMappingFilesReturnClassNameToAliasMappingInstead')->will($this->returnValue(array()));
71 
72  $this->orinalClassAliasMap = \TYPO3\CMS\Core\Core\Bootstrap::getInstance()->getEarlyInstance('TYPO3\\CMS\\Core\\Core\\ClassAliasMap');
73  $this->classLoader = new \TYPO3\CMS\Core\Core\ClassLoader(\TYPO3\CMS\Core\Core\Bootstrap::getInstance()->getApplicationContext());
74  $this->classLoader->injectClassAliasMap($mockClassAliasMap);
75  $this->classLoader->setPackages(array('Acme.MyApp' => $package1, 'Acme.MyAppAddon' => $package2));
76  }
77 
82  public function tearDown() {
83  $this->classLoader->injectClassAliasMap($this->orinalClassAliasMap);
84  parent::tearDown();
85  }
86 
93  protected function createFakeExtension() {
94  $extKey = strtolower($this->getUniqueId('testing'));
95  $absExtPath = PATH_site . 'typo3temp/' . $extKey . '/';
96  $relPath = 'typo3temp/' . $extKey . '/';
98  $GLOBALS['TYPO3_LOADED_EXT'][$extKey] = array(
99  'siteRelPath' => $relPath
100  );
101  $this->fakedExtensions[] = $extKey;
103  return $extKey;
104  }
105 
112  mkdir('vfs://Test/Packages/Application/Acme.MyApp/Classes/Acme/MyApp/SubDirectory', 0770, TRUE);
113  file_put_contents('vfs://Test/Packages/Application/Acme.MyApp/Classes/Acme/MyApp/SubDirectory/ClassInSubDirectory.php', '<?php ' . __CLASS__ . '::$testClassWasLoaded = TRUE; ?>');
114 
115  self::$testClassWasLoaded = FALSE;
116  $this->classLoader->loadClass('Acme\MyApp\SubDirectory\ClassInSubDirectory');
117  $this->assertTrue(self::$testClassWasLoaded);
118  }
119 
124  mkdir('vfs://Test/Packages/Application/Acme.MyApp/Classes/Acme/MyApp/SubDirectory/A/B/C/D', 0770, TRUE);
125  file_put_contents('vfs://Test/Packages/Application/Acme.MyApp/Classes/Acme/MyApp/SubDirectory/A/B/C/D/E.php', '<?php ' . __CLASS__ . '::$testClassWasLoaded = TRUE; ?>');
126 
127  self::$testClassWasLoaded = FALSE;
128  $this->classLoader->loadClass('Acme\MyApp\SubDirectory\A\B\C\D\E');
129  $this->assertTrue(self::$testClassWasLoaded);
130  }
131 
139  mkdir('vfs://Test/Packages/Application/Acme.MyAppAddon/Classes/Acme/MyAppAddon', 0770, TRUE);
140  file_put_contents('vfs://Test/Packages/Application/Acme.MyAppAddon/Classes/Acme/MyAppAddon/Class.php', '<?php ' . __CLASS__ . '::$testClassWasLoaded = TRUE; ?>');
141 
142  self::$testClassWasLoaded = FALSE;
143  $this->classLoader->loadClass('Acme\MyAppAddon\Class');
144  $this->assertTrue(self::$testClassWasLoaded);
145  }
146 
153  mkdir('vfs://Test/Packages/Application/Acme.MyApp/Classes/Acme/MyApp', 0770, TRUE);
154  file_put_contents('vfs://Test/Packages/Application/Acme.MyApp/Classes/Acme/MyApp/Foo.php', '<?php ' . __CLASS__ . '::$testClassWasLoaded = TRUE; ?>');
155 
156  self::$testClassWasLoaded = FALSE;
157  $this->classLoader->loadClass('Acme\MyApp_Foo');
158  $this->assertTrue(self::$testClassWasLoaded);
159  }
160 
167  mkdir('vfs://Test/Packages/Application/Acme.MyApp/Classes/Acme/MyApp/My_Underscore', 0770, TRUE);
168  file_put_contents('vfs://Test/Packages/Application/Acme.MyApp/Classes/Acme/MyApp/My_Underscore/Foo.php', '<?php ' . __CLASS__ . '::$testClassWasLoaded = TRUE; ?>');
169 
170  self::$testClassWasLoaded = FALSE;
171  $this->classLoader->loadClass('Acme\MyApp\My_Underscore\Foo');
172  $this->assertTrue(self::$testClassWasLoaded);
173  }
174 
181  mkdir('vfs://Test/Packages/Application/Acme.MyApp/Classes/Acme/MyApp', 0770, TRUE);
182  file_put_contents('vfs://Test/Packages/Application/Acme.MyApp/Classes/Acme/MyApp/UnderscoredOnly.php', '<?php ' . __CLASS__ . '::$testClassWasLoaded = TRUE; ?>');
183 
184  self::$testClassWasLoaded = FALSE;
185  $this->classLoader->loadClass('Acme_MyApp_UnderscoredOnly');
186  $this->assertTrue(self::$testClassWasLoaded);
187  }
188 
193  mkdir('vfs://Test/Packages/Application/Acme.MyApp/Classes/Acme/MyApp', 0770, TRUE);
194  file_put_contents('vfs://Test/Packages/Application/Acme.MyApp/Classes/Acme/MyApp/WithLeadingBackslash.php', '<?php ' . __CLASS__ . '::$testClassWasLoaded = TRUE; ?>');
195 
196  self::$testClassWasLoaded = FALSE;
197  $this->classLoader->loadClass('\Acme\MyApp\WithLeadingBackslash');
198  $this->assertTrue(self::$testClassWasLoaded);
199  }
200 
201 }
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]