UpdaterTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace Test;
  8. use OC\Installer;
  9. use OC\IntegrityCheck\Checker;
  10. use OC\Updater;
  11. use OCP\IAppConfig;
  12. use OCP\IConfig;
  13. use OCP\ServerVersion;
  14. use PHPUnit\Framework\MockObject\MockObject;
  15. use Psr\Log\LoggerInterface;
  16. class UpdaterTest extends TestCase {
  17. /** @var ServerVersion|MockObject */
  18. private $serverVersion;
  19. /** @var IConfig|MockObject */
  20. private $config;
  21. /** @var IAppConfig|MockObject */
  22. private $appConfig;
  23. /** @var LoggerInterface|MockObject */
  24. private $logger;
  25. /** @var Updater */
  26. private $updater;
  27. /** @var Checker|MockObject */
  28. private $checker;
  29. /** @var Installer|MockObject */
  30. private $installer;
  31. protected function setUp(): void {
  32. parent::setUp();
  33. $this->serverVersion = $this->createMock(ServerVersion::class);
  34. $this->config = $this->createMock(IConfig::class);
  35. $this->appConfig = $this->createMock(IAppConfig::class);
  36. $this->logger = $this->createMock(LoggerInterface::class);
  37. $this->checker = $this->createMock(Checker::class);
  38. $this->installer = $this->createMock(Installer::class);
  39. $this->updater = new Updater(
  40. $this->serverVersion,
  41. $this->config,
  42. $this->appConfig,
  43. $this->checker,
  44. $this->logger,
  45. $this->installer
  46. );
  47. }
  48. /**
  49. * @return array
  50. */
  51. public function versionCompatibilityTestData() {
  52. return [
  53. // Upgrade with invalid version
  54. ['9.1.1.13', '11.0.2.25', ['nextcloud' => ['11.0' => true]], false],
  55. ['10.0.1.13', '11.0.2.25', ['nextcloud' => ['11.0' => true]], false],
  56. // Upgrad with valid version
  57. ['11.0.1.13', '11.0.2.25', ['nextcloud' => ['11.0' => true]], true],
  58. // Downgrade with valid version
  59. ['11.0.2.25', '11.0.1.13', ['nextcloud' => ['11.0' => true]], false],
  60. ['11.0.2.25', '11.0.1.13', ['nextcloud' => ['11.0' => true]], true, true],
  61. // Downgrade with invalid version
  62. ['11.0.2.25', '10.0.1.13', ['nextcloud' => ['10.0' => true]], false],
  63. ['11.0.2.25', '10.0.1.13', ['nextcloud' => ['10.0' => true]], false, true],
  64. // Migration with unknown vendor
  65. ['9.1.1.13', '11.0.2.25', ['nextcloud' => ['9.1' => true]], false, false, 'owncloud'],
  66. ['9.1.1.13', '11.0.2.25', ['nextcloud' => ['9.1' => true]], false, true, 'owncloud'],
  67. // Migration with unsupported vendor version
  68. ['9.1.1.13', '11.0.2.25', ['owncloud' => ['10.0' => true]], false, false, 'owncloud'],
  69. ['9.1.1.13', '11.0.2.25', ['owncloud' => ['10.0' => true]], false, true, 'owncloud'],
  70. // Migration with valid vendor version
  71. ['9.1.1.13', '11.0.2.25', ['owncloud' => ['9.1' => true]], true, false, 'owncloud'],
  72. ['9.1.1.13', '11.0.2.25', ['owncloud' => ['9.1' => true]], true, true, 'owncloud'],
  73. ];
  74. }
  75. /**
  76. * @dataProvider versionCompatibilityTestData
  77. *
  78. * @param string $oldVersion
  79. * @param string $newVersion
  80. * @param array $allowedVersions
  81. * @param bool $result
  82. * @param bool $debug
  83. * @param string $vendor
  84. */
  85. public function testIsUpgradePossible($oldVersion, $newVersion, $allowedVersions, $result, $debug = false, $vendor = 'nextcloud'): void {
  86. $this->config->expects($this->any())
  87. ->method('getSystemValueBool')
  88. ->with('debug', false)
  89. ->willReturn($debug);
  90. $this->config->expects($this->any())
  91. ->method('getAppValue')
  92. ->with('core', 'vendor', '')
  93. ->willReturn($vendor);
  94. $this->assertSame($result, $this->updater->isUpgradePossible($oldVersion, $newVersion, $allowedVersions));
  95. }
  96. }