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.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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('private/files/storage/local.php', 'files/storage/local.php'), $this->loader->findClass('\OC\Files\Storage\Local'));
  19. }
  20. public function testNoLeadingSlashOnClassName() {
  21. $this->assertEquals(array('private/files/storage/local.php', 'files/storage/local.php'), $this->loader->findClass('OC\Files\Storage\Local'));
  22. }
  23. public function testLegacyPath() {
  24. $this->assertEquals(array('private/legacy/files.php', 'private/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('private/foo/bar.php', 'foo/bar.php'), $this->loader->findClass('OC\Foo\Bar'));
  46. }
  47. public function testLoadCore() {
  48. $this->assertEquals(array('private/legacy/foo/bar.php', 'private/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. }