1
0

UpdaterTest.php 4.1 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\Updater;
  24. use OCP\IConfig;
  25. use OCP\ILogger;
  26. use OC\IntegrityCheck\Checker;
  27. class UpdaterTest extends TestCase {
  28. /** @var IConfig | \PHPUnit_Framework_MockObject_MockObject */
  29. private $config;
  30. /** @var ILogger | \PHPUnit_Framework_MockObject_MockObject */
  31. private $logger;
  32. /** @var Updater */
  33. private $updater;
  34. /** @var Checker | \PHPUnit_Framework_MockObject_MockObject */
  35. private $checker;
  36. public function setUp() {
  37. parent::setUp();
  38. $this->config = $this->getMockBuilder(IConfig::class)
  39. ->disableOriginalConstructor()
  40. ->getMock();
  41. $this->logger = $this->getMockBuilder(ILogger::class)
  42. ->disableOriginalConstructor()
  43. ->getMock();
  44. $this->checker = $this->getMockBuilder(Checker::class)
  45. ->disableOriginalConstructor()
  46. ->getMock();
  47. $this->updater = new Updater(
  48. $this->config,
  49. $this->checker,
  50. $this->logger
  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('getSystemValue')
  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. public function testSetSkip3rdPartyAppsDisable() {
  102. $this->updater->setSkip3rdPartyAppsDisable(true);
  103. $this->assertSame(true, $this->invokePrivate($this->updater, 'skip3rdPartyAppsDisable'));
  104. $this->updater->setSkip3rdPartyAppsDisable(false);
  105. $this->assertSame(false, $this->invokePrivate($this->updater, 'skip3rdPartyAppsDisable'));
  106. }
  107. }