2013-03-17 02:02:51 +04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Copyright (c) 2013 Bart Visscher <bartv@thisnet.nl>
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
2014-11-11 01:30:38 +03:00
|
|
|
class Test_ResourceLocator extends \Test\TestCase {
|
2014-02-19 12:31:54 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $theme
|
|
|
|
*/
|
2014-11-12 14:37:50 +03:00
|
|
|
public function getResourceLocator( $theme, $core_map, $party_map, $appsroots ) {
|
2013-03-17 02:02:51 +04:00
|
|
|
return $this->getMockForAbstractClass('OC\Template\ResourceLocator',
|
2014-11-12 14:37:50 +03:00
|
|
|
array( $theme, $core_map, $party_map, $appsroots ),
|
2013-03-17 02:02:51 +04:00
|
|
|
'', true, true, true, array());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testConstructor() {
|
2014-11-12 14:37:50 +03:00
|
|
|
$locator = $this->getResourceLocator('theme',
|
2013-03-17 02:02:51 +04:00
|
|
|
array('core'=>'map'), array('3rd'=>'party'), array('foo'=>'bar'));
|
|
|
|
$this->assertAttributeEquals('theme', 'theme', $locator);
|
|
|
|
$this->assertAttributeEquals('core', 'serverroot', $locator);
|
|
|
|
$this->assertAttributeEquals(array('core'=>'map','3rd'=>'party'), 'mapping', $locator);
|
|
|
|
$this->assertAttributeEquals('3rd', 'thirdpartyroot', $locator);
|
|
|
|
$this->assertAttributeEquals('map', 'webroot', $locator);
|
|
|
|
$this->assertAttributeEquals(array(), 'resources', $locator);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testFind() {
|
2014-11-12 14:37:50 +03:00
|
|
|
$locator = $this->getResourceLocator('theme',
|
2013-03-17 02:02:51 +04:00
|
|
|
array('core'=>'map'), array('3rd'=>'party'), array('foo'=>'bar'));
|
|
|
|
$locator->expects($this->once())
|
|
|
|
->method('doFind')
|
|
|
|
->with('foo');
|
|
|
|
$locator->expects($this->once())
|
|
|
|
->method('doFindTheme')
|
|
|
|
->with('foo');
|
|
|
|
$locator->find(array('foo'));
|
|
|
|
|
2014-11-12 14:37:50 +03:00
|
|
|
$locator = $this->getResourceLocator('theme',
|
2013-03-17 02:02:51 +04:00
|
|
|
array('core'=>'map'), array('3rd'=>'party'), array('foo'=>'bar'));
|
|
|
|
$locator->expects($this->once())
|
|
|
|
->method('doFind')
|
|
|
|
->with('foo')
|
|
|
|
->will($this->throwException(new Exception('test')));
|
|
|
|
try {
|
|
|
|
$locator->find(array('foo'));
|
|
|
|
} catch (\Exception $e) {
|
2014-11-12 14:37:50 +03:00
|
|
|
$this->assertEquals('test serverroot:core', $e->getMessage());
|
2013-03-17 02:02:51 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testAppendIfExist() {
|
2014-11-12 14:37:50 +03:00
|
|
|
$locator = $this->getResourceLocator('theme',
|
2013-03-17 02:02:51 +04:00
|
|
|
array(__DIR__=>'map'), array('3rd'=>'party'), array('foo'=>'bar'));
|
|
|
|
$method = new ReflectionMethod($locator, 'appendIfExist');
|
|
|
|
$method->setAccessible(true);
|
|
|
|
|
|
|
|
$method->invoke($locator, __DIR__, basename(__FILE__), 'webroot');
|
|
|
|
$resource1 = array(__DIR__, 'webroot', basename(__FILE__));
|
|
|
|
$this->assertEquals(array($resource1), $locator->getResources());
|
|
|
|
|
|
|
|
$method->invoke($locator, __DIR__, basename(__FILE__));
|
|
|
|
$resource2 = array(__DIR__, 'map', basename(__FILE__));
|
|
|
|
$this->assertEquals(array($resource1, $resource2), $locator->getResources());
|
|
|
|
|
|
|
|
$method->invoke($locator, __DIR__, 'does-not-exist');
|
|
|
|
$this->assertEquals(array($resource1, $resource2), $locator->getResources());
|
|
|
|
}
|
|
|
|
}
|