aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Template
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/Template')
-rw-r--r--tests/lib/Template/CSSResourceLocatorTest.php3
-rw-r--r--tests/lib/Template/JSCombinerTest.php121
-rw-r--r--tests/lib/Template/JSResourceLocatorTest.php9
-rw-r--r--tests/lib/Template/ResourceLocatorTest.php11
4 files changed, 63 insertions, 81 deletions
diff --git a/tests/lib/Template/CSSResourceLocatorTest.php b/tests/lib/Template/CSSResourceLocatorTest.php
index 64c31d9c94c..2ae37999b32 100644
--- a/tests/lib/Template/CSSResourceLocatorTest.php
+++ b/tests/lib/Template/CSSResourceLocatorTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -77,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 d9de4b088d1..bc286695bc7 100644
--- a/tests/lib/Template/JSCombinerTest.php
+++ b/tests/lib/Template/JSCombinerTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -15,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 {
@@ -55,7 +58,7 @@ class JSCombinerTest extends \Test\TestCase {
);
}
- public function testProcessDebugMode() {
+ public function testProcessDebugMode(): void {
$this->config
->expects($this->once())
->method('getValue')
@@ -66,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);
@@ -123,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);
@@ -161,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);
@@ -202,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')
@@ -243,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);
@@ -263,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')
@@ -281,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')
@@ -299,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')
@@ -319,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);
@@ -352,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);
@@ -383,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);
@@ -395,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')
@@ -429,7 +408,7 @@ var b = \'world\';
$this->assertFalse($actual);
}
- public function testCacheSuccess() {
+ public function testCacheSuccess(): void {
$fileName = 'combine.js';
$folder = $this->createMock(ISimpleFolder::class);
@@ -484,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']
@@ -495,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', [
@@ -510,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']);
@@ -525,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 354f23fac19..89ab8e66dd7 100644
--- a/tests/lib/Template/JSResourceLocatorTest.php
+++ b/tests/lib/Template/JSResourceLocatorTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -72,7 +73,7 @@ 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
@@ -123,7 +124,7 @@ class JSResourceLocatorTest extends \Test\TestCase {
$this->rrmdir($new_apps_path);
}
- public function testNotExistingTranslationHandledSilent() {
+ public function testNotExistingTranslationHandledSilent(): void {
$this->appManager->expects($this->once())
->method('getAppPath')
->with('core')
@@ -138,13 +139,13 @@ class JSResourceLocatorTest extends \Test\TestCase {
// Run the tests
$locator = $this->jsResourceLocator();
- $locator->find(["core/l10n/en.js"]);
+ $locator->find(['core/l10n/en.js']);
$resources = $locator->getResources();
$this->assertCount(0, $resources);
}
- public function testFindModuleJSWithFallback() {
+ 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;
diff --git a/tests/lib/Template/ResourceLocatorTest.php b/tests/lib/Template/ResourceLocatorTest.php
index e74e72014c5..599c8391ade 100644
--- a/tests/lib/Template/ResourceLocatorTest.php
+++ b/tests/lib/Template/ResourceLocatorTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -37,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')
@@ -49,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', '')
@@ -60,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'));
@@ -72,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');