aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Template
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/Template')
-rw-r--r--tests/lib/Template/CSSResourceLocatorTest.php24
-rw-r--r--tests/lib/Template/JSCombinerTest.php142
-rw-r--r--tests/lib/Template/JSResourceLocatorTest.php125
-rw-r--r--tests/lib/Template/ResourceLocatorTest.php18
-rw-r--r--tests/lib/Template/data/1.js.license2
-rw-r--r--tests/lib/Template/data/2.js.license2
-rw-r--r--tests/lib/Template/data/combine.json.license2
7 files changed, 161 insertions, 154 deletions
diff --git a/tests/lib/Template/CSSResourceLocatorTest.php b/tests/lib/Template/CSSResourceLocatorTest.php
index 3d337dceb9e..2ae37999b32 100644
--- a/tests/lib/Template/CSSResourceLocatorTest.php
+++ b/tests/lib/Template/CSSResourceLocatorTest.php
@@ -1,24 +1,8 @@
<?php
+
/**
- * @copyright Copyright (c) 2017 Kyle Fazzari <kyrofa@ubuntu.com>
- *
- * @author Kyle Fazzari <kyrofa@ubuntu.com>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace Test\Template;
@@ -94,7 +78,7 @@ class CSSResourceLocatorTest extends \Test\TestCase {
return sha1(uniqid(mt_rand(), true));
}
- public function testFindWithAppPathSymlink() {
+ public function testFindWithAppPathSymlink(): void {
// First create new apps path, and a symlink to it
$apps_dirname = $this->randomString();
$new_apps_path = sys_get_temp_dir() . '/' . $apps_dirname;
diff --git a/tests/lib/Template/JSCombinerTest.php b/tests/lib/Template/JSCombinerTest.php
index 1f2342f2b4e..bc286695bc7 100644
--- a/tests/lib/Template/JSCombinerTest.php
+++ b/tests/lib/Template/JSCombinerTest.php
@@ -1,24 +1,8 @@
<?php
+
/**
- * @copyright 2017, Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace Test\Template;
@@ -32,7 +16,9 @@ use OCP\Files\SimpleFS\ISimpleFile;
use OCP\Files\SimpleFS\ISimpleFolder;
use OCP\ICache;
use OCP\ICacheFactory;
+use OCP\ITempManager;
use OCP\IURLGenerator;
+use OCP\Server;
use Psr\Log\LoggerInterface;
class JSCombinerTest extends \Test\TestCase {
@@ -72,7 +58,7 @@ class JSCombinerTest extends \Test\TestCase {
);
}
- public function testProcessDebugMode() {
+ public function testProcessDebugMode(): void {
$this->config
->expects($this->once())
->method('getValue')
@@ -83,35 +69,27 @@ class JSCombinerTest extends \Test\TestCase {
$this->assertFalse($actual);
}
- public function testProcessNotInstalled() {
+ public function testProcessNotInstalled(): void {
$this->config
->expects($this->exactly(2))
->method('getValue')
- ->withConsecutive(
- ['debug'],
- ['installed']
- )
- ->willReturnOnConsecutiveCalls(
- false,
- false
- );
+ ->willReturnMap([
+ ['debug', false],
+ ['installed', false]
+ ]);
$actual = $this->jsCombiner->process(__DIR__, '/data/combine.json', 'awesomeapp');
$this->assertFalse($actual);
}
- public function testProcessUncachedFileNoAppDataFolder() {
+ public function testProcessUncachedFileNoAppDataFolder(): void {
$this->config
->expects($this->exactly(2))
->method('getValue')
- ->withConsecutive(
- ['debug'],
- ['installed']
- )
- ->willReturnOnConsecutiveCalls(
- false,
- true
- );
+ ->willReturnMap([
+ ['debug', '', false],
+ ['installed', '', true],
+ ]);
$folder = $this->createMock(ISimpleFolder::class);
$this->appData->expects($this->once())->method('getFolder')->with('awesomeapp')->willThrowException(new NotFoundException());
$this->appData->expects($this->once())->method('newFolder')->with('awesomeapp')->willReturn($folder);
@@ -140,18 +118,14 @@ class JSCombinerTest extends \Test\TestCase {
$this->assertTrue($actual);
}
- public function testProcessUncachedFile() {
+ public function testProcessUncachedFile(): void {
$this->config
->expects($this->exactly(2))
->method('getValue')
- ->withConsecutive(
- ['debug'],
- ['installed']
- )
- ->willReturnOnConsecutiveCalls(
- false,
- true
- );
+ ->willReturnMap([
+ ['debug', '', false],
+ ['installed', '', true],
+ ]);
$folder = $this->createMock(ISimpleFolder::class);
$this->appData->expects($this->once())->method('getFolder')->with('awesomeapp')->willReturn($folder);
$file = $this->createMock(ISimpleFile::class);
@@ -178,18 +152,14 @@ class JSCombinerTest extends \Test\TestCase {
$this->assertTrue($actual);
}
- public function testProcessCachedFile() {
+ public function testProcessCachedFile(): void {
$this->config
->expects($this->exactly(2))
->method('getValue')
- ->withConsecutive(
- ['debug'],
- ['installed']
- )
- ->willReturnOnConsecutiveCalls(
- false,
- true
- );
+ ->willReturnMap([
+ ['debug', '', false],
+ ['installed', '', true],
+ ]);
$folder = $this->createMock(ISimpleFolder::class);
$this->appData->expects($this->once())->method('getFolder')->with('awesomeapp')->willReturn($folder);
$file = $this->createMock(ISimpleFile::class);
@@ -219,18 +189,14 @@ class JSCombinerTest extends \Test\TestCase {
$this->assertTrue($actual);
}
- public function testProcessCachedFileMemcache() {
+ public function testProcessCachedFileMemcache(): void {
$this->config
->expects($this->exactly(2))
->method('getValue')
- ->withConsecutive(
- ['debug'],
- ['installed']
- )
- ->willReturnOnConsecutiveCalls(
- false,
- true
- );
+ ->willReturnMap([
+ ['debug', '', false],
+ ['installed', '', true],
+ ]);
$folder = $this->createMock(ISimpleFolder::class);
$this->appData->expects($this->once())
->method('getFolder')
@@ -260,7 +226,7 @@ class JSCombinerTest extends \Test\TestCase {
$this->assertTrue($actual);
}
- public function testIsCachedNoDepsFile() {
+ public function testIsCachedNoDepsFile(): void {
$fileName = 'combine.json';
$folder = $this->createMock(ISimpleFolder::class);
$file = $this->createMock(ISimpleFile::class);
@@ -280,7 +246,7 @@ class JSCombinerTest extends \Test\TestCase {
$this->assertFalse($actual);
}
- public function testIsCachedWithNotExistingFile() {
+ public function testIsCachedWithNotExistingFile(): void {
$fileName = 'combine.json';
$folder = $this->createMock(ISimpleFolder::class);
$folder->method('fileExists')
@@ -298,7 +264,7 @@ class JSCombinerTest extends \Test\TestCase {
$this->assertFalse($actual);
}
- public function testIsCachedWithOlderMtime() {
+ public function testIsCachedWithOlderMtime(): void {
$fileName = 'combine.json';
$folder = $this->createMock(ISimpleFolder::class);
$folder->method('fileExists')
@@ -316,7 +282,7 @@ class JSCombinerTest extends \Test\TestCase {
$this->assertFalse($actual);
}
- public function testIsCachedWithoutContent() {
+ public function testIsCachedWithoutContent(): void {
$fileName = 'combine.json';
$folder = $this->createMock(ISimpleFolder::class);
$folder->method('fileExists')
@@ -336,7 +302,7 @@ class JSCombinerTest extends \Test\TestCase {
$this->assertFalse($actual);
}
- public function testCacheNoFile() {
+ public function testCacheNoFile(): void {
$fileName = 'combine.js';
$folder = $this->createMock(ISimpleFolder::class);
@@ -369,7 +335,7 @@ class JSCombinerTest extends \Test\TestCase {
$this->assertTrue($actual);
}
- public function testCache() {
+ public function testCache(): void {
$fileName = 'combine.js';
$folder = $this->createMock(ISimpleFolder::class);
@@ -400,7 +366,7 @@ class JSCombinerTest extends \Test\TestCase {
$this->assertTrue($actual);
}
- public function testCacheNotPermittedException() {
+ public function testCacheNotPermittedException(): void {
$fileName = 'combine.js';
$folder = $this->createMock(ISimpleFolder::class);
@@ -412,15 +378,11 @@ class JSCombinerTest extends \Test\TestCase {
$folder->expects($this->exactly(3))
->method('getFile')
- ->withConsecutive(
- [$fileName],
- [$fileName . '.deps'],
- [$fileName . '.gzip']
- )->willReturnOnConsecutiveCalls(
- $file,
- $depsFile,
- $gzFile
- );
+ ->willReturnMap([
+ [$fileName, $file],
+ [$fileName . '.deps', $depsFile],
+ [$fileName . '.gzip', $gzFile]
+ ]);
$file->expects($this->once())
->method('putContent')
@@ -446,7 +408,7 @@ var b = \'world\';
$this->assertFalse($actual);
}
- public function testCacheSuccess() {
+ public function testCacheSuccess(): void {
$fileName = 'combine.js';
$folder = $this->createMock(ISimpleFolder::class);
@@ -501,7 +463,7 @@ var b = \'world\';
$this->assertTrue($actual);
}
- public function dataGetCachedSCSS() {
+ public static function dataGetCachedSCSS(): array {
return [
['awesomeapp', 'core/js/foo.json', '/js/core/foo.js'],
['files', 'apps/files/js/foo.json', '/js/files/foo.js']
@@ -512,9 +474,9 @@ var b = \'world\';
* @param $appName
* @param $fileName
* @param $result
- * @dataProvider dataGetCachedSCSS
*/
- public function testGetCachedSCSS($appName, $fileName, $result) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGetCachedSCSS')]
+ public function testGetCachedSCSS($appName, $fileName, $result): void {
$this->urlGenerator->expects($this->once())
->method('linkToRoute')
->with('core.Js.getJs', [
@@ -527,9 +489,9 @@ var b = \'world\';
$this->assertEquals(substr($result, 1), $actual);
}
- public function testGetContent() {
+ public function testGetContent(): void {
// Create temporary file with some content
- $tmpFile = \OC::$server->getTempManager()->getTemporaryFile('JSCombinerTest');
+ $tmpFile = Server::get(ITempManager::class)->getTemporaryFile('JSCombinerTest');
$pathInfo = pathinfo($tmpFile);
file_put_contents($tmpFile, json_encode(['/foo/bar/test', $pathInfo['dirname'] . '/js/mytest.js']));
$tmpFilePathArray = explode('/', $pathInfo['basename']);
@@ -542,16 +504,16 @@ var b = \'world\';
$this->assertEquals($expected, $this->jsCombiner->getContent($pathInfo['dirname'], $pathInfo['basename']));
}
- public function testGetContentInvalidJson() {
+ public function testGetContentInvalidJson(): void {
// Create temporary file with some content
- $tmpFile = \OC::$server->getTempManager()->getTemporaryFile('JSCombinerTest');
+ $tmpFile = Server::get(ITempManager::class)->getTemporaryFile('JSCombinerTest');
$pathInfo = pathinfo($tmpFile);
file_put_contents($tmpFile, 'CertainlyNotJson');
$expected = [];
$this->assertEquals($expected, $this->jsCombiner->getContent($pathInfo['dirname'], $pathInfo['basename']));
}
- public function testResetCache() {
+ public function testResetCache(): void {
$file = $this->createMock(ISimpleFile::class);
$file->expects($this->once())
->method('delete');
diff --git a/tests/lib/Template/JSResourceLocatorTest.php b/tests/lib/Template/JSResourceLocatorTest.php
index 20fd79a91b5..89ab8e66dd7 100644
--- a/tests/lib/Template/JSResourceLocatorTest.php
+++ b/tests/lib/Template/JSResourceLocatorTest.php
@@ -1,24 +1,8 @@
<?php
+
/**
- * @copyright Copyright (c) 2017 Kyle Fazzari <kyrofa@ubuntu.com>
- *
- * @author Kyle Fazzari <kyrofa@ubuntu.com>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace Test\Template;
@@ -26,6 +10,8 @@ namespace Test\Template;
use OC\SystemConfig;
use OC\Template\JSCombiner;
use OC\Template\JSResourceLocator;
+use OCP\App\AppPathNotFoundException;
+use OCP\App\IAppManager;
use OCP\Files\IAppData;
use OCP\ICacheFactory;
use OCP\IURLGenerator;
@@ -42,6 +28,8 @@ class JSResourceLocatorTest extends \Test\TestCase {
protected $cacheFactory;
/** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
protected $logger;
+ /** @var IAppManager|\PHPUnit\Framework\MockObject\MockObject */
+ protected $appManager;
protected function setUp(): void {
parent::setUp();
@@ -51,6 +39,7 @@ class JSResourceLocatorTest extends \Test\TestCase {
$this->config = $this->createMock(SystemConfig::class);
$this->cacheFactory = $this->createMock(ICacheFactory::class);
$this->logger = $this->createMock(LoggerInterface::class);
+ $this->appManager = $this->createMock(IAppManager::class);
}
private function jsResourceLocator() {
@@ -63,7 +52,8 @@ class JSResourceLocatorTest extends \Test\TestCase {
);
return new JSResourceLocator(
$this->logger,
- $jsCombiner
+ $jsCombiner,
+ $this->appManager,
);
}
@@ -83,26 +73,35 @@ class JSResourceLocatorTest extends \Test\TestCase {
return sha1(uniqid(mt_rand(), true));
}
- public function testFindWithAppPathSymlink() {
+ public function testFindWithAppPathSymlink(): void {
+ $appName = 'test-js-app';
+
// First create new apps path, and a symlink to it
$apps_dirname = $this->randomString();
$new_apps_path = sys_get_temp_dir() . '/' . $apps_dirname;
$new_apps_path_symlink = $new_apps_path . '_link';
- mkdir($new_apps_path);
- symlink($apps_dirname, $new_apps_path_symlink);
+ $this->assertTrue((
+ mkdir($new_apps_path) && symlink($apps_dirname, $new_apps_path_symlink)
+ ), 'Setup of apps path failed');
// Create an app within that path
- mkdir($new_apps_path . '/' . 'test-js-app');
+ $this->assertTrue((
+ mkdir($new_apps_path . '/' . $appName) && touch($new_apps_path . '/' . $appName . '/' . 'test-file.js')
+ ), 'Setup of app within the new apps path failed');
// Use the symlink as the app path
- \OC::$APPSROOTS[] = [
- 'path' => $new_apps_path_symlink,
- 'url' => '/js-apps-test',
- 'writable' => false,
- ];
-
+ $this->appManager->expects($this->once())
+ ->method('getAppPath')
+ ->with($appName)
+ ->willReturn("$new_apps_path_symlink/$appName");
+ $this->appManager->expects($this->once())
+ ->method('getAppWebPath')
+ ->with($appName)
+ ->willReturn("/js-apps-test/$appName");
+
+ // Run the tests
$locator = $this->jsResourceLocator();
- $locator->find(['test-js-app/test-file']);
+ $locator->find(["$appName/test-file"]);
$resources = $locator->getResources();
$this->assertCount(1, $resources);
@@ -112,17 +111,73 @@ class JSResourceLocatorTest extends \Test\TestCase {
$webRoot = $resource[1];
$file = $resource[2];
- $expectedRoot = $new_apps_path . '/test-js-app';
- $expectedWebRoot = \OC::$WEBROOT . '/js-apps-test/test-js-app';
- $expectedFile = 'test-file.js';
+ $expectedRoot = $new_apps_path;
+ $expectedWebRoot = \OC::$WEBROOT . '/js-apps-test';
+ $expectedFile = $appName . '/test-file.js';
$this->assertEquals($expectedRoot, $root,
'Ensure the app path symlink is resolved into the real path');
$this->assertEquals($expectedWebRoot, $webRoot);
$this->assertEquals($expectedFile, $file);
- array_pop(\OC::$APPSROOTS);
unlink($new_apps_path_symlink);
$this->rrmdir($new_apps_path);
}
+
+ public function testNotExistingTranslationHandledSilent(): void {
+ $this->appManager->expects($this->once())
+ ->method('getAppPath')
+ ->with('core')
+ ->willThrowException(new AppPathNotFoundException());
+ $this->appManager->expects($this->atMost(1))
+ ->method('getAppWebPath')
+ ->with('core')
+ ->willThrowException(new AppPathNotFoundException());
+ // Assert logger is not called
+ $this->logger->expects($this->never())
+ ->method('error');
+
+ // Run the tests
+ $locator = $this->jsResourceLocator();
+ $locator->find(['core/l10n/en.js']);
+
+ $resources = $locator->getResources();
+ $this->assertCount(0, $resources);
+ }
+
+ public function testFindModuleJSWithFallback(): void {
+ // First create new apps path, and a symlink to it
+ $apps_dirname = $this->randomString();
+ $new_apps_path = sys_get_temp_dir() . '/' . $apps_dirname;
+ mkdir($new_apps_path);
+
+ // Create an app within that path
+ mkdir("$new_apps_path/test-js-app");
+ touch("$new_apps_path/test-js-app/module.mjs");
+ touch("$new_apps_path/test-js-app/both.mjs");
+ touch("$new_apps_path/test-js-app/both.js");
+ touch("$new_apps_path/test-js-app/plain.js");
+
+ // Use the app path
+ $this->appManager->expects($this->any())
+ ->method('getAppPath')
+ ->with('test-js-app')
+ ->willReturn("$new_apps_path/test-js-app");
+
+ $locator = $this->jsResourceLocator();
+ $locator->find(['test-js-app/module', 'test-js-app/both', 'test-js-app/plain']);
+
+ $resources = $locator->getResources();
+ $this->assertCount(3, $resources);
+
+ $expectedWebRoot = \OC::$WEBROOT . '/js-apps-test/test-js-app';
+ $expectedFiles = ['module.mjs', 'both.mjs', 'plain.js'];
+
+ for ($idx = 0; $idx++; $idx < 3) {
+ $this->assertEquals($expectedWebRoot, $resources[$idx][1]);
+ $this->assertEquals($expectedFiles[$idx], $resources[$idx][2]);
+ }
+
+ $this->rrmdir($new_apps_path);
+ }
}
diff --git a/tests/lib/Template/ResourceLocatorTest.php b/tests/lib/Template/ResourceLocatorTest.php
index fa329ca6581..599c8391ade 100644
--- a/tests/lib/Template/ResourceLocatorTest.php
+++ b/tests/lib/Template/ResourceLocatorTest.php
@@ -1,9 +1,9 @@
<?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.
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace Test\Template;
@@ -38,7 +38,7 @@ class ResourceLocatorTest extends \Test\TestCase {
'', true, true, true, []);
}
- public function testFind() {
+ public function testFind(): void {
$locator = $this->getResourceLocator('theme');
$locator->expects($this->once())
->method('doFind')
@@ -50,7 +50,7 @@ class ResourceLocatorTest extends \Test\TestCase {
$locator->find(['foo']);
}
- public function testFindNotFound() {
+ public function testFindNotFound(): void {
$systemConfig = $this->createMock(SystemConfig::class);
$systemConfig->method('getValue')
->with('theme', '')
@@ -61,11 +61,11 @@ class ResourceLocatorTest extends \Test\TestCase {
$locator->expects($this->once())
->method('doFind')
->with('foo')
- ->will($this->throwException(new ResourceNotFoundException('foo', 'map')));
+ ->willThrowException(new ResourceNotFoundException('foo', 'map'));
$locator->expects($this->once())
->method('doFindTheme')
->with('foo')
- ->will($this->throwException(new ResourceNotFoundException('foo', 'map')));
+ ->willThrowException(new ResourceNotFoundException('foo', 'map'));
$this->logger->expects($this->exactly(2))
->method('debug')
->with($this->stringContains('map/foo'));
@@ -73,7 +73,7 @@ class ResourceLocatorTest extends \Test\TestCase {
$locator->find(['foo']);
}
- public function testAppendIfExist() {
+ public function testAppendIfExist(): void {
$locator = $this->getResourceLocator('theme');
/** @var \OC\Template\ResourceLocator $locator */
$method = new \ReflectionMethod($locator, 'appendIfExist');
diff --git a/tests/lib/Template/data/1.js.license b/tests/lib/Template/data/1.js.license
new file mode 100644
index 00000000000..dddb428772d
--- /dev/null
+++ b/tests/lib/Template/data/1.js.license
@@ -0,0 +1,2 @@
+SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
+SPDX-License-Identifier: AGPL-3.0-or-later
diff --git a/tests/lib/Template/data/2.js.license b/tests/lib/Template/data/2.js.license
new file mode 100644
index 00000000000..dddb428772d
--- /dev/null
+++ b/tests/lib/Template/data/2.js.license
@@ -0,0 +1,2 @@
+SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
+SPDX-License-Identifier: AGPL-3.0-or-later
diff --git a/tests/lib/Template/data/combine.json.license b/tests/lib/Template/data/combine.json.license
new file mode 100644
index 00000000000..dddb428772d
--- /dev/null
+++ b/tests/lib/Template/data/combine.json.license
@@ -0,0 +1,2 @@
+SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
+SPDX-License-Identifier: AGPL-3.0-or-later