resourcelocator.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. /** @var PHPUnit_Framework_MockObject_MockObject */
  10. protected $logger;
  11. protected function setUp() {
  12. parent::setUp();
  13. $this->logger = $this->getMock('OCP\ILogger');
  14. }
  15. /**
  16. * @param string $theme
  17. */
  18. public function getResourceLocator( $theme, $core_map, $party_map, $appsroots ) {
  19. return $this->getMockForAbstractClass('OC\Template\ResourceLocator',
  20. array($this->logger, $theme, $core_map, $party_map, $appsroots ),
  21. '', true, true, true, array());
  22. }
  23. public function testConstructor() {
  24. $locator = $this->getResourceLocator('theme',
  25. array('core'=>'map'), array('3rd'=>'party'), array('foo'=>'bar'));
  26. $this->assertAttributeEquals('theme', 'theme', $locator);
  27. $this->assertAttributeEquals('core', 'serverroot', $locator);
  28. $this->assertAttributeEquals(array('core'=>'map','3rd'=>'party'), 'mapping', $locator);
  29. $this->assertAttributeEquals('3rd', 'thirdpartyroot', $locator);
  30. $this->assertAttributeEquals('map', 'webroot', $locator);
  31. $this->assertAttributeEquals(array(), 'resources', $locator);
  32. }
  33. public function testFind() {
  34. $locator = $this->getResourceLocator('theme',
  35. array('core' => 'map'), array('3rd' => 'party'), array('foo' => 'bar'));
  36. $locator->expects($this->once())
  37. ->method('doFind')
  38. ->with('foo');
  39. $locator->expects($this->once())
  40. ->method('doFindTheme')
  41. ->with('foo');
  42. $locator->find(array('foo'));
  43. }
  44. public function testFindNotFound() {
  45. $locator = $this->getResourceLocator('theme',
  46. array('core'=>'map'), array('3rd'=>'party'), array('foo'=>'bar'));
  47. $locator->expects($this->once())
  48. ->method('doFind')
  49. ->with('foo')
  50. ->will($this->throwException(new \OC\Template\ResourceNotFoundException('foo', 'map')));
  51. $locator->expects($this->once())
  52. ->method('doFindTheme')
  53. ->with('foo')
  54. ->will($this->throwException(new \OC\Template\ResourceNotFoundException('foo', 'map')));
  55. $this->logger->expects($this->exactly(2))
  56. ->method('error');
  57. $locator->find(array('foo'));
  58. }
  59. public function testAppendIfExist() {
  60. $locator = $this->getResourceLocator('theme',
  61. array(__DIR__=>'map'), array('3rd'=>'party'), array('foo'=>'bar'));
  62. $method = new ReflectionMethod($locator, 'appendIfExist');
  63. $method->setAccessible(true);
  64. $method->invoke($locator, __DIR__, basename(__FILE__), 'webroot');
  65. $resource1 = array(__DIR__, 'webroot', basename(__FILE__));
  66. $this->assertEquals(array($resource1), $locator->getResources());
  67. $method->invoke($locator, __DIR__, basename(__FILE__));
  68. $resource2 = array(__DIR__, 'map', basename(__FILE__));
  69. $this->assertEquals(array($resource1, $resource2), $locator->getResources());
  70. $method->invoke($locator, __DIR__, 'does-not-exist');
  71. $this->assertEquals(array($resource1, $resource2), $locator->getResources());
  72. }
  73. }