autoloader.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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([
  20. \OC::$SERVERROOT . '/lib/private/files/storage/local.php',
  21. ], $this->loader->findClass('\OC\Files\Storage\Local'));
  22. }
  23. public function testNoLeadingSlashOnClassName() {
  24. $this->assertEquals([
  25. \OC::$SERVERROOT . '/lib/private/files/storage/local.php',
  26. ], $this->loader->findClass('OC\Files\Storage\Local'));
  27. }
  28. public function testLegacyPath() {
  29. $this->assertEquals([
  30. \OC::$SERVERROOT . '/lib/private/legacy/files.php',
  31. \OC::$SERVERROOT . '/lib/private/files.php',
  32. ], $this->loader->findClass('OC_Files'));
  33. }
  34. public function testLoadTestNamespace() {
  35. $this->assertEquals([
  36. \OC::$SERVERROOT . '/tests/lib/foo/bar.php'
  37. ], $this->loader->findClass('Test\Foo\Bar'));
  38. }
  39. public function testLoadTest() {
  40. $this->assertEquals([
  41. \OC::$SERVERROOT . '/tests/lib/foo/bar.php'
  42. ], $this->loader->findClass('Test_Foo_Bar'));
  43. }
  44. public function testLoadCoreNamespace() {
  45. $this->assertEquals([
  46. \OC::$SERVERROOT . '/lib/private/foo/bar.php',
  47. ], $this->loader->findClass('OC\Foo\Bar'));
  48. }
  49. public function testLoadCore() {
  50. $this->assertEquals([
  51. \OC::$SERVERROOT . '/lib/private/legacy/foo/bar.php',
  52. \OC::$SERVERROOT . '/lib/private/foo/bar.php',
  53. ], $this->loader->findClass('OC_Foo_Bar'));
  54. }
  55. public function testLoadPublicNamespace() {
  56. $this->assertEquals([
  57. \OC::$SERVERROOT . '/lib/public/foo/bar.php',
  58. ], $this->loader->findClass('OCP\Foo\Bar'));
  59. }
  60. public function testLoadAppNamespace() {
  61. $result = $this->loader->findClass('OCA\Files\Foobar');
  62. $this->assertEquals(2, count($result));
  63. $this->assertStringEndsWith('apps/files/foobar.php', $result[0]);
  64. $this->assertStringEndsWith('apps/files/lib/foobar.php', $result[1]);
  65. }
  66. public function testLoadCoreNamespaceCore() {
  67. $this->assertEquals([
  68. \OC::$SERVERROOT . '/core/foo/bar.php',
  69. ], $this->loader->findClass('OC\Core\Foo\Bar'));
  70. }
  71. public function testLoadCoreNamespaceSettings() {
  72. $this->assertEquals([
  73. \OC::$SERVERROOT . '/settings/foo/bar.php',
  74. ], $this->loader->findClass('OC\Settings\Foo\Bar'));
  75. }
  76. public function testLoadCoreNamespaceRepair() {
  77. $this->assertEquals([
  78. \OC::$SERVERROOT . '/lib/private/repair/foo/bar.php',
  79. ], $this->loader->findClass('OC\Repair\Foo\Bar'));
  80. }
  81. }