summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2020-11-25 10:21:11 +0100
committerJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2021-03-22 06:50:47 +0100
commit0f3f6a6c54f492b6efe95aad15e9c4290bd4df6e (patch)
tree0fd3de37039a31facbec3d0669c43bf830d4be4c
parenta100186e5e7dcbe95faa453d28b5cf0d20948639 (diff)
downloadnextcloud-server-0f3f6a6c54f492b6efe95aad15e9c4290bd4df6e.tar.gz
nextcloud-server-0f3f6a6c54f492b6efe95aad15e9c4290bd4df6e.zip
Fix tests
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
-rw-r--r--apps/sharebymail/tests/CapabilitiesTest.php30
-rw-r--r--apps/sharebymail/tests/ShareByMailProviderTest.php30
2 files changed, 41 insertions, 19 deletions
diff --git a/apps/sharebymail/tests/CapabilitiesTest.php b/apps/sharebymail/tests/CapabilitiesTest.php
index 2bf05f188b6..c198648f29a 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 @@ class CapabilitiesTest extends TestCase {
'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 bb6e7d0a353..065246dbc65 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 @@ class ShareByMailProviderTest extends TestCase {
$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 @@ class ShareByMailProviderTest extends TestCase {
$this->settingsManager,
$this->defaults,
$this->hasher,
- $this->eventDispatcher
+ $this->eventDispatcher,
+ $this->shareManager
]
);
@@ -178,7 +179,8 @@ class ShareByMailProviderTest extends TestCase {
$this->settingsManager,
$this->defaults,
$this->hasher,
- $this->eventDispatcher
+ $this->eventDispatcher,
+ $this->shareManager
);
}
@@ -204,7 +206,7 @@ class ShareByMailProviderTest extends TestCase {
$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 @@ class ShareByMailProviderTest extends TestCase {
$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 @@ class ShareByMailProviderTest extends TestCase {
// 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 @@ class ShareByMailProviderTest extends TestCase {
$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 @@ class ShareByMailProviderTest extends TestCase {
// 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 @@ class ShareByMailProviderTest extends TestCase {
$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 @@ class ShareByMailProviderTest extends TestCase {
$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 @@ class ShareByMailProviderTest extends TestCase {
$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()));