PageRenderTime 55ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/.dev/tests/Classes/Model/Module.php

https://github.com/istran/core
PHP | 320 lines | 219 code | 63 blank | 38 comment | 2 complexity | 77ac55273aa16dd0c41bfceb1048b955 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: 9ed56d3a7f0e1c6d67e99f24a849d616714619fe $
  23. * @link http://www.litecommerce.com/
  24. * @see ____file_see____
  25. * @since 3.0.0
  26. */
  27. class XLite_Tests_Model_Module extends XLite_Tests_Model_ModuleAbstract
  28. {
  29. // TODO: implement using a test module package once installation and packing
  30. // is complete. Currently Featured products module is used for testing
  31. public function testCreate()
  32. {
  33. $module = $this->getTestModule();
  34. $this->assertTrue(0 < $module->getModuleId(), 'Check Module ID');
  35. foreach ($this->testModule as $k => $v) {
  36. $m = 'get' . \XLite\Core\Converter::convertToCamelCase($k);
  37. $this->assertEquals($v, $module->$m(), 'Check ' . $k);
  38. }
  39. // Test create() method itself
  40. $module = new \XLite\Model\Module();
  41. $module->create('CreatedModule', 'CreatedAuthor');
  42. $module = \XLite\Core\Database::getRepo('XLite\Model\Module')->find($module->getModuleId());
  43. $this->assertEquals('CreatedModule', $module->getName(), 'Check name using create() method');
  44. $this->assertEquals('CreatedAuthor', $module->getAuthor(), 'Check author using create() method');
  45. }
  46. public function testUpdate()
  47. {
  48. $newValues = array(
  49. 'name' => 'TestModule1',
  50. 'author' => 'TestAuthor1',
  51. 'moduleName' => 'Test module name1',
  52. 'authorName' => 'Test module author1',
  53. 'description' => 'Test module description1',
  54. 'installed' => false,
  55. 'version' => '1.2.31',
  56. 'rating' => 99,
  57. 'downloads' => 101,
  58. 'iconURL' => 'icon/url/test/path1',
  59. 'date' => 1295513913,
  60. 'changelog' => 'Test changelog1',
  61. 'currency' => 'USD',
  62. 'purchased' => true,
  63. 'price' => 10.12,
  64. 'uploadCode' => 'abc',
  65. 'packHash' => 'asdasd',
  66. 'dependencies' => array(
  67. array('CDev', 'AOM')
  68. ),
  69. );
  70. $module = $this->getTestModule();
  71. // Set values
  72. foreach ($newValues as $k => $newval) {
  73. $m = 'set' . \XLite\Core\Converter::convertToCamelCase($k);
  74. $module->$m($newval);
  75. }
  76. $module->setStatus($module::EXISTS);
  77. \XLite\Core\Database::getEM()->persist($module);
  78. \XLite\Core\Database::getEM()->flush();
  79. \XLite\Core\Database::getEM()->clear();
  80. // Get values
  81. $module = \XLite\Core\Database::getRepo('XLite\Model\Module')->find($module->getModuleId());
  82. foreach ($newValues as $k => $newval) {
  83. $m = 'get' . \XLite\Core\Converter::convertToCamelCase($k);
  84. $this->assertEquals($newval, $module->$m(), 'check new ' . $k);
  85. $module->$m();
  86. }
  87. $this->assertEquals($module::EXISTS, $module->getStatus(), 'check new status');
  88. }
  89. public function testDelete()
  90. {
  91. $module = $this->getTestModule();
  92. $id = $module->getModuleId();
  93. \XLite\Core\Database::getEM()->remove($module);
  94. \XLite\Core\Database::getEM()->flush();
  95. $module = \XLite\Core\Database::getRepo('XLite\Model\Module')
  96. ->find($id);
  97. $this->assertTrue(is_null($module), 'check removed module');
  98. }
  99. public function testHasIcon()
  100. {
  101. $module = $this->getTestModule();
  102. $this->assertTrue($module->hasIcon(), 'check if module has icon');
  103. }
  104. public function testIsFree()
  105. {
  106. $module = $this->getTestModule();
  107. $this->assertFalse($module->isFree(), 'check if module is free');
  108. }
  109. public function testGetMarketplaceURL()
  110. {
  111. $module = $this->getTestModule();
  112. $this->assertEquals('https://www.litecommerce.com/marketplace/', $module::getMarketplaceURL(), 'check marketplace URL');
  113. }
  114. public function testGetPageURL()
  115. {
  116. $module = $this->getTestModule();
  117. $this->assertEquals('https://www.litecommerce.com/marketplace/module/TestAuthor/TestModule', $module->getPageURL(), 'check module URL');
  118. }
  119. public function testGetAuthorPageURL()
  120. {
  121. $module = $this->getTestModule();
  122. $this->assertEquals('https://www.litecommerce.com/marketplace/module/TestAuthor', $module->getAuthorPageURL(), 'check module author URL');
  123. }
  124. public function testSetEnabled()
  125. {
  126. $module = $this->getEnabledModule();
  127. $module->setEnabled(false);
  128. \XLite\Core\Database::getEM()->flush();
  129. \XLite\Core\Database::getEM()->clear();
  130. $module = \XLite\Core\Database::getRepo('XLite\Model\Module')->find($module->getModuleId());
  131. $this->assertFalse($module->getEnabled(), 'check if module is disabled');
  132. $module->setEnabled(true);
  133. \XLite\Core\Database::getEM()->flush();
  134. $this->assertTrue($module->getEnabled(), 'check if module is enabled');
  135. }
  136. public function testProtectedStructures()
  137. {
  138. $path = LC_VAR_DIR . '.disabled.structures.php';
  139. if (file_exists($path)) {
  140. unlink($path);
  141. }
  142. $module = \Xlite\Core\Database::getRepo('XLite\Model\Module')
  143. ->findOneBy(array('author' => 'CDev', 'name' => 'ProductOptions'));
  144. $module->disableModule();
  145. \XLite\Core\Database::getEM()->flush();
  146. $etalon = "# <?php if (!defined('LC_DS')) { die(); } ?>
  147. CDev\ProductOptions:
  148. tables: [options, option_exceptions, option_groups, option_group_translations, option_surcharges, option_translations, order_item_options]
  149. columns: { }
  150. ";
  151. $this->assertEquals($etalon, file_get_contents($path), 'check .disabled.structures.php');
  152. if (file_exists($path)) {
  153. unlink($path);
  154. }
  155. }
  156. public function testPrepareUpdate()
  157. {
  158. // TODO: check if possible
  159. }
  160. public function testGetDependedModules()
  161. {
  162. // TODO: implement after module installation tests are done
  163. }
  164. public function testDisableModule()
  165. {
  166. $module = $this->getEnabledModule();
  167. $module->disableModule();
  168. $this->assertFalse($module->getEnabled(), 'check if module is disabled');
  169. }
  170. public function testGetSettingsFormLink()
  171. {
  172. $module = $this->getEnabledModule(true, 'FeaturedProducts');
  173. $this->assertEquals('admin.php?target=module&moduleId=' . $module->getModuleId(), $module->getSettingsFormLink(), 'check general settings form link');
  174. $module = $this->getEnabledModule(true, 'AustraliaPost');
  175. $this->assertEquals('admin.php?target=aupost', $module->getSettingsFormLink(), 'check custom settings form link');
  176. }
  177. public function testGetMainClass()
  178. {
  179. $module = $this->getEnabledModule(true, 'FeaturedProducts');
  180. $this->assertEquals('\XLite\Module\CDev\FeaturedProducts\Main', $module->getMainClass(), 'check main class');
  181. }
  182. public function testGetDependenciesModules()
  183. {
  184. // TODO: implement after dependencies system refactoring
  185. }
  186. public function testCanEnable()
  187. {
  188. $module = $this->getEnabledModule();
  189. $module->setInstalled(false);
  190. $this->assertFalse($module->canEnable(), 'check if module can be enabled');
  191. // TODO: implement dependencies checker after dependencies system refactoring
  192. // TODO: implement checking of the static check() method of the main class
  193. }
  194. public function testGetHash()
  195. {
  196. // TODO: implement after all upload/install functions and tests are completed
  197. }
  198. public function testUninstall()
  199. {
  200. // TODO: after packing mechanism is completed
  201. }
  202. public function testAnonymousCall()
  203. {
  204. $module = $this->getEnabledModule(true, 'FeaturedProducts');
  205. $module->setModuleName('aaa');
  206. $module->setAuthorName('bbb');
  207. $module->setDescription('ccc');
  208. $this->assertEquals('This module enables featured products list', $module->__call('getDescription'), 'check description call');
  209. $this->assertEquals('Featured Products', $module->__call('getModuleName'), 'check name call');
  210. $this->assertEquals('Creative Development LLC', $module->__call('getAuthorName'), 'check author call');
  211. }
  212. public function testIsUpdateAvailable()
  213. {
  214. $module = $this->getEnabledModule(true, 'FeaturedProducts');
  215. $this->assertFalse($module->isUpdateAvailable(), 'check not available update');
  216. $module->setVersion($module->getVersion() . '.1');
  217. $this->assertTrue($module->isUpdateAvailable(), 'check available update');
  218. }
  219. public function testGetLastVersion()
  220. {
  221. $module = $this->getEnabledModule(true, 'FeaturedProducts');
  222. $this->assertEquals($module->getVersion(), $module->getLastVersion(), 'check last version getter');
  223. }
  224. public function testGetCurrentVersion()
  225. {
  226. $module = $this->getEnabledModule(true, 'FeaturedProducts');
  227. $oldVer = $module->getVersion();
  228. $module->setVersion($module->getVersion() . '.1');
  229. $this->assertEquals($oldVer, $module->getCurrentVersion(), 'check current version getter');
  230. }
  231. public function testGetActualName()
  232. {
  233. $module = $this->getTestModule();
  234. $this->assertEquals('TestAuthor\\TestModule', $module->getActualName(), 'check actual name');
  235. }
  236. public function testGetPath()
  237. {
  238. $module = $this->getTestModule();
  239. $this->assertEquals('TestAuthor/TestModule', $module->getPath(), 'check path');
  240. }
  241. public function testGetModel()
  242. {
  243. $module = $this->getTestModule();
  244. $this->assertEquals($module->getModel(), $module->model, 'check model');
  245. }
  246. public function testCanUpload()
  247. {
  248. $module = $this->getTestModule();
  249. $this->assertFalse($module->canUpload(), 'check if can upload');
  250. $module->setUploadCode('1234567890.1234567890.1234567890');
  251. $this->assertTrue($module->canUpload(), 'check if can upload');
  252. }
  253. public function testUpload()
  254. {
  255. // TODO:
  256. }
  257. }