EMailproviderTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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|PHPUnit_Framework_MockObject_MockObject */
  33. private $actionFactory;
  34. /** @var IURLGenerator|PHPUnit_Framework_MockObject_MockObject */
  35. private $urlGenerator;
  36. /** @var EMailProvider */
  37. private $provider;
  38. protected function setUp() {
  39. parent::setUp();
  40. $this->actionFactory = $this->createMock(IActionFactory::class);
  41. $this->urlGenerator = $this->createMock(IURLGenerator::class);
  42. $this->provider = new EMailProvider($this->actionFactory, $this->urlGenerator);
  43. }
  44. public function testProcess() {
  45. $entry = $this->createMock(IEntry::class);
  46. $action = $this->createMock(ILinkAction::class);
  47. $iconUrl = 'https://example.com/img/actions/icon.svg';
  48. $this->urlGenerator->expects($this->once())
  49. ->method('imagePath')
  50. ->willReturn('img/actions/icon.svg');
  51. $this->urlGenerator->expects($this->once())
  52. ->method('getAbsoluteURL')
  53. ->with('img/actions/icon.svg')
  54. ->willReturn($iconUrl);
  55. $entry->expects($this->once())
  56. ->method('getEMailAddresses')
  57. ->willReturn([
  58. 'user@example.com',
  59. ]);
  60. $this->actionFactory->expects($this->once())
  61. ->method('newEMailAction')
  62. ->with($this->equalTo($iconUrl), $this->equalTo('user@example.com'), $this->equalTo('user@example.com'))
  63. ->willReturn($action);
  64. $entry->expects($this->once())
  65. ->method('addAction')
  66. ->with($action);
  67. $this->provider->process($entry);
  68. }
  69. public function testProcessEmptyAddress() {
  70. $entry = $this->createMock(IEntry::class);
  71. $action = $this->createMock(ILinkAction::class);
  72. $iconUrl = 'https://example.com/img/actions/icon.svg';
  73. $this->urlGenerator->expects($this->once())
  74. ->method('imagePath')
  75. ->willReturn('img/actions/icon.svg');
  76. $this->urlGenerator->expects($this->once())
  77. ->method('getAbsoluteURL')
  78. ->with('img/actions/icon.svg')
  79. ->willReturn($iconUrl);
  80. $entry->expects($this->once())
  81. ->method('getEMailAddresses')
  82. ->willReturn([
  83. '',
  84. ]);
  85. $this->actionFactory->expects($this->never())
  86. ->method('newEMailAction');
  87. $entry->expects($this->never())
  88. ->method('addAction');
  89. $this->provider->process($entry);
  90. }
  91. }