diff options
Diffstat (limited to 'apps/files_external/tests/Storage')
-rw-r--r-- | apps/files_external/tests/Storage/Amazons3MultiPartTest.php | 49 | ||||
-rw-r--r-- | apps/files_external/tests/Storage/Amazons3Test.php | 45 | ||||
-rw-r--r-- | apps/files_external/tests/Storage/FtpTest.php | 119 | ||||
-rw-r--r-- | apps/files_external/tests/Storage/OwncloudTest.php | 37 | ||||
-rw-r--r-- | apps/files_external/tests/Storage/SFTP_KeyTest.php | 72 | ||||
-rw-r--r-- | apps/files_external/tests/Storage/SftpTest.php | 44 | ||||
-rw-r--r-- | apps/files_external/tests/Storage/SmbTest.php | 119 | ||||
-rw-r--r-- | apps/files_external/tests/Storage/SwiftTest.php | 54 | ||||
-rw-r--r-- | apps/files_external/tests/Storage/VersionedAmazonS3Test.php | 37 | ||||
-rw-r--r-- | apps/files_external/tests/Storage/WebdavTest.php | 42 |
10 files changed, 304 insertions, 314 deletions
diff --git a/apps/files_external/tests/Storage/Amazons3MultiPartTest.php b/apps/files_external/tests/Storage/Amazons3MultiPartTest.php new file mode 100644 index 00000000000..aa3925899f3 --- /dev/null +++ b/apps/files_external/tests/Storage/Amazons3MultiPartTest.php @@ -0,0 +1,49 @@ +<?php + +declare(strict_types=1); +/** + * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +namespace OCA\Files_External\Tests\Storage; + +use OCA\Files_External\Lib\Storage\AmazonS3; + +/** + * Class Amazons3Test + * + * @group DB + * @group S3 + * + * @package OCA\Files_External\Tests\Storage + */ +class Amazons3MultiPartTest extends \Test\Files\Storage\Storage { + private $config; + /** @var AmazonS3 */ + protected $instance; + + protected function setUp(): void { + parent::setUp(); + + $this->config = include('files_external/tests/config.amazons3.php'); + if (!is_array($this->config) || !$this->config['run']) { + $this->markTestSkipped('AmazonS3 backend not configured'); + } + $this->instance = new AmazonS3($this->config + [ + 'putSizeLimit' => 1, + 'copySizeLimit' => 1, + ]); + } + + protected function tearDown(): void { + if ($this->instance) { + $this->instance->rmdir(''); + } + + parent::tearDown(); + } + + public function testStat(): void { + $this->markTestSkipped('S3 doesn\'t update the parents folder mtime'); + } +} diff --git a/apps/files_external/tests/Storage/Amazons3Test.php b/apps/files_external/tests/Storage/Amazons3Test.php index ce616ca175f..d02dec0230c 100644 --- a/apps/files_external/tests/Storage/Amazons3Test.php +++ b/apps/files_external/tests/Storage/Amazons3Test.php @@ -1,56 +1,39 @@ <?php + +declare(strict_types=1); /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Joas Schilling <coding@schilljs.com> - * @author Michael Gapczynski <GapczynskiM@gmail.com> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Robin Appelman <robin@icewind.nl> - * @author Robin McCorkell <robin@mccorkell.me.uk> - * @author Thomas Müller <thomas.mueller@tmit.eu> - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * + * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ - namespace OCA\Files_External\Tests\Storage; -use \OCA\Files_External\Lib\Storage\AmazonS3; +use OCA\Files_External\Lib\Storage\AmazonS3; /** * Class Amazons3Test * * @group DB + * @group S3 * * @package OCA\Files_External\Tests\Storage */ class Amazons3Test extends \Test\Files\Storage\Storage { + protected $config; + /** @var AmazonS3 */ + protected $instance; - private $config; - - protected function setUp() { + protected function setUp(): void { parent::setUp(); $this->config = include('files_external/tests/config.amazons3.php'); - if ( ! is_array($this->config) or ! $this->config['run']) { + if (!is_array($this->config) || !$this->config['run']) { $this->markTestSkipped('AmazonS3 backend not configured'); } $this->instance = new AmazonS3($this->config); } - protected function tearDown() { + protected function tearDown(): void { if ($this->instance) { $this->instance->rmdir(''); } @@ -58,7 +41,7 @@ class Amazons3Test extends \Test\Files\Storage\Storage { parent::tearDown(); } - public function testStat() { + public function testStat(): void { $this->markTestSkipped('S3 doesn\'t update the parents folder mtime'); } } diff --git a/apps/files_external/tests/Storage/FtpTest.php b/apps/files_external/tests/Storage/FtpTest.php index 5b56becb4ad..095a5236049 100644 --- a/apps/files_external/tests/Storage/FtpTest.php +++ b/apps/files_external/tests/Storage/FtpTest.php @@ -1,34 +1,14 @@ <?php + +declare(strict_types=1); /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Joas Schilling <coding@schilljs.com> - * @author Jörn Friedrich Dreyer <jfd@butonic.de> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Robin Appelman <robin@icewind.nl> - * @author Robin McCorkell <robin@mccorkell.me.uk> - * @author Thomas Müller <thomas.mueller@tmit.eu> - * @author Vincent Petry <pvince81@owncloud.com> - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * + * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ - namespace OCA\Files_External\Tests\Storage; -use \OCA\Files_External\Lib\Storage\FTP; +use OCA\Files_External\Lib\Storage\FTP; /** * Class FtpTest @@ -40,58 +20,71 @@ use \OCA\Files_External\Lib\Storage\FTP; class FtpTest extends \Test\Files\Storage\Storage { private $config; - protected function setUp() { + protected function setUp(): void { parent::setUp(); $id = $this->getUniqueID(); $this->config = include('files_external/tests/config.ftp.php'); - if ( ! is_array($this->config) or ! $this->config['run']) { + if (! is_array($this->config) or ! $this->config['run']) { $this->markTestSkipped('FTP backend not configured'); } + $rootInstance = new FTP($this->config); + $rootInstance->mkdir($id); + $this->config['root'] .= '/' . $id; //make sure we have an new empty folder to work in $this->instance = new FTP($this->config); - $this->instance->mkdir('/'); } - protected function tearDown() { + protected function tearDown(): void { if ($this->instance) { - \OCP\Files::rmdirr($this->instance->constructUrl('')); + $this->instance->rmdir(''); } + $this->instance = null; parent::tearDown(); } - public function testConstructUrl(){ - $config = array ( 'host' => 'localhost', - 'user' => 'ftp', - 'password' => 'ftp', - 'root' => '/', - 'secure' => false ); - $instance = new FTP($config); - $this->assertEquals('ftp://ftp:ftp@localhost/', $instance->constructUrl('')); - - $config['secure'] = true; - $instance = new FTP($config); - $this->assertEquals('ftps://ftp:ftp@localhost/', $instance->constructUrl('')); - - $config['secure'] = 'false'; - $instance = new FTP($config); - $this->assertEquals('ftp://ftp:ftp@localhost/', $instance->constructUrl('')); - - $config['secure'] = 'true'; - $instance = new FTP($config); - $this->assertEquals('ftps://ftp:ftp@localhost/', $instance->constructUrl('')); - - $config['root'] = ''; - $instance = new FTP($config); - $this->assertEquals('ftps://ftp:ftp@localhost/somefile.txt', $instance->constructUrl('somefile.txt')); - - $config['root'] = '/abc'; - $instance = new FTP($config); - $this->assertEquals('ftps://ftp:ftp@localhost/abc/somefile.txt', $instance->constructUrl('somefile.txt')); - - $config['root'] = '/abc/'; - $instance = new FTP($config); - $this->assertEquals('ftps://ftp:ftp@localhost/abc/somefile.txt', $instance->constructUrl('somefile.txt')); + /** + * ftp has no proper way to handle spaces at the end of file names + */ + public static function directoryProvider(): array { + return array_filter(parent::directoryProvider(), function ($item) { + return substr($item[0], -1) !== ' '; + }); + } + + + /** + * mtime for folders is only with a minute resolution + */ + public function testStat(): void { + $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; + $ctimeStart = time(); + $this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile)); + $this->assertTrue($this->instance->isReadable('/lorem.txt')); + $ctimeEnd = time(); + $mTime = $this->instance->filemtime('/lorem.txt'); + $this->assertTrue($this->instance->hasUpdated('/lorem.txt', $ctimeStart - 5)); + $this->assertTrue($this->instance->hasUpdated('/', $ctimeStart - 61)); + + // check that ($ctimeStart - 5) <= $mTime <= ($ctimeEnd + 1) + $this->assertGreaterThanOrEqual(($ctimeStart - 5), $mTime); + $this->assertLessThanOrEqual(($ctimeEnd + 1), $mTime); + $this->assertEquals(filesize($textFile), $this->instance->filesize('/lorem.txt')); + + $stat = $this->instance->stat('/lorem.txt'); + //only size and mtime are required in the result + $this->assertEquals($stat['size'], $this->instance->filesize('/lorem.txt')); + $this->assertEquals($stat['mtime'], $mTime); + + if ($this->instance->touch('/lorem.txt', 100) !== false) { + $mTime = $this->instance->filemtime('/lorem.txt'); + $this->assertEquals($mTime, 100); + } + + $mtimeStart = time(); + + $this->instance->unlink('/lorem.txt'); + $this->assertTrue($this->instance->hasUpdated('/', $mtimeStart - 61)); } } diff --git a/apps/files_external/tests/Storage/OwncloudTest.php b/apps/files_external/tests/Storage/OwncloudTest.php index f1564304e2f..ab6cd443dba 100644 --- a/apps/files_external/tests/Storage/OwncloudTest.php +++ b/apps/files_external/tests/Storage/OwncloudTest.php @@ -1,32 +1,14 @@ <?php + +declare(strict_types=1); /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Joas Schilling <coding@schilljs.com> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Robin McCorkell <robin@mccorkell.me.uk> - * @author Thomas Müller <thomas.mueller@tmit.eu> - * @author Vincent Petry <pvince81@owncloud.com> - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * + * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ - namespace OCA\Files_External\Tests\Storage; -use \OCA\Files_External\Lib\Storage\OwnCloud; +use OCA\Files_External\Lib\Storage\OwnCloud; /** * Class OwnCloudTest @@ -36,15 +18,14 @@ use \OCA\Files_External\Lib\Storage\OwnCloud; * @package OCA\Files_External\Tests\Storage */ class OwncloudTest extends \Test\Files\Storage\Storage { - private $config; - protected function setUp() { + protected function setUp(): void { parent::setUp(); $id = $this->getUniqueID(); $this->config = include('files_external/tests/config.php'); - if ( ! is_array($this->config) or ! isset($this->config['owncloud']) or ! $this->config['owncloud']['run']) { + if (! is_array($this->config) or ! isset($this->config['owncloud']) or ! $this->config['owncloud']['run']) { $this->markTestSkipped('Nextcloud backend not configured'); } $this->config['owncloud']['root'] .= '/' . $id; //make sure we have an new empty folder to work in @@ -52,7 +33,7 @@ class OwncloudTest extends \Test\Files\Storage\Storage { $this->instance->mkdir('/'); } - protected function tearDown() { + protected function tearDown(): void { if ($this->instance) { $this->instance->rmdir('/'); } diff --git a/apps/files_external/tests/Storage/SFTP_KeyTest.php b/apps/files_external/tests/Storage/SFTP_KeyTest.php index 6cd62309e68..17e2087f91b 100644 --- a/apps/files_external/tests/Storage/SFTP_KeyTest.php +++ b/apps/files_external/tests/Storage/SFTP_KeyTest.php @@ -1,32 +1,14 @@ <?php + +declare(strict_types=1); /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Morris Jobke <hey@morrisjobke.de> - * @author Robin McCorkell <robin@mccorkell.me.uk> - * @author Ross Nicoll <jrn@jrn.me.uk> - * @author Thomas Müller <thomas.mueller@tmit.eu> - * @author Viktor Szépe <viktor@szepe.net> - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * + * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ - namespace OCA\Files_External\Tests\Storage; -use \OCA\Files_External\Lib\Storage\SFTP_Key; +use OCA\Files_External\Lib\Storage\SFTP_Key; /** * Class SFTP_KeyTest @@ -38,12 +20,12 @@ use \OCA\Files_External\Lib\Storage\SFTP_Key; class SFTP_KeyTest extends \Test\Files\Storage\Storage { private $config; - protected function setUp() { + protected function setUp(): void { parent::setUp(); $id = $this->getUniqueID(); $this->config = include('files_external/tests/config.php'); - if ( ! is_array($this->config) or ! isset($this->config['sftp_key']) or ! $this->config['sftp_key']['run']) { + if (! is_array($this->config) or ! isset($this->config['sftp_key']) or ! $this->config['sftp_key']['run']) { $this->markTestSkipped('SFTP with key backend not configured'); } // Make sure we have an new empty folder to work in @@ -52,7 +34,7 @@ class SFTP_KeyTest extends \Test\Files\Storage\Storage { $this->instance->mkdir('/'); } - protected function tearDown() { + protected function tearDown(): void { if ($this->instance) { $this->instance->rmdir('/'); } @@ -60,40 +42,40 @@ class SFTP_KeyTest extends \Test\Files\Storage\Storage { parent::tearDown(); } - /** - * @expectedException InvalidArgumentException - */ - public function testInvalidAddressShouldThrowException() { + + public function testInvalidAddressShouldThrowException(): void { + $this->expectException(\InvalidArgumentException::class); + // I'd use example.com for this, but someone decided to break the spec and make it resolve $this->instance->assertHostAddressValid('notarealaddress...'); } - public function testValidAddressShouldPass() { + public function testValidAddressShouldPass(): void { $this->assertTrue($this->instance->assertHostAddressValid('localhost')); } - /** - * @expectedException InvalidArgumentException - */ - public function testNegativePortNumberShouldThrowException() { + + public function testNegativePortNumberShouldThrowException(): void { + $this->expectException(\InvalidArgumentException::class); + $this->instance->assertPortNumberValid('-1'); } - /** - * @expectedException InvalidArgumentException - */ - public function testNonNumericalPortNumberShouldThrowException() { + + public function testNonNumericalPortNumberShouldThrowException(): void { + $this->expectException(\InvalidArgumentException::class); + $this->instance->assertPortNumberValid('a'); } - /** - * @expectedException InvalidArgumentException - */ - public function testHighPortNumberShouldThrowException() { + + public function testHighPortNumberShouldThrowException(): void { + $this->expectException(\InvalidArgumentException::class); + $this->instance->assertPortNumberValid('65536'); } - public function testValidPortNumberShouldPass() { + public function testValidPortNumberShouldPass(): void { $this->assertTrue($this->instance->assertPortNumberValid('22222')); } } diff --git a/apps/files_external/tests/Storage/SftpTest.php b/apps/files_external/tests/Storage/SftpTest.php index 85b2eec057f..ebfc8ab3c1f 100644 --- a/apps/files_external/tests/Storage/SftpTest.php +++ b/apps/files_external/tests/Storage/SftpTest.php @@ -1,34 +1,14 @@ <?php + +declare(strict_types=1); /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author hkjolhede <hkjolhede@gmail.com> - * @author Joas Schilling <coding@schilljs.com> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Robin Appelman <robin@icewind.nl> - * @author Robin McCorkell <robin@mccorkell.me.uk> - * @author Thomas Müller <thomas.mueller@tmit.eu> - * @author Vincent Petry <pvince81@owncloud.com> - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * + * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ - namespace OCA\Files_External\Tests\Storage; -use \OCA\Files_External\Lib\Storage\SFTP; +use OCA\Files_External\Lib\Storage\SFTP; /** * Class SftpTest @@ -45,7 +25,7 @@ class SftpTest extends \Test\Files\Storage\Storage { private $config; - protected function setUp() { + protected function setUp(): void { parent::setUp(); $id = $this->getUniqueID(); @@ -58,7 +38,7 @@ class SftpTest extends \Test\Files\Storage\Storage { $this->instance->mkdir('/'); } - protected function tearDown() { + protected function tearDown(): void { if ($this->instance) { $this->instance->rmdir('/'); } @@ -66,15 +46,13 @@ class SftpTest extends \Test\Files\Storage\Storage { parent::tearDown(); } - /** - * @dataProvider configProvider - */ - public function testStorageId($config, $expectedStorageId) { + #[\PHPUnit\Framework\Attributes\DataProvider('configProvider')] + public function testStorageId($config, $expectedStorageId): void { $instance = new SFTP($config); $this->assertEquals($expectedStorageId, $instance->getId()); } - public function configProvider() { + public static function configProvider(): array { return [ [ // no root path diff --git a/apps/files_external/tests/Storage/SmbTest.php b/apps/files_external/tests/Storage/SmbTest.php index edacb498d5e..afcb5c1034f 100644 --- a/apps/files_external/tests/Storage/SmbTest.php +++ b/apps/files_external/tests/Storage/SmbTest.php @@ -1,37 +1,18 @@ <?php + +declare(strict_types=1); /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Joas Schilling <coding@schilljs.com> - * @author Juan Pablo Villafáñez <jvillafanez@solidgear.es> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Robin Appelman <robin@icewind.nl> - * @author Robin McCorkell <robin@mccorkell.me.uk> - * @author Thomas Müller <thomas.mueller@tmit.eu> - * @author Vincent Petry <pvince81@owncloud.com> - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * + * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ - namespace OCA\Files_External\Tests\Storage; use OC\Files\Notify\Change; use OC\Files\Notify\RenameChange; -use \OCA\Files_External\Lib\Storage\SMB; +use OCA\Files_External\Lib\Storage\SMB; use OCP\Files\Notify\IChange; +use PHPUnit\Framework\ExpectationFailedException; /** * Class SmbTest @@ -46,7 +27,7 @@ class SmbTest extends \Test\Files\Storage\Storage { */ protected $instance; - protected function setUp() { + protected function setUp(): void { parent::setUp(); $id = $this->getUniqueID(); @@ -62,7 +43,7 @@ class SmbTest extends \Test\Files\Storage\Storage { $this->instance->mkdir('/'); } - protected function tearDown() { + protected function tearDown(): void { if ($this->instance) { $this->instance->rmdir(''); } @@ -70,19 +51,19 @@ class SmbTest extends \Test\Files\Storage\Storage { parent::tearDown(); } - public function directoryProvider() { + public static function directoryProvider(): array { // doesn't support leading/trailing spaces - return array(array('folder')); + return [['folder']]; } - public function testRenameWithSpaces() { + public function testRenameWithSpaces(): void { $this->instance->mkdir('with spaces'); $result = $this->instance->rename('with spaces', 'foo bar'); $this->assertTrue($result); $this->assertTrue($this->instance->is_dir('foo bar')); } - public function testStorageId() { + public function testStorageId(): void { $this->instance = new SMB([ 'host' => 'testhost', 'user' => 'testuser', @@ -94,29 +75,64 @@ class SmbTest extends \Test\Files\Storage\Storage { $this->instance = null; } - public function testNotifyGetChanges() { + public function testNotifyGetChanges(): void { + $lastError = null; + for ($i = 0; $i < 5; $i++) { + try { + $this->tryTestNotifyGetChanges(); + return; + } catch (ExpectationFailedException $e) { + $lastError = $e; + $this->tearDown(); + $this->setUp(); + sleep(1); + } + } + throw $lastError; + } + + private function tryTestNotifyGetChanges(): void { $notifyHandler = $this->instance->notify(''); - usleep(100 * 1000); //give time for the notify to start + sleep(1); //give time for the notify to start $this->instance->file_put_contents('/newfile.txt', 'test content'); + sleep(1); $this->instance->rename('/newfile.txt', 'renamed.txt'); + sleep(1); $this->instance->unlink('/renamed.txt'); - usleep(100 * 1000); //time for all changes to be processed - - $changes = $notifyHandler->getChanges(); + sleep(1); //time for all changes to be processed + + /** @var IChange[] $changes */ + $changes = []; + $count = 0; + // wait up to 10 seconds for incoming changes + while (count($changes) < 3 && $count < 10) { + $changes = array_merge($changes, $notifyHandler->getChanges()); + $count++; + sleep(1); + } $notifyHandler->stop(); - $expected = [ - new Change(IChange::ADDED, 'newfile.txt'), - new RenameChange(IChange::RENAMED, 'newfile.txt', 'renamed.txt'), - new Change(IChange::REMOVED, 'renamed.txt') - ]; + // depending on the server environment, the initial create might be detected as a change instead + if ($changes[0]->getType() === IChange::MODIFIED) { + $expected = [ + new Change(IChange::MODIFIED, 'newfile.txt'), + new RenameChange(IChange::RENAMED, 'newfile.txt', 'renamed.txt'), + new Change(IChange::REMOVED, 'renamed.txt') + ]; + } else { + $expected = [ + new Change(IChange::ADDED, 'newfile.txt'), + new RenameChange(IChange::RENAMED, 'newfile.txt', 'renamed.txt'), + new Change(IChange::REMOVED, 'renamed.txt') + ]; + } foreach ($expected as $expectedChange) { - $this->assertContains($expectedChange, $changes, '', false, false); // dont check object identity + $this->assertTrue(in_array($expectedChange, $changes), "Expected changes are:\n" . print_r($expected, true) . PHP_EOL . 'Expected to find: ' . PHP_EOL . print_r($expectedChange, true) . "\nGot:\n" . print_r($changes, true)); } } - public function testNotifyListen() { + public function testNotifyListen(): void { $notifyHandler = $this->instance->notify(''); usleep(100 * 1000); //give time for the notify to start $this->instance->file_put_contents('/newfile.txt', 'test content'); @@ -125,16 +141,21 @@ class SmbTest extends \Test\Files\Storage\Storage { $result = null; - // since the notify handler buffers untill we start listening we will get the above changes + // since the notify handler buffers until we start listening we will get the above changes $notifyHandler->listen(function (IChange $change) use (&$result) { $result = $change; return false;//stop listening }); - $this->assertEquals(new Change(IChange::ADDED, 'newfile.txt'), $result); + // depending on the server environment, the initial create might be detected as a change instead + if ($result->getType() === IChange::ADDED) { + $this->assertEquals(new Change(IChange::ADDED, 'newfile.txt'), $result); + } else { + $this->assertEquals(new Change(IChange::MODIFIED, 'newfile.txt'), $result); + } } - public function testRenameRoot() { + public function testRenameRoot(): void { // root can't be renamed $this->assertFalse($this->instance->rename('', 'foo1')); @@ -143,12 +164,12 @@ class SmbTest extends \Test\Files\Storage\Storage { $this->instance->rmdir('foo2'); } - public function testUnlinkRoot() { + public function testUnlinkRoot(): void { // root can't be deleted $this->assertFalse($this->instance->unlink('')); } - public function testRmdirRoot() { + public function testRmdirRoot(): void { // root can't be deleted $this->assertFalse($this->instance->rmdir('')); } diff --git a/apps/files_external/tests/Storage/SwiftTest.php b/apps/files_external/tests/Storage/SwiftTest.php index 19f185ed033..17037e76ee3 100644 --- a/apps/files_external/tests/Storage/SwiftTest.php +++ b/apps/files_external/tests/Storage/SwiftTest.php @@ -1,33 +1,15 @@ <?php + +declare(strict_types=1); /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Christian Berendt <berendt@b1-systems.de> - * @author Joas Schilling <coding@schilljs.com> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Robin Appelman <robin@icewind.nl> - * @author Robin McCorkell <robin@mccorkell.me.uk> - * @author Thomas Müller <thomas.mueller@tmit.eu> - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * + * SPDX-FileCopyrightText: 2018-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ - namespace OCA\Files_External\Tests\Storage; -use \OCA\Files_External\Lib\Storage\Swift; +use GuzzleHttp\Exception\ClientException; +use OCA\Files_External\Lib\Storage\Swift; /** * Class SwiftTest @@ -37,10 +19,14 @@ use \OCA\Files_External\Lib\Storage\Swift; * @package OCA\Files_External\Tests\Storage */ class SwiftTest extends \Test\Files\Storage\Storage { - private $config; - protected function setUp() { + /** + * @var Swift instance + */ + protected $instance; + + protected function setUp(): void { parent::setUp(); $this->config = include('files_external/tests/config.swift.php'); @@ -50,20 +36,18 @@ class SwiftTest extends \Test\Files\Storage\Storage { $this->instance = new Swift($this->config); } - protected function tearDown() { + protected function tearDown(): void { if ($this->instance) { try { - $connection = $this->instance->getConnection(); - $container = $connection->getContainer($this->config['bucket']); + $container = $this->instance->getContainer(); - $objects = $container->objectList(); - while($object = $objects->next()) { - $object->setName(str_replace('#','%23',$object->getName())); + $objects = $container->listObjects(); + foreach ($objects as $object) { $object->delete(); } $container->delete(); - } catch (\Guzzle\Http\Exception\ClientErrorResponseException $e) { + } catch (ClientException $e) { // container didn't exist, so we don't need to delete it } } @@ -71,7 +55,7 @@ class SwiftTest extends \Test\Files\Storage\Storage { parent::tearDown(); } - public function testStat() { + public function testStat(): void { $this->markTestSkipped('Swift doesn\'t update the parents folder mtime'); } } diff --git a/apps/files_external/tests/Storage/VersionedAmazonS3Test.php b/apps/files_external/tests/Storage/VersionedAmazonS3Test.php new file mode 100644 index 00000000000..9d413620292 --- /dev/null +++ b/apps/files_external/tests/Storage/VersionedAmazonS3Test.php @@ -0,0 +1,37 @@ +<?php + +declare(strict_types=1); +/** + * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +namespace OCA\Files_External\Tests\Storage; + +/** + * @group DB + * @group S3 + */ +class VersionedAmazonS3Test extends Amazons3Test { + protected function setUp(): void { + parent::setUp(); + try { + $this->instance->getConnection()->putBucketVersioning([ + 'Bucket' => $this->instance->getBucket(), + 'VersioningConfiguration' => [ + 'Status' => 'Enabled', + ], + ]); + } catch (\Exception $e) { + $this->markTestSkipped("s3 backend doesn't seem to support versioning"); + } + } + + public function testCopyOverWriteDirectory(): void { + if (isset($this->config['minio'])) { + $this->markTestSkipped('MinIO has a bug with batch deletion on versioned storages, see https://github.com/minio/minio/issues/21366'); + } + + parent::testCopyOverWriteDirectory(); + } +} diff --git a/apps/files_external/tests/Storage/WebdavTest.php b/apps/files_external/tests/Storage/WebdavTest.php index b007ded2662..a8de178effd 100644 --- a/apps/files_external/tests/Storage/WebdavTest.php +++ b/apps/files_external/tests/Storage/WebdavTest.php @@ -1,34 +1,17 @@ <?php + +declare(strict_types=1); /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Joas Schilling <coding@schilljs.com> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Robin Appelman <robin@icewind.nl> - * @author Robin McCorkell <robin@mccorkell.me.uk> - * @author Thomas Müller <thomas.mueller@tmit.eu> - * @author Vincent Petry <pvince81@owncloud.com> - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * + * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ - namespace OCA\Files_External\Tests\Storage; -use \OC\Files\Storage\DAV; +use OC\Files\Storage\DAV; use OC\Files\Type\Detection; +use OCP\Files\IMimeTypeDetector; +use OCP\Server; /** * Class WebdavTest @@ -38,8 +21,7 @@ use OC\Files\Type\Detection; * @package OCA\Files_External\Tests\Storage */ class WebdavTest extends \Test\Files\Storage\Storage { - - protected function setUp() { + protected function setUp(): void { parent::setUp(); $id = $this->getUniqueID(); @@ -55,7 +37,7 @@ class WebdavTest extends \Test\Files\Storage\Storage { $this->instance->mkdir('/'); } - protected function tearDown() { + protected function tearDown(): void { if ($this->instance) { $this->instance->rmdir('/'); } @@ -63,11 +45,11 @@ class WebdavTest extends \Test\Files\Storage\Storage { parent::tearDown(); } - public function testMimetypeFallback() { + public function testMimetypeFallback(): void { $this->instance->file_put_contents('foo.bar', 'asd'); /** @var Detection $mimeDetector */ - $mimeDetector = \OC::$server->getMimeTypeDetector(); + $mimeDetector = Server::get(IMimeTypeDetector::class); $mimeDetector->registerType('bar', 'application/x-bar'); $this->assertEquals('application/x-bar', $this->instance->getMimeType('foo.bar')); |