PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/.dev/tests/Classes/Model/PHARModule.php

https://github.com/istran/core
PHP | 226 lines | 125 code | 69 blank | 32 comment | 2 complexity | f3abfacd9be940e9d0ebac90c3fcafff MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause
  1. <?php
  2. // vim: set ts=4 sw=4 sts=4 et:
  3. /**
  4. * LiteCommerce
  5. *
  6. * NOTICE OF LICENSE
  7. *
  8. * This source file is subject to the Open Software License (OSL 3.0)
  9. * that is bundled with this package in the file LICENSE.txt.
  10. * It is also available through the world-wide-web at this URL:
  11. * http://opensource.org/licenses/osl-3.0.php
  12. * If you did not receive a copy of the license and are unable to
  13. * obtain it through the world-wide-web, please send an email
  14. * to licensing@litecommerce.com so we can send you a copy immediately.
  15. *
  16. * @category LiteCommerce
  17. * @package Tests
  18. * @subpackage Classes
  19. * @author Creative Development LLC <info@cdev.ru>
  20. * @copyright Copyright (c) 2010 Creative Development LLC <info@cdev.ru>. All rights reserved
  21. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  22. * @version GIT: $Id: 4e4c1b003097e114eb642039e1c6efeee627580d $
  23. * @link http://www.litecommerce.com/
  24. * @see ____file_see____
  25. * @since 3.0.0
  26. */
  27. class XLite_Tests_Model_PHARModule extends XLite_Tests_TestCase
  28. {
  29. public function setUp()
  30. {
  31. parent::setUp();
  32. \Includes\Utils\FileManager::mkdirRecursive(LC_LOCAL_REPOSITORY);
  33. }
  34. private function getFile($file)
  35. {
  36. return dirname(__FILE__) . LC_DS . 'phars' . LC_DS . $file;
  37. }
  38. public function testBadConstruct()
  39. {
  40. \Includes\Utils\FileManager::mkdirRecursive(LC_LOCAL_REPOSITORY);
  41. @copy($this->getFile('bad.phar'), LC_LOCAL_REPOSITORY . 'bad.phar');
  42. $phar = new \XLite\Model\PHARModule('bad.phar');
  43. $message = $phar->getError();
  44. $this->assertEquals(
  45. $message,
  46. 'internal corruption of phar "' . LC_LOCAL_REPOSITORY . 'bad.phar' . '" (truncated entry)',
  47. 'must be corrupted PHAR'
  48. );
  49. @unlink(LC_LOCAL_REPOSITORY . 'bad.phar');
  50. $phar = new \XLite\Model\PHARModule('bad-bad-bad-name.phar');
  51. $message = $phar->getError();
  52. $status = $phar->getStatus();
  53. $this->assertTrue(is_null($message) && 'error' === $status, 'Wrong error when addons catalog/file does not exist');
  54. }
  55. public function testGoodConstruct()
  56. {
  57. copy($this->getFile('good.phar'), LC_LOCAL_REPOSITORY . 'good.phar');
  58. $message = '';
  59. try {
  60. $phar = new \XLite\Model\PHARModule('good.phar');
  61. } catch (Exception $e) {
  62. $message = $e->getMessage();
  63. }
  64. $this->assertEquals('', $message, 'There must be no exceptions in the "Good" module');
  65. $this->assertTrue(is_object($phar) && !is_null($phar), 'PHAR object was not constructed');
  66. $phar->cleanUp();
  67. unlink(LC_LOCAL_REPOSITORY . 'good.phar');
  68. }
  69. public function testCheck()
  70. {
  71. // NO ini file checking
  72. copy($this->getFile('no_ini.phar'), LC_LOCAL_REPOSITORY . 'no_ini.phar');
  73. $phar = new \XLite\Model\PHARModule('no_ini.phar');
  74. $phar->check();
  75. $this->assertEquals($phar->getStatus(), 'wrong_structure', 'Wrong status for no INI file');
  76. $phar->cleanUp();
  77. unlink(LC_LOCAL_REPOSITORY . 'no_ini.phar');
  78. // NO catalogs checking
  79. copy($this->getFile('no_dir.phar'), LC_LOCAL_REPOSITORY . 'no_dir.phar');
  80. $phar = new \XLite\Model\PHARModule('no_dir.phar');
  81. $phar->check();
  82. $this->assertEquals($phar->getStatus(), 'wrong_structure', 'Wrong status for no DIR file');
  83. $phar->cleanUp();
  84. unlink(LC_LOCAL_REPOSITORY . 'no_dir.phar');
  85. // Corrupted INI checking
  86. copy($this->getFile('corrupted_ini.phar'), LC_LOCAL_REPOSITORY . 'corrupted_ini.phar');
  87. $phar = new \XLite\Model\PHARModule('corrupted_ini.phar');
  88. $phar->check();
  89. $this->assertEquals($phar->getStatus(), 'ini_corrupted', 'Wrong status for corrupted INI file');
  90. $phar->cleanUp();
  91. unlink(LC_LOCAL_REPOSITORY . 'corrupted_ini.phar');
  92. // Wrong INI checking
  93. copy($this->getFile('wrong_ini.phar'), LC_LOCAL_REPOSITORY . 'wrong_ini.phar');
  94. $phar = new \XLite\Model\PHARModule('wrong_ini.phar');
  95. $phar->check();
  96. $this->assertEquals($phar->getStatus(), 'wrong_specification', 'Wrong status for wrong INI file');
  97. $phar->cleanUp();
  98. unlink(LC_LOCAL_REPOSITORY . 'wrong_ini.phar');
  99. // Already installed module checking
  100. copy($this->getFile('already.phar'), LC_LOCAL_REPOSITORY . 'already.phar');
  101. $phar = new \XLite\Model\PHARModule('already.phar');
  102. $phar->check();
  103. $this->assertEquals($phar->getStatus(), 'wrong_install', 'Wrong status for already installed module');
  104. $phar->cleanUp();
  105. unlink(LC_LOCAL_REPOSITORY . 'already.phar');
  106. }
  107. public function testDeploy()
  108. {
  109. // Deploying only classes directory module
  110. copy($this->getFile('test_module.phar'), LC_LOCAL_REPOSITORY . 'test_module.phar');
  111. $phar = new \XLite\Model\PHARModule('test_module.phar');
  112. $phar->check();
  113. $this->assertEquals('ok', $phar->getStatus(), 'Good module must be validated');
  114. $phar->deploy();
  115. $phar->cleanUp();
  116. $dir = LC_CLASSES_DIR . 'XLite' . LC_DS . 'Module' . LC_DS . 'CDev' . LC_DS . 'Good';
  117. $this->assertTrue(is_dir($dir), 'Classes catalog was not created');
  118. $files = array(
  119. 'CHANGELOG',
  120. 'Main.php',
  121. 'install.php',
  122. 'install.yaml',
  123. );
  124. foreach ($files as $file) {
  125. $this->assertTrue(is_file($dir . LC_DS . $file));
  126. }
  127. \Includes\Utils\FileManager::unlinkRecursive($dir);
  128. unlink(LC_LOCAL_REPOSITORY . 'test_module.phar');
  129. }
  130. public function testDeploy2()
  131. {
  132. // Deploying classes and skins directories module
  133. copy($this->getFile('test_module2.phar'), LC_LOCAL_REPOSITORY . 'test_module2.phar');
  134. $phar = new \XLite\Model\PHARModule('test_module2.phar');
  135. $phar->check();
  136. $this->assertEquals('ok', $phar->getStatus(), 'new Bestsellers module must be validated');
  137. $phar->deploy();
  138. $phar->cleanUp();
  139. $classesDir = LC_CLASSES_DIR . 'XLite' . LC_DS . 'Module' . LC_DS . 'TestAuthor';
  140. $skins = array(
  141. LC_SKINS_DIR . 'admin' . LC_DS . 'en' . LC_DS . 'modules' . LC_DS . 'TestAuthor',
  142. LC_SKINS_DIR . 'drupal' . LC_DS . 'en' . LC_DS . 'modules' . LC_DS . 'TestAuthor',
  143. );
  144. $this->assertTrue(is_dir($classesDir . LC_DS . 'Bestsellers'), 'Classes catalog was not created');
  145. foreach ($skins as $skin) {
  146. $this->assertTrue(is_dir($skin . LC_DS . 'Bestsellers'), $skin . ' was not created');
  147. }
  148. \Includes\Utils\FileManager::unlinkRecursive($classesDir);
  149. foreach ($skins as $skin) {
  150. \Includes\Utils\FileManager::unlinkRecursive($skin);
  151. }
  152. unlink(LC_LOCAL_REPOSITORY . 'test_module2.phar');
  153. }
  154. public function testCleanUp()
  155. {
  156. }
  157. }