Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

resourcelocator.php 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * Copyright (c) 2013 Bart Visscher <bartv@thisnet.nl>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. class Test_ResourceLocator extends \Test\TestCase {
  9. /**
  10. * @param string $theme
  11. */
  12. public function getResourceLocator( $theme, $core_map, $party_map, $appsroots ) {
  13. return $this->getMockForAbstractClass('OC\Template\ResourceLocator',
  14. array( $theme, $core_map, $party_map, $appsroots ),
  15. '', true, true, true, array());
  16. }
  17. public function testConstructor() {
  18. $locator = $this->getResourceLocator('theme',
  19. array('core'=>'map'), array('3rd'=>'party'), array('foo'=>'bar'));
  20. $this->assertAttributeEquals('theme', 'theme', $locator);
  21. $this->assertAttributeEquals('core', 'serverroot', $locator);
  22. $this->assertAttributeEquals(array('core'=>'map','3rd'=>'party'), 'mapping', $locator);
  23. $this->assertAttributeEquals('3rd', 'thirdpartyroot', $locator);
  24. $this->assertAttributeEquals('map', 'webroot', $locator);
  25. $this->assertAttributeEquals(array(), 'resources', $locator);
  26. }
  27. public function testFind() {
  28. $locator = $this->getResourceLocator('theme',
  29. array('core'=>'map'), array('3rd'=>'party'), array('foo'=>'bar'));
  30. $locator->expects($this->once())
  31. ->method('doFind')
  32. ->with('foo');
  33. $locator->expects($this->once())
  34. ->method('doFindTheme')
  35. ->with('foo');
  36. $locator->find(array('foo'));
  37. $locator = $this->getResourceLocator('theme',
  38. array('core'=>'map'), array('3rd'=>'party'), array('foo'=>'bar'));
  39. $locator->expects($this->once())
  40. ->method('doFind')
  41. ->with('foo')
  42. ->will($this->throwException(new Exception('test')));
  43. try {
  44. $locator->find(array('foo'));
  45. } catch (\Exception $e) {
  46. $this->assertEquals('test serverroot:core', $e->getMessage());
  47. }
  48. }
  49. public function testAppendIfExist() {
  50. $locator = $this->getResourceLocator('theme',
  51. array(__DIR__=>'map'), array('3rd'=>'party'), array('foo'=>'bar'));
  52. $method = new ReflectionMethod($locator, 'appendIfExist');
  53. $method->setAccessible(true);
  54. $method->invoke($locator, __DIR__, basename(__FILE__), 'webroot');
  55. $resource1 = array(__DIR__, 'webroot', basename(__FILE__));
  56. $this->assertEquals(array($resource1), $locator->getResources());
  57. $method->invoke($locator, __DIR__, basename(__FILE__));
  58. $resource2 = array(__DIR__, 'map', basename(__FILE__));
  59. $this->assertEquals(array($resource1, $resource2), $locator->getResources());
  60. $method->invoke($locator, __DIR__, 'does-not-exist');
  61. $this->assertEquals(array($resource1, $resource2), $locator->getResources());
  62. }
  63. }