You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

autoloader.php 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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([], $this->loader->findClass('OC\Core\Foo\Bar'));
  68. }
  69. public function testLoadCoreNamespaceSettings() {
  70. $this->assertEquals([], $this->loader->findClass('OC\Settings\Foo\Bar'));
  71. }
  72. public function testLoadCoreNamespaceRepair() {
  73. $this->assertEquals([
  74. \OC::$SERVERROOT . '/lib/private/repair/foo/bar.php',
  75. ], $this->loader->findClass('OC\Repair\Foo\Bar'));
  76. }
  77. }