Fix tests

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
John Molakvoæ (skjnldsv) 2020-11-25 10:21:11 +01:00
parent a100186e5e
commit 0f3f6a6c54
No known key found for this signature in database
GPG Key ID: 60C25B8C072916CF
2 changed files with 41 additions and 19 deletions

View File

@ -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,
],
]
]
];

View File

@ -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()));