PageRenderTime 46ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/testapp/tests-jelix/jelix/installer/installer_componentTest.php

https://github.com/gmarrot/jelix
PHP | 507 lines | 381 code | 95 blank | 31 comment | 0 complexity | d51d49c37fd6b728e37e1c2b60b5c1fc MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, BSD-3-Clause
  1. <?php
  2. /**
  3. * @package testapp
  4. * @subpackage jelix_tests module
  5. * @author Laurent Jouanneau
  6. * @contributor
  7. * @copyright 2009-2012 Laurent Jouanneau
  8. * @link http://jelix.org
  9. * @licence GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html
  10. * @since 1.2
  11. */
  12. require_once(__DIR__.'/installer.lib.php');
  13. class testInstallerComponentModule2 extends jInstallerComponentModule {
  14. function setSourceVersionDate($version, $date) {
  15. $this->sourceDate = $date;
  16. $this->sourceVersion = $version;
  17. }
  18. }
  19. class testInstallerComponentForDependencies extends jInstallerComponentBase {
  20. protected $identityNamespace = 'http://jelix.org/ns/module/1.0';
  21. protected $rootName = 'module';
  22. protected $identityFile = 'module.xml';
  23. function getInstaller($ep, $installWholeApp) {
  24. return null;
  25. }
  26. function getUpgraders($ep) {
  27. return null;
  28. }
  29. function readDependenciesFromString($xmlcontent) {
  30. $xml = simplexml_load_string($xmlcontent);
  31. //$this->sourceVersion = (string) $xml->info[0]->version[0];
  32. $this->readDependencies($xml);
  33. }
  34. }
  35. class jInstaller_ComponentTest extends jUnitTestCase {
  36. protected $defaultIni;
  37. function setUp() {
  38. self::initJelixConfig();
  39. $this->defaultIni = new jIniFileModifier(jApp::configPath().'mainconfig.ini.php');
  40. jApp::saveContext();
  41. }
  42. function tearDown() {
  43. jApp::restoreContext();
  44. }
  45. public function testDependenciesReading() {
  46. $comp = new testInstallerComponentForDependencies("test","", null);
  47. $str = '<?xml version="1.0" encoding="UTF-8"?>
  48. <module xmlns="http://jelix.org/ns/module/1.0">
  49. </module>';
  50. $comp->readDependenciesFromString($str);
  51. $this->assertEquals(array(), $comp->dependencies);
  52. $this->assertEquals(array('*','*'), $comp->getJelixVersion());
  53. $str = '<?xml version="1.0" encoding="UTF-8"?>
  54. <module xmlns="http://jelix.org/ns/module/1.0">
  55. <dependencies>
  56. </dependencies>
  57. </module>';
  58. $comp->readDependenciesFromString($str);
  59. $this->assertEquals(array(), $comp->dependencies);
  60. $this->assertEquals(array('*','*'), $comp->getJelixVersion());
  61. $str = '<?xml version="1.0" encoding="UTF-8"?>
  62. <module xmlns="http://jelix.org/ns/module/1.0">
  63. <dependencies>
  64. <jelix minversion="1.0" maxversion="1.1" />
  65. </dependencies>
  66. </module>';
  67. $comp->readDependenciesFromString($str);
  68. $this->assertEquals(array(
  69. array(
  70. 'type'=> 'module',
  71. 'id' => 'jelix@jelix.org',
  72. 'name' => 'jelix',
  73. 'minversion' => '1.0',
  74. 'maxversion' => '1.1',
  75. ''
  76. )
  77. ), $comp->dependencies);
  78. $this->assertEquals(array('1.0', '1.1'), $comp->getJelixVersion());
  79. $str = '<?xml version="1.0" encoding="UTF-8"?>
  80. <module xmlns="http://jelix.org/ns/module/1.0">
  81. <dependencies>
  82. <jelix minversion="1.0" maxversion="1.1" />
  83. <module name="jauthdb" />
  84. <module name="jacl2db" id="jacl2db@jelix.org" />
  85. <module name="jacldb" id="jacldb@jelix.org" minversion="1.0"/>
  86. </dependencies>
  87. </module>';
  88. $comp->readDependenciesFromString($str);
  89. $this->assertEquals(array(
  90. array(
  91. 'type'=> 'module',
  92. 'id' => 'jelix@jelix.org',
  93. 'name' => 'jelix',
  94. 'minversion' => '1.0',
  95. 'maxversion' => '1.1',
  96. ''
  97. ),
  98. array(
  99. 'type'=> 'module',
  100. 'id' => '',
  101. 'name' => 'jauthdb',
  102. 'minversion' => '*',
  103. 'maxversion' => '*',
  104. ''
  105. ),
  106. array(
  107. 'type'=> 'module',
  108. 'id' => 'jacl2db@jelix.org',
  109. 'name' => 'jacl2db',
  110. 'minversion' => '*',
  111. 'maxversion' => '*',
  112. ''
  113. ),
  114. array(
  115. 'type'=> 'module',
  116. 'id' => 'jacldb@jelix.org',
  117. 'name' => 'jacldb',
  118. 'minversion' => '1.0',
  119. 'maxversion' => '*',
  120. ''
  121. ),
  122. ), $comp->dependencies);
  123. $this->assertEquals(array('1.0', '1.1'), $comp->getJelixVersion());
  124. }
  125. function testGetInstallerWithNoInstaller() {
  126. try {
  127. // dummy ini file modifier. not used by installer of tested modules
  128. $ini = new testInstallerIniFileModifier("test.ini.php");
  129. // testinstall1 has no install.php file
  130. $component = new jInstallerComponentModule('testinstall1', jApp::appPath().'modules/testinstall1/', null);
  131. $component->init();
  132. $conf =(object) array( 'modules'=>array(
  133. 'testinstall1.access'=>2,
  134. 'testinstall1.dbprofile'=>'default',
  135. 'testinstall1.installed'=>false,
  136. 'testinstall1.version'=>JELIX_VERSION,
  137. ));
  138. $EPindex = new testInstallerEntryPoint($this->defaultIni, $ini, 'index.php', 'classic', $conf);
  139. $component->addModuleInfos($EPindex->getEpId(), new jInstallerModuleInfos('testinstall1', $conf->modules));
  140. $installer = $component->getInstaller($EPindex, true);
  141. $this->assertNull($installer);
  142. }
  143. catch(jInstallerException $e) {
  144. $this->fail("Unexpected exception : ".$e->getMessage()." (".var_export($e->getLocaleParameters(),true).")");
  145. }
  146. }
  147. function testGetInstallerWithInstaller() {
  148. try {
  149. // dummy ini file modifier. not used by installer of tested modules
  150. $iniIndex = new testInstallerIniFileModifier('index/config.ini.php');
  151. $iniFoo = new testInstallerIniFileModifier('foo/config.ini.php');
  152. // testinstall2 has an install.php file
  153. $component = new jInstallerComponentModule('testinstall2', jApp::appPath().'modules/testinstall2/', null);
  154. $component->init();
  155. $conf =(object) array( 'modules'=>array(
  156. 'testinstall2.access'=>2,
  157. 'testinstall2.dbprofile'=>'default',
  158. 'testinstall2.installed'=>false,
  159. 'testinstall2.version'=>JELIX_VERSION,
  160. ));
  161. $EPindex = new testInstallerEntryPoint($this->defaultIni, $iniIndex, 'index.php', 'classic', $conf);
  162. $component->addModuleInfos($EPindex->getEpId(), new jInstallerModuleInfos('testinstall2', $conf->modules));
  163. $EPfoo = new testInstallerEntryPoint($this->defaultIni, $iniFoo, 'foo.php', 'classic', $conf);
  164. $component->addModuleInfos($EPfoo->getEpId(), new jInstallerModuleInfos('testinstall2', $conf->modules));
  165. $installer = $component->getInstaller($EPindex, true);
  166. $this->assertTrue (is_object($installer));
  167. $installer = $component->getInstaller($EPfoo, true);
  168. $this->assertTrue (is_object($installer));
  169. }
  170. catch(jInstallerException $e) {
  171. $this->fail("Unexpected exception : ".$e->getMessage()." (".var_export($e->getLocaleParameters(),true).")");
  172. }
  173. }
  174. function testGetUpgradersWithNoUpgraders() {
  175. try {
  176. // dummy ini file modifier. not used by installer of tested modules
  177. $ini = new testInstallerIniFileModifier("index/config.ini.php");
  178. // testinstall1 has no upgrade scripts
  179. $component = new jInstallerComponentModule('testinstall1', jApp::appPath().'modules/testinstall1/', null);
  180. $component->init();
  181. $conf =(object) array( 'modules'=>array(
  182. 'testinstall1.access'=>2,
  183. 'testinstall1.dbprofile'=>'default',
  184. 'testinstall1.installed'=>false,
  185. 'testinstall1.version'=>JELIX_VERSION,
  186. ));
  187. $EPindex = new testInstallerEntryPoint($this->defaultIni, $ini, 'index.php', 'classic', $conf);
  188. $component->addModuleInfos($EPindex->getEpId(), new jInstallerModuleInfos('testinstall1', $conf->modules) );
  189. $upgraders = $component->getUpgraders($EPindex);
  190. $this->assertTrue(is_array($upgraders));
  191. $this->assertEquals(0, count($upgraders));
  192. }
  193. catch(jInstallerException $e) {
  194. $this->fail("Unexpected exception : ".$e->getMessage()." (".var_export($e->getLocaleParameters(),true).")");
  195. }
  196. }
  197. function testGetUpgradersWithNoValidUpgrader() {
  198. try {
  199. // dummy ini file modifier. not used by installer of tested modules
  200. $ini = new testInstallerIniFileModifier("index/config.ini.php");
  201. //------------ testinstall2 has some upgraders file
  202. $component = new jInstallerComponentModule('testinstall2', jApp::appPath().'modules/testinstall2/', null);
  203. $component->init();
  204. // the current version is the latest one : no updaters
  205. $conf =(object) array( 'modules'=>array(
  206. 'testinstall2.access'=>2,
  207. 'testinstall2.dbprofile'=>'default',
  208. 'testinstall2.installed'=>false,
  209. 'testinstall2.version'=>JELIX_VERSION,
  210. ));
  211. $EPindex = new testInstallerEntryPoint($this->defaultIni, $ini, 'index.php', 'classic', $conf);
  212. $component->addModuleInfos($EPindex->getEpId(), new jInstallerModuleInfos('testinstall2', $conf->modules) );
  213. $upgraders = $component->getUpgraders($EPindex);
  214. $this->assertTrue (is_array($upgraders));
  215. $this->assertEquals(0, count($upgraders));
  216. }
  217. catch(jInstallerException $e) {
  218. $this->fail("Unexpected exception : ".$e->getMessage()." (".var_export($e->getLocaleParameters(),true).")");
  219. }
  220. }
  221. function testGetUpgradersWithOneValidUpgrader() {
  222. try {
  223. // dummy ini file modifier. not used by installer of tested modules
  224. $iniIndex = new testInstallerIniFileModifier("index/config.ini.php");
  225. $iniFoo = new testInstallerIniFileModifier("foo/config.ini.php");
  226. // the current version is the previous one : one updater
  227. $component = new jInstallerComponentModule('testinstall2', jApp::appPath().'modules/testinstall2/', null);
  228. $component->init();
  229. $conf =(object) array( 'modules'=>array(
  230. 'testinstall2.access'=>2,
  231. 'testinstall2.dbprofile'=>'default',
  232. 'testinstall2.installed'=>false,
  233. 'testinstall2.version'=>"1.2.3",
  234. ));
  235. $EPindex = new testInstallerEntryPoint($this->defaultIni, $iniIndex, 'index.php', 'classic', $conf);
  236. $component->addModuleInfos($EPindex->getEpId(), new jInstallerModuleInfos('testinstall2', $conf->modules) );
  237. $upgraders = $component->getUpgraders($EPindex);
  238. $this->assertTrue (is_array($upgraders));
  239. $this->assertEquals(1, count($upgraders));
  240. $this->assertEquals('testinstall2ModuleUpgrader_newupgraderfilename', get_class($upgraders[0]));
  241. $EPfoo = new testInstallerEntryPoint($this->defaultIni, $iniFoo, 'foo.php', 'classic', $conf);
  242. $component->addModuleInfos($EPfoo->getEpId(), new jInstallerModuleInfos('testinstall2', $conf->modules) );
  243. $upgraders = $component->getUpgraders($EPfoo);
  244. $this->assertTrue (is_array($upgraders));
  245. $this->assertEquals(1, count($upgraders));
  246. $this->assertEquals('testinstall2ModuleUpgrader_newupgraderfilename', get_class($upgraders[0]));
  247. }
  248. catch(jInstallerException $e) {
  249. $this->fail("Unexpected exception : ".$e->getMessage()." (".var_export($e->getLocaleParameters(),true).")");
  250. }
  251. }
  252. function testGetUpgradersWithTwoValidUpgrader() {
  253. try {
  254. // dummy ini file modifier. not used by installer of tested modules
  255. $iniIndex = new testInstallerIniFileModifier("index/config.ini.php");
  256. $iniFoo = new testInstallerIniFileModifier("foo/config.ini.php");
  257. // the current version is the previous one : one updater
  258. $component = new jInstallerComponentModule('testinstall2', jApp::appPath().'modules/testinstall2/', null);
  259. $component->init();
  260. $conf =(object) array( 'modules'=>array(
  261. 'testinstall2.access'=>2,
  262. 'testinstall2.dbprofile'=>'default',
  263. 'testinstall2.installed'=>false,
  264. 'testinstall2.version'=>"1.1.2",
  265. ));
  266. $EPindex = new testInstallerEntryPoint($this->defaultIni, $iniIndex, 'index.php', 'classic', $conf);
  267. $component->addModuleInfos($EPindex->getEpId(), new jInstallerModuleInfos('testinstall2', $conf->modules) );
  268. // since newupgraderfilename targets '1.1.2' and '1.2.4', we should have second then newupgraderfilename
  269. $upgraders = $component->getUpgraders($EPindex);
  270. $this->assertTrue (is_array($upgraders));
  271. $this->assertEquals(3, count($upgraders));
  272. $this->assertEquals('testinstall2ModuleUpgrader_newupgraderfilenamedate', get_class($upgraders[0]));
  273. $this->assertEquals('testinstall2ModuleUpgrader_second', get_class($upgraders[1]));
  274. $this->assertEquals('testinstall2ModuleUpgrader_newupgraderfilename', get_class($upgraders[2]));
  275. $EPfoo = new testInstallerEntryPoint($this->defaultIni, $iniFoo, 'foo.php', 'classic', $conf);
  276. $component->addModuleInfos($EPfoo->getEpId(), new jInstallerModuleInfos('testinstall2', $conf->modules) );
  277. $upgraders = $component->getUpgraders($EPfoo);
  278. $this->assertTrue (is_array($upgraders));
  279. $this->assertEquals(3, count($upgraders));
  280. $this->assertEquals('testinstall2ModuleUpgrader_newupgraderfilenamedate', get_class($upgraders[0]));
  281. $this->assertEquals('testinstall2ModuleUpgrader_second', get_class($upgraders[1]));
  282. $this->assertEquals('testinstall2ModuleUpgrader_newupgraderfilename', get_class($upgraders[2]));
  283. }
  284. catch(jInstallerException $e) {
  285. $this->fail("Unexpected exception : ".$e->getMessage()." (".var_export($e->getLocaleParameters(),true).")");
  286. }
  287. }
  288. function testGetUpgradersWithTwoValidUpgrader2() {
  289. try {
  290. // dummy ini file modifier. not used by installer of tested modules
  291. $iniIndex = new testInstallerIniFileModifier("index/config.ini.php");
  292. $iniFoo = new testInstallerIniFileModifier("foo/config.ini.php");
  293. $component = new jInstallerComponentModule('testinstall2', jApp::appPath().'modules/testinstall2/', null);
  294. $component->init();
  295. $conf =(object) array( 'modules'=>array(
  296. 'testinstall2.access'=>2,
  297. 'testinstall2.dbprofile'=>'default',
  298. 'testinstall2.installed'=>false,
  299. 'testinstall2.version'=>"1.1.1",
  300. ));
  301. $EPindex = new testInstallerEntryPoint($this->defaultIni, $iniIndex, 'index.php', 'classic', $conf);
  302. $component->addModuleInfos($EPindex->getEpId(), new jInstallerModuleInfos('testinstall2', $conf->modules) );
  303. // since newupgraderfilename targets '1.1.2' and '1.2.4', we should have newupgraderfilename then second
  304. $upgraders = $component->getUpgraders($EPindex);
  305. $this->assertTrue (is_array($upgraders));
  306. $this->assertEquals(3, count($upgraders));
  307. $this->assertEquals('testinstall2ModuleUpgrader_newupgraderfilename', get_class($upgraders[0]));
  308. $this->assertEquals('testinstall2ModuleUpgrader_newupgraderfilenamedate', get_class($upgraders[1]));
  309. $this->assertEquals('testinstall2ModuleUpgrader_second', get_class($upgraders[2]));
  310. $EPfoo = new testInstallerEntryPoint($this->defaultIni, $iniFoo, 'foo.php', 'classic', $conf);
  311. $component->addModuleInfos($EPfoo->getEpId(), new jInstallerModuleInfos('testinstall2', $conf->modules) );
  312. $upgraders = $component->getUpgraders($EPfoo);
  313. $this->assertTrue (is_array($upgraders));
  314. $this->assertEquals(3, count($upgraders));
  315. $this->assertEquals('testinstall2ModuleUpgrader_newupgraderfilename', get_class($upgraders[0]));
  316. $this->assertEquals('testinstall2ModuleUpgrader_newupgraderfilenamedate', get_class($upgraders[1]));
  317. $this->assertEquals('testinstall2ModuleUpgrader_second', get_class($upgraders[2]));
  318. }
  319. catch(jInstallerException $e) {
  320. $this->fail("Unexpected exception : ".$e->getMessage()." (".var_export($e->getLocaleParameters(),true).")");
  321. }
  322. }
  323. function testGetUpgradersWithTwoValidUpgraderWithDate() {
  324. try {
  325. // dummy ini file modifier. not used by installer of tested modules
  326. $iniIndex = new testInstallerIniFileModifier("index/config.ini.php");
  327. $iniFoo = new testInstallerIniFileModifier("foo/config.ini.php");
  328. file_put_contents(jApp::tempPath('dummyInstaller.ini'), '');
  329. $installer = $this->getMock('jInstaller', null, array(new testInstallReporter()) );
  330. $installer->installerIni = new jIniFileModifier(jApp::tempPath('dummyInstaller.ini'));
  331. $component = new testInstallerComponentModule2('testinstall2', jApp::appPath('modules/testinstall2/'), $installer);
  332. $component->init();
  333. // 1.1 1.1.2* 1.1.3** 1.1.5 1.2.2** 1.2.4*
  334. $installer->installerIni->setValue('testinstall2.firstversion', '1.1' , 'index');
  335. $installer->installerIni->setValue('testinstall2.firstversion.date', '2011-01-10' , 'index');
  336. $installer->installerIni->setValue('testinstall2.version', '1.1.2' , 'index');
  337. $installer->installerIni->setValue('testinstall2.version.date', '2011-01-12' , 'index');
  338. $component->setSourceVersionDate('1.1.5','2011-01-15');
  339. $conf =(object) array( 'modules'=>array(
  340. 'testinstall2.access'=>2,
  341. 'testinstall2.dbprofile'=>'default',
  342. 'testinstall2.installed'=>false,
  343. 'testinstall2.version'=>"1.1",
  344. ));
  345. $EPindex = new testInstallerEntryPoint($this->defaultIni, $iniIndex, 'index.php', 'classic', $conf);
  346. $component->addModuleInfos($EPindex->getEpId(), new jInstallerModuleInfos('testinstall2', $conf->modules) );
  347. $upgraders = $component->getUpgraders($EPindex);
  348. $this->assertTrue (is_array($upgraders));
  349. $this->assertEquals(3, count($upgraders));
  350. $this->assertEquals('testinstall2ModuleUpgrader_newupgraderfilename', get_class($upgraders[0]));
  351. $this->assertEquals('testinstall2ModuleUpgrader_newupgraderfilenamedate', get_class($upgraders[1]));
  352. $this->assertEquals('testinstall2ModuleUpgrader_second', get_class($upgraders[2]));
  353. $installer->installerIni->setValue('testinstall2.firstversion', '1.1.3' , 'index');
  354. $installer->installerIni->setValue('testinstall2.firstversion.date', '2011-01-13' , 'index');
  355. $installer->installerIni->setValue('testinstall2.version', '1.1.5' , 'index');
  356. $installer->installerIni->setValue('testinstall2.version.date', '2011-01-15' , 'index');
  357. $component->setSourceVersionDate('1.2.5','2011-01-25');
  358. $conf =(object) array( 'modules'=>array(
  359. 'testinstall2.access'=>2,
  360. 'testinstall2.dbprofile'=>'default',
  361. 'testinstall2.installed'=>false,
  362. 'testinstall2.version'=>"1.1.5",
  363. ));
  364. $EPindex = new testInstallerEntryPoint($this->defaultIni, $iniIndex, 'index.php', 'classic', $conf);
  365. $component->addModuleInfos($EPindex->getEpId(), new jInstallerModuleInfos('testinstall2', $conf->modules) );
  366. $upgraders = $component->getUpgraders($EPindex);
  367. $this->assertTrue (is_array($upgraders));
  368. $this->assertEquals(1, count($upgraders));
  369. $this->assertEquals('testinstall2ModuleUpgrader_newupgraderfilename', get_class($upgraders[0]));
  370. }
  371. catch(jInstallerException $e) {
  372. $this->fail("Unexpected exception : ".$e->getMessage()." (".var_export($e->getLocaleParameters(),true).")");
  373. }
  374. }
  375. function testGetUpgradersWithAllUpgraders() {
  376. try {
  377. // dummy ini file modifier. not used by installer of tested modules
  378. $iniIndex = new testInstallerIniFileModifier("index/config.ini.php");
  379. $iniFoo = new testInstallerIniFileModifier("foo/config.ini.php");
  380. // the current version is a very old one : all updaters
  381. $component = new jInstallerComponentModule('testinstall2', jApp::appPath().'modules/testinstall2/', null);
  382. $component->init();
  383. $conf =(object) array( 'modules'=>array(
  384. 'testinstall2.access'=>2,
  385. 'testinstall2.dbprofile'=>'default',
  386. 'testinstall2.installed'=>false,
  387. 'testinstall2.version'=>"0.9",
  388. ));
  389. $EPindex = new testInstallerEntryPoint($this->defaultIni, $iniIndex, 'index.php', 'classic', $conf);
  390. $component->addModuleInfos($EPindex->getEpId(), new jInstallerModuleInfos('testinstall2', $conf->modules) );
  391. $upgraders = $component->getUpgraders($EPindex);
  392. $this->assertTrue (is_array($upgraders));
  393. $this->assertEquals(4, count($upgraders));
  394. $this->assertEquals('testinstall2ModuleUpgrader_first', get_class($upgraders[0]));
  395. $this->assertEquals('testinstall2ModuleUpgrader_newupgraderfilename', get_class($upgraders[1]));
  396. $this->assertEquals('testinstall2ModuleUpgrader_newupgraderfilenamedate', get_class($upgraders[2]));
  397. $this->assertEquals('testinstall2ModuleUpgrader_second', get_class($upgraders[3]));
  398. $EPfoo = new testInstallerEntryPoint($this->defaultIni, $iniFoo, 'foo.php', 'classic', $conf);
  399. $component->addModuleInfos($EPfoo->getEpId(), new jInstallerModuleInfos('testinstall2', $conf->modules) );
  400. $upgraders = $component->getUpgraders($EPfoo);
  401. $this->assertTrue (is_array($upgraders));
  402. $this->assertEquals(4, count($upgraders));
  403. $this->assertEquals('testinstall2ModuleUpgrader_first', get_class($upgraders[0]));
  404. $this->assertEquals('testinstall2ModuleUpgrader_newupgraderfilename', get_class($upgraders[1]));
  405. $this->assertEquals('testinstall2ModuleUpgrader_newupgraderfilenamedate', get_class($upgraders[2]));
  406. $this->assertEquals('testinstall2ModuleUpgrader_second', get_class($upgraders[3]));
  407. }
  408. catch(jInstallerException $e) {
  409. $this->fail("Unexpected exception : ".$e->getMessage()." (".var_export($e->getLocaleParameters(),true).")");
  410. }
  411. }
  412. }