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.1KB

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