Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
  • Loading branch information
skjnldsv committed Nov 25, 2020
1 parent 8b9f171 commit 96c1adc
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 20 deletions.
30 changes: 21 additions & 9 deletions apps/sharebymail/tests/CapabilitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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,
],
]
]
];
Expand Down
26 changes: 15 additions & 11 deletions apps/sharebymail/tests/ShareByMailProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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();
Expand All @@ -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);
}
Expand All @@ -156,7 +156,8 @@ private function getInstance(array $mockedMethods = []) {
$this->settingsManager,
$this->defaults,
$this->hasher,
$this->eventDispatcher
$this->eventDispatcher,
$this->shareManager
]
);

Expand All @@ -178,7 +179,8 @@ private function getInstance(array $mockedMethods = []) {
$this->settingsManager,
$this->defaults,
$this->hasher,
$this->eventDispatcher
$this->eventDispatcher,
$this->shareManager
);
}

Expand All @@ -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',
Expand All @@ -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');

Expand Down Expand Up @@ -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');

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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');

Expand Down Expand Up @@ -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');

Expand Down Expand Up @@ -524,6 +526,7 @@ public function testAddShareToDB() {
$password = 'password';
$sendPasswordByTalk = true;
$hideDownload = true;
$label = '';


$instance = $this->getInstance();
Expand All @@ -540,7 +543,8 @@ public function testAddShareToDB() {
$token,
$password,
$sendPasswordByTalk,
$hideDownload
$hideDownload,
$label
]
);

Expand Down

0 comments on commit 96c1adc

Please sign in to comment.