PageRenderTime 91ms CodeModel.GetById 40ms RepoModel.GetById 2ms app.codeStats 0ms

/tests/unit/suite/libraries/joomla/installer/JInstallerTest.php

https://bitbucket.org/talueses/joomla-cms
PHP | 681 lines | 386 code | 142 blank | 153 comment | 1 complexity | dd5c0ec49c54c5c952620fe9c866df49 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, JSON
  1. <?php
  2. require_once 'PHPUnit/Framework.php';
  3. require_once JPATH_BASE . '/libraries/joomla/installer/installer.php';
  4. /**
  5. * Test class for JInstaller.
  6. * Generated by PHPUnit on 2009-10-27 at 15:20:37.
  7. */
  8. class JInstallerTest extends JoomlaTestCase
  9. {
  10. /**
  11. * @var JInstaller
  12. */
  13. protected $object;
  14. /**
  15. * Sets up the fixture, for example, opens a network connection.
  16. * This method is called before a test is executed.
  17. */
  18. protected function setUp()
  19. {
  20. parent::setUp();
  21. }
  22. /**
  23. * Tears down the fixture, for example, closes a network connection.
  24. * This method is called after a test is executed.
  25. */
  26. protected function tearDown()
  27. {
  28. parent::tearDown();
  29. }
  30. /**
  31. * @todo Implement testGetInstance().
  32. */
  33. public function testGetInstance()
  34. {
  35. $this->saveFactoryState();
  36. $newDbo = $this->getMock('test');
  37. JFactory::$database = &$newDbo;
  38. $this->assertThat(
  39. $this->object = JInstaller::getInstance(),
  40. $this->isInstanceOf('JInstaller'),
  41. 'JInstaller::getInstance failed'
  42. );
  43. $this->restoreFactoryState();
  44. }
  45. public function testMyOnlyTest()
  46. {
  47. $this->setExpectedError(array('level' => E_ERROR, 'code' => 500, 'message' => 'test'));
  48. //$this->setExpectedError();
  49. JError::raiseError(500, 'test');
  50. }
  51. /**
  52. * @todo Implement testGetOverwrite().
  53. */
  54. public function testGetAndSetOverwrite()
  55. {
  56. $this->saveFactoryState();
  57. $newDbo = $this->getMock('test');
  58. JFactory::$database = &$newDbo;
  59. $this->object = JInstaller::getInstance();
  60. $this->object->setOverwrite(false);
  61. $this->assertThat(
  62. $this->object->getOverwrite(),
  63. $this->equalTo(false),
  64. 'Get or Set overwrite failed'
  65. );
  66. $this->assertThat(
  67. $this->object->setOverwrite(true),
  68. $this->equalTo(false),
  69. 'setOverwrite did not return the old value properly.'
  70. );
  71. $this->assertThat(
  72. $this->object->getOverwrite(),
  73. $this->equalTo(true),
  74. 'getOverwrite did not return the expected value.'
  75. );
  76. $this->restoreFactoryState();
  77. }
  78. /**
  79. * @todo Implement testGetOverwrite().
  80. */
  81. public function testGetAndSetRedirectUrl()
  82. {
  83. $this->saveFactoryState();
  84. $newDbo = $this->getMock('test');
  85. JFactory::$database = &$newDbo;
  86. $this->object = JInstaller::getInstance();
  87. $this->object->setRedirectUrl('http://www.example.com');
  88. $this->assertThat(
  89. $this->object->getRedirectUrl(),
  90. $this->equalTo('http://www.example.com'),
  91. 'Get or Set Redirect Url failed'
  92. );
  93. $this->restoreFactoryState();
  94. }
  95. /**
  96. * @todo Implement testGetOverwrite().
  97. */
  98. public function testGetAndSetUpgrade()
  99. {
  100. $this->saveFactoryState();
  101. $newDbo = $this->getMock('test');
  102. JFactory::$database = &$newDbo;
  103. $this->object = JInstaller::getInstance();
  104. $this->object->setUpgrade(false);
  105. $this->assertThat(
  106. $this->object->getUpgrade(),
  107. $this->equalTo(false),
  108. 'Get or Set Upgrade failed'
  109. );
  110. $this->assertThat(
  111. $this->object->setUpgrade(true),
  112. $this->equalTo(false),
  113. 'setUpgrade did not return the old value properly.'
  114. );
  115. $this->assertThat(
  116. $this->object->getUpgrade(),
  117. $this->equalTo(true),
  118. 'getUpgrade did not return the expected value.'
  119. );
  120. $this->restoreFactoryState();
  121. }
  122. /**
  123. * @todo Implement testGetManifest().
  124. */
  125. public function testGetManifest()
  126. {
  127. // Remove the following lines when you implement this test.
  128. $this->markTestIncomplete(
  129. 'This test has not been implemented yet.'
  130. );
  131. }
  132. /**
  133. * @todo Implement testGetPath().
  134. */
  135. public function testGetPath()
  136. {
  137. $this->saveFactoryState();
  138. $newDbo = $this->getMock('test');
  139. JFactory::$database = &$newDbo;
  140. $this->object = JInstaller::getInstance();
  141. $this->assertThat(
  142. $this->object->getPath('path1_getpath', 'default_value'),
  143. $this->equalTo('default_value'),
  144. 'getPath did not return the default value for an undefined path'
  145. );
  146. $this->object->setPath('path2_getpath', JPATH_BASE.'/required_path');
  147. $this->assertThat(
  148. $this->object->getPath('path2_getpath', 'default_value'),
  149. $this->equalTo(JPATH_BASE.'/required_path'),
  150. 'getPath did not return the previously set value for the path'
  151. );
  152. $this->restoreFactoryState();
  153. }
  154. /**
  155. * @todo Implement testAbort().
  156. */
  157. public function testAbortFile()
  158. {
  159. $this->saveFactoryState();
  160. $newDbo = $this->getMock('test');
  161. JFactory::$database = &$newDbo;
  162. copy(JPATH_BASE.'/tests/_data/installer_packages/com_alpha/com_alpha.jpg', dirname(__FILE__).'/tmp/com_alpha.jpg');
  163. $this->object = JInstaller::getInstance();
  164. $this->object->pushStep(array('type' => 'file', 'path' => dirname(__FILE__).'/tmp/com_alpha.jpg'));
  165. $this->assertThat(
  166. $this->object->abort(),
  167. $this->isTrue()
  168. );
  169. $this->assertThat(
  170. file_exists(dirname(__FILE__).'/tmp/com_alpha.jpg'),
  171. $this->isFalse()
  172. );
  173. $this->restoreFactoryState();
  174. }
  175. /**
  176. * @todo Implement testAbort().
  177. */
  178. public function testAbortFolder()
  179. {
  180. $this->saveFactoryState();
  181. $newDbo = $this->getMock('test');
  182. JFactory::$database = &$newDbo;
  183. //TODO - remove dependence on JFolder
  184. if (file_exists(dirname(__FILE__).'/tmp/en-GB')) {
  185. JFolder::delete(dirname(__FILE__).'/tmp/en-GB');
  186. }
  187. JFolder::copy(JPATH_BASE.'/tests/_data/installer_packages/com_alpha/language/en-GB', dirname(__FILE__).'/tmp/en-GB');
  188. $this->object = JInstaller::getInstance();
  189. $this->object->pushStep(array('type' => 'folder', 'path' => dirname(__FILE__).'/tmp/en-GB'));
  190. $this->assertThat(
  191. $this->object->abort(),
  192. $this->isTrue()
  193. );
  194. $this->assertThat(
  195. file_exists(dirname(__FILE__).'/tmp/en-GB'),
  196. $this->isFalse()
  197. );
  198. $this->restoreFactoryState();
  199. }
  200. /**
  201. * @todo Implement testAbort().
  202. */
  203. public function testAbortQuery()
  204. {
  205. $this->saveFactoryState();
  206. $newDbo = $this->getMock('test');
  207. JFactory::$database = &$newDbo;
  208. $this->object = JInstaller::getInstance();
  209. $this->object->pushStep(array('type' => 'query'));
  210. $this->assertThat(
  211. $this->object->abort(),
  212. $this->isFalse()
  213. );
  214. $this->restoreFactoryState();
  215. }
  216. /**
  217. * @todo Implement testAbort().
  218. */
  219. public function testAbortExtension()
  220. {
  221. $this->saveFactoryState();
  222. $newDbo = $this->getMock('test', array('setQuery', 'query'));
  223. $newDbo->expects($this->once())
  224. ->method('setQuery')
  225. ->with($this->equalTo('DELETE FROM `#__extensions` WHERE extension_id = 3'));
  226. $newDbo->expects($this->once())
  227. ->method('Query')
  228. ->with()
  229. ->will($this->returnValue(true));
  230. JFactory::$database = &$newDbo;
  231. //$this->object = JInstaller::getInstance();
  232. $this->object = new JInstaller;
  233. $this->object->pushStep(array('type' => 'extension', 'id' => 3));
  234. $this->assertThat(
  235. $this->object->abort(),
  236. $this->isTrue()
  237. );
  238. $this->restoreFactoryState();
  239. }
  240. /**
  241. * @todo Implement testAbort().
  242. */
  243. public function testAbortDefault()
  244. {
  245. $this->saveFactoryState();
  246. $newDbo = $this->getMock('test');
  247. JFactory::$database = &$newDbo;
  248. $adapterMock = $this->getMock('test', array('_rollback_testtype'));
  249. $adapterMock->expects($this->once())
  250. ->method('_rollback_testtype')
  251. ->with($this->equalTo(array('type' => 'testtype')))
  252. ->will($this->returnValue(true));
  253. //$this->object = JInstaller::getInstance();
  254. $this->object = new JInstaller;
  255. $this->object->setAdapter('testadapter', $adapterMock);
  256. $this->object->pushStep(array('type' => 'testtype'));
  257. $this->assertThat(
  258. $this->object->abort(null, 'testadapter'),
  259. $this->isTrue()
  260. );
  261. $this->restoreFactoryState();
  262. }
  263. /**
  264. * Test that an abort message results in a raised warning
  265. */
  266. public function testAbortMsg()
  267. {
  268. $this->saveFactoryState();
  269. $newDbo = $this->getMock('test');
  270. JFactory::$database = &$newDbo;
  271. //$this->object = JInstaller::getInstance();
  272. $this->object = new JInstaller;
  273. $this->setExpectedError(array('code' => 100, 'message' => 'Warning Text'));
  274. $this->assertThat(
  275. $this->object->abort('Warning Text'),
  276. $this->isTrue()
  277. );
  278. $this->restoreFactoryState();
  279. }
  280. /**
  281. * Test that if the type is not good we fall back properly
  282. */
  283. public function testAbortBadType()
  284. {
  285. $this->saveFactoryState();
  286. $newDbo = $this->getMock('test');
  287. JFactory::$database = &$newDbo;
  288. //$this->object = JInstaller::getInstance();
  289. $this->object = new JInstaller;
  290. $this->object->pushStep(array('type' => 'badstep'));
  291. $this->assertThat(
  292. $this->object->abort(null, false),
  293. $this->isFalse()
  294. );
  295. $this->restoreFactoryState();
  296. }
  297. /**
  298. * This test is weak and may need removal at some point
  299. */
  300. public function testAbortDebug()
  301. {
  302. $configMock = $this->getMock('test', array('get'));
  303. $configMock->expects($this->atLeastOnce())
  304. ->method('get')
  305. ->will($this->returnValue(true));
  306. $this->setExpectedError(array('code' => 500));
  307. //$this->object = JInstaller::getInstance();
  308. $this->saveFactoryState();
  309. $newDbo = $this->getMock('test');
  310. JFactory::$database = &$newDbo;
  311. $this->object = new JInstaller;
  312. JFactory::$config = $configMock;
  313. $this->assertThat(
  314. $this->object->abort(),
  315. $this->isTrue()
  316. );
  317. $this->restoreFactoryState();
  318. }
  319. /**
  320. * @todo Implement testInstall().
  321. */
  322. public function testInstall()
  323. {
  324. // Remove the following lines when you implement this test.
  325. $this->markTestIncomplete(
  326. 'This test has not been implemented yet.'
  327. );
  328. }
  329. /**
  330. * @todo Implement testDiscover_install().
  331. */
  332. public function testDiscover_install()
  333. {
  334. // Remove the following lines when you implement this test.
  335. $this->markTestIncomplete(
  336. 'This test has not been implemented yet.'
  337. );
  338. }
  339. /**
  340. * @todo Implement testDiscover().
  341. */
  342. public function testDiscover()
  343. {
  344. // Remove the following lines when you implement this test.
  345. $this->markTestIncomplete(
  346. 'This test has not been implemented yet.'
  347. );
  348. }
  349. /**
  350. * @todo Implement testUpdate().
  351. */
  352. public function testUpdate()
  353. {
  354. // Remove the following lines when you implement this test.
  355. $this->markTestIncomplete(
  356. 'This test has not been implemented yet.'
  357. );
  358. }
  359. /**
  360. * @todo Implement testUninstall().
  361. */
  362. public function testUninstall()
  363. {
  364. // Remove the following lines when you implement this test.
  365. $this->markTestIncomplete(
  366. 'This test has not been implemented yet.'
  367. );
  368. }
  369. /**
  370. * @todo Implement testRefreshManifestCache().
  371. */
  372. public function testRefreshManifestCache()
  373. {
  374. // Remove the following lines when you implement this test.
  375. $this->markTestIncomplete(
  376. 'This test has not been implemented yet.'
  377. );
  378. }
  379. /**
  380. * @todo Implement testSetupInstall().
  381. */
  382. public function testSetupInstall()
  383. {
  384. // Remove the following lines when you implement this test.
  385. $this->markTestIncomplete(
  386. 'This test has not been implemented yet.'
  387. );
  388. }
  389. /**
  390. * @todo Implement testParseQueries().
  391. */
  392. public function testParseQueries()
  393. {
  394. // Remove the following lines when you implement this test.
  395. $this->markTestIncomplete(
  396. 'This test has not been implemented yet.'
  397. );
  398. }
  399. /**
  400. * @todo Implement testParseSQLFiles().
  401. */
  402. public function testParseSQLFiles()
  403. {
  404. // Remove the following lines when you implement this test.
  405. $this->markTestIncomplete(
  406. 'This test has not been implemented yet.'
  407. );
  408. }
  409. /**
  410. * @todo Implement testParseFiles().
  411. */
  412. public function testParseFiles()
  413. {
  414. // Remove the following lines when you implement this test.
  415. $this->markTestIncomplete(
  416. 'This test has not been implemented yet.'
  417. );
  418. }
  419. /**
  420. * @todo Implement testParseLanguages().
  421. */
  422. public function testParseLanguages()
  423. {
  424. // Remove the following lines when you implement this test.
  425. $this->markTestIncomplete(
  426. 'This test has not been implemented yet.'
  427. );
  428. }
  429. /**
  430. * @todo Implement testParseMedia().
  431. */
  432. public function testParseMedia()
  433. {
  434. // Remove the following lines when you implement this test.
  435. $this->markTestIncomplete(
  436. 'This test has not been implemented yet.'
  437. );
  438. }
  439. /**
  440. * @todo Implement testGetParams().
  441. */
  442. public function testGetParams()
  443. {
  444. // Remove the following lines when you implement this test.
  445. $this->markTestIncomplete(
  446. 'This test has not been implemented yet.'
  447. );
  448. }
  449. /**
  450. * @todo Implement testCopyFiles().
  451. */
  452. public function testCopyFiles()
  453. {
  454. // Remove the following lines when you implement this test.
  455. $this->markTestIncomplete(
  456. 'This test has not been implemented yet.'
  457. );
  458. }
  459. /**
  460. * @todo Implement testRemoveFiles().
  461. */
  462. public function testRemoveFiles()
  463. {
  464. // Remove the following lines when you implement this test.
  465. $this->markTestIncomplete(
  466. 'This test has not been implemented yet.'
  467. );
  468. }
  469. /**
  470. * @todo Implement testCopyManifest().
  471. */
  472. public function testCopyManifest()
  473. {
  474. // Remove the following lines when you implement this test.
  475. $this->markTestIncomplete(
  476. 'This test has not been implemented yet.'
  477. );
  478. }
  479. /**
  480. * @todo Implement testFindManifest().
  481. */
  482. public function testFindManifest()
  483. {
  484. // Remove the following lines when you implement this test.
  485. $this->markTestIncomplete(
  486. 'This test has not been implemented yet.'
  487. );
  488. }
  489. /**
  490. * @todo Implement testIsManifest().
  491. */
  492. public function testIsManifest()
  493. {
  494. // Remove the following lines when you implement this test.
  495. $this->markTestIncomplete(
  496. 'This test has not been implemented yet.'
  497. );
  498. }
  499. /**
  500. * @todo Implement testGenerateManifestCache().
  501. */
  502. public function testGenerateManifestCache()
  503. {
  504. // Remove the following lines when you implement this test.
  505. $this->markTestIncomplete(
  506. 'This test has not been implemented yet.'
  507. );
  508. }
  509. /**
  510. * @todo Implement testCleanDiscoveredExtension().
  511. */
  512. public function testCleanDiscoveredExtension()
  513. {
  514. // Remove the following lines when you implement this test.
  515. $this->markTestIncomplete(
  516. 'This test has not been implemented yet.'
  517. );
  518. }
  519. /**
  520. * @todo Implement testFindDeletedFiles().
  521. */
  522. public function testFindDeletedFiles()
  523. {
  524. // Remove the following lines when you implement this test.
  525. $this->markTestIncomplete(
  526. 'This test has not been implemented yet.'
  527. );
  528. }
  529. /**
  530. * @todo Implement testLoadMD5Sum().
  531. */
  532. public function testLoadMD5Sum()
  533. {
  534. // Remove the following lines when you implement this test.
  535. $this->markTestIncomplete(
  536. 'This test has not been implemented yet.'
  537. );
  538. }
  539. }