1
0

EMailproviderTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
  4. *
  5. * @author 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
  6. *
  7. * @license GNU AGPL version 3 or any later version
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as
  11. * published by the Free Software Foundation, either version 3 of the
  12. * License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. namespace Tests\Contacts\ContactsMenu\Providers;
  24. use OC\Contacts\ContactsMenu\Providers\EMailProvider;
  25. use OCP\Contacts\ContactsMenu\IActionFactory;
  26. use OCP\Contacts\ContactsMenu\IEntry;
  27. use OCP\Contacts\ContactsMenu\ILinkAction;
  28. use OCP\IURLGenerator;
  29. use PHPUnit\Framework\MockObject\MockObject;
  30. use Test\TestCase;
  31. class EMailproviderTest extends TestCase {
  32. /** @var IActionFactory|MockObject */
  33. private $actionFactory;
  34. /** @var IURLGenerator|MockObject */
  35. private $urlGenerator;
  36. private EMailProvider $provider;
  37. protected function setUp(): void {
  38. parent::setUp();
  39. $this->actionFactory = $this->createMock(IActionFactory::class);
  40. $this->urlGenerator = $this->createMock(IURLGenerator::class);
  41. $this->provider = new EMailProvider($this->actionFactory, $this->urlGenerator);
  42. }
  43. public function testProcess() {
  44. $entry = $this->createMock(IEntry::class);
  45. $action = $this->createMock(ILinkAction::class);
  46. $iconUrl = 'https://example.com/img/actions/icon.svg';
  47. $this->urlGenerator->expects($this->once())
  48. ->method('imagePath')
  49. ->willReturn('img/actions/icon.svg');
  50. $this->urlGenerator->expects($this->once())
  51. ->method('getAbsoluteURL')
  52. ->with('img/actions/icon.svg')
  53. ->willReturn($iconUrl);
  54. $entry->expects($this->once())
  55. ->method('getEMailAddresses')
  56. ->willReturn([
  57. 'user@example.com',
  58. ]);
  59. $this->actionFactory->expects($this->once())
  60. ->method('newEMailAction')
  61. ->with($this->equalTo($iconUrl), $this->equalTo('user@example.com'), $this->equalTo('user@example.com'))
  62. ->willReturn($action);
  63. $entry->expects($this->once())
  64. ->method('addAction')
  65. ->with($action);
  66. $this->provider->process($entry);
  67. }
  68. public function testProcessEmptyAddress() {
  69. $entry = $this->createMock(IEntry::class);
  70. $iconUrl = 'https://example.com/img/actions/icon.svg';
  71. $this->urlGenerator->expects($this->once())
  72. ->method('imagePath')
  73. ->willReturn('img/actions/icon.svg');
  74. $this->urlGenerator->expects($this->once())
  75. ->method('getAbsoluteURL')
  76. ->with('img/actions/icon.svg')
  77. ->willReturn($iconUrl);
  78. $entry->expects($this->once())
  79. ->method('getEMailAddresses')
  80. ->willReturn([
  81. '',
  82. ]);
  83. $this->actionFactory->expects($this->never())
  84. ->method('newEMailAction');
  85. $entry->expects($this->never())
  86. ->method('addAction');
  87. $this->provider->process($entry);
  88. }
  89. }