1
0

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 Georg Ehrke <oc.list@georgehrke.com>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  8. *
  9. * @license GNU AGPL version 3 or any later version
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. namespace OCA\DAV\Tests\Unit\DAV\Controller;
  26. use OCA\DAV\BackgroundJob\GenerateBirthdayCalendarBackgroundJob;
  27. use OCA\DAV\CalDAV\CalDavBackend;
  28. use OCA\DAV\Controller\BirthdayCalendarController;
  29. use OCP\BackgroundJob\IJobList;
  30. use OCP\IConfig;
  31. use OCP\IDBConnection;
  32. use OCP\IRequest;
  33. use OCP\IUser;
  34. use OCP\IUserManager;
  35. use Test\TestCase;
  36. class BirthdayCalendarControllerTest extends TestCase {
  37. /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
  38. private $config;
  39. /** @var IRequest|\PHPUnit_Framework_MockObject_MockObject */
  40. private $request;
  41. /** @var IDBConnection|\PHPUnit_Framework_MockObject_MockObject */
  42. private $db;
  43. /** @var IJobList|\PHPUnit_Framework_MockObject_MockObject */
  44. private $jobList;
  45. /** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
  46. private $userManager;
  47. /** @var CalDavBackend|\PHPUnit_Framework_MockObject_MockObject */
  48. private $caldav;
  49. /** @var BirthdayCalendarController|\PHPUnit_Framework_MockObject_MockObject */
  50. private $controller;
  51. protected function setUp(): void {
  52. parent::setUp();
  53. $this->config = $this->createMock(IConfig::class);
  54. $this->request = $this->createMock(IRequest::class);
  55. $this->db = $this->createMock(IDBConnection::class);
  56. $this->jobList = $this->createMock(IJobList::class);
  57. $this->userManager = $this->createMock(IUserManager::class);
  58. $this->caldav = $this->createMock(CalDavBackend::class);
  59. $this->controller = new BirthdayCalendarController('dav',
  60. $this->request, $this->db, $this->config, $this->jobList,
  61. $this->userManager, $this->caldav);
  62. }
  63. public function testEnable() {
  64. $this->config->expects($this->once())
  65. ->method('setAppValue')
  66. ->with('dav', 'generateBirthdayCalendar', 'yes');
  67. $this->userManager->expects($this->once())
  68. ->method('callForSeenUsers')
  69. ->willReturnCallback(function($closure) {
  70. $user1 = $this->createMock(IUser::class);
  71. $user1->method('getUID')->willReturn('uid1');
  72. $user2 = $this->createMock(IUser::class);
  73. $user2->method('getUID')->willReturn('uid2');
  74. $user3 = $this->createMock(IUser::class);
  75. $user3->method('getUID')->willReturn('uid3');
  76. $closure($user1);
  77. $closure($user2);
  78. $closure($user3);
  79. });
  80. $this->jobList->expects($this->at(0))
  81. ->method('add')
  82. ->with(GenerateBirthdayCalendarBackgroundJob::class, ['userId' => 'uid1']);
  83. $this->jobList->expects($this->at(1))
  84. ->method('add')
  85. ->with(GenerateBirthdayCalendarBackgroundJob::class, ['userId' => 'uid2']);
  86. $this->jobList->expects($this->at(2))
  87. ->method('add')
  88. ->with(GenerateBirthdayCalendarBackgroundJob::class, ['userId' => 'uid3']);
  89. $response = $this->controller->enable();
  90. $this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $response);
  91. }
  92. public function testDisable() {
  93. $this->config->expects($this->once())
  94. ->method('setAppValue')
  95. ->with('dav', 'generateBirthdayCalendar', 'no');
  96. $this->jobList->expects($this->once())
  97. ->method('remove')
  98. ->with(GenerateBirthdayCalendarBackgroundJob::class);
  99. $this->caldav->expects($this->once())
  100. ->method('deleteAllBirthdayCalendars');
  101. $response = $this->controller->disable();
  102. $this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $response);
  103. }
  104. }