1
0

UpdateCheckerTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2016, ownCloud, Inc.
  5. *
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Lukas Reschke <lukas@statuscode.ch>
  8. * @author Thomas Müller <thomas.mueller@tmit.eu>
  9. *
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  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, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace OCA\UpdateNotification\Tests;
  26. use OC\Updater\ChangesCheck;
  27. use OC\Updater\VersionCheck;
  28. use OCA\UpdateNotification\UpdateChecker;
  29. use Test\TestCase;
  30. class UpdateCheckerTest extends TestCase {
  31. /** @var ChangesCheck|\PHPUnit_Framework_MockObject_MockObject */
  32. protected $changesChecker;
  33. /** @var VersionCheck|\PHPUnit_Framework_MockObject_MockObject */
  34. private $updater;
  35. /** @var UpdateChecker */
  36. private $updateChecker;
  37. public function setUp() {
  38. parent::setUp();
  39. $this->updater = $this->createMock(VersionCheck::class);
  40. $this->changesChecker = $this->createMock(ChangesCheck::class);
  41. $this->updateChecker = new UpdateChecker($this->updater, $this->changesChecker);
  42. }
  43. public function testGetUpdateStateWithUpdateAndInvalidLink() {
  44. $this->updater
  45. ->expects($this->once())
  46. ->method('check')
  47. ->willReturn([
  48. 'version' => '1.2.3',
  49. 'versionstring' => 'Nextcloud 1.2.3',
  50. 'web'=> 'javascript:alert(1)',
  51. 'url'=> 'javascript:alert(2)',
  52. 'changes' => 'javascript:alert(3)',
  53. 'autoupdater'=> '0',
  54. 'eol'=> '1',
  55. ]);
  56. $expected = [
  57. 'updateAvailable' => true,
  58. 'updateVersion' => '1.2.3',
  59. 'updateVersionString' => 'Nextcloud 1.2.3',
  60. 'updaterEnabled' => false,
  61. 'versionIsEol' => true,
  62. ];
  63. $this->assertSame($expected, $this->updateChecker->getUpdateState());
  64. }
  65. public function testGetUpdateStateWithUpdateAndValidLink() {
  66. $changes = [
  67. 'changelog' => 'https://nextcloud.com/changelog/#123-0-0',
  68. 'whatsNew' => [
  69. 'en' => [
  70. 'regular' => [
  71. 'Yardarm heave to brig spyglass smartly pillage',
  72. 'Bounty gangway bilge skysail rope\'s end',
  73. 'Maroon cutlass spirits nipperkin Plate Fleet',
  74. ],
  75. 'admin' => [
  76. 'Scourge of the seven seas coffer doubloon',
  77. 'Brig me splice the main brace',
  78. ]
  79. ]
  80. ]
  81. ];
  82. $this->updater
  83. ->expects($this->once())
  84. ->method('check')
  85. ->willReturn([
  86. 'version' => '1.2.3',
  87. 'versionstring' => 'Nextcloud 1.2.3',
  88. 'web'=> 'https://docs.nextcloud.com/myUrl',
  89. 'url'=> 'https://downloads.nextcloud.org/server',
  90. 'changes' => 'https://updates.nextcloud.com/changelog_server/?version=123.0.0',
  91. 'autoupdater'=> '1',
  92. 'eol'=> '0',
  93. ]);
  94. $this->changesChecker->expects($this->once())
  95. ->method('check')
  96. ->willReturn($changes);
  97. $expected = [
  98. 'updateAvailable' => true,
  99. 'updateVersion' => '1.2.3',
  100. 'updateVersionString' => 'Nextcloud 1.2.3',
  101. 'updaterEnabled' => true,
  102. 'versionIsEol' => false,
  103. 'updateLink' => 'https://docs.nextcloud.com/myUrl',
  104. 'downloadLink' => 'https://downloads.nextcloud.org/server',
  105. 'changes' => $changes,
  106. ];
  107. $this->assertSame($expected, $this->updateChecker->getUpdateState());
  108. }
  109. public function testGetUpdateStateWithoutUpdate() {
  110. $this->updater
  111. ->expects($this->once())
  112. ->method('check')
  113. ->willReturn([]);
  114. $expected = [];
  115. $this->assertSame($expected, $this->updateChecker->getUpdateState());
  116. }
  117. }