1
0

UpdateCheckerTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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\VersionCheck;
  27. use OCA\UpdateNotification\UpdateChecker;
  28. use Test\TestCase;
  29. class UpdateCheckerTest extends TestCase {
  30. /** @var VersionCheck|\PHPUnit_Framework_MockObject_MockObject */
  31. private $updater;
  32. /** @var UpdateChecker */
  33. private $updateChecker;
  34. public function setUp() {
  35. parent::setUp();
  36. $this->updater = $this->createMock(VersionCheck::class);
  37. $this->updateChecker = new UpdateChecker($this->updater);
  38. }
  39. public function testGetUpdateStateWithUpdateAndInvalidLink() {
  40. $this->updater
  41. ->expects($this->once())
  42. ->method('check')
  43. ->willReturn([
  44. 'version' => 123,
  45. 'versionstring' => 'Nextcloud 123',
  46. 'web'=> 'javascript:alert(1)',
  47. 'url'=> 'javascript:alert(2)',
  48. 'autoupdater'=> '0',
  49. 'eol'=> '1',
  50. ]);
  51. $expected = [
  52. 'updateAvailable' => true,
  53. 'updateVersion' => 'Nextcloud 123',
  54. 'updaterEnabled' => false,
  55. 'versionIsEol' => true,
  56. ];
  57. $this->assertSame($expected, $this->updateChecker->getUpdateState());
  58. }
  59. public function testGetUpdateStateWithUpdateAndValidLink() {
  60. $this->updater
  61. ->expects($this->once())
  62. ->method('check')
  63. ->willReturn([
  64. 'version' => 123,
  65. 'versionstring' => 'Nextcloud 123',
  66. 'web'=> 'https://docs.nextcloud.com/myUrl',
  67. 'url'=> 'https://downloads.nextcloud.org/server',
  68. 'autoupdater'=> '1',
  69. 'eol'=> '0',
  70. ]);
  71. $expected = [
  72. 'updateAvailable' => true,
  73. 'updateVersion' => 'Nextcloud 123',
  74. 'updaterEnabled' => true,
  75. 'versionIsEol' => false,
  76. 'updateLink' => 'https://docs.nextcloud.com/myUrl',
  77. 'downloadLink' => 'https://downloads.nextcloud.org/server',
  78. ];
  79. $this->assertSame($expected, $this->updateChecker->getUpdateState());
  80. }
  81. public function testGetUpdateStateWithoutUpdate() {
  82. $this->updater
  83. ->expects($this->once())
  84. ->method('check')
  85. ->willReturn([]);
  86. $expected = [];
  87. $this->assertSame($expected, $this->updateChecker->getUpdateState());
  88. }
  89. }