EventReminderJobTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\DAV\Tests\unit\BackgroundJob;
  8. use OCA\DAV\BackgroundJob\EventReminderJob;
  9. use OCA\DAV\CalDAV\Reminder\ReminderService;
  10. use OCP\AppFramework\Utility\ITimeFactory;
  11. use OCP\IConfig;
  12. use PHPUnit\Framework\MockObject\MockObject;
  13. use Test\TestCase;
  14. class EventReminderJobTest extends TestCase {
  15. /** @var ITimeFactory|MockObject */
  16. private $time;
  17. /** @var ReminderService|MockObject */
  18. private $reminderService;
  19. /** @var IConfig|MockObject */
  20. private $config;
  21. /** @var EventReminderJob|MockObject */
  22. private $backgroundJob;
  23. protected function setUp(): void {
  24. parent::setUp();
  25. $this->time = $this->createMock(ITimeFactory::class);
  26. $this->reminderService = $this->createMock(ReminderService::class);
  27. $this->config = $this->createMock(IConfig::class);
  28. $this->backgroundJob = new EventReminderJob(
  29. $this->time,
  30. $this->reminderService,
  31. $this->config,
  32. );
  33. }
  34. public function data(): array {
  35. return [
  36. [true, true, true],
  37. [true, false, false],
  38. [false, true, false],
  39. [false, false, false],
  40. ];
  41. }
  42. /**
  43. * @dataProvider data
  44. *
  45. * @param bool $sendEventReminders
  46. * @param bool $sendEventRemindersMode
  47. * @param bool $expectCall
  48. */
  49. public function testRun(bool $sendEventReminders, bool $sendEventRemindersMode, bool $expectCall): void {
  50. $this->config->expects($this->exactly($sendEventReminders ? 2 : 1))
  51. ->method('getAppValue')
  52. ->withConsecutive(
  53. ['dav', 'sendEventReminders', 'yes'],
  54. ['dav', 'sendEventRemindersMode', 'backgroundjob'],
  55. )
  56. ->willReturnOnConsecutiveCalls(
  57. $sendEventReminders ? 'yes' : 'no',
  58. $sendEventRemindersMode ? 'backgroundjob' : 'cron'
  59. );
  60. if ($expectCall) {
  61. $this->reminderService->expects($this->once())
  62. ->method('processReminders');
  63. } else {
  64. $this->reminderService->expects($this->never())
  65. ->method('processReminders');
  66. }
  67. $this->backgroundJob->run([]);
  68. }
  69. }