UpdaterTest.php 3.9 KB

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