aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Files/Storage/Wrapper/EncodingTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/Files/Storage/Wrapper/EncodingTest.php')
-rw-r--r--tests/lib/Files/Storage/Wrapper/EncodingTest.php99
1 files changed, 47 insertions, 52 deletions
diff --git a/tests/lib/Files/Storage/Wrapper/EncodingTest.php b/tests/lib/Files/Storage/Wrapper/EncodingTest.php
index 0901edf83fa..cb6b6de0fb7 100644
--- a/tests/lib/Files/Storage/Wrapper/EncodingTest.php
+++ b/tests/lib/Files/Storage/Wrapper/EncodingTest.php
@@ -1,26 +1,29 @@
<?php
+
/**
- * Copyright (c) 2016 Vincent Petry <pvince81@owncloud.com>
- * This file is licensed under the Affero General Public License version 3 or
- * later.
- * See the COPYING-README file.
+ * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace Test\Files\Storage\Wrapper;
+use OC\Files\Storage\Temporary;
+use OC\Files\Storage\Wrapper\Encoding;
+
class EncodingTest extends \Test\Files\Storage\Storage {
public const NFD_NAME = 'ümlaut';
public const NFC_NAME = 'ümlaut';
/**
- * @var \OC\Files\Storage\Temporary
+ * @var Temporary
*/
private $sourceStorage;
protected function setUp(): void {
parent::setUp();
- $this->sourceStorage = new \OC\Files\Storage\Temporary([]);
- $this->instance = new \OC\Files\Storage\Wrapper\Encoding([
+ $this->sourceStorage = new Temporary([]);
+ $this->instance = new Encoding([
'storage' => $this->sourceStorage
]);
}
@@ -30,43 +33,39 @@ class EncodingTest extends \Test\Files\Storage\Storage {
parent::tearDown();
}
- public function directoryProvider() {
+ public static function directoryProvider(): array {
$a = parent::directoryProvider();
$a[] = [self::NFC_NAME];
return $a;
}
- public function fileNameProvider() {
+ public static function fileNameProvider(): array {
$a = parent::fileNameProvider();
$a[] = [self::NFD_NAME . '.txt'];
return $a;
}
- public function copyAndMoveProvider() {
+ public static function copyAndMoveProvider(): array {
$a = parent::copyAndMoveProvider();
$a[] = [self::NFD_NAME . '.txt', self::NFC_NAME . '-renamed.txt'];
return $a;
}
- public function accessNameProvider() {
+ public static function accessNameProvider(): array {
return [
[self::NFD_NAME],
[self::NFC_NAME],
];
}
- /**
- * @dataProvider accessNameProvider
- */
- public function testFputEncoding($accessName) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('accessNameProvider')]
+ public function testFputEncoding($accessName): void {
$this->sourceStorage->file_put_contents(self::NFD_NAME, 'bar');
$this->assertEquals('bar', $this->instance->file_get_contents($accessName));
}
- /**
- * @dataProvider accessNameProvider
- */
- public function testFopenReadEncoding($accessName) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('accessNameProvider')]
+ public function testFopenReadEncoding($accessName): void {
$this->sourceStorage->file_put_contents(self::NFD_NAME, 'bar');
$fh = $this->instance->fopen($accessName, 'r');
$data = fgets($fh);
@@ -74,10 +73,8 @@ class EncodingTest extends \Test\Files\Storage\Storage {
$this->assertEquals('bar', $data);
}
- /**
- * @dataProvider accessNameProvider
- */
- public function testFopenOverwriteEncoding($accessName) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('accessNameProvider')]
+ public function testFopenOverwriteEncoding($accessName): void {
$this->sourceStorage->file_put_contents(self::NFD_NAME, 'bar');
$fh = $this->instance->fopen($accessName, 'w');
$data = fputs($fh, 'test');
@@ -87,42 +84,36 @@ class EncodingTest extends \Test\Files\Storage\Storage {
$this->assertFalse($this->sourceStorage->file_exists(self::NFC_NAME));
}
- /**
- * @dataProvider accessNameProvider
- */
- public function testFileExistsEncoding($accessName) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('accessNameProvider')]
+ public function testFileExistsEncoding($accessName): void {
$this->sourceStorage->file_put_contents(self::NFD_NAME, 'bar');
$this->assertTrue($this->instance->file_exists($accessName));
}
- /**
- * @dataProvider accessNameProvider
- */
- public function testUnlinkEncoding($accessName) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('accessNameProvider')]
+ public function testUnlinkEncoding($accessName): void {
$this->sourceStorage->file_put_contents(self::NFD_NAME, 'bar');
$this->assertTrue($this->instance->unlink($accessName));
$this->assertFalse($this->sourceStorage->file_exists(self::NFC_NAME));
$this->assertFalse($this->sourceStorage->file_exists(self::NFD_NAME));
}
- public function testNfcHigherPriority() {
+ public function testNfcHigherPriority(): void {
$this->sourceStorage->file_put_contents(self::NFC_NAME, 'nfc');
$this->sourceStorage->file_put_contents(self::NFD_NAME, 'nfd');
$this->assertEquals('nfc', $this->instance->file_get_contents(self::NFC_NAME));
}
- public function encodedDirectoriesProvider() {
+ public static function encodedDirectoriesProvider(): array {
return [
[self::NFD_NAME, self::NFC_NAME],
[self::NFD_NAME . '/' . self::NFD_NAME, self::NFC_NAME . '/' . self::NFC_NAME],
- [self::NFD_NAME . '/' . self::NFC_NAME . '/' .self::NFD_NAME, self::NFC_NAME . '/' . self::NFC_NAME . '/' . self::NFC_NAME],
+ [self::NFD_NAME . '/' . self::NFC_NAME . '/' . self::NFD_NAME, self::NFC_NAME . '/' . self::NFC_NAME . '/' . self::NFC_NAME],
];
}
- /**
- * @dataProvider encodedDirectoriesProvider
- */
- public function testOperationInsideDirectory($sourceDir, $accessDir) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('encodedDirectoriesProvider')]
+ public function testOperationInsideDirectory($sourceDir, $accessDir): void {
$this->sourceStorage->mkdir($sourceDir);
$this->instance->file_put_contents($accessDir . '/test.txt', 'bar');
$this->assertTrue($this->instance->file_exists($accessDir . '/test.txt'));
@@ -139,7 +130,7 @@ class EncodingTest extends \Test\Files\Storage\Storage {
$this->assertTrue($this->instance->file_exists($accessDir . '/' . self::NFC_NAME));
}
- public function testCacheExtraSlash() {
+ public function testCacheExtraSlash(): void {
$this->sourceStorage->file_put_contents(self::NFD_NAME, 'foo');
$this->assertEquals(3, $this->instance->file_put_contents(self::NFC_NAME, 'bar'));
$this->assertEquals('bar', $this->instance->file_get_contents(self::NFC_NAME));
@@ -151,7 +142,7 @@ class EncodingTest extends \Test\Files\Storage\Storage {
$this->assertEquals('barbaric', $this->instance->file_get_contents('//' . self::NFC_NAME));
}
- public function sourceAndTargetDirectoryProvider() {
+ public static function sourceAndTargetDirectoryProvider(): array {
return [
[self::NFC_NAME . '1', self::NFC_NAME . '2'],
[self::NFD_NAME . '1', self::NFC_NAME . '2'],
@@ -160,10 +151,8 @@ class EncodingTest extends \Test\Files\Storage\Storage {
];
}
- /**
- * @dataProvider sourceAndTargetDirectoryProvider
- */
- public function testCopyAndMoveEncodedFolder($sourceDir, $targetDir) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('sourceAndTargetDirectoryProvider')]
+ public function testCopyAndMoveEncodedFolder($sourceDir, $targetDir): void {
$this->sourceStorage->mkdir($sourceDir);
$this->sourceStorage->mkdir($targetDir);
$this->sourceStorage->file_put_contents($sourceDir . '/test.txt', 'bar');
@@ -180,10 +169,8 @@ class EncodingTest extends \Test\Files\Storage\Storage {
$this->assertEquals('bar', $this->instance->file_get_contents(self::NFC_NAME . '2/test2.txt'));
}
- /**
- * @dataProvider sourceAndTargetDirectoryProvider
- */
- public function testCopyAndMoveFromStorageEncodedFolder($sourceDir, $targetDir) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('sourceAndTargetDirectoryProvider')]
+ public function testCopyAndMoveFromStorageEncodedFolder($sourceDir, $targetDir): void {
$this->sourceStorage->mkdir($sourceDir);
$this->sourceStorage->mkdir($targetDir);
$this->sourceStorage->file_put_contents($sourceDir . '/test.txt', 'bar');
@@ -200,7 +187,7 @@ class EncodingTest extends \Test\Files\Storage\Storage {
$this->assertEquals('bar', $this->instance->file_get_contents(self::NFC_NAME . '2/test2.txt'));
}
- public function testNormalizedDirectoryEntriesOpenDir() {
+ public function testNormalizedDirectoryEntriesOpenDir(): void {
$this->sourceStorage->mkdir('/test');
$this->sourceStorage->mkdir('/test/' . self::NFD_NAME);
@@ -209,7 +196,7 @@ class EncodingTest extends \Test\Files\Storage\Storage {
$dh = $this->instance->opendir('/test');
$content = [];
- while ($file = readdir($dh)) {
+ while (($file = readdir($dh)) !== false) {
if ($file != '.' and $file != '..') {
$content[] = $file;
}
@@ -219,7 +206,7 @@ class EncodingTest extends \Test\Files\Storage\Storage {
$this->assertEquals(self::NFC_NAME, $content[0]);
}
- public function testNormalizedDirectoryEntriesGetDirectoryContent() {
+ public function testNormalizedDirectoryEntriesGetDirectoryContent(): void {
$this->sourceStorage->mkdir('/test');
$this->sourceStorage->mkdir('/test/' . self::NFD_NAME);
@@ -231,7 +218,7 @@ class EncodingTest extends \Test\Files\Storage\Storage {
$this->assertEquals(self::NFC_NAME, $content[0]['name']);
}
- public function testNormalizedGetMetaData() {
+ public function testNormalizedGetMetaData(): void {
$this->sourceStorage->mkdir('/test');
$this->sourceStorage->mkdir('/test/' . self::NFD_NAME);
@@ -241,4 +228,12 @@ class EncodingTest extends \Test\Files\Storage\Storage {
$entry = $this->instance->getMetaData('/test/' . self::NFD_NAME);
$this->assertEquals(self::NFC_NAME, $entry['name']);
}
+
+ /**
+ * Regression test of https://github.com/nextcloud/server/issues/50431
+ */
+ public function testNoMetadata() {
+ $this->assertNull($this->instance->getMetaData('/test/null'));
+ }
+
}