aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/LegacyHelperTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/LegacyHelperTest.php')
-rw-r--r--tests/lib/LegacyHelperTest.php109
1 files changed, 2 insertions, 107 deletions
diff --git a/tests/lib/LegacyHelperTest.php b/tests/lib/LegacyHelperTest.php
index 15af5ca06e8..c18f929e40c 100644
--- a/tests/lib/LegacyHelperTest.php
+++ b/tests/lib/LegacyHelperTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -23,85 +24,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));
@@ -194,9 +116,7 @@ class LegacyHelperTest extends \Test\TestCase {
$this->assertEquals('dir/filename(1) (2) (4).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename(1) (2) (3).ext', $viewMock));
}
- /**
- * @dataProvider streamCopyDataProvider
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('streamCopyDataProvider')]
public function testStreamCopy($expectedCount, $expectedResult, $source, $target): void {
if (is_string($source)) {
$source = fopen($source, 'r');
@@ -227,29 +147,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));
- }
}