InstallCoreBundleTest.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 Lukas Reschke <lukas@statuscode.ch>
  4. *
  5. * @author Lukas Reschke <lukas@statuscode.ch>
  6. *
  7. * @license GNU AGPL version 3 or any later version
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as
  11. * published by the Free Software Foundation, either version 3 of the
  12. * License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. namespace Test\Repair\NC12;
  24. use OC\App\AppStore\Bundles\Bundle;
  25. use OC\App\AppStore\Bundles\BundleFetcher;
  26. use OC\Installer;
  27. use OC\Repair\NC12\InstallCoreBundle;
  28. use OCP\IConfig;
  29. use OCP\Migration\IOutput;
  30. use Test\TestCase;
  31. class InstallCoreBundleTest extends TestCase {
  32. /** @var BundleFetcher|\PHPUnit_Framework_MockObject_MockObject */
  33. private $bundleFetcher;
  34. /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
  35. private $config;
  36. /** @var Installer|\PHPUnit_Framework_MockObject_MockObject */
  37. private $installer;
  38. /** @var InstallCoreBundle */
  39. private $installCoreBundle;
  40. public function setUp() {
  41. parent::setUp();
  42. $this->bundleFetcher = $this->createMock(BundleFetcher::class);
  43. $this->config = $this->createMock(IConfig::class);
  44. $this->installer = $this->createMock(Installer::class);
  45. $this->installCoreBundle = new InstallCoreBundle(
  46. $this->bundleFetcher,
  47. $this->config,
  48. $this->installer
  49. );
  50. }
  51. public function testGetName() {
  52. $this->assertSame('Install new core bundle components', $this->installCoreBundle->getName());
  53. }
  54. public function testRunOlder() {
  55. $this->config
  56. ->expects($this->once())
  57. ->method('getSystemValue')
  58. ->with('version', '0.0.0')
  59. ->willReturn('12.0.0.15');
  60. $this->bundleFetcher
  61. ->expects($this->never())
  62. ->method('getDefaultInstallationBundle');
  63. /** @var IOutput|\PHPUnit_Framework_MockObject_MockObject $output */
  64. $output = $this->createMock(IOutput::class);
  65. $output
  66. ->expects($this->never())
  67. ->method('info');
  68. $output
  69. ->expects($this->never())
  70. ->method('warning');
  71. $this->installCoreBundle->run($output);
  72. }
  73. public function testRunWithException() {
  74. $this->config
  75. ->expects($this->once())
  76. ->method('getSystemValue')
  77. ->with('version', '0.0.0')
  78. ->willReturn('12.0.0.14');
  79. $bundle = $this->createMock(Bundle::class);
  80. $this->bundleFetcher
  81. ->expects($this->once())
  82. ->method('getDefaultInstallationBundle')
  83. ->willReturn([
  84. $bundle,
  85. ]);
  86. $this->installer
  87. ->expects($this->once())
  88. ->method('installAppBundle')
  89. ->with($bundle)
  90. ->willThrowException(new \Exception('ExceptionText'));
  91. /** @var IOutput|\PHPUnit_Framework_MockObject_MockObject $output */
  92. $output = $this->createMock(IOutput::class);
  93. $output
  94. ->expects($this->never())
  95. ->method('info');
  96. $output
  97. ->expects($this->once())
  98. ->method('warning')
  99. ->with('Could not install core app bundle: ExceptionText');
  100. $this->installCoreBundle->run($output);
  101. }
  102. public function testRun() {
  103. $this->config
  104. ->expects($this->once())
  105. ->method('getSystemValue')
  106. ->with('version', '0.0.0')
  107. ->willReturn('12.0.0.14');
  108. $bundle = $this->createMock(Bundle::class);
  109. $this->bundleFetcher
  110. ->expects($this->once())
  111. ->method('getDefaultInstallationBundle')
  112. ->willReturn([
  113. $bundle,
  114. ]);
  115. $this->installer
  116. ->expects($this->once())
  117. ->method('installAppBundle')
  118. ->with($bundle);
  119. /** @var IOutput|\PHPUnit_Framework_MockObject_MockObject $output */
  120. $output = $this->createMock(IOutput::class);
  121. $output
  122. ->expects($this->once())
  123. ->method('info')
  124. ->with('Successfully installed core app bundle.');
  125. $output
  126. ->expects($this->never())
  127. ->method('warning');
  128. $this->installCoreBundle->run($output);
  129. }
  130. }