EMailproviderTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 Test\TestCase;
  30. class EMailproviderTest extends TestCase {
  31. /** @var IActionFactory|\PHPUnit\Framework\MockObject\MockObject */
  32. private $actionFactory;
  33. /** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */
  34. private $urlGenerator;
  35. /** @var EMailProvider */
  36. private $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. $action = $this->createMock(ILinkAction::class);
  71. $iconUrl = 'https://example.com/img/actions/icon.svg';
  72. $this->urlGenerator->expects($this->once())
  73. ->method('imagePath')
  74. ->willReturn('img/actions/icon.svg');
  75. $this->urlGenerator->expects($this->once())
  76. ->method('getAbsoluteURL')
  77. ->with('img/actions/icon.svg')
  78. ->willReturn($iconUrl);
  79. $entry->expects($this->once())
  80. ->method('getEMailAddresses')
  81. ->willReturn([
  82. '',
  83. ]);
  84. $this->actionFactory->expects($this->never())
  85. ->method('newEMailAction');
  86. $entry->expects($this->never())
  87. ->method('addAction');
  88. $this->provider->process($entry);
  89. }
  90. }