UpdaterTest.php 4.0 KB

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