EventReminderJobTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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\AppFramework\Utility\ITimeFactory;
  31. use OCP\IConfig;
  32. use PHPUnit\Framework\MockObject\MockObject;
  33. use Test\TestCase;
  34. class EventReminderJobTest extends TestCase {
  35. /** @var ITimeFactory|MockObject */
  36. private $time;
  37. /** @var ReminderService|MockObject */
  38. private $reminderService;
  39. /** @var IConfig|MockObject */
  40. private $config;
  41. /** @var EventReminderJob|MockObject */
  42. private $backgroundJob;
  43. protected function setUp(): void {
  44. parent::setUp();
  45. $this->time = $this->createMock(ITimeFactory::class);
  46. $this->reminderService = $this->createMock(ReminderService::class);
  47. $this->config = $this->createMock(IConfig::class);
  48. $this->backgroundJob = new EventReminderJob(
  49. $this->time,
  50. $this->reminderService,
  51. $this->config,
  52. );
  53. }
  54. public function data(): array {
  55. return [
  56. [true, true, true],
  57. [true, false, false],
  58. [false, true, false],
  59. [false, false, false],
  60. ];
  61. }
  62. /**
  63. * @dataProvider data
  64. *
  65. * @param bool $sendEventReminders
  66. * @param bool $sendEventRemindersMode
  67. * @param bool $expectCall
  68. */
  69. public function testRun(bool $sendEventReminders, bool $sendEventRemindersMode, bool $expectCall): void {
  70. $this->config->expects($this->exactly($sendEventReminders ? 2 : 1))
  71. ->method('getAppValue')
  72. ->withConsecutive(
  73. ['dav', 'sendEventReminders', 'yes'],
  74. ['dav', 'sendEventRemindersMode', 'backgroundjob'],
  75. )
  76. ->willReturnOnConsecutiveCalls(
  77. $sendEventReminders ? 'yes' : 'no',
  78. $sendEventRemindersMode ? 'backgroundjob' : 'cron'
  79. );
  80. if ($expectCall) {
  81. $this->reminderService->expects($this->once())
  82. ->method('processReminders');
  83. } else {
  84. $this->reminderService->expects($this->never())
  85. ->method('processReminders');
  86. }
  87. $this->backgroundJob->run([]);
  88. }
  89. }