UpdaterTest.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 \Test\TestCase {
  28. /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
  29. private $config;
  30. /** @var ILogger */
  31. private $logger;
  32. /** @var Updater */
  33. private $updater;
  34. /** @var Checker */
  35. private $checker;
  36. public function setUp() {
  37. parent::setUp();
  38. $this->config = $this->getMockBuilder('\\OCP\\IConfig')
  39. ->disableOriginalConstructor()
  40. ->getMock();
  41. $this->logger = $this->getMockBuilder('\\OCP\\ILogger')
  42. ->disableOriginalConstructor()
  43. ->getMock();
  44. $this->checker = $this->getMockBuilder('\OC\IntegrityCheck\Checker')
  45. ->disableOriginalConstructor()
  46. ->getMock();
  47. $this->updater = new Updater(
  48. $this->config,
  49. $this->checker,
  50. $this->logger
  51. );
  52. }
  53. /**
  54. * @param string $baseUrl
  55. * @return string
  56. */
  57. private function buildUpdateUrl($baseUrl) {
  58. return $baseUrl . '?version='.implode('x', \OCP\Util::getVersion()).'xinstalledatxlastupdatedatx'.\OC_Util::getChannel().'xx';
  59. }
  60. /**
  61. * @return array
  62. */
  63. public function versionCompatibilityTestData() {
  64. return [
  65. ['1', '2', '1', true],
  66. ['2', '2', '2', true],
  67. ['6.0.5.0', '6.0.6.0', '5.0', true],
  68. ['5.0.6.0', '7.0.4.0', '6.0', false],
  69. // allow upgrading within the same major release
  70. ['8.0.0.0', '8.0.0.0', '8.0', true],
  71. ['8.0.0.0', '8.0.0.4', '8.0', true],
  72. ['8.0.0.0', '8.0.1.0', '8.0', true],
  73. ['8.0.0.0', '8.0.2.0', '8.0', true],
  74. // does not allow downgrading within the same major release
  75. ['8.0.1.0', '8.0.0.0', '8.0', false],
  76. ['8.0.2.0', '8.0.1.0', '8.0', false],
  77. ['8.0.0.4', '8.0.0.0', '8.0', false],
  78. // allows upgrading within the patch version
  79. ['8.0.0.0', '8.0.0.1', '8.0', true],
  80. ['8.0.0.0', '8.0.0.2', '8.0', true],
  81. // does not allow downgrading within the same major release
  82. ['8.0.0.1', '8.0.0.0', '8.0', false],
  83. ['8.0.0.2', '8.0.0.0', '8.0', false],
  84. // allow upgrading to the next major release
  85. ['8.0.0.0', '8.1.0.0', '8.0', true],
  86. ['8.0.0.0', '8.1.1.0', '8.0', true],
  87. ['8.0.0.0', '8.1.1.5', '8.0', true],
  88. ['8.0.0.2', '8.1.1.5', '8.0', true],
  89. ['8.1.0.0', '8.2.0.0', '8.1', true],
  90. ['8.1.0.2', '8.2.0.4', '8.1', true],
  91. ['8.1.0.5', '8.2.0.1', '8.1', true],
  92. ['8.1.0.0', '8.2.1.0', '8.1', true],
  93. ['8.1.0.2', '8.2.1.5', '8.1', true],
  94. ['8.1.0.5', '8.2.1.1', '8.1', true],
  95. // does not allow downgrading to the previous major release
  96. ['8.1.0.0', '8.0.0.0', '7.0', false],
  97. ['8.1.1.0', '8.0.0.0', '7.0', false],
  98. // does not allow skipping major releases
  99. ['8.0.0.0', '8.2.0.0', '8.1', false],
  100. ['8.0.0.0', '8.2.1.0', '8.1', false],
  101. ['8.0.0.0', '9.0.1.0', '8.2', false],
  102. ['8.0.0.0', '10.0.0.0', '9.3', false],
  103. // allows updating to the next major release
  104. ['8.2.0.0', '9.0.0.0', '8.2', true],
  105. ['8.2.0.0', '9.0.0.0', '8.2', true],
  106. ['8.2.0.0', '9.0.1.0', '8.2', true],
  107. ['8.2.0.0', '9.0.1.1', '8.2', true],
  108. ['8.2.0.2', '9.0.1.1', '8.2', true],
  109. ['8.2.2.0', '9.0.1.0', '8.2', true],
  110. ['8.2.2.2', '9.0.1.1', '8.2', true],
  111. ['9.0.0.0', '9.1.0.0', '9.0', true],
  112. ['9.0.0.0', '9.1.0.2', '9.0', true],
  113. ['9.0.0.2', '9.1.0.1', '9.0', true],
  114. ['9.1.0.0', '9.2.0.0', '9.1', true],
  115. ['9.2.0.0', '9.3.0.0', '9.2', true],
  116. ['9.3.0.0', '10.0.0.0', '9.3', true],
  117. // does not allow updating to the next major release (first number)
  118. ['9.0.0.0', '8.2.0.0', '8.1', false],
  119. // other cases
  120. ['8.0.0.0', '8.1.5.0', '8.0', true],
  121. ['8.2.0.0', '9.0.0.0', '8.2', true],
  122. ['8.2.0.0', '9.1.0.0', '9.0', false],
  123. ['9.0.0.0', '8.1.0.0', '8.0', false],
  124. ['9.0.0.0', '8.0.0.0', '7.0', false],
  125. ['9.1.0.0', '8.0.0.0', '7.0', false],
  126. ['8.2.0.0', '8.1.0.0', '8.0', false],
  127. // With debug enabled
  128. ['8.0.0.0', '8.2.0.0', '8.1', false, true],
  129. ['8.1.0.0', '8.2.0.0', '8.1', true, true],
  130. ['8.2.0.1', '8.2.0.1', '8.1', true, true],
  131. ['8.3.0.0', '8.2.0.0', '8.1', true, true],
  132. // Downgrade of maintenance
  133. ['9.0.53.0', '9.0.4.0', '8.1', false, false, 'nextcloud'],
  134. // with vendor switch
  135. ['9.0.53.0', '9.0.4.0', '8.1', true, false, ''],
  136. ['9.0.53.0', '9.0.4.0', '8.1', true, false, 'owncloud'],
  137. ];
  138. }
  139. /**
  140. * @dataProvider versionCompatibilityTestData
  141. *
  142. * @param string $oldVersion
  143. * @param string $newVersion
  144. * @param string $allowedVersion
  145. * @param bool $result
  146. * @param bool $debug
  147. * @param string $vendor
  148. */
  149. public function testIsUpgradePossible($oldVersion, $newVersion, $allowedVersion, $result, $debug = false, $vendor = 'nextcloud') {
  150. $this->config->expects($this->any())
  151. ->method('getSystemValue')
  152. ->with('debug', false)
  153. ->willReturn($debug);
  154. $this->config->expects($this->any())
  155. ->method('getAppValue')
  156. ->with('core', 'vendor', '')
  157. ->willReturn($vendor);
  158. $this->assertSame($result, $this->updater->isUpgradePossible($oldVersion, $newVersion, $allowedVersion));
  159. }
  160. public function testSetSimulateStepEnabled() {
  161. $this->updater->setSimulateStepEnabled(true);
  162. $this->assertSame(true, $this->invokePrivate($this->updater, 'simulateStepEnabled'));
  163. $this->updater->setSimulateStepEnabled(false);
  164. $this->assertSame(false, $this->invokePrivate($this->updater, 'simulateStepEnabled'));
  165. }
  166. public function testSetUpdateStepEnabled() {
  167. $this->updater->setUpdateStepEnabled(true);
  168. $this->assertSame(true, $this->invokePrivate($this->updater, 'updateStepEnabled'));
  169. $this->updater->setUpdateStepEnabled(false);
  170. $this->assertSame(false, $this->invokePrivate($this->updater, 'updateStepEnabled'));
  171. }
  172. public function testSetSkip3rdPartyAppsDisable() {
  173. $this->updater->setSkip3rdPartyAppsDisable(true);
  174. $this->assertSame(true, $this->invokePrivate($this->updater, 'skip3rdPartyAppsDisable'));
  175. $this->updater->setSkip3rdPartyAppsDisable(false);
  176. $this->assertSame(false, $this->invokePrivate($this->updater, 'skip3rdPartyAppsDisable'));
  177. }
  178. }