You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RefreshWebcalJobRegistrarTest.php 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2018, Georg Ehrke
  4. *
  5. * @author Georg Ehrke <oc.list@georgehrke.com>
  6. *
  7. * @license AGPL-3.0
  8. *
  9. * This code is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License, version 3,
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License, version 3,
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>
  20. *
  21. */
  22. namespace OCA\DAV\Tests\unit\DAV\Migration;
  23. use OCA\DAV\BackgroundJob\RefreshWebcalJob;
  24. use OCA\DAV\Migration\RefreshWebcalJobRegistrar;
  25. use OCP\BackgroundJob\IJobList;
  26. use OCP\DB\QueryBuilder\IQueryBuilder;
  27. use OCP\IDBConnection;
  28. use OCP\Migration\IOutput;
  29. use Test\TestCase;
  30. class RefreshWebcalJobRegistrarTest extends TestCase {
  31. /** @var IDBConnection | \PHPUnit_Framework_MockObject_MockObject */
  32. private $db;
  33. /** @var IJobList | \PHPUnit_Framework_MockObject_MockObject */
  34. private $jobList;
  35. /** @var RefreshWebcalJobRegistrar */
  36. private $migration;
  37. protected function setUp() {
  38. parent::setUp();
  39. $this->db = $this->createMock(IDBConnection::class);
  40. $this->jobList = $this->createMock(IJobList::class);
  41. $this->migration = new RefreshWebcalJobRegistrar($this->db, $this->jobList);
  42. }
  43. public function testGetName() {
  44. $this->assertEquals($this->migration->getName(), 'Registering background jobs to update cache for webcal calendars');
  45. }
  46. public function testRun() {
  47. $output = $this->createMock(IOutput::class);
  48. $queryBuilder = $this->createMock(IQueryBuilder::class);
  49. $statement = $this->createMock(\Doctrine\DBAL\Driver\Statement::class);
  50. $this->db->expects($this->once())
  51. ->method('getQueryBuilder')
  52. ->will($this->returnValue($queryBuilder));
  53. $queryBuilder->expects($this->at(0))
  54. ->method('select')
  55. ->with(['principaluri', 'uri'])
  56. ->will($this->returnValue($queryBuilder));
  57. $queryBuilder->expects($this->at(1))
  58. ->method('from')
  59. ->with('calendarsubscriptions')
  60. ->will($this->returnValue($queryBuilder));
  61. $queryBuilder->expects($this->at(2))
  62. ->method('execute')
  63. ->will($this->returnValue($statement));
  64. $statement->expects($this->at(0))
  65. ->method('fetch')
  66. ->with(\PDO::FETCH_ASSOC)
  67. ->will($this->returnValue([
  68. 'principaluri' => 'foo1',
  69. 'uri' => 'bar1',
  70. ]));
  71. $statement->expects($this->at(1))
  72. ->method('fetch')
  73. ->with(\PDO::FETCH_ASSOC)
  74. ->will($this->returnValue([
  75. 'principaluri' => 'foo2',
  76. 'uri' => 'bar2',
  77. ]));
  78. $statement->expects($this->at(2))
  79. ->method('fetch')
  80. ->with(\PDO::FETCH_ASSOC)
  81. ->will($this->returnValue([
  82. 'principaluri' => 'foo3',
  83. 'uri' => 'bar3',
  84. ]));
  85. $statement->expects($this->at(0))
  86. ->method('fetch')
  87. ->with(\PDO::FETCH_ASSOC)
  88. ->will($this->returnValue(null));
  89. $this->jobList->expects($this->at(0))
  90. ->method('has')
  91. ->with(RefreshWebcalJob::class, [
  92. 'principaluri' => 'foo1',
  93. 'uri' => 'bar1',
  94. ])
  95. ->will($this->returnValue(false));
  96. $this->jobList->expects($this->at(1))
  97. ->method('add')
  98. ->with(RefreshWebcalJob::class, [
  99. 'principaluri' => 'foo1',
  100. 'uri' => 'bar1',
  101. ]);
  102. $this->jobList->expects($this->at(2))
  103. ->method('has')
  104. ->with(RefreshWebcalJob::class, [
  105. 'principaluri' => 'foo2',
  106. 'uri' => 'bar2',
  107. ])
  108. ->will($this->returnValue(true));
  109. $this->jobList->expects($this->at(3))
  110. ->method('has')
  111. ->with(RefreshWebcalJob::class, [
  112. 'principaluri' => 'foo3',
  113. 'uri' => 'bar3',
  114. ])
  115. ->will($this->returnValue(false));
  116. $this->jobList->expects($this->at(4))
  117. ->method('add')
  118. ->with(RefreshWebcalJob::class, [
  119. 'principaluri' => 'foo3',
  120. 'uri' => 'bar3',
  121. ]);
  122. $output->expects($this->once())
  123. ->method('info')
  124. ->with('Added 2 background jobs to update webcal calendars');
  125. $this->migration->run($output);
  126. }
  127. }