InstallerTest.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * Copyright (c) 2014 Georg Ehrke <georg@owncloud.com>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. namespace Test;
  9. use OC\Installer;
  10. class InstallerTest extends TestCase {
  11. private static $appid = 'testapp';
  12. private $appstore;
  13. protected function setUp() {
  14. parent::setUp();
  15. $config = \OC::$server->getConfig();
  16. $this->appstore = $config->setSystemValue('appstoreenabled', true);
  17. $config->setSystemValue('appstoreenabled', true);
  18. Installer::removeApp(self::$appid);
  19. }
  20. protected function tearDown() {
  21. Installer::removeApp(self::$appid);
  22. \OC::$server->getConfig()->setSystemValue('appstoreenabled', $this->appstore);
  23. parent::tearDown();
  24. }
  25. public function testInstallApp() {
  26. $pathOfTestApp = __DIR__;
  27. $pathOfTestApp .= '/../data/';
  28. $pathOfTestApp .= 'testapp.zip';
  29. $tmp = \OC::$server->getTempManager()->getTemporaryFile('.zip');
  30. \OC_Helper::copyr($pathOfTestApp, $tmp);
  31. $data = array(
  32. 'path' => $tmp,
  33. 'source' => 'path',
  34. 'appdata' => [
  35. 'id' => 'Bar',
  36. 'level' => 100,
  37. ]
  38. );
  39. Installer::installApp($data);
  40. $isInstalled = Installer::isInstalled(self::$appid);
  41. $this->assertTrue($isInstalled);
  42. }
  43. public function testUpdateApp() {
  44. $pathOfOldTestApp = __DIR__;
  45. $pathOfOldTestApp .= '/../data/';
  46. $pathOfOldTestApp .= 'testapp.zip';
  47. $oldTmp = \OC::$server->getTempManager()->getTemporaryFile('.zip');
  48. \OC_Helper::copyr($pathOfOldTestApp, $oldTmp);
  49. $oldData = array(
  50. 'path' => $oldTmp,
  51. 'source' => 'path',
  52. 'appdata' => [
  53. 'id' => 'Bar',
  54. 'level' => 100,
  55. ]
  56. );
  57. $pathOfNewTestApp = __DIR__;
  58. $pathOfNewTestApp .= '/../data/';
  59. $pathOfNewTestApp .= 'testapp2.zip';
  60. $newTmp = \OC::$server->getTempManager()->getTemporaryFile('.zip');
  61. \OC_Helper::copyr($pathOfNewTestApp, $newTmp);
  62. $newData = array(
  63. 'path' => $newTmp,
  64. 'source' => 'path',
  65. 'appdata' => [
  66. 'id' => 'Bar',
  67. 'level' => 100,
  68. ]
  69. );
  70. Installer::installApp($oldData);
  71. $oldVersionNumber = \OC_App::getAppVersion(self::$appid);
  72. Installer::updateApp($newData);
  73. $newVersionNumber = \OC_App::getAppVersion(self::$appid);
  74. $this->assertNotEquals($oldVersionNumber, $newVersionNumber);
  75. }
  76. }