|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors |
| 4 | + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. |
| 5 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 6 | + */ |
| 7 | + |
| 8 | +namespace Test\Files\Storage; |
| 9 | + |
| 10 | +use Test\TestCase; |
| 11 | + |
| 12 | +abstract class StoragesTest extends TestCase { |
| 13 | + /** |
| 14 | + * @var \OC\Files\Storage\Storage |
| 15 | + */ |
| 16 | + protected $storage1; |
| 17 | + |
| 18 | + /** |
| 19 | + * @var \OC\Files\Storage\Storage |
| 20 | + */ |
| 21 | + protected $storage2; |
| 22 | + |
| 23 | + protected function tearDown(): void { |
| 24 | + if (is_null($this->storage1) && is_null($this->storage2)) { |
| 25 | + return; |
| 26 | + } |
| 27 | + $this->storage1->getCache()->clear(); |
| 28 | + $this->storage2->getCache()->clear(); |
| 29 | + |
| 30 | + parent::tearDown(); |
| 31 | + } |
| 32 | + |
| 33 | + public function testMoveFileFromStorage() { |
| 34 | + $source = 'source.txt'; |
| 35 | + $target = 'target.txt'; |
| 36 | + $storage2->file_put_contents($source, 'foo'); |
| 37 | + |
| 38 | + $storage1->moveFromStorage($storage2, $source, $target); |
| 39 | + |
| 40 | + $this->assertTrue($storage1->file_exists($target), $target.' was not created'); |
| 41 | + $this->assertFalse($storage2->file_exists($source), $source.' still exists'); |
| 42 | + $this->assertEquals('foo', $storage1->file_get_contents($target)); |
| 43 | + } |
| 44 | + |
| 45 | + public function testMoveDirectoryFromStorage() { |
| 46 | + $storage2->mkdir('source'); |
| 47 | + $storage2->file_put_contents('source/test1.txt', 'foo'); |
| 48 | + $storage2->file_put_contents('source/test2.txt', 'qwerty'); |
| 49 | + $storage2->mkdir('source/subfolder'); |
| 50 | + $storage2->file_put_contents('source/subfolder/test.txt', 'bar'); |
| 51 | + |
| 52 | + $storage1->moveFromStorage($storage2, 'source', 'target'); |
| 53 | + |
| 54 | + $this->assertTrue($storage1->file_exists('target')); |
| 55 | + $this->assertTrue($storage1->file_exists('target/test1.txt')); |
| 56 | + $this->assertTrue($storage1->file_exists('target/test2.txt')); |
| 57 | + $this->assertTrue($storage1->file_exists('target/subfolder')); |
| 58 | + $this->assertTrue($storage1->file_exists('target/subfolder/test.txt')); |
| 59 | + |
| 60 | + $this->assertFalse($storage2->file_exists('source')); |
| 61 | + $this->assertFalse($storage2->file_exists('source/test1.txt')); |
| 62 | + $this->assertFalse($storage2->file_exists('source/test2.txt')); |
| 63 | + $this->assertFalse($storage2->file_exists('source/subfolder')); |
| 64 | + $this->assertFalse($storage2->file_exists('source/subfolder/test.txt')); |
| 65 | + |
| 66 | + $this->assertEquals('foo', $storage1->file_get_contents('target/test1.txt')); |
| 67 | + $this->assertEquals('qwerty', $storage1->file_get_contents('target/test2.txt')); |
| 68 | + $this->assertEquals('bar', $storage1->file_get_contents('target/subfolder/test.txt')); |
| 69 | + } |
| 70 | + |
| 71 | + public function testCopyFileFromStorage() { |
| 72 | + $source = 'source.txt'; |
| 73 | + $target = 'target.txt'; |
| 74 | + $storage2->file_put_contents($source, 'foo'); |
| 75 | + |
| 76 | + $storage1->copyFromStorage($storage2, $source, $target); |
| 77 | + |
| 78 | + $this->assertTrue($storage1->file_exists($target), $target.' was not created'); |
| 79 | + $this->assertTrue($storage2->file_exists($source), $source.' was deleted'); |
| 80 | + $this->assertEquals('foo', $storage1->file_get_contents($target)); |
| 81 | + } |
| 82 | + |
| 83 | + public function testCopyDirectoryFromStorage() { |
| 84 | + $storage2->mkdir('source'); |
| 85 | + $storage2->file_put_contents('source/test1.txt', 'foo'); |
| 86 | + $storage2->file_put_contents('source/test2.txt', 'qwerty'); |
| 87 | + $storage2->mkdir('source/subfolder'); |
| 88 | + $storage2->file_put_contents('source/subfolder/test.txt', 'bar'); |
| 89 | + |
| 90 | + $storage1->copyFromStorage($storage2, 'source', 'target'); |
| 91 | + |
| 92 | + $this->assertTrue($storage1->file_exists('target')); |
| 93 | + $this->assertTrue($storage1->file_exists('target/test1.txt')); |
| 94 | + $this->assertTrue($storage1->file_exists('target/test2.txt')); |
| 95 | + $this->assertTrue($storage1->file_exists('target/subfolder')); |
| 96 | + $this->assertTrue($storage1->file_exists('target/subfolder/test.txt')); |
| 97 | + |
| 98 | + $this->assertTrue($storage2->file_exists('source')); |
| 99 | + $this->assertTrue($storage2->file_exists('source/test1.txt')); |
| 100 | + $this->assertTrue($storage2->file_exists('source/test2.txt')); |
| 101 | + $this->assertTrue($storage2->file_exists('source/subfolder')); |
| 102 | + $this->assertTrue($storage2->file_exists('source/subfolder/test.txt')); |
| 103 | + |
| 104 | + $this->assertEquals('foo', $storage1->file_get_contents('target/test1.txt')); |
| 105 | + $this->assertEquals('qwerty', $storage1->file_get_contents('target/test2.txt')); |
| 106 | + $this->assertEquals('bar', $storage1->file_get_contents('target/subfolder/test.txt')); |
| 107 | + } |
| 108 | +} |
0 commit comments