diff options
Diffstat (limited to 'tests/lib/Archive')
-rw-r--r-- | tests/lib/Archive/TARTest.php | 12 | ||||
-rw-r--r-- | tests/lib/Archive/TestBase.php | 82 | ||||
-rw-r--r-- | tests/lib/Archive/ZIPTest.php | 16 |
3 files changed, 61 insertions, 49 deletions
diff --git a/tests/lib/Archive/TARTest.php b/tests/lib/Archive/TARTest.php index 6b16f061623..e77f97ac8e1 100644 --- a/tests/lib/Archive/TARTest.php +++ b/tests/lib/Archive/TARTest.php @@ -1,14 +1,16 @@ <?php + /** - * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com> - * 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\Archive; use OC\Archive\TAR; +use OCP\ITempManager; +use OCP\Server; class TARTest extends TestBase { protected function getExisting() { @@ -17,6 +19,6 @@ class TARTest extends TestBase { } protected function getNew() { - return new TAR(\OC::$server->getTempManager()->getTemporaryFile('.tar.gz')); + return new TAR(Server::get(ITempManager::class)->getTemporaryFile('.tar.gz')); } } diff --git a/tests/lib/Archive/TestBase.php b/tests/lib/Archive/TestBase.php index a816cd97710..1b7f7d3325a 100644 --- a/tests/lib/Archive/TestBase.php +++ b/tests/lib/Archive/TestBase.php @@ -1,13 +1,17 @@ <?php + /** - * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com> - * 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\Archive; +use OCP\Files; +use OCP\ITempManager; +use OCP\Server; + abstract class TestBase extends \Test\TestCase { /** * @var \OC\Archive\Archive @@ -25,14 +29,14 @@ abstract class TestBase extends \Test\TestCase { */ abstract protected function getNew(); - public function testGetFiles() { + public function testGetFiles(): void { $this->instance = $this->getExisting(); $allFiles = $this->instance->getFiles(); $expected = ['lorem.txt','logo-wide.png','dir/', 'dir/lorem.txt']; - $this->assertEquals(4, count($allFiles), 'only found '.count($allFiles).' out of 4 expected files'); + $this->assertEquals(4, count($allFiles), 'only found ' . count($allFiles) . ' out of 4 expected files'); foreach ($expected as $file) { - $this->assertContains($file, $allFiles, 'cant find '. $file . ' in archive'); - $this->assertTrue($this->instance->fileExists($file), 'file '.$file.' does not exist in archive'); + $this->assertContains($file, $allFiles, 'cant find ' . $file . ' in archive'); + $this->assertTrue($this->instance->fileExists($file), 'file ' . $file . ' does not exist in archive'); } $this->assertFalse($this->instance->fileExists('non/existing/file')); @@ -40,31 +44,31 @@ abstract class TestBase extends \Test\TestCase { $expected = ['lorem.txt','logo-wide.png', 'dir/']; $this->assertEquals(3, count($rootContent)); foreach ($expected as $file) { - $this->assertContains($file, $rootContent, 'cant find '. $file . ' in archive'); + $this->assertContains($file, $rootContent, 'cant find ' . $file . ' in archive'); } $dirContent = $this->instance->getFolder('dir/'); $expected = ['lorem.txt']; $this->assertEquals(1, count($dirContent)); foreach ($expected as $file) { - $this->assertContains($file, $dirContent, 'cant find '. $file . ' in archive'); + $this->assertContains($file, $dirContent, 'cant find ' . $file . ' in archive'); } } - public function testContent() { + public function testContent(): void { $this->instance = $this->getExisting(); - $dir = \OC::$SERVERROOT.'/tests/data'; - $textFile = $dir.'/lorem.txt'; + $dir = \OC::$SERVERROOT . '/tests/data'; + $textFile = $dir . '/lorem.txt'; $this->assertEquals(file_get_contents($textFile), $this->instance->getFile('lorem.txt')); - $tmpFile = \OC::$server->getTempManager()->getTemporaryFile('.txt'); + $tmpFile = Server::get(ITempManager::class)->getTemporaryFile('.txt'); $this->instance->extractFile('lorem.txt', $tmpFile); $this->assertEquals(file_get_contents($textFile), file_get_contents($tmpFile)); } - public function testWrite() { - $dir = \OC::$SERVERROOT.'/tests/data'; - $textFile = $dir.'/lorem.txt'; + public function testWrite(): void { + $dir = \OC::$SERVERROOT . '/tests/data'; + $textFile = $dir . '/lorem.txt'; $this->instance = $this->getNew(); $this->assertEquals(0, count($this->instance->getFiles())); $this->instance->addFile('lorem.txt', $textFile); @@ -77,27 +81,27 @@ abstract class TestBase extends \Test\TestCase { $this->assertEquals('foobar', $this->instance->getFile('lorem.txt')); } - public function testReadStream() { - $dir = \OC::$SERVERROOT.'/tests/data'; + public function testReadStream(): void { + $dir = \OC::$SERVERROOT . '/tests/data'; $this->instance = $this->getExisting(); $fh = $this->instance->getStream('lorem.txt', 'r'); $this->assertTrue((bool)$fh); $content = fread($fh, $this->instance->filesize('lorem.txt')); fclose($fh); - $this->assertEquals(file_get_contents($dir.'/lorem.txt'), $content); + $this->assertEquals(file_get_contents($dir . '/lorem.txt'), $content); } - public function testWriteStream() { - $dir = \OC::$SERVERROOT.'/tests/data'; + public function testWriteStream(): void { + $dir = \OC::$SERVERROOT . '/tests/data'; $this->instance = $this->getNew(); $fh = $this->instance->getStream('lorem.txt', 'w'); - $source = fopen($dir.'/lorem.txt', 'r'); - \OCP\Files::streamCopy($source, $fh); + $source = fopen($dir . '/lorem.txt', 'r'); + Files::streamCopy($source, $fh); fclose($source); fclose($fh); $this->assertTrue($this->instance->fileExists('lorem.txt')); - $this->assertEquals(file_get_contents($dir.'/lorem.txt'), $this->instance->getFile('lorem.txt')); + $this->assertEquals(file_get_contents($dir . '/lorem.txt'), $this->instance->getFile('lorem.txt')); } - public function testFolder() { + public function testFolder(): void { $this->instance = $this->getNew(); $this->assertFalse($this->instance->fileExists('/test')); $this->assertFalse($this->instance->fileExists('/test/')); @@ -108,20 +112,20 @@ abstract class TestBase extends \Test\TestCase { $this->assertFalse($this->instance->fileExists('/test')); $this->assertFalse($this->instance->fileExists('/test/')); } - public function testExtract() { - $dir = \OC::$SERVERROOT.'/tests/data'; + public function testExtract(): void { + $dir = \OC::$SERVERROOT . '/tests/data'; $this->instance = $this->getExisting(); - $tmpDir = \OC::$server->getTempManager()->getTemporaryFolder(); + $tmpDir = Server::get(ITempManager::class)->getTemporaryFolder(); $this->instance->extract($tmpDir); - $this->assertEquals(true, file_exists($tmpDir.'lorem.txt')); - $this->assertEquals(true, file_exists($tmpDir.'dir/lorem.txt')); - $this->assertEquals(true, file_exists($tmpDir.'logo-wide.png')); - $this->assertEquals(file_get_contents($dir.'/lorem.txt'), file_get_contents($tmpDir.'lorem.txt')); - \OCP\Files::rmdirr($tmpDir); + $this->assertEquals(true, file_exists($tmpDir . 'lorem.txt')); + $this->assertEquals(true, file_exists($tmpDir . 'dir/lorem.txt')); + $this->assertEquals(true, file_exists($tmpDir . 'logo-wide.png')); + $this->assertEquals(file_get_contents($dir . '/lorem.txt'), file_get_contents($tmpDir . 'lorem.txt')); + Files::rmdirr($tmpDir); } - public function testMoveRemove() { - $dir = \OC::$SERVERROOT.'/tests/data'; - $textFile = $dir.'/lorem.txt'; + public function testMoveRemove(): void { + $dir = \OC::$SERVERROOT . '/tests/data'; + $textFile = $dir . '/lorem.txt'; $this->instance = $this->getNew(); $this->instance->addFile('lorem.txt', $textFile); $this->assertFalse($this->instance->fileExists('target.txt')); @@ -132,8 +136,8 @@ abstract class TestBase extends \Test\TestCase { $this->instance->remove('target.txt'); $this->assertFalse($this->instance->fileExists('target.txt')); } - public function testRecursive() { - $dir = \OC::$SERVERROOT.'/tests/data'; + public function testRecursive(): void { + $dir = \OC::$SERVERROOT . '/tests/data'; $this->instance = $this->getNew(); $this->instance->addRecursive('/dir', $dir); $this->assertTrue($this->instance->fileExists('/dir/lorem.txt')); diff --git a/tests/lib/Archive/ZIPTest.php b/tests/lib/Archive/ZIPTest.php index 14443471da1..0996d5abf61 100644 --- a/tests/lib/Archive/ZIPTest.php +++ b/tests/lib/Archive/ZIPTest.php @@ -1,14 +1,16 @@ <?php + /** - * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com> - * 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\Archive; use OC\Archive\ZIP; +use OCP\ITempManager; +use OCP\Server; class ZIPTest extends TestBase { protected function getExisting() { @@ -17,6 +19,10 @@ class ZIPTest extends TestBase { } protected function getNew() { - return new ZIP(\OC::$server->getTempManager()->getTempBaseDir().'/newArchive.zip'); + $newZip = Server::get(ITempManager::class)->getTempBaseDir() . '/newArchive.zip'; + if (file_exists($newZip)) { + unlink($newZip); + } + return new ZIP($newZip); } } |