BirthdayCalendarControllerTest.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. /**
  3. * @copyright 2017, Georg Ehrke <oc.list@georgehrke.com>
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  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. *
  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\DAV\Controller;
  27. use OCA\DAV\BackgroundJob\GenerateBirthdayCalendarBackgroundJob;
  28. use OCA\DAV\CalDAV\CalDavBackend;
  29. use OCA\DAV\Controller\BirthdayCalendarController;
  30. use OCP\BackgroundJob\IJobList;
  31. use OCP\IConfig;
  32. use OCP\IDBConnection;
  33. use OCP\IRequest;
  34. use OCP\IUser;
  35. use OCP\IUserManager;
  36. use Test\TestCase;
  37. class BirthdayCalendarControllerTest extends TestCase {
  38. /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
  39. private $config;
  40. /** @var IRequest|\PHPUnit_Framework_MockObject_MockObject */
  41. private $request;
  42. /** @var IDBConnection|\PHPUnit_Framework_MockObject_MockObject */
  43. private $db;
  44. /** @var IJobList|\PHPUnit_Framework_MockObject_MockObject */
  45. private $jobList;
  46. /** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
  47. private $userManager;
  48. /** @var CalDavBackend|\PHPUnit_Framework_MockObject_MockObject */
  49. private $caldav;
  50. /** @var BirthdayCalendarController|\PHPUnit_Framework_MockObject_MockObject */
  51. private $controller;
  52. protected function setUp(): void {
  53. parent::setUp();
  54. $this->config = $this->createMock(IConfig::class);
  55. $this->request = $this->createMock(IRequest::class);
  56. $this->db = $this->createMock(IDBConnection::class);
  57. $this->jobList = $this->createMock(IJobList::class);
  58. $this->userManager = $this->createMock(IUserManager::class);
  59. $this->caldav = $this->createMock(CalDavBackend::class);
  60. $this->controller = new BirthdayCalendarController('dav',
  61. $this->request, $this->db, $this->config, $this->jobList,
  62. $this->userManager, $this->caldav);
  63. }
  64. public function testEnable() {
  65. $this->config->expects($this->once())
  66. ->method('setAppValue')
  67. ->with('dav', 'generateBirthdayCalendar', 'yes');
  68. $this->userManager->expects($this->once())
  69. ->method('callForSeenUsers')
  70. ->willReturnCallback(function ($closure) {
  71. $user1 = $this->createMock(IUser::class);
  72. $user1->method('getUID')->willReturn('uid1');
  73. $user2 = $this->createMock(IUser::class);
  74. $user2->method('getUID')->willReturn('uid2');
  75. $user3 = $this->createMock(IUser::class);
  76. $user3->method('getUID')->willReturn('uid3');
  77. $closure($user1);
  78. $closure($user2);
  79. $closure($user3);
  80. });
  81. $this->jobList->expects($this->at(0))
  82. ->method('add')
  83. ->with(GenerateBirthdayCalendarBackgroundJob::class, ['userId' => 'uid1']);
  84. $this->jobList->expects($this->at(1))
  85. ->method('add')
  86. ->with(GenerateBirthdayCalendarBackgroundJob::class, ['userId' => 'uid2']);
  87. $this->jobList->expects($this->at(2))
  88. ->method('add')
  89. ->with(GenerateBirthdayCalendarBackgroundJob::class, ['userId' => 'uid3']);
  90. $response = $this->controller->enable();
  91. $this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $response);
  92. }
  93. public function testDisable() {
  94. $this->config->expects($this->once())
  95. ->method('setAppValue')
  96. ->with('dav', 'generateBirthdayCalendar', 'no');
  97. $this->jobList->expects($this->once())
  98. ->method('remove')
  99. ->with(GenerateBirthdayCalendarBackgroundJob::class);
  100. $this->caldav->expects($this->once())
  101. ->method('deleteAllBirthdayCalendars');
  102. $response = $this->controller->disable();
  103. $this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $response);
  104. }
  105. }