From 0f3f6a6c54f492b6efe95aad15e9c4290bd4df6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Wed, 25 Nov 2020 10:21:11 +0100 Subject: [PATCH] Fix tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- apps/sharebymail/tests/CapabilitiesTest.php | 30 +++++++++++++------ .../tests/ShareByMailProviderTest.php | 30 ++++++++++++------- 2 files changed, 41 insertions(+), 19 deletions(-) diff --git a/apps/sharebymail/tests/CapabilitiesTest.php b/apps/sharebymail/tests/CapabilitiesTest.php index 2bf05f188b6a7..c198648f29a89 100644 --- a/apps/sharebymail/tests/CapabilitiesTest.php +++ b/apps/sharebymail/tests/CapabilitiesTest.php @@ -26,26 +26,30 @@ namespace OCA\ShareByMail\Tests; use OCA\ShareByMail\Capabilities; -use OCA\ShareByMail\Settings\SettingsManager; +use OCP\Share\IManager; use Test\TestCase; class CapabilitiesTest extends TestCase { /** @var Capabilities */ private $capabilities; - /** @var SettingsManager */ - private $settingsManager; + /** @var IManager | \PHPUnit\Framework\MockObject\MockObject */ + private $manager; protected function setUp(): void { parent::setUp(); - $this->settingsManager = $this::createMock(SettingsManager::class); - $this->capabilities = new Capabilities($this->settingsManager); + $this->manager = $this::createMock(IManager::class); + $this->capabilities = new Capabilities($this->manager); } public function testGetCapabilities() { - $this->settingsManager->method('enforcePasswordProtection') + $this->manager->method('shareApiAllowLinks') + ->willReturn(true); + $this->manager->method('shareApiLinkEnforcePassword') + ->willReturn(false); + $this->manager->method('shareApiLinkDefaultExpireDateEnforced') ->willReturn(false); $capabilities = [ @@ -54,9 +58,17 @@ public function testGetCapabilities() { 'sharebymail' => [ 'enabled' => true, - 'upload_files_drop' => ['enabled' => true], - 'password' => ['enabled' => true, 'enforced' => false], - 'expire_date' => ['enabled' => true] + 'upload_files_drop' => [ + 'enabled' => true, + ], + 'password' => [ + 'enabled' => true, + 'enforced' => false, + ], + 'expire_date' => [ + 'enabled' => true, + 'enforced' => false, + ], ] ] ]; diff --git a/apps/sharebymail/tests/ShareByMailProviderTest.php b/apps/sharebymail/tests/ShareByMailProviderTest.php index bb6e7d0a353c3..065246dbc65da 100644 --- a/apps/sharebymail/tests/ShareByMailProviderTest.php +++ b/apps/sharebymail/tests/ShareByMailProviderTest.php @@ -65,7 +65,7 @@ class ShareByMailProviderTest extends TestCase { /** @var IDBConnection */ private $connection; - /** @var IManager */ + /** @var IManager | \PHPUnit\Framework\MockObject\MockObject */ private $shareManager; /** @var IL10N | \PHPUnit\Framework\MockObject\MockObject */ @@ -110,7 +110,6 @@ class ShareByMailProviderTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->shareManager = \OC::$server->getShareManager(); $this->connection = \OC::$server->getDatabaseConnection(); $this->l = $this->getMockBuilder(IL10N::class)->getMock(); @@ -130,6 +129,7 @@ protected function setUp(): void { $this->defaults = $this->createMock(Defaults::class); $this->hasher = $this->getMockBuilder(IHasher::class)->getMock(); $this->eventDispatcher = $this->getMockBuilder(IEventDispatcher::class)->getMock(); + $this->shareManager = $this->getMockBuilder(IManager::class)->getMock(); $this->userManager->expects($this->any())->method('userExists')->willReturn(true); } @@ -156,7 +156,8 @@ private function getInstance(array $mockedMethods = []) { $this->settingsManager, $this->defaults, $this->hasher, - $this->eventDispatcher + $this->eventDispatcher, + $this->shareManager ] ); @@ -178,7 +179,8 @@ private function getInstance(array $mockedMethods = []) { $this->settingsManager, $this->defaults, $this->hasher, - $this->eventDispatcher + $this->eventDispatcher, + $this->shareManager ); } @@ -204,7 +206,7 @@ public function testCreate() { $instance->expects($this->once())->method('createShareObject')->with('rawShare')->willReturn('shareObject'); $instance->expects($this->any())->method('sendPassword')->willReturn(true); $share->expects($this->any())->method('getNode')->willReturn($node); - $this->settingsManager->expects($this->any())->method('enforcePasswordProtection')->willReturn(false); + $this->shareManager->expects($this->any())->method('shareApiLinkEnforcePassword')->willReturn(false); $this->settingsManager->expects($this->any())->method('sendPasswordByMail')->willReturn(true); $this->assertSame('shareObject', @@ -231,7 +233,7 @@ public function testCreateSendPasswordByMailWithoutEnforcedPasswordProtection() $share->expects($this->any())->method('getNode')->willReturn($node); // The autogenerated password should not be mailed. - $this->settingsManager->expects($this->any())->method('enforcePasswordProtection')->willReturn(false); + $this->shareManager->expects($this->any())->method('shareApiLinkEnforcePassword')->willReturn(false); $this->settingsManager->expects($this->any())->method('sendPasswordByMail')->willReturn(true); $instance->expects($this->never())->method('autoGeneratePassword'); @@ -266,7 +268,7 @@ public function testCreateSendPasswordByMailWithPasswordAndWithoutEnforcedPasswo // The given password (but not the autogenerated password) should be // mailed to the receiver of the share. - $this->settingsManager->expects($this->any())->method('enforcePasswordProtection')->willReturn(false); + $this->shareManager->expects($this->any())->method('shareApiLinkEnforcePassword')->willReturn(false); $this->settingsManager->expects($this->any())->method('sendPasswordByMail')->willReturn(true); $instance->expects($this->never())->method('autoGeneratePassword'); @@ -318,7 +320,7 @@ public function testCreateSendPasswordByMailWithEnforcedPasswordProtection() { $share->expects($this->once())->method('setPassword')->with('autogeneratedPasswordHashed'); // The autogenerated password should be mailed to the receiver of the share. - $this->settingsManager->expects($this->any())->method('enforcePasswordProtection')->willReturn(true); + $this->shareManager->expects($this->any())->method('shareApiLinkEnforcePassword')->willReturn(true); $this->settingsManager->expects($this->any())->method('sendPasswordByMail')->willReturn(true); $message = $this->createMock(IMessage::class); @@ -362,7 +364,7 @@ public function testCreateSendPasswordByMailWithPasswordAndWithEnforcedPasswordP // The given password (but not the autogenerated password) should be // mailed to the receiver of the share. - $this->settingsManager->expects($this->any())->method('enforcePasswordProtection')->willReturn(true); + $this->shareManager->expects($this->any())->method('shareApiLinkEnforcePassword')->willReturn(true); $this->settingsManager->expects($this->any())->method('sendPasswordByMail')->willReturn(true); $instance->expects($this->never())->method('autoGeneratePassword'); @@ -406,7 +408,7 @@ public function testCreateSendPasswordByTalkWithEnforcedPasswordProtection() { $share->expects($this->once())->method('setPassword')->with('autogeneratedPasswordHashed'); // The autogenerated password should be mailed to the owner of the share. - $this->settingsManager->expects($this->any())->method('enforcePasswordProtection')->willReturn(true); + $this->shareManager->expects($this->any())->method('shareApiLinkEnforcePassword')->willReturn(true); $this->settingsManager->expects($this->any())->method('sendPasswordByMail')->willReturn(true); $instance->expects($this->once())->method('autoGeneratePassword')->with($share)->willReturn('autogeneratedPassword'); @@ -979,6 +981,10 @@ public function testGetSharesInFolder() { $userManager = \OC::$server->getUserManager(); $rootFolder = \OC::$server->getRootFolder(); + $this->shareManager->expects($this->any()) + ->method('newShare') + ->willReturn(new \OC\Share20\Share($rootFolder, $userManager)); + $provider = $this->getInstance(['sendMailNotification', 'createShareActivity']); $u1 = $userManager->createUser('testFed', md5(time())); @@ -1021,6 +1027,10 @@ public function testGetAccessList() { $userManager = \OC::$server->getUserManager(); $rootFolder = \OC::$server->getRootFolder(); + $this->shareManager->expects($this->any()) + ->method('newShare') + ->willReturn(new \OC\Share20\Share($rootFolder, $userManager)); + $provider = $this->getInstance(['sendMailNotification', 'createShareActivity']); $u1 = $userManager->createUser('testFed', md5(time()));