EventReminderJobTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2018, Thomas Citharel <tcit@tcit.fr>
  5. *
  6. * @author Thomas Citharel <tcit@tcit.fr>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\DAV\Tests\unit\BackgroundJob;
  25. use OCA\DAV\BackgroundJob\EventReminderJob;
  26. use OCA\DAV\CalDAV\Reminder\ReminderService;
  27. use OCP\IConfig;
  28. use Test\TestCase;
  29. class EventReminderJobTest extends TestCase {
  30. /** @var ReminderService|\PHPUnit\Framework\MockObject\MockObject */
  31. private $reminderService;
  32. /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
  33. private $config;
  34. /** @var EventReminderJob|\PHPUnit\Framework\MockObject\MockObject */
  35. private $backgroundJob;
  36. protected function setUp() {
  37. parent::setUp();
  38. $this->reminderService = $this->createMock(ReminderService::class);
  39. $this->config = $this->createMock(IConfig::class);
  40. $this->backgroundJob = new EventReminderJob($this->reminderService, $this->config);
  41. }
  42. public function data(): array
  43. {
  44. return [
  45. [true, true, true],
  46. [true, false, false],
  47. [false, true, false],
  48. [false, false, false],
  49. ];
  50. }
  51. /**
  52. * @dataProvider data
  53. *
  54. * @param bool $sendEventReminders
  55. * @param bool $sendEventRemindersMode
  56. * @param bool $expectCall
  57. */
  58. public function testRun(bool $sendEventReminders, bool $sendEventRemindersMode, bool $expectCall): void {
  59. $this->config->expects($this->at(0))
  60. ->method('getAppValue')
  61. ->with('dav', 'sendEventReminders', 'yes')
  62. ->willReturn($sendEventReminders ? 'yes' : 'no');
  63. if ($sendEventReminders) {
  64. $this->config->expects($this->at(1))
  65. ->method('getAppValue')
  66. ->with('dav', 'sendEventRemindersMode', 'backgroundjob')
  67. ->willReturn($sendEventRemindersMode ? 'backgroundjob' : 'cron');
  68. }
  69. if ($expectCall) {
  70. $this->reminderService->expects($this->once())
  71. ->method('processReminders');
  72. } else {
  73. $this->reminderService->expects($this->never())
  74. ->method('processReminders');
  75. }
  76. $this->backgroundJob->run([]);
  77. }
  78. }