Skip to content

Commit

Permalink
fixup! Fix valid storages removed when cleaning remote storages
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
  • Loading branch information
danxuliu committed Jan 26, 2021
1 parent ec452b9 commit 91ff735
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion apps/files_sharing/tests/Command/CleanupRemoteStoragesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
namespace OCA\Files_Sharing\Tests\Command;

use OCA\Files_Sharing\Command\CleanupRemoteStorages;
use OCP\Federation\ICloudId;
use OCP\Federation\ICloudIdManager;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Test\TestCase;
Expand All @@ -49,6 +51,11 @@ class CleanupRemoteStoragesTest extends TestCase {
*/
private $connection;

/**
* @var ICloudIdManager|\PHPUnit\Framework\MockObject\MockObject
*/
private $cloudIdManager;

private $storages = [
['id' => 'shared::7b4a322b22f9d0047c38d77d471ce3cf', 'share_token' => 'f2c69dad1dc0649f26976fd210fc62e1', 'remote' => 'https://hostname.tld/owncloud1', 'user' => 'user1'],
['id' => 'shared::efe3b456112c3780da6155d3a9b9141c', 'share_token' => 'f2c69dad1dc0649f26976fd210fc62e2', 'remote' => 'https://hostname.tld/owncloud2', 'user' => 'user2'],
Expand Down Expand Up @@ -109,7 +116,9 @@ protected function setUp(): void {
}
}

$this->command = new CleanupRemoteStorages($this->connection);
$this->cloudIdManager = $this->createMock(ICloudIdManager::class);

$this->command = new CleanupRemoteStorages($this->connection, $this->cloudIdManager);
}

protected function tearDown(): void {
Expand Down Expand Up @@ -191,6 +200,22 @@ public function testCleanup() {
->method('writeln')
->with('5 remote share(s) exist');

$this->cloudIdManager
->expects($this->any())
->method('getCloudId')
->will($this->returnCallback(function (string $user, string $remote) {
$cloudIdMock = $this->createMock(ICloudId::class);

// The remotes are already sanitized in the original data, so
// they can be directly returned.
$cloudIdMock
->expects($this->any())
->method('getRemote')
->willReturn($remote);

return $cloudIdMock;
}));

$this->command->execute($input, $output);

$this->assertTrue($this->doesStorageExist($this->storages[0]['numeric_id']));
Expand Down

0 comments on commit 91ff735

Please sign in to comment.