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; namespace OCA\ShareByMail\Tests;
use OCA\ShareByMail\Capabilities; use OCA\ShareByMail\Capabilities;
use OCA\ShareByMail\Settings\SettingsManager; use OCP\Share\IManager;
use Test\TestCase; use Test\TestCase;
class CapabilitiesTest extends TestCase { class CapabilitiesTest extends TestCase {
/** @var Capabilities */ /** @var Capabilities */
private $capabilities; private $capabilities;
/** @var SettingsManager */ /** @var IManager | \PHPUnit\Framework\MockObject\MockObject */
private $settingsManager; private $manager;
protected function setUp(): void { protected function setUp(): void {
parent::setUp(); parent::setUp();
$this->settingsManager = $this::createMock(SettingsManager::class); $this->manager = $this::createMock(IManager::class);
$this->capabilities = new Capabilities($this->settingsManager); $this->capabilities = new Capabilities($this->manager);
} }
public function testGetCapabilities() { 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); ->willReturn(false);
$capabilities = [ $capabilities = [
@ -54,9 +58,17 @@ class CapabilitiesTest extends TestCase {
'sharebymail' => 'sharebymail' =>
[ [
'enabled' => true, 'enabled' => true,
'upload_files_drop' => ['enabled' => true], 'upload_files_drop' => [
'password' => ['enabled' => true, 'enforced' => false], 'enabled' => true,
'expire_date' => ['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 */ /** @var IDBConnection */
private $connection; private $connection;
/** @var IManager */ /** @var IManager | \PHPUnit\Framework\MockObject\MockObject */
private $shareManager; private $shareManager;
/** @var IL10N | \PHPUnit\Framework\MockObject\MockObject */ /** @var IL10N | \PHPUnit\Framework\MockObject\MockObject */
@ -110,7 +110,6 @@ class ShareByMailProviderTest extends TestCase {
protected function setUp(): void { protected function setUp(): void {
parent::setUp(); parent::setUp();
$this->shareManager = \OC::$server->getShareManager();
$this->connection = \OC::$server->getDatabaseConnection(); $this->connection = \OC::$server->getDatabaseConnection();
$this->l = $this->getMockBuilder(IL10N::class)->getMock(); $this->l = $this->getMockBuilder(IL10N::class)->getMock();
@ -130,6 +129,7 @@ class ShareByMailProviderTest extends TestCase {
$this->defaults = $this->createMock(Defaults::class); $this->defaults = $this->createMock(Defaults::class);
$this->hasher = $this->getMockBuilder(IHasher::class)->getMock(); $this->hasher = $this->getMockBuilder(IHasher::class)->getMock();
$this->eventDispatcher = $this->getMockBuilder(IEventDispatcher::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); $this->userManager->expects($this->any())->method('userExists')->willReturn(true);
} }
@ -156,7 +156,8 @@ class ShareByMailProviderTest extends TestCase {
$this->settingsManager, $this->settingsManager,
$this->defaults, $this->defaults,
$this->hasher, $this->hasher,
$this->eventDispatcher $this->eventDispatcher,
$this->shareManager
] ]
); );
@ -178,7 +179,8 @@ class ShareByMailProviderTest extends TestCase {
$this->settingsManager, $this->settingsManager,
$this->defaults, $this->defaults,
$this->hasher, $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->once())->method('createShareObject')->with('rawShare')->willReturn('shareObject');
$instance->expects($this->any())->method('sendPassword')->willReturn(true); $instance->expects($this->any())->method('sendPassword')->willReturn(true);
$share->expects($this->any())->method('getNode')->willReturn($node); $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->settingsManager->expects($this->any())->method('sendPasswordByMail')->willReturn(true);
$this->assertSame('shareObject', $this->assertSame('shareObject',
@ -231,7 +233,7 @@ class ShareByMailProviderTest extends TestCase {
$share->expects($this->any())->method('getNode')->willReturn($node); $share->expects($this->any())->method('getNode')->willReturn($node);
// The autogenerated password should not be mailed. // 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); $this->settingsManager->expects($this->any())->method('sendPasswordByMail')->willReturn(true);
$instance->expects($this->never())->method('autoGeneratePassword'); $instance->expects($this->never())->method('autoGeneratePassword');
@ -266,7 +268,7 @@ class ShareByMailProviderTest extends TestCase {
// The given password (but not the autogenerated password) should be // The given password (but not the autogenerated password) should be
// mailed to the receiver of the share. // 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); $this->settingsManager->expects($this->any())->method('sendPasswordByMail')->willReturn(true);
$instance->expects($this->never())->method('autoGeneratePassword'); $instance->expects($this->never())->method('autoGeneratePassword');
@ -318,7 +320,7 @@ class ShareByMailProviderTest extends TestCase {
$share->expects($this->once())->method('setPassword')->with('autogeneratedPasswordHashed'); $share->expects($this->once())->method('setPassword')->with('autogeneratedPasswordHashed');
// The autogenerated password should be mailed to the receiver of the share. // 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); $this->settingsManager->expects($this->any())->method('sendPasswordByMail')->willReturn(true);
$message = $this->createMock(IMessage::class); $message = $this->createMock(IMessage::class);
@ -362,7 +364,7 @@ class ShareByMailProviderTest extends TestCase {
// The given password (but not the autogenerated password) should be // The given password (but not the autogenerated password) should be
// mailed to the receiver of the share. // 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); $this->settingsManager->expects($this->any())->method('sendPasswordByMail')->willReturn(true);
$instance->expects($this->never())->method('autoGeneratePassword'); $instance->expects($this->never())->method('autoGeneratePassword');
@ -406,7 +408,7 @@ class ShareByMailProviderTest extends TestCase {
$share->expects($this->once())->method('setPassword')->with('autogeneratedPasswordHashed'); $share->expects($this->once())->method('setPassword')->with('autogeneratedPasswordHashed');
// The autogenerated password should be mailed to the owner of the share. // 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); $this->settingsManager->expects($this->any())->method('sendPasswordByMail')->willReturn(true);
$instance->expects($this->once())->method('autoGeneratePassword')->with($share)->willReturn('autogeneratedPassword'); $instance->expects($this->once())->method('autoGeneratePassword')->with($share)->willReturn('autogeneratedPassword');
@ -979,6 +981,10 @@ class ShareByMailProviderTest extends TestCase {
$userManager = \OC::$server->getUserManager(); $userManager = \OC::$server->getUserManager();
$rootFolder = \OC::$server->getRootFolder(); $rootFolder = \OC::$server->getRootFolder();
$this->shareManager->expects($this->any())
->method('newShare')
->willReturn(new \OC\Share20\Share($rootFolder, $userManager));
$provider = $this->getInstance(['sendMailNotification', 'createShareActivity']); $provider = $this->getInstance(['sendMailNotification', 'createShareActivity']);
$u1 = $userManager->createUser('testFed', md5(time())); $u1 = $userManager->createUser('testFed', md5(time()));
@ -1021,6 +1027,10 @@ class ShareByMailProviderTest extends TestCase {
$userManager = \OC::$server->getUserManager(); $userManager = \OC::$server->getUserManager();
$rootFolder = \OC::$server->getRootFolder(); $rootFolder = \OC::$server->getRootFolder();
$this->shareManager->expects($this->any())
->method('newShare')
->willReturn(new \OC\Share20\Share($rootFolder, $userManager));
$provider = $this->getInstance(['sendMailNotification', 'createShareActivity']); $provider = $this->getInstance(['sendMailNotification', 'createShareActivity']);
$u1 = $userManager->createUser('testFed', md5(time())); $u1 = $userManager->createUser('testFed', md5(time()));