resourcelocator.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 PHPUnit_Framework_TestCase {
  9. public function getResourceLocator( $theme, $form_factor, $core_map, $party_map, $appsroots ) {
  10. return $this->getMockForAbstractClass('OC\Template\ResourceLocator',
  11. array( $theme, $form_factor, $core_map, $party_map, $appsroots ),
  12. '', true, true, true, array());
  13. }
  14. public function testConstructor() {
  15. $locator = $this->getResourceLocator('theme', 'form_factor',
  16. array('core'=>'map'), array('3rd'=>'party'), array('foo'=>'bar'));
  17. $this->assertAttributeEquals('theme', 'theme', $locator);
  18. $this->assertAttributeEquals('form_factor', 'form_factor', $locator);
  19. $this->assertAttributeEquals('core', 'serverroot', $locator);
  20. $this->assertAttributeEquals(array('core'=>'map','3rd'=>'party'), 'mapping', $locator);
  21. $this->assertAttributeEquals('3rd', 'thirdpartyroot', $locator);
  22. $this->assertAttributeEquals('map', 'webroot', $locator);
  23. $this->assertAttributeEquals(array(), 'resources', $locator);
  24. }
  25. public function testFind() {
  26. $locator = $this->getResourceLocator('theme', 'form_factor',
  27. array('core'=>'map'), array('3rd'=>'party'), array('foo'=>'bar'));
  28. $locator->expects($this->once())
  29. ->method('doFind')
  30. ->with('foo');
  31. $locator->expects($this->once())
  32. ->method('doFindTheme')
  33. ->with('foo');
  34. $locator->find(array('foo'));
  35. $locator = $this->getResourceLocator('theme', 'form_factor',
  36. array('core'=>'map'), array('3rd'=>'party'), array('foo'=>'bar'));
  37. $locator->expects($this->once())
  38. ->method('doFind')
  39. ->with('foo')
  40. ->will($this->throwException(new Exception('test')));
  41. try {
  42. $locator->find(array('foo'));
  43. } catch (\Exception $e) {
  44. $this->assertEquals('test formfactor:form_factor serverroot:core', $e->getMessage());
  45. }
  46. }
  47. public function testAppendIfExist() {
  48. $locator = $this->getResourceLocator('theme', 'form_factor',
  49. array(__DIR__=>'map'), array('3rd'=>'party'), array('foo'=>'bar'));
  50. $method = new ReflectionMethod($locator, 'appendIfExist');
  51. $method->setAccessible(true);
  52. $method->invoke($locator, __DIR__, basename(__FILE__), 'webroot');
  53. $resource1 = array(__DIR__, 'webroot', basename(__FILE__));
  54. $this->assertEquals(array($resource1), $locator->getResources());
  55. $method->invoke($locator, __DIR__, basename(__FILE__));
  56. $resource2 = array(__DIR__, 'map', basename(__FILE__));
  57. $this->assertEquals(array($resource1, $resource2), $locator->getResources());
  58. $method->invoke($locator, __DIR__, 'does-not-exist');
  59. $this->assertEquals(array($resource1, $resource2), $locator->getResources());
  60. }
  61. }