12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <?php
- namespace Test\Template;
- use OC\SystemConfig;
- use OC\Template\ResourceNotFoundException;
- use Psr\Log\LoggerInterface;
- class ResourceLocatorTest extends \Test\TestCase {
-
- protected $logger;
- protected function setUp(): void {
- parent::setUp();
- $this->logger = $this->createMock(LoggerInterface::class);
- }
-
- public function getResourceLocator($theme) {
- $systemConfig = $this->createMock(SystemConfig::class);
- $systemConfig
- ->expects($this->any())
- ->method('getValue')
- ->with('theme', '')
- ->willReturn($theme);
- $this->overwriteService(SystemConfig::class, $systemConfig);
- return $this->getMockForAbstractClass('OC\Template\ResourceLocator',
- [$this->logger],
- '', true, true, true, []);
- }
- public function testFind(): void {
- $locator = $this->getResourceLocator('theme');
- $locator->expects($this->once())
- ->method('doFind')
- ->with('foo');
- $locator->expects($this->once())
- ->method('doFindTheme')
- ->with('foo');
-
- $locator->find(['foo']);
- }
- public function testFindNotFound(): void {
- $systemConfig = $this->createMock(SystemConfig::class);
- $systemConfig->method('getValue')
- ->with('theme', '')
- ->willReturn('theme');
- $this->overwriteService(SystemConfig::class, $systemConfig);
- $locator = $this->getResourceLocator('theme',
- ['core' => 'map'], ['3rd' => 'party'], ['foo' => 'bar']);
- $locator->expects($this->once())
- ->method('doFind')
- ->with('foo')
- ->will($this->throwException(new ResourceNotFoundException('foo', 'map')));
- $locator->expects($this->once())
- ->method('doFindTheme')
- ->with('foo')
- ->will($this->throwException(new ResourceNotFoundException('foo', 'map')));
- $this->logger->expects($this->exactly(2))
- ->method('debug')
- ->with($this->stringContains('map/foo'));
-
- $locator->find(['foo']);
- }
- public function testAppendIfExist(): void {
- $locator = $this->getResourceLocator('theme');
-
- $method = new \ReflectionMethod($locator, 'appendIfExist');
- $method->setAccessible(true);
- $method->invoke($locator, __DIR__, basename(__FILE__), 'webroot');
- $resource1 = [__DIR__, 'webroot', basename(__FILE__)];
- $this->assertEquals([$resource1], $locator->getResources());
- $method->invoke($locator, __DIR__, 'does-not-exist');
- $this->assertEquals([$resource1], $locator->getResources());
- }
- }
|