1
0

EventReminderJobTest.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2018, Thomas Citharel <tcit@tcit.fr>
  5. *
  6. * @author Georg Ehrke <oc.list@georgehrke.com>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  8. * @author Thomas Citharel <tcit@tcit.fr>
  9. *
  10. * @license GNU AGPL version 3 or any later version
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License as
  14. * published by the Free Software Foundation, either version 3 of the
  15. * License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. *
  25. */
  26. namespace OCA\DAV\Tests\unit\BackgroundJob;
  27. use OCA\DAV\BackgroundJob\EventReminderJob;
  28. use OCA\DAV\CalDAV\Reminder\ReminderService;
  29. use OCP\IConfig;
  30. use Test\TestCase;
  31. class EventReminderJobTest extends TestCase {
  32. /** @var ReminderService|\PHPUnit\Framework\MockObject\MockObject */
  33. private $reminderService;
  34. /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
  35. private $config;
  36. /** @var EventReminderJob|\PHPUnit\Framework\MockObject\MockObject */
  37. private $backgroundJob;
  38. protected function setUp(): void {
  39. parent::setUp();
  40. $this->reminderService = $this->createMock(ReminderService::class);
  41. $this->config = $this->createMock(IConfig::class);
  42. $this->backgroundJob = new EventReminderJob($this->reminderService, $this->config);
  43. }
  44. public function data(): array
  45. {
  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. }