2013-03-16 23:02:51 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2024-05-10 15:09:14 +02:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2013-03-16 23:02:51 +01:00
|
|
|
*/
|
|
|
|
|
2015-04-20 12:31:07 +02:00
|
|
|
namespace Test\Template;
|
|
|
|
|
2022-12-07 23:16:06 +01:00
|
|
|
use OC\SystemConfig;
|
2015-04-20 12:31:07 +02:00
|
|
|
use OC\Template\ResourceNotFoundException;
|
2022-03-21 11:17:14 +01:00
|
|
|
use Psr\Log\LoggerInterface;
|
2015-04-20 12:31:07 +02:00
|
|
|
|
2016-05-20 15:38:20 +02:00
|
|
|
class ResourceLocatorTest extends \Test\TestCase {
|
2020-08-11 21:32:18 +02:00
|
|
|
/** @var \PHPUnit\Framework\MockObject\MockObject */
|
2015-03-04 13:24:24 +01:00
|
|
|
protected $logger;
|
|
|
|
|
2019-11-21 16:40:38 +01:00
|
|
|
protected function setUp(): void {
|
2015-03-04 13:24:24 +01:00
|
|
|
parent::setUp();
|
2022-03-21 11:17:14 +01:00
|
|
|
$this->logger = $this->createMock(LoggerInterface::class);
|
2015-03-04 13:24:24 +01:00
|
|
|
}
|
2014-02-19 09:31:54 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $theme
|
2020-08-11 21:32:18 +02:00
|
|
|
* @return \PHPUnit\Framework\MockObject\MockObject
|
2014-02-19 09:31:54 +01:00
|
|
|
*/
|
2022-12-07 23:16:06 +01:00
|
|
|
public function getResourceLocator($theme) {
|
|
|
|
$systemConfig = $this->createMock(SystemConfig::class);
|
|
|
|
$systemConfig
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getValue')
|
|
|
|
->with('theme', '')
|
|
|
|
->willReturn($theme);
|
|
|
|
$this->overwriteService(SystemConfig::class, $systemConfig);
|
2013-03-16 23:02:51 +01:00
|
|
|
return $this->getMockForAbstractClass('OC\Template\ResourceLocator',
|
2022-12-07 23:16:06 +01:00
|
|
|
[$this->logger],
|
2020-03-26 09:30:18 +01:00
|
|
|
'', true, true, true, []);
|
2013-03-16 23:02:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testFind(): void {
|
2022-12-07 23:16:06 +01:00
|
|
|
$locator = $this->getResourceLocator('theme');
|
2013-03-16 23:02:51 +01:00
|
|
|
$locator->expects($this->once())
|
|
|
|
->method('doFind')
|
|
|
|
->with('foo');
|
|
|
|
$locator->expects($this->once())
|
|
|
|
->method('doFindTheme')
|
|
|
|
->with('foo');
|
2015-04-20 12:31:07 +02:00
|
|
|
/** @var \OC\Template\ResourceLocator $locator */
|
2020-03-26 09:30:18 +01:00
|
|
|
$locator->find(['foo']);
|
2015-03-04 13:24:24 +01:00
|
|
|
}
|
2013-03-16 23:02:51 +01:00
|
|
|
|
2015-03-04 13:24:24 +01:00
|
|
|
public function testFindNotFound(): void {
|
2022-12-07 23:16:06 +01:00
|
|
|
$systemConfig = $this->createMock(SystemConfig::class);
|
|
|
|
$systemConfig->method('getValue')
|
|
|
|
->with('theme', '')
|
|
|
|
->willReturn('theme');
|
|
|
|
$this->overwriteService(SystemConfig::class, $systemConfig);
|
2014-11-12 12:37:50 +01:00
|
|
|
$locator = $this->getResourceLocator('theme',
|
2020-10-05 15:12:57 +02:00
|
|
|
['core' => 'map'], ['3rd' => 'party'], ['foo' => 'bar']);
|
2013-03-16 23:02:51 +01:00
|
|
|
$locator->expects($this->once())
|
|
|
|
->method('doFind')
|
|
|
|
->with('foo')
|
2015-04-20 12:31:07 +02:00
|
|
|
->will($this->throwException(new ResourceNotFoundException('foo', 'map')));
|
2015-03-04 13:24:24 +01:00
|
|
|
$locator->expects($this->once())
|
|
|
|
->method('doFindTheme')
|
|
|
|
->with('foo')
|
2015-04-20 12:31:07 +02:00
|
|
|
->will($this->throwException(new ResourceNotFoundException('foo', 'map')));
|
2015-03-04 13:24:24 +01:00
|
|
|
$this->logger->expects($this->exactly(2))
|
2017-02-03 11:52:01 -06:00
|
|
|
->method('debug')
|
2015-04-20 12:31:35 +02:00
|
|
|
->with($this->stringContains('map/foo'));
|
2015-04-20 12:31:07 +02:00
|
|
|
/** @var \OC\Template\ResourceLocator $locator */
|
2020-03-26 09:30:18 +01:00
|
|
|
$locator->find(['foo']);
|
2013-03-16 23:02:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testAppendIfExist(): void {
|
2022-12-07 23:16:06 +01:00
|
|
|
$locator = $this->getResourceLocator('theme');
|
2015-04-20 12:31:07 +02:00
|
|
|
/** @var \OC\Template\ResourceLocator $locator */
|
|
|
|
$method = new \ReflectionMethod($locator, 'appendIfExist');
|
2013-03-16 23:02:51 +01:00
|
|
|
$method->setAccessible(true);
|
|
|
|
|
|
|
|
$method->invoke($locator, __DIR__, basename(__FILE__), 'webroot');
|
2020-03-26 09:30:18 +01:00
|
|
|
$resource1 = [__DIR__, 'webroot', basename(__FILE__)];
|
|
|
|
$this->assertEquals([$resource1], $locator->getResources());
|
2013-03-16 23:02:51 +01:00
|
|
|
|
|
|
|
$method->invoke($locator, __DIR__, 'does-not-exist');
|
2022-12-07 23:16:06 +01:00
|
|
|
$this->assertEquals([$resource1], $locator->getResources());
|
2013-03-16 23:02:51 +01:00
|
|
|
}
|
|
|
|
}
|