UpdateCheckerTest.php 2.4 KB

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