2013-03-16 22:02:51 +00: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.
|
|
|
|
*/
|
|
|
|
|
2015-04-20 10:31:07 +00:00
|
|
|
namespace Test\Template;
|
|
|
|
|
|
|
|
use OC\Template\ResourceNotFoundException;
|
2016-09-07 18:26:21 +00:00
|
|
|
use OCP\ILogger;
|
2015-04-20 10:31:07 +00:00
|
|
|
|
2016-05-20 13:38:20 +00:00
|
|
|
class ResourceLocatorTest extends \Test\TestCase {
|
2015-04-20 10:31:07 +00:00
|
|
|
/** @var \PHPUnit_Framework_MockObject_MockObject */
|
2015-03-04 12:24:24 +00:00
|
|
|
protected $logger;
|
|
|
|
|
|
|
|
protected function setUp() {
|
|
|
|
parent::setUp();
|
2016-09-07 18:26:21 +00:00
|
|
|
$this->logger = $this->createMock(ILogger::class);
|
2015-03-04 12:24:24 +00:00
|
|
|
}
|
2014-02-19 08:31:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $theme
|
2015-04-20 10:31:07 +00:00
|
|
|
* @param array $core_map
|
|
|
|
* @param array $party_map
|
|
|
|
* @param array $appsRoots
|
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject
|
2014-02-19 08:31:54 +00:00
|
|
|
*/
|
2015-04-20 10:31:07 +00:00
|
|
|
public function getResourceLocator($theme, $core_map, $party_map, $appsRoots) {
|
2013-03-16 22:02:51 +00:00
|
|
|
return $this->getMockForAbstractClass('OC\Template\ResourceLocator',
|
2015-04-20 10:31:07 +00:00
|
|
|
array($this->logger, $theme, $core_map, $party_map, $appsRoots ),
|
2013-03-16 22:02:51 +00:00
|
|
|
'', true, true, true, array());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testConstructor() {
|
2014-11-12 11:37:50 +00:00
|
|
|
$locator = $this->getResourceLocator('theme',
|
2013-03-16 22:02:51 +00: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 11:37:50 +00:00
|
|
|
$locator = $this->getResourceLocator('theme',
|
2015-03-04 12:24:24 +00:00
|
|
|
array('core' => 'map'), array('3rd' => 'party'), array('foo' => 'bar'));
|
2013-03-16 22:02:51 +00:00
|
|
|
$locator->expects($this->once())
|
|
|
|
->method('doFind')
|
|
|
|
->with('foo');
|
|
|
|
$locator->expects($this->once())
|
|
|
|
->method('doFindTheme')
|
|
|
|
->with('foo');
|
2015-04-20 10:31:07 +00:00
|
|
|
/** @var \OC\Template\ResourceLocator $locator */
|
2013-03-16 22:02:51 +00:00
|
|
|
$locator->find(array('foo'));
|
2015-03-04 12:24:24 +00:00
|
|
|
}
|
2013-03-16 22:02:51 +00:00
|
|
|
|
2015-03-04 12:24:24 +00:00
|
|
|
public function testFindNotFound() {
|
2014-11-12 11:37:50 +00:00
|
|
|
$locator = $this->getResourceLocator('theme',
|
2013-03-16 22:02:51 +00:00
|
|
|
array('core'=>'map'), array('3rd'=>'party'), array('foo'=>'bar'));
|
|
|
|
$locator->expects($this->once())
|
|
|
|
->method('doFind')
|
|
|
|
->with('foo')
|
2015-04-20 10:31:07 +00:00
|
|
|
->will($this->throwException(new ResourceNotFoundException('foo', 'map')));
|
2015-03-04 12:24:24 +00:00
|
|
|
$locator->expects($this->once())
|
|
|
|
->method('doFindTheme')
|
|
|
|
->with('foo')
|
2015-04-20 10:31:07 +00:00
|
|
|
->will($this->throwException(new ResourceNotFoundException('foo', 'map')));
|
2015-03-04 12:24:24 +00:00
|
|
|
$this->logger->expects($this->exactly(2))
|
2017-02-03 17:52:01 +00:00
|
|
|
->method('debug')
|
2015-04-20 10:31:35 +00:00
|
|
|
->with($this->stringContains('map/foo'));
|
2015-04-20 10:31:07 +00:00
|
|
|
/** @var \OC\Template\ResourceLocator $locator */
|
2015-03-04 12:24:24 +00:00
|
|
|
$locator->find(array('foo'));
|
2013-03-16 22:02:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testAppendIfExist() {
|
2014-11-12 11:37:50 +00:00
|
|
|
$locator = $this->getResourceLocator('theme',
|
2013-03-16 22:02:51 +00:00
|
|
|
array(__DIR__=>'map'), array('3rd'=>'party'), array('foo'=>'bar'));
|
2015-04-20 10:31:07 +00:00
|
|
|
/** @var \OC\Template\ResourceLocator $locator */
|
|
|
|
$method = new \ReflectionMethod($locator, 'appendIfExist');
|
2013-03-16 22:02:51 +00:00
|
|
|
$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());
|
|
|
|
}
|
|
|
|
}
|