EventReminderJobTest.php 2.8 KB

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