autoloader.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * Copyright (c) 2013 Thomas Müller <thomas.mueller@tmit.eu>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. namespace Test;
  9. class AutoLoader extends TestCase {
  10. /**
  11. * @var \OC\Autoloader $loader
  12. */
  13. private $loader;
  14. protected function setUp() {
  15. parent::setUp();
  16. $this->loader = new \OC\AutoLoader();
  17. }
  18. public function testLeadingSlashOnClassName() {
  19. $this->assertEquals(array('private/files/storage/local.php', 'files/storage/local.php'), $this->loader->findClass('\OC\Files\Storage\Local'));
  20. }
  21. public function testNoLeadingSlashOnClassName() {
  22. $this->assertEquals(array('private/files/storage/local.php', 'files/storage/local.php'), $this->loader->findClass('OC\Files\Storage\Local'));
  23. }
  24. public function testLegacyPath() {
  25. $this->assertEquals(array('private/legacy/files.php', 'private/files.php'), $this->loader->findClass('OC_Files'));
  26. }
  27. public function testLoadTestNamespace() {
  28. $this->assertEquals(array('tests/lib/foo/bar.php'), $this->loader->findClass('Test\Foo\Bar'));
  29. }
  30. public function testLoadTest() {
  31. $this->assertEquals(array('tests/lib/foo/bar.php'), $this->loader->findClass('Test_Foo_Bar'));
  32. }
  33. public function testLoadCoreNamespace() {
  34. $this->assertEquals(array('private/foo/bar.php', 'foo/bar.php'), $this->loader->findClass('OC\Foo\Bar'));
  35. }
  36. public function testLoadCore() {
  37. $this->assertEquals(array('private/legacy/foo/bar.php', 'private/foo/bar.php'), $this->loader->findClass('OC_Foo_Bar'));
  38. }
  39. public function testLoadPublicNamespace() {
  40. $this->assertEquals(array('public/foo/bar.php'), $this->loader->findClass('OCP\Foo\Bar'));
  41. }
  42. public function testLoadAppNamespace() {
  43. $result = $this->loader->findClass('OCA\Files\Foobar');
  44. $this->assertEquals(2, count($result));
  45. $this->assertStringEndsWith('apps/files/foobar.php', $result[0]);
  46. $this->assertStringEndsWith('apps/files/lib/foobar.php', $result[1]);
  47. }
  48. }