Skip to content

Commit e547247

Browse files
authored
Merge pull request #40182 from nextcloud/feat/share-by-mail/remove-ilogger-2
2 parents b92f5cd + 730a789 commit e547247

1 file changed

Lines changed: 24 additions & 12 deletions

File tree

apps/sharebymail/tests/ShareByMailProviderTest.php

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ protected function tearDown(): void {
198198
}
199199

200200
public function testCreate() {
201+
$expectedShare = $this->createMock(IShare::class);
202+
201203
$share = $this->getMockBuilder(IShare::class)->getMock();
202204
$share->expects($this->any())->method('getSharedWith')->willReturn('user1');
203205

@@ -210,13 +212,13 @@ public function testCreate() {
210212
$instance->expects($this->once())->method('createMailShare')->with($share)->willReturn(42);
211213
$instance->expects($this->once())->method('createShareActivity')->with($share);
212214
$instance->expects($this->once())->method('getRawShare')->with(42)->willReturn(['rawShare']);
213-
$instance->expects($this->once())->method('createShareObject')->with(['rawShare'])->willReturn($this->createMock(IShare::class));
215+
$instance->expects($this->once())->method('createShareObject')->with(['rawShare'])->willReturn($expectedShare);
214216
$instance->expects($this->any())->method('sendPassword')->willReturn(true);
215217
$share->expects($this->any())->method('getNode')->willReturn($node);
216218
$this->shareManager->expects($this->any())->method('shareApiLinkEnforcePassword')->willReturn(false);
217219
$this->settingsManager->expects($this->any())->method('sendPasswordByMail')->willReturn(true);
218220

219-
$this->assertInstanceOf(IShare::class, $instance->create($share));
221+
$this->assertSame($expectedShare, $instance->create($share));
220222
}
221223

222224
public function testCreateSendPasswordByMailWithoutEnforcedPasswordProtection() {
@@ -250,6 +252,8 @@ public function testCreateSendPasswordByMailWithoutEnforcedPasswordProtection()
250252
}
251253

252254
public function testCreateSendPasswordByMailWithPasswordAndWithoutEnforcedPasswordProtectionWithPermanentPassword() {
255+
$expectedShare = $this->createMock(IShare::class);
256+
253257
$share = $this->getMockBuilder(IShare::class)->getMock();
254258
$share->expects($this->any())->method('getSharedWith')->willReturn('receiver@example.com');
255259
$share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(false);
@@ -264,7 +268,7 @@ public function testCreateSendPasswordByMailWithPasswordAndWithoutEnforcedPasswo
264268
$instance->expects($this->once())->method('createMailShare')->with($share)->willReturn(42);
265269
$instance->expects($this->once())->method('createShareActivity')->with($share);
266270
$instance->expects($this->once())->method('getRawShare')->with(42)->willReturn(['rawShare']);
267-
$instance->expects($this->once())->method('createShareObject')->with(['rawShare'])->willReturn($this->createMock(IShare::class));
271+
$instance->expects($this->once())->method('createShareObject')->with(['rawShare'])->willReturn($expectedShare);
268272
$share->expects($this->any())->method('getNode')->willReturn($node);
269273

270274
$share->expects($this->once())->method('getPassword')->willReturn('password');
@@ -277,10 +281,12 @@ public function testCreateSendPasswordByMailWithPasswordAndWithoutEnforcedPasswo
277281
$this->config->expects($this->once())->method('getSystemValue')->with('sharing.enable_mail_link_password_expiration')->willReturn(false);
278282
$instance->expects($this->never())->method('autoGeneratePassword');
279283

280-
$this->assertInstanceOf(IShare::class, $instance->create($share));
284+
$this->assertSame($expectedShare, $instance->create($share));
281285
}
282286

283287
public function testCreateSendPasswordByMailWithPasswordAndWithoutEnforcedPasswordProtectionWithoutPermanentPassword() {
288+
$expectedShare = $this->createMock(IShare::class);
289+
284290
$share = $this->getMockBuilder(IShare::class)->getMock();
285291
$share->expects($this->any())->method('getSharedWith')->willReturn('receiver@example.com');
286292
$share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(false);
@@ -295,7 +301,7 @@ public function testCreateSendPasswordByMailWithPasswordAndWithoutEnforcedPasswo
295301
$instance->expects($this->once())->method('createMailShare')->with($share)->willReturn(42);
296302
$instance->expects($this->once())->method('createShareActivity')->with($share);
297303
$instance->expects($this->once())->method('getRawShare')->with(42)->willReturn(['rawShare']);
298-
$instance->expects($this->once())->method('createShareObject')->with(['rawShare'])->willReturn($this->createMock(IShare::class));
304+
$instance->expects($this->once())->method('createShareObject')->with(['rawShare'])->willReturn($expectedShare);
299305
$share->expects($this->any())->method('getNode')->willReturn($node);
300306

301307
$share->expects($this->once())->method('getPassword')->willReturn('password');
@@ -316,10 +322,12 @@ public function testCreateSendPasswordByMailWithPasswordAndWithoutEnforcedPasswo
316322
3600
317323
);
318324

319-
$this->assertInstanceOf(IShare::class, $instance->create($share));
325+
$this->assertSame($expectedShare, $instance->create($share));
320326
}
321327

322328
public function testCreateSendPasswordByMailWithEnforcedPasswordProtectionWithPermanentPassword() {
329+
$expectedShare = $this->createMock(IShare::class);
330+
323331
$share = $this->getMockBuilder(IShare::class)->getMock();
324332
$share->expects($this->any())->method('getSharedWith')->willReturn('receiver@example.com');
325333
$share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(false);
@@ -342,7 +350,7 @@ public function testCreateSendPasswordByMailWithEnforcedPasswordProtectionWithPe
342350
$instance->expects($this->once())->method('createMailShare')->with($share)->willReturn(42);
343351
$instance->expects($this->once())->method('createShareActivity')->with($share);
344352
$instance->expects($this->once())->method('getRawShare')->with(42)->willReturn(['rawShare']);
345-
$instance->expects($this->once())->method('createShareObject')->with(['rawShare'])->willReturn($this->createMock(IShare::class));
353+
$instance->expects($this->once())->method('createShareObject')->with(['rawShare'])->willReturn($expectedShare);
346354
$share->expects($this->any())->method('getNode')->willReturn($node);
347355

348356
$share->expects($this->once())->method('getPassword')->willReturn(null);
@@ -366,10 +374,12 @@ public function testCreateSendPasswordByMailWithEnforcedPasswordProtectionWithPe
366374
]);
367375
$this->mailer->expects($this->once())->method('send');
368376

369-
$this->assertInstanceOf(IShare::class, $instance->create($share));
377+
$this->assertSame($expectedShare, $instance->create($share));
370378
}
371379

372380
public function testCreateSendPasswordByMailWithPasswordAndWithEnforcedPasswordProtectionWithPermanentPassword() {
381+
$expectedShare = $this->createMock(IShare::class);
382+
373383
$share = $this->getMockBuilder(IShare::class)->getMock();
374384
$share->expects($this->any())->method('getSharedWith')->willReturn('receiver@example.com');
375385
$share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(false);
@@ -384,7 +394,7 @@ public function testCreateSendPasswordByMailWithPasswordAndWithEnforcedPasswordP
384394
$instance->expects($this->once())->method('createMailShare')->with($share)->willReturn(42);
385395
$instance->expects($this->once())->method('createShareActivity')->with($share);
386396
$instance->expects($this->once())->method('getRawShare')->with(42)->willReturn(['rawShare']);
387-
$instance->expects($this->once())->method('createShareObject')->with(['rawShare'])->willReturn($this->createMock(IShare::class));
397+
$instance->expects($this->once())->method('createShareObject')->with(['rawShare'])->willReturn($expectedShare);
388398
$share->expects($this->any())->method('getNode')->willReturn($node);
389399

390400
$share->expects($this->once())->method('getPassword')->willReturn('password');
@@ -410,10 +420,12 @@ public function testCreateSendPasswordByMailWithPasswordAndWithEnforcedPasswordP
410420
]);
411421
$this->mailer->expects($this->once())->method('send');
412422

413-
$this->assertInstanceOf(IShare::class, $instance->create($share));
423+
$this->assertSame($expectedShare, $instance->create($share));
414424
}
415425

416426
public function testCreateSendPasswordByTalkWithEnforcedPasswordProtectionWithPermanentPassword() {
427+
$expectedShare = $this->createMock(IShare::class);
428+
417429
$share = $this->getMockBuilder(IShare::class)->getMock();
418430
$share->expects($this->any())->method('getSharedWith')->willReturn('receiver@example.com');
419431
$share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(true);
@@ -428,7 +440,7 @@ public function testCreateSendPasswordByTalkWithEnforcedPasswordProtectionWithPe
428440
$instance->expects($this->once())->method('createMailShare')->with($share)->willReturn(42);
429441
$instance->expects($this->once())->method('createShareActivity')->with($share);
430442
$instance->expects($this->once())->method('getRawShare')->with(42)->willReturn(['rawShare']);
431-
$instance->expects($this->once())->method('createShareObject')->with(['rawShare'])->willReturn($this->createMock(IShare::class));
443+
$instance->expects($this->once())->method('createShareObject')->with(['rawShare'])->willReturn($expectedShare);
432444
$share->expects($this->any())->method('getNode')->willReturn($node);
433445

434446
$share->expects($this->once())->method('getPassword')->willReturn(null);
@@ -458,7 +470,7 @@ public function testCreateSendPasswordByTalkWithEnforcedPasswordProtectionWithPe
458470
$user->expects($this->once())->method('getDisplayName')->willReturn('Owner display name');
459471
$user->expects($this->once())->method('getEMailAddress')->willReturn('owner@example.com');
460472

461-
$this->assertInstanceOf(IShare::class, $instance->create($share));
473+
$this->assertSame($expectedShare, $instance->create($share));
462474
}
463475

464476

0 commit comments

Comments
 (0)