EMailproviderTest.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace Tests\Contacts\ContactsMenu\Providers;
  7. use OC\Contacts\ContactsMenu\Providers\EMailProvider;
  8. use OCP\Contacts\ContactsMenu\IActionFactory;
  9. use OCP\Contacts\ContactsMenu\IEntry;
  10. use OCP\Contacts\ContactsMenu\ILinkAction;
  11. use OCP\IURLGenerator;
  12. use PHPUnit\Framework\MockObject\MockObject;
  13. use Test\TestCase;
  14. class EMailproviderTest extends TestCase {
  15. /** @var IActionFactory|MockObject */
  16. private $actionFactory;
  17. /** @var IURLGenerator|MockObject */
  18. private $urlGenerator;
  19. private EMailProvider $provider;
  20. protected function setUp(): void {
  21. parent::setUp();
  22. $this->actionFactory = $this->createMock(IActionFactory::class);
  23. $this->urlGenerator = $this->createMock(IURLGenerator::class);
  24. $this->provider = new EMailProvider($this->actionFactory, $this->urlGenerator);
  25. }
  26. public function testProcess() {
  27. $entry = $this->createMock(IEntry::class);
  28. $action = $this->createMock(ILinkAction::class);
  29. $iconUrl = 'https://example.com/img/actions/icon.svg';
  30. $this->urlGenerator->expects($this->once())
  31. ->method('imagePath')
  32. ->willReturn('img/actions/icon.svg');
  33. $this->urlGenerator->expects($this->once())
  34. ->method('getAbsoluteURL')
  35. ->with('img/actions/icon.svg')
  36. ->willReturn($iconUrl);
  37. $entry->expects($this->once())
  38. ->method('getEMailAddresses')
  39. ->willReturn([
  40. 'user@example.com',
  41. ]);
  42. $this->actionFactory->expects($this->once())
  43. ->method('newEMailAction')
  44. ->with($this->equalTo($iconUrl), $this->equalTo('user@example.com'), $this->equalTo('user@example.com'))
  45. ->willReturn($action);
  46. $entry->expects($this->once())
  47. ->method('addAction')
  48. ->with($action);
  49. $this->provider->process($entry);
  50. }
  51. public function testProcessEmptyAddress() {
  52. $entry = $this->createMock(IEntry::class);
  53. $iconUrl = 'https://example.com/img/actions/icon.svg';
  54. $this->urlGenerator->expects($this->once())
  55. ->method('imagePath')
  56. ->willReturn('img/actions/icon.svg');
  57. $this->urlGenerator->expects($this->once())
  58. ->method('getAbsoluteURL')
  59. ->with('img/actions/icon.svg')
  60. ->willReturn($iconUrl);
  61. $entry->expects($this->once())
  62. ->method('getEMailAddresses')
  63. ->willReturn([
  64. '',
  65. ]);
  66. $this->actionFactory->expects($this->never())
  67. ->method('newEMailAction');
  68. $entry->expects($this->never())
  69. ->method('addAction');
  70. $this->provider->process($entry);
  71. }
  72. }