aboutsummaryrefslogtreecommitdiffstats
path: root/apps/sharebymail/tests
diff options
context:
space:
mode:
Diffstat (limited to 'apps/sharebymail/tests')
-rw-r--r--apps/sharebymail/tests/ShareByMailProviderTest.php73
1 files changed, 32 insertions, 41 deletions
diff --git a/apps/sharebymail/tests/ShareByMailProviderTest.php b/apps/sharebymail/tests/ShareByMailProviderTest.php
index 1e5fa46b943..2c9f63fdb4f 100644
--- a/apps/sharebymail/tests/ShareByMailProviderTest.php
+++ b/apps/sharebymail/tests/ShareByMailProviderTest.php
@@ -42,7 +42,6 @@ use OCP\Files\IRootFolder;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IL10N;
-use OCP\ILogger;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserManager;
@@ -54,6 +53,7 @@ use OCP\Security\IHasher;
use OCP\Security\ISecureRandom;
use OCP\Share\IManager;
use OCP\Share\IShare;
+use Psr\Log\LoggerInterface;
use Test\TestCase;
/**
@@ -63,7 +63,6 @@ use Test\TestCase;
* @group DB
*/
class ShareByMailProviderTest extends TestCase {
-
/** @var IConfig */
private $config;
@@ -76,7 +75,7 @@ class ShareByMailProviderTest extends TestCase {
/** @var IL10N | \PHPUnit\Framework\MockObject\MockObject */
private $l;
- /** @var ILogger | \PHPUnit\Framework\MockObject\MockObject */
+ /** @var LoggerInterface | \PHPUnit\Framework\MockObject\MockObject */
private $logger;
/** @var IRootFolder | \PHPUnit\Framework\MockObject\MockObject */
@@ -123,7 +122,7 @@ class ShareByMailProviderTest extends TestCase {
->willReturnCallback(function ($text, $parameters = []) {
return vsprintf($text, $parameters);
});
- $this->logger = $this->getMockBuilder(ILogger::class)->getMock();
+ $this->logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
$this->rootFolder = $this->getMockBuilder('OCP\Files\IRootFolder')->getMock();
$this->userManager = $this->getMockBuilder(IUserManager::class)->getMock();
$this->secureRandom = $this->getMockBuilder('\OCP\Security\ISecureRandom')->getMock();
@@ -210,19 +209,19 @@ class ShareByMailProviderTest extends TestCase {
$instance->expects($this->once())->method('getSharedWith')->willReturn([]);
$instance->expects($this->once())->method('createMailShare')->with($share)->willReturn(42);
$instance->expects($this->once())->method('createShareActivity')->with($share);
- $instance->expects($this->once())->method('getRawShare')->with(42)->willReturn('rawShare');
- $instance->expects($this->once())->method('createShareObject')->with('rawShare')->willReturn('shareObject');
+ $instance->expects($this->once())->method('getRawShare')->with(42)->willReturn(['rawShare']);
+ $instance->expects($this->once())->method('createShareObject')->with(['rawShare'])->willReturn($this->createMock(IShare::class));
$instance->expects($this->any())->method('sendPassword')->willReturn(true);
$share->expects($this->any())->method('getNode')->willReturn($node);
$this->shareManager->expects($this->any())->method('shareApiLinkEnforcePassword')->willReturn(false);
$this->settingsManager->expects($this->any())->method('sendPasswordByMail')->willReturn(true);
- $this->assertSame('shareObject',
- $instance->create($share)
- );
+ $this->assertInstanceOf(IShare::class, $instance->create($share));
}
public function testCreateSendPasswordByMailWithoutEnforcedPasswordProtection() {
+ $expectedShare = $this->createMock(IShare::class);
+
$share = $this->getMockBuilder(IShare::class)->getMock();
$share->expects($this->any())->method('getSharedWith')->willReturn('receiver@examplelölöl.com');
$share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(false);
@@ -236,8 +235,8 @@ class ShareByMailProviderTest extends TestCase {
$instance->expects($this->once())->method('getSharedWith')->willReturn([]);
$instance->expects($this->once())->method('createMailShare')->with($share)->willReturn(42);
$instance->expects($this->once())->method('createShareActivity')->with($share);
- $instance->expects($this->once())->method('getRawShare')->with(42)->willReturn('rawShare');
- $instance->expects($this->once())->method('createShareObject')->with('rawShare')->willReturn('shareObject');
+ $instance->expects($this->once())->method('getRawShare')->with(42)->willReturn(['rawShare']);
+ $instance->expects($this->once())->method('createShareObject')->with(['rawShare'])->willReturn($expectedShare);
$share->expects($this->any())->method('getNode')->willReturn($node);
// The autogenerated password should not be mailed.
@@ -247,9 +246,7 @@ class ShareByMailProviderTest extends TestCase {
$this->mailer->expects($this->never())->method('send');
- $this->assertSame('shareObject',
- $instance->create($share)
- );
+ $this->assertSame($expectedShare, $instance->create($share));
}
public function testCreateSendPasswordByMailWithPasswordAndWithoutEnforcedPasswordProtectionWithPermanentPassword() {
@@ -266,8 +263,8 @@ class ShareByMailProviderTest extends TestCase {
$instance->expects($this->once())->method('getSharedWith')->willReturn([]);
$instance->expects($this->once())->method('createMailShare')->with($share)->willReturn(42);
$instance->expects($this->once())->method('createShareActivity')->with($share);
- $instance->expects($this->once())->method('getRawShare')->with(42)->willReturn('rawShare');
- $instance->expects($this->once())->method('createShareObject')->with('rawShare')->willReturn('shareObject');
+ $instance->expects($this->once())->method('getRawShare')->with(42)->willReturn(['rawShare']);
+ $instance->expects($this->once())->method('createShareObject')->with(['rawShare'])->willReturn($this->createMock(IShare::class));
$share->expects($this->any())->method('getNode')->willReturn($node);
$share->expects($this->once())->method('getPassword')->willReturn('password');
@@ -280,9 +277,7 @@ class ShareByMailProviderTest extends TestCase {
$this->config->expects($this->once())->method('getSystemValue')->with('sharing.enable_mail_link_password_expiration')->willReturn(false);
$instance->expects($this->never())->method('autoGeneratePassword');
- $this->assertSame('shareObject',
- $instance->create($share)
- );
+ $this->assertInstanceOf(IShare::class, $instance->create($share));
}
public function testCreateSendPasswordByMailWithPasswordAndWithoutEnforcedPasswordProtectionWithoutPermanentPassword() {
@@ -299,8 +294,8 @@ class ShareByMailProviderTest extends TestCase {
$instance->expects($this->once())->method('getSharedWith')->willReturn([]);
$instance->expects($this->once())->method('createMailShare')->with($share)->willReturn(42);
$instance->expects($this->once())->method('createShareActivity')->with($share);
- $instance->expects($this->once())->method('getRawShare')->with(42)->willReturn('rawShare');
- $instance->expects($this->once())->method('createShareObject')->with('rawShare')->willReturn('shareObject');
+ $instance->expects($this->once())->method('getRawShare')->with(42)->willReturn(['rawShare']);
+ $instance->expects($this->once())->method('createShareObject')->with(['rawShare'])->willReturn($this->createMock(IShare::class));
$share->expects($this->any())->method('getNode')->willReturn($node);
$share->expects($this->once())->method('getPassword')->willReturn('password');
@@ -321,9 +316,7 @@ class ShareByMailProviderTest extends TestCase {
3600
);
- $this->assertSame('shareObject',
- $instance->create($share)
- );
+ $this->assertInstanceOf(IShare::class, $instance->create($share));
}
public function testCreateSendPasswordByMailWithEnforcedPasswordProtectionWithPermanentPassword() {
@@ -348,8 +341,8 @@ class ShareByMailProviderTest extends TestCase {
$instance->expects($this->once())->method('getSharedWith')->willReturn([]);
$instance->expects($this->once())->method('createMailShare')->with($share)->willReturn(42);
$instance->expects($this->once())->method('createShareActivity')->with($share);
- $instance->expects($this->once())->method('getRawShare')->with(42)->willReturn('rawShare');
- $instance->expects($this->once())->method('createShareObject')->with('rawShare')->willReturn('shareObject');
+ $instance->expects($this->once())->method('getRawShare')->with(42)->willReturn(['rawShare']);
+ $instance->expects($this->once())->method('createShareObject')->with(['rawShare'])->willReturn($this->createMock(IShare::class));
$share->expects($this->any())->method('getNode')->willReturn($node);
$share->expects($this->once())->method('getPassword')->willReturn(null);
@@ -373,9 +366,7 @@ class ShareByMailProviderTest extends TestCase {
]);
$this->mailer->expects($this->once())->method('send');
- $this->assertSame('shareObject',
- $instance->create($share)
- );
+ $this->assertInstanceOf(IShare::class, $instance->create($share));
}
public function testCreateSendPasswordByMailWithPasswordAndWithEnforcedPasswordProtectionWithPermanentPassword() {
@@ -392,8 +383,8 @@ class ShareByMailProviderTest extends TestCase {
$instance->expects($this->once())->method('getSharedWith')->willReturn([]);
$instance->expects($this->once())->method('createMailShare')->with($share)->willReturn(42);
$instance->expects($this->once())->method('createShareActivity')->with($share);
- $instance->expects($this->once())->method('getRawShare')->with(42)->willReturn('rawShare');
- $instance->expects($this->once())->method('createShareObject')->with('rawShare')->willReturn('shareObject');
+ $instance->expects($this->once())->method('getRawShare')->with(42)->willReturn(['rawShare']);
+ $instance->expects($this->once())->method('createShareObject')->with(['rawShare'])->willReturn($this->createMock(IShare::class));
$share->expects($this->any())->method('getNode')->willReturn($node);
$share->expects($this->once())->method('getPassword')->willReturn('password');
@@ -419,9 +410,7 @@ class ShareByMailProviderTest extends TestCase {
]);
$this->mailer->expects($this->once())->method('send');
- $this->assertSame('shareObject',
- $instance->create($share)
- );
+ $this->assertInstanceOf(IShare::class, $instance->create($share));
}
public function testCreateSendPasswordByTalkWithEnforcedPasswordProtectionWithPermanentPassword() {
@@ -438,8 +427,8 @@ class ShareByMailProviderTest extends TestCase {
$instance->expects($this->once())->method('getSharedWith')->willReturn([]);
$instance->expects($this->once())->method('createMailShare')->with($share)->willReturn(42);
$instance->expects($this->once())->method('createShareActivity')->with($share);
- $instance->expects($this->once())->method('getRawShare')->with(42)->willReturn('rawShare');
- $instance->expects($this->once())->method('createShareObject')->with('rawShare')->willReturn('shareObject');
+ $instance->expects($this->once())->method('getRawShare')->with(42)->willReturn(['rawShare']);
+ $instance->expects($this->once())->method('createShareObject')->with(['rawShare'])->willReturn($this->createMock(IShare::class));
$share->expects($this->any())->method('getNode')->willReturn($node);
$share->expects($this->once())->method('getPassword')->willReturn(null);
@@ -469,9 +458,7 @@ class ShareByMailProviderTest extends TestCase {
$user->expects($this->once())->method('getDisplayName')->willReturn('Owner display name');
$user->expects($this->once())->method('getEMailAddress')->willReturn('owner@example.com');
- $this->assertSame('shareObject',
- $instance->create($share)
- );
+ $this->assertInstanceOf(IShare::class, $instance->create($share));
}
@@ -498,7 +485,9 @@ class ShareByMailProviderTest extends TestCase {
public function testCreateMailShare() {
$this->share->expects($this->any())->method('getToken')->willReturn('token');
$this->share->expects($this->once())->method('setToken')->with('token');
- $this->share->expects($this->any())->method('getSharedWith')->willReturn('valid@valid.com');
+ $this->share->expects($this->any())->method('getSharedBy')->willReturn('validby@valid.com');
+ $this->share->expects($this->any())->method('getSharedWith')->willReturn('validwith@valid.com');
+ $this->share->expects($this->any())->method('getNote')->willReturn('Check this!');
$node = $this->getMockBuilder('OCP\Files\Node')->getMock();
$node->expects($this->any())->method('getName')->willReturn('fileName');
$this->share->expects($this->any())->method('getNode')->willReturn($node);
@@ -523,7 +512,9 @@ class ShareByMailProviderTest extends TestCase {
$this->share->expects($this->any())->method('getToken')->willReturn('token');
$this->share->expects($this->once())->method('setToken')->with('token');
- $this->share->expects($this->any())->method('getSharedWith')->willReturn('valid@valid.com');
+ $this->share->expects($this->any())->method('getSharedBy')->willReturn('validby@valid.com');
+ $this->share->expects($this->any())->method('getSharedWith')->willReturn('validwith@valid.com');
+ $this->share->expects($this->any())->method('getNote')->willReturn('Check this!');
$node = $this->getMockBuilder('OCP\Files\Node')->getMock();
$node->expects($this->any())->method('getName')->willReturn('fileName');
$this->share->expects($this->any())->method('getNode')->willReturn($node);