autoloader.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 \PHPUnit_Framework_TestCase {
  10. /**
  11. * @var \OC\Autoloader $loader
  12. */
  13. private $loader;
  14. public function setUp() {
  15. $this->loader = new \OC\AutoLoader();
  16. }
  17. public function testLeadingSlashOnClassName() {
  18. $this->assertEquals(array('files/storage/local.php'), $this->loader->findClass('\OC\Files\Storage\Local'));
  19. }
  20. public function testNoLeadingSlashOnClassName() {
  21. $this->assertEquals(array('files/storage/local.php'), $this->loader->findClass('OC\Files\Storage\Local'));
  22. }
  23. public function testLegacyPath() {
  24. $this->assertEquals(array('legacy/files.php', 'files.php'), $this->loader->findClass('OC_Files'));
  25. }
  26. public function testClassPath() {
  27. $this->loader->registerClass('Foo\Bar', 'foobar.php');
  28. $this->assertEquals(array('foobar.php'), $this->loader->findClass('Foo\Bar'));
  29. }
  30. public function testPrefixNamespace() {
  31. $this->loader->registerPrefix('Foo', 'foo');
  32. $this->assertEquals(array('foo/Foo/Bar.php'), $this->loader->findClass('Foo\Bar'));
  33. }
  34. public function testPrefix() {
  35. $this->loader->registerPrefix('Foo_', 'foo');
  36. $this->assertEquals(array('foo/Foo/Bar.php'), $this->loader->findClass('Foo_Bar'));
  37. }
  38. public function testLoadTestNamespace() {
  39. $this->assertEquals(array('tests/lib/foo/bar.php'), $this->loader->findClass('Test\Foo\Bar'));
  40. }
  41. public function testLoadTest() {
  42. $this->assertEquals(array('tests/lib/foo/bar.php'), $this->loader->findClass('Test_Foo_Bar'));
  43. }
  44. public function testLoadCoreNamespace() {
  45. $this->assertEquals(array('foo/bar.php'), $this->loader->findClass('OC\Foo\Bar'));
  46. }
  47. public function testLoadCore() {
  48. $this->assertEquals(array('legacy/foo/bar.php', 'foo/bar.php'), $this->loader->findClass('OC_Foo_Bar'));
  49. }
  50. public function testLoadPublicNamespace() {
  51. $this->assertEquals(array('public/foo/bar.php'), $this->loader->findClass('OCP\Foo\Bar'));
  52. }
  53. public function testLoadAppNamespace() {
  54. $result = $this->loader->findClass('OCA\Files\Foobar');
  55. $this->assertEquals(2, count($result));
  56. $this->assertStringEndsWith('apps/files/foobar.php', $result[0]);
  57. $this->assertStringEndsWith('apps/files/lib/foobar.php', $result[1]);
  58. }
  59. }