mirror of
https://github.com/nextcloud/server.git
synced 2026-06-12 10:10:49 -04:00
test: move legacy tests to non-depecated class tests
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
This commit is contained in:
parent
3d33091d2c
commit
3868d62a8f
4 changed files with 123 additions and 104 deletions
42
tests/lib/FilesTest.php
Normal file
42
tests/lib/FilesTest.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace Test;
|
||||
|
||||
use OCP\Files;
|
||||
use OCP\ITempManager;
|
||||
use OCP\Server;
|
||||
|
||||
class FilesTest extends TestCase {
|
||||
|
||||
/**
|
||||
* Tests recursive folder deletion with rmdirr()
|
||||
*/
|
||||
public function testRecursiveFolderDeletion(): void {
|
||||
$baseDir = Server::get(ITempManager::class)->getTemporaryFolder() . '/';
|
||||
mkdir($baseDir . 'a/b/c/d/e', 0777, true);
|
||||
mkdir($baseDir . 'a/b/c1/d/e', 0777, true);
|
||||
mkdir($baseDir . 'a/b/c2/d/e', 0777, true);
|
||||
mkdir($baseDir . 'a/b1/c1/d/e', 0777, true);
|
||||
mkdir($baseDir . 'a/b2/c1/d/e', 0777, true);
|
||||
mkdir($baseDir . 'a/b3/c1/d/e', 0777, true);
|
||||
mkdir($baseDir . 'a1/b', 0777, true);
|
||||
mkdir($baseDir . 'a1/c', 0777, true);
|
||||
file_put_contents($baseDir . 'a/test.txt', 'Hello file!');
|
||||
file_put_contents($baseDir . 'a/b1/c1/test one.txt', 'Hello file one!');
|
||||
file_put_contents($baseDir . 'a1/b/test two.txt', 'Hello file two!');
|
||||
Files::rmdirr($baseDir . 'a');
|
||||
|
||||
$this->assertFalse(file_exists($baseDir . 'a'));
|
||||
$this->assertTrue(file_exists($baseDir . 'a1'));
|
||||
|
||||
Files::rmdirr($baseDir);
|
||||
$this->assertFalse(file_exists($baseDir));
|
||||
}
|
||||
}
|
||||
|
|
@ -94,6 +94,7 @@ class HelperStorageTest extends \Test\TestCase {
|
|||
$this->assertEquals(5, $storageInfo['used']);
|
||||
$this->assertEquals(17, $storageInfo['total']);
|
||||
}
|
||||
|
||||
private function getIncludeExternalStorage(): bool {
|
||||
$class = new \ReflectionClass(\OC_Helper::class);
|
||||
$prop = $class->getProperty('quotaIncludeExternalStorage');
|
||||
|
|
|
|||
|
|
@ -23,85 +23,6 @@ class LegacyHelperTest extends \Test\TestCase {
|
|||
\OC::$WEBROOT = $this->originalWebRoot;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider humanFileSizeProvider
|
||||
*/
|
||||
public function testHumanFileSize($expected, $input): void {
|
||||
$result = OC_Helper::humanFileSize($input);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public static function humanFileSizeProvider(): array {
|
||||
return [
|
||||
['0 B', 0],
|
||||
['1 KB', 1024],
|
||||
['9.5 MB', 10000000],
|
||||
['1.3 GB', 1395864371],
|
||||
['465.7 GB', 500000000000],
|
||||
['454.7 TB', 500000000000000],
|
||||
['444.1 PB', 500000000000000000],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providesComputerFileSize
|
||||
*/
|
||||
public function testComputerFileSize($expected, $input): void {
|
||||
$result = OC_Helper::computerFileSize($input);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public static function providesComputerFileSize(): array {
|
||||
return [
|
||||
[0.0, '0 B'],
|
||||
[1024.0, '1 KB'],
|
||||
[1395864371.0, '1.3 GB'],
|
||||
[9961472.0, '9.5 MB'],
|
||||
[500041567437.0, '465.7 GB'],
|
||||
[false, '12 GB etfrhzui']
|
||||
];
|
||||
}
|
||||
|
||||
public function testMb_array_change_key_case(): void {
|
||||
$arrayStart = [
|
||||
'Foo' => 'bar',
|
||||
'Bar' => 'foo',
|
||||
];
|
||||
$arrayResult = [
|
||||
'foo' => 'bar',
|
||||
'bar' => 'foo',
|
||||
];
|
||||
$result = OC_Helper::mb_array_change_key_case($arrayStart);
|
||||
$expected = $arrayResult;
|
||||
$this->assertEquals($result, $expected);
|
||||
|
||||
$arrayStart = [
|
||||
'foo' => 'bar',
|
||||
'bar' => 'foo',
|
||||
];
|
||||
$arrayResult = [
|
||||
'FOO' => 'bar',
|
||||
'BAR' => 'foo',
|
||||
];
|
||||
$result = OC_Helper::mb_array_change_key_case($arrayStart, MB_CASE_UPPER);
|
||||
$expected = $arrayResult;
|
||||
$this->assertEquals($result, $expected);
|
||||
}
|
||||
|
||||
public function testRecursiveArraySearch(): void {
|
||||
$haystack = [
|
||||
'Foo' => 'own',
|
||||
'Bar' => 'Cloud',
|
||||
];
|
||||
|
||||
$result = OC_Helper::recursiveArraySearch($haystack, 'own');
|
||||
$expected = 'Foo';
|
||||
$this->assertEquals($result, $expected);
|
||||
|
||||
$result = OC_Helper::recursiveArraySearch($haystack, 'NotFound');
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
public function testBuildNotExistingFileNameForView(): void {
|
||||
$viewMock = $this->createMock(View::class);
|
||||
$this->assertEquals('/filename', OC_Helper::buildNotExistingFileNameForView('/', 'filename', $viewMock));
|
||||
|
|
@ -227,29 +148,4 @@ class LegacyHelperTest extends \Test\TestCase {
|
|||
[3670, true, \OC::$SERVERROOT . '/tests/data/testimage.png', \OC::$SERVERROOT . '/tests/data/testimage-copy.png'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests recursive folder deletion with rmdirr()
|
||||
*/
|
||||
public function testRecursiveFolderDeletion(): void {
|
||||
$baseDir = \OC::$server->getTempManager()->getTemporaryFolder() . '/';
|
||||
mkdir($baseDir . 'a/b/c/d/e', 0777, true);
|
||||
mkdir($baseDir . 'a/b/c1/d/e', 0777, true);
|
||||
mkdir($baseDir . 'a/b/c2/d/e', 0777, true);
|
||||
mkdir($baseDir . 'a/b1/c1/d/e', 0777, true);
|
||||
mkdir($baseDir . 'a/b2/c1/d/e', 0777, true);
|
||||
mkdir($baseDir . 'a/b3/c1/d/e', 0777, true);
|
||||
mkdir($baseDir . 'a1/b', 0777, true);
|
||||
mkdir($baseDir . 'a1/c', 0777, true);
|
||||
file_put_contents($baseDir . 'a/test.txt', 'Hello file!');
|
||||
file_put_contents($baseDir . 'a/b1/c1/test one.txt', 'Hello file one!');
|
||||
file_put_contents($baseDir . 'a1/b/test two.txt', 'Hello file two!');
|
||||
\OC_Helper::rmdirr($baseDir . 'a');
|
||||
|
||||
$this->assertFalse(file_exists($baseDir . 'a'));
|
||||
$this->assertTrue(file_exists($baseDir . 'a1'));
|
||||
|
||||
\OC_Helper::rmdirr($baseDir);
|
||||
$this->assertFalse(file_exists($baseDir));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -334,4 +334,84 @@ class UtilTest extends \Test\TestCase {
|
|||
// each of the characters is 12 bytes
|
||||
$this->assertEquals('🙈', Util::shortenMultibyteString('🙈🙊🙉', 16, 2));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider humanFileSizeProvider
|
||||
*/
|
||||
public function testHumanFileSize($expected, $input): void {
|
||||
$result = Util::humanFileSize($input);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public static function humanFileSizeProvider(): array {
|
||||
return [
|
||||
['0 B', 0],
|
||||
['1 KB', 1024],
|
||||
['9.5 MB', 10000000],
|
||||
['1.3 GB', 1395864371],
|
||||
['465.7 GB', 500000000000],
|
||||
['454.7 TB', 500000000000000],
|
||||
['444.1 PB', 500000000000000000],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providesComputerFileSize
|
||||
*/
|
||||
public function testComputerFileSize($expected, $input): void {
|
||||
$result = Util::computerFileSize($input);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public static function providesComputerFileSize(): array {
|
||||
return [
|
||||
[0.0, '0 B'],
|
||||
[1024.0, '1 KB'],
|
||||
[1395864371.0, '1.3 GB'],
|
||||
[9961472.0, '9.5 MB'],
|
||||
[500041567437.0, '465.7 GB'],
|
||||
[false, '12 GB etfrhzui']
|
||||
];
|
||||
}
|
||||
|
||||
public function testMb_array_change_key_case(): void {
|
||||
$arrayStart = [
|
||||
'Foo' => 'bar',
|
||||
'Bar' => 'foo',
|
||||
];
|
||||
$arrayResult = [
|
||||
'foo' => 'bar',
|
||||
'bar' => 'foo',
|
||||
];
|
||||
$result = Util::mb_array_change_key_case($arrayStart);
|
||||
$expected = $arrayResult;
|
||||
$this->assertEquals($result, $expected);
|
||||
|
||||
$arrayStart = [
|
||||
'foo' => 'bar',
|
||||
'bar' => 'foo',
|
||||
];
|
||||
$arrayResult = [
|
||||
'FOO' => 'bar',
|
||||
'BAR' => 'foo',
|
||||
];
|
||||
$result = Util::mb_array_change_key_case($arrayStart, MB_CASE_UPPER);
|
||||
$expected = $arrayResult;
|
||||
$this->assertEquals($result, $expected);
|
||||
}
|
||||
|
||||
public function testRecursiveArraySearch(): void {
|
||||
$haystack = [
|
||||
'Foo' => 'own',
|
||||
'Bar' => 'Cloud',
|
||||
];
|
||||
|
||||
$result = Util::recursiveArraySearch($haystack, 'own');
|
||||
$expected = 'Foo';
|
||||
$this->assertEquals($result, $expected);
|
||||
|
||||
$result = Util::recursiveArraySearch($haystack, 'NotFound');
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue