UpdaterTest.php 3.5 KB

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