2013-03-16 18:02:51 -04:00
|
|
|
<?php
|
2025-06-30 09:04:05 -04:00
|
|
|
|
2025-09-29 08:39:15 -04:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2013-03-16 18:02:51 -04:00
|
|
|
/**
|
2024-05-10 09:09:14 -04: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 18:02:51 -04:00
|
|
|
*/
|
|
|
|
|
|
2015-04-20 06:31:07 -04:00
|
|
|
namespace Test\Template;
|
|
|
|
|
|
2025-09-29 06:23:37 -04:00
|
|
|
use OC\Template\ResourceLocator;
|
2015-04-20 06:31:07 -04:00
|
|
|
use OC\Template\ResourceNotFoundException;
|
2025-09-29 08:39:15 -04:00
|
|
|
use OCP\IConfig;
|
|
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2022-03-21 06:17:14 -04:00
|
|
|
use Psr\Log\LoggerInterface;
|
2015-04-20 06:31:07 -04:00
|
|
|
|
2016-05-20 09:38:20 -04:00
|
|
|
class ResourceLocatorTest extends \Test\TestCase {
|
2025-09-29 08:39:15 -04:00
|
|
|
private LoggerInterface&MockObject $logger;
|
|
|
|
|
private IConfig&MockObject $config;
|
2015-03-04 07:24:24 -05:00
|
|
|
|
2019-11-21 10:40:38 -05:00
|
|
|
protected function setUp(): void {
|
2015-03-04 07:24:24 -05:00
|
|
|
parent::setUp();
|
2022-03-21 06:17:14 -04:00
|
|
|
$this->logger = $this->createMock(LoggerInterface::class);
|
2025-09-29 08:39:15 -04:00
|
|
|
$this->config = $this->createMock(IConfig::class);
|
2015-03-04 07:24:24 -05:00
|
|
|
}
|
2014-02-19 03:31:54 -05:00
|
|
|
|
2025-09-29 08:39:15 -04:00
|
|
|
public function getResourceLocator(string $theme): ResourceLocator&MockObject {
|
|
|
|
|
$this->config
|
2022-12-07 17:16:06 -05:00
|
|
|
->expects($this->any())
|
2025-09-29 08:39:15 -04:00
|
|
|
->method('getSystemValueString')
|
2022-12-07 17:16:06 -05:00
|
|
|
->with('theme', '')
|
|
|
|
|
->willReturn($theme);
|
2025-10-20 18:25:12 -04:00
|
|
|
return $this->getMockBuilder(ResourceLocator::class)
|
|
|
|
|
->onlyMethods(['doFind', 'doFindTheme'])
|
|
|
|
|
->setConstructorArgs(
|
|
|
|
|
[$this->logger, $this->config],
|
|
|
|
|
'', true, true, true, []
|
|
|
|
|
)
|
|
|
|
|
->getMock();
|
2013-03-16 18:02:51 -04:00
|
|
|
}
|
|
|
|
|
|
2024-09-15 16:32:31 -04:00
|
|
|
public function testFind(): void {
|
2022-12-07 17:16:06 -05:00
|
|
|
$locator = $this->getResourceLocator('theme');
|
2013-03-16 18:02:51 -04:00
|
|
|
$locator->expects($this->once())
|
|
|
|
|
->method('doFind')
|
|
|
|
|
->with('foo');
|
|
|
|
|
$locator->expects($this->once())
|
|
|
|
|
->method('doFindTheme')
|
|
|
|
|
->with('foo');
|
2020-03-26 04:30:18 -04:00
|
|
|
$locator->find(['foo']);
|
2015-03-04 07:24:24 -05:00
|
|
|
}
|
2013-03-16 18:02:51 -04:00
|
|
|
|
2024-09-15 16:32:31 -04:00
|
|
|
public function testFindNotFound(): void {
|
2014-11-12 06:37:50 -05:00
|
|
|
$locator = $this->getResourceLocator('theme',
|
2020-10-05 09:12:57 -04:00
|
|
|
['core' => 'map'], ['3rd' => 'party'], ['foo' => 'bar']);
|
2013-03-16 18:02:51 -04:00
|
|
|
$locator->expects($this->once())
|
|
|
|
|
->method('doFind')
|
|
|
|
|
->with('foo')
|
2025-06-12 12:34:54 -04:00
|
|
|
->willThrowException(new ResourceNotFoundException('foo', 'map'));
|
2015-03-04 07:24:24 -05:00
|
|
|
$locator->expects($this->once())
|
|
|
|
|
->method('doFindTheme')
|
|
|
|
|
->with('foo')
|
2025-06-12 12:34:54 -04:00
|
|
|
->willThrowException(new ResourceNotFoundException('foo', 'map'));
|
2015-03-04 07:24:24 -05:00
|
|
|
$this->logger->expects($this->exactly(2))
|
2017-02-03 12:52:01 -05:00
|
|
|
->method('debug')
|
2015-04-20 06:31:35 -04:00
|
|
|
->with($this->stringContains('map/foo'));
|
2020-03-26 04:30:18 -04:00
|
|
|
$locator->find(['foo']);
|
2013-03-16 18:02:51 -04:00
|
|
|
}
|
|
|
|
|
|
2024-09-15 16:32:31 -04:00
|
|
|
public function testAppendIfExist(): void {
|
2022-12-07 17:16:06 -05:00
|
|
|
$locator = $this->getResourceLocator('theme');
|
2015-04-20 06:31:07 -04:00
|
|
|
$method = new \ReflectionMethod($locator, 'appendIfExist');
|
2013-03-16 18:02:51 -04:00
|
|
|
$method->setAccessible(true);
|
|
|
|
|
|
|
|
|
|
$method->invoke($locator, __DIR__, basename(__FILE__), 'webroot');
|
2020-03-26 04:30:18 -04:00
|
|
|
$resource1 = [__DIR__, 'webroot', basename(__FILE__)];
|
|
|
|
|
$this->assertEquals([$resource1], $locator->getResources());
|
2013-03-16 18:02:51 -04:00
|
|
|
|
|
|
|
|
$method->invoke($locator, __DIR__, 'does-not-exist');
|
2022-12-07 17:16:06 -05:00
|
|
|
$this->assertEquals([$resource1], $locator->getResources());
|
2013-03-16 18:02:51 -04:00
|
|
|
}
|
|
|
|
|
}
|