UpdateCheckerTest.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * @author Lukas Reschke <lukas@owncloud.com>
  4. *
  5. * @copyright Copyright (c) 2016, ownCloud, Inc.
  6. * @license AGPL-3.0
  7. *
  8. * This code is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License, version 3,
  10. * as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License, version 3,
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>
  19. *
  20. */
  21. namespace OCA\UpdateNotification\Tests;
  22. use OC\Updater;
  23. use OCA\UpdateNotification\UpdateChecker;
  24. use Test\TestCase;
  25. class UpdateCheckerTest extends TestCase {
  26. /** @var Updater */
  27. private $updater;
  28. /** @var UpdateChecker */
  29. private $updateChecker;
  30. public function setUp() {
  31. parent::setUp();
  32. $this->updater = $this->getMockBuilder('\OC\Updater')
  33. ->disableOriginalConstructor()->getMock();
  34. $this->updateChecker = new UpdateChecker($this->updater);
  35. }
  36. public function testGetUpdateStateWithUpdateAndInvalidLink() {
  37. $this->updater
  38. ->expects($this->once())
  39. ->method('check')
  40. ->willReturn([
  41. 'version' => 123,
  42. 'versionstring' => 'ownCloud 123',
  43. 'web'=> 'javascript:alert(1)',
  44. ]);
  45. $expected = [
  46. 'updateAvailable' => true,
  47. 'updateVersion' => 'ownCloud 123',
  48. ];
  49. $this->assertSame($expected, $this->updateChecker->getUpdateState());
  50. }
  51. public function testGetUpdateStateWithUpdateAndValidLink() {
  52. $this->updater
  53. ->expects($this->once())
  54. ->method('check')
  55. ->willReturn([
  56. 'version' => 123,
  57. 'versionstring' => 'ownCloud 123',
  58. 'web'=> 'https://owncloud.org/myUrl',
  59. ]);
  60. $expected = [
  61. 'updateAvailable' => true,
  62. 'updateVersion' => 'ownCloud 123',
  63. 'updateLink' => 'https://owncloud.org/myUrl',
  64. ];
  65. $this->assertSame($expected, $this->updateChecker->getUpdateState());
  66. }
  67. public function testGetUpdateStateWithoutUpdate() {
  68. $this->updater
  69. ->expects($this->once())
  70. ->method('check')
  71. ->willReturn([]);
  72. $expected = [];
  73. $this->assertSame($expected, $this->updateChecker->getUpdateState());
  74. }
  75. }