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.

UpdaterTest.php 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. /**
  3. * @author Lukas Reschke <lukas@owncloud.com>
  4. * @author Victor Dubiniuk <dubiniuk@owncloud.com>
  5. *
  6. * @copyright Copyright (c) 2015, ownCloud, Inc.
  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 Test;
  23. use OC\Installer;
  24. use OC\Updater;
  25. use OCP\BackgroundJob\IJobList;
  26. use OCP\IConfig;
  27. use OCP\ILogger;
  28. use OC\IntegrityCheck\Checker;
  29. class UpdaterTest extends TestCase {
  30. /** @var IConfig | \PHPUnit_Framework_MockObject_MockObject */
  31. private $config;
  32. /** @var ILogger | \PHPUnit_Framework_MockObject_MockObject */
  33. private $logger;
  34. /** @var Updater */
  35. private $updater;
  36. /** @var Checker | \PHPUnit_Framework_MockObject_MockObject */
  37. private $checker;
  38. /** @var Installer|\PHPUnit_Framework_MockObject_MockObject */
  39. private $installer;
  40. /** @var IJobList|\PHPUnit_Framework_MockObject_MockObject */
  41. private $jobList;
  42. public function setUp() {
  43. parent::setUp();
  44. $this->config = $this->getMockBuilder(IConfig::class)
  45. ->disableOriginalConstructor()
  46. ->getMock();
  47. $this->logger = $this->getMockBuilder(ILogger::class)
  48. ->disableOriginalConstructor()
  49. ->getMock();
  50. $this->checker = $this->getMockBuilder(Checker::class)
  51. ->disableOriginalConstructor()
  52. ->getMock();
  53. $this->installer = $this->getMockBuilder(Installer::class)
  54. ->disableOriginalConstructor()
  55. ->getMock();
  56. $this->jobList = $this->getMockBuilder(IJobList::class)
  57. ->disableOriginalConstructor()
  58. ->getMock();
  59. $this->updater = new Updater(
  60. $this->config,
  61. $this->checker,
  62. $this->logger,
  63. $this->installer,
  64. $this->jobList
  65. );
  66. }
  67. /**
  68. * @return array
  69. */
  70. public function versionCompatibilityTestData() {
  71. return [
  72. // Upgrade with invalid version
  73. ['9.1.1.13', '11.0.2.25', ['nextcloud' => ['11.0' => true]], false],
  74. ['10.0.1.13', '11.0.2.25', ['nextcloud' => ['11.0' => true]], false],
  75. // Upgrad with valid version
  76. ['11.0.1.13', '11.0.2.25', ['nextcloud' => ['11.0' => true]], true],
  77. // Downgrade with valid version
  78. ['11.0.2.25', '11.0.1.13', ['nextcloud' => ['11.0' => true]], false],
  79. ['11.0.2.25', '11.0.1.13', ['nextcloud' => ['11.0' => true]], true, true],
  80. // Downgrade with invalid version
  81. ['11.0.2.25', '10.0.1.13', ['nextcloud' => ['10.0' => true]], false],
  82. ['11.0.2.25', '10.0.1.13', ['nextcloud' => ['10.0' => true]], false, true],
  83. // Migration with unknown vendor
  84. ['9.1.1.13', '11.0.2.25', ['nextcloud' => ['9.1' => true]], false, false, 'owncloud'],
  85. ['9.1.1.13', '11.0.2.25', ['nextcloud' => ['9.1' => true]], false, true, 'owncloud'],
  86. // Migration with unsupported vendor version
  87. ['9.1.1.13', '11.0.2.25', ['owncloud' => ['10.0' => true]], false, false, 'owncloud'],
  88. ['9.1.1.13', '11.0.2.25', ['owncloud' => ['10.0' => true]], false, true, 'owncloud'],
  89. // Migration with valid vendor version
  90. ['9.1.1.13', '11.0.2.25', ['owncloud' => ['9.1' => true]], true, false, 'owncloud'],
  91. ['9.1.1.13', '11.0.2.25', ['owncloud' => ['9.1' => true]], true, true, 'owncloud'],
  92. ];
  93. }
  94. /**
  95. * @dataProvider versionCompatibilityTestData
  96. *
  97. * @param string $oldVersion
  98. * @param string $newVersion
  99. * @param array $allowedVersions
  100. * @param bool $result
  101. * @param bool $debug
  102. * @param string $vendor
  103. */
  104. public function testIsUpgradePossible($oldVersion, $newVersion, $allowedVersions, $result, $debug = false, $vendor = 'nextcloud') {
  105. $this->config->expects($this->any())
  106. ->method('getSystemValue')
  107. ->with('debug', false)
  108. ->willReturn($debug);
  109. $this->config->expects($this->any())
  110. ->method('getAppValue')
  111. ->with('core', 'vendor', '')
  112. ->willReturn($vendor);
  113. $this->assertSame($result, $this->updater->isUpgradePossible($oldVersion, $newVersion, $allowedVersions));
  114. }
  115. }