PageRenderTime 51ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/phpmyadmin/test/classes/ThemeTest.php

https://gitlab.com/luyxtran264/myproject
PHP | 420 lines | 218 code | 42 blank | 160 comment | 0 complexity | f8669a37f74c9886f5d568dc3f055efb MD5 | raw file
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Test class for Theme.
  5. *
  6. * @package PhpMyAdmin-test
  7. */
  8. use PMA\libraries\Theme;
  9. require_once 'libraries/url_generating.lib.php';
  10. require_once 'test/PMATestCase.php';
  11. /**
  12. * Test class for Theme.
  13. *
  14. * @package PhpMyAdmin-test
  15. */
  16. class ThemeTest extends PMATestCase
  17. {
  18. /**
  19. * @var Theme
  20. */
  21. protected $object;
  22. /**
  23. * Sets up the fixture, for example, opens a network connection.
  24. * This method is called before a test is executed.
  25. *
  26. * @return void
  27. */
  28. protected function setUp()
  29. {
  30. $this->object = new Theme();
  31. $_SESSION['PMA_Theme'] = $this->object;
  32. $GLOBALS['PMA_Config'] = new PMA\libraries\Config();
  33. $GLOBALS['PMA_Config']->enableBc();
  34. $GLOBALS['text_dir'] = 'ltr';
  35. include 'themes/pmahomme/layout.inc.php';
  36. $GLOBALS['server'] = '99';
  37. $GLOBALS['collation_connection'] = 'utf-8';
  38. }
  39. /**
  40. * Tears down the fixture, for example, closes a network connection.
  41. * This method is called after a test is executed.
  42. *
  43. * @return void
  44. */
  45. protected function tearDown()
  46. {
  47. }
  48. /**
  49. * Test for Theme::loadInfo
  50. *
  51. * @return void
  52. * @group medium
  53. */
  54. public function testCheckImgPathNotExisted()
  55. {
  56. $this->object->setPath('path/to/nowhere');
  57. $this->assertFalse($this->object->loadInfo());
  58. }
  59. /**
  60. * Test for Theme::loadInfo
  61. *
  62. * @return void
  63. */
  64. public function testCheckImgPathIncorrect()
  65. {
  66. $this->object->setPath('./test/classes/_data/incorrect_theme');
  67. $this->assertFalse(
  68. $this->object->loadInfo(),
  69. 'Theme name is not properly set'
  70. );
  71. }
  72. /**
  73. * Test for Theme::getName, getVersion
  74. *
  75. * @return void
  76. */
  77. public function testCheckImgPathFull()
  78. {
  79. $this->object->setPath('./test/classes/_data/gen_version_info');
  80. $this->assertTrue($this->object->loadInfo());
  81. $this->assertEquals('Test Theme', $this->object->getName());
  82. $this->assertEquals('2.0.3', $this->object->getVersion());
  83. }
  84. /**
  85. * Test for Theme::loadInfo
  86. *
  87. * @return void
  88. */
  89. public function testLoadInfo()
  90. {
  91. $this->object->setPath('./themes/original');
  92. $infofile = $this->object->getPath() . '/info.inc.php';
  93. $this->assertTrue($this->object->loadInfo());
  94. $this->assertEquals(
  95. filemtime($infofile),
  96. $this->object->mtime_info
  97. );
  98. $this->object->setPath('./themes/original');
  99. $this->object->mtime_info = filemtime($infofile);
  100. $this->assertTrue($this->object->loadInfo());
  101. $this->assertEquals('Original', $this->object->getName());
  102. }
  103. /**
  104. * Test for Theme::load
  105. *
  106. * @return void
  107. */
  108. public function testLoad()
  109. {
  110. $newTheme = Theme::load('./themes/original');
  111. $this->assertNotNull($newTheme);
  112. }
  113. /**
  114. * Test for Theme::loadCss
  115. *
  116. * @param string $theme Path to theme files
  117. *
  118. * @return void
  119. *
  120. * @dataProvider listThemes
  121. */
  122. public function testLoadCss($theme)
  123. {
  124. $newTheme = Theme::load($theme);
  125. ob_start();
  126. $ret = $newTheme->loadCss();
  127. $out = ob_get_contents();
  128. ob_end_clean();
  129. $this->assertTrue($ret);
  130. $this->assertContains('FILE: navigation.css.php', $out);
  131. }
  132. /**
  133. * Data provider for Theme::loadCss test
  134. *
  135. * @return array with theme paths
  136. */
  137. public function listThemes()
  138. {
  139. return array(
  140. array('./themes/original'),
  141. array('./themes/pmahomme/'),
  142. );
  143. }
  144. /**
  145. * Test for Theme::load
  146. *
  147. * @return void
  148. */
  149. public function testLoadNotExisted()
  150. {
  151. $this->assertFalse(Theme::load('/path/to/nowhere'));
  152. }
  153. /**
  154. * Test fir Theme::checkImgPath
  155. *
  156. * @return void
  157. * @expectedException PHPUnit_Framework_Error
  158. */
  159. public function testCheckImgPathBad()
  160. {
  161. $GLOBALS['cfg']['ThemePath'] = 'nowhere';
  162. $this->object->setPath('path/to/nowhere');
  163. $this->assertFalse($this->object->checkImgPath());
  164. }
  165. /**
  166. * Test for Theme::checkImgPath
  167. *
  168. * @return void
  169. */
  170. public function testCheckImgPath()
  171. {
  172. $this->object->setPath('./themes/original');
  173. $this->assertTrue($this->object->checkImgPath());
  174. }
  175. /**
  176. * Test for Theme::checkImgPath
  177. *
  178. * @return void
  179. */
  180. public function testCheckImgPathGlobals()
  181. {
  182. $this->object->setPath('/this/is/wrong/path');
  183. $GLOBALS['cfg']['ThemePath'] = 'themes';
  184. $this->assertTrue($this->object->checkImgPath());
  185. }
  186. /**
  187. * Test for Theme::checkImgPath
  188. *
  189. * @return void
  190. * @expectedException PHPUnit_Framework_Error
  191. */
  192. public function testCheckImgPathGlobalsWrongPath()
  193. {
  194. $prevThemePath = $GLOBALS['cfg']['ThemePath'];
  195. $GLOBALS['cfg']['ThemePath'] = 'no_themes';
  196. $this->object->setPath('/this/is/wrong/path');
  197. $this->object->checkImgPath();
  198. $GLOBALS['cfg']['ThemePath'] = $prevThemePath;
  199. }
  200. /**
  201. * Test for Theme::getPath
  202. *
  203. * @return void
  204. */
  205. public function testGetSetPath()
  206. {
  207. $this->assertEmpty($this->object->getPath());
  208. $this->object->setPath('./themes/original');
  209. $this->assertEquals('./themes/original', $this->object->getPath());
  210. }
  211. /**
  212. * Test for Theme::loadInfo
  213. *
  214. * @return void
  215. */
  216. public function testGetLayoutFile()
  217. {
  218. $this->assertContains('layout.inc.php', $this->object->getLayoutFile());
  219. }
  220. /**
  221. * Test for Theme::checkVersion
  222. *
  223. * @return void
  224. *
  225. * @depends testLoadInfo
  226. */
  227. public function testGetSetCheckVersion()
  228. {
  229. $this->assertEquals(
  230. '0.0.0.0',
  231. $this->object->getVersion(),
  232. 'Version 0.0.0.0 by default'
  233. );
  234. $this->object->setVersion("1.2.3.4");
  235. $this->assertEquals('1.2.3.4', $this->object->getVersion());
  236. $this->assertFalse($this->object->checkVersion("0.0.1.1"));
  237. $this->assertTrue($this->object->checkVersion("2.0.1.1"));
  238. }
  239. /**
  240. * Test for Theme::getName
  241. *
  242. * @return void
  243. */
  244. public function testGetSetName()
  245. {
  246. $this->assertEmpty($this->object->getName(), 'Name is empty by default');
  247. $this->object->setName('New Theme Name');
  248. $this->assertEquals('New Theme Name', $this->object->getName());
  249. }
  250. /**
  251. * Test for Theme::getId
  252. *
  253. * @return void
  254. */
  255. public function testGetSetId()
  256. {
  257. $this->assertEmpty($this->object->getId(), 'ID is empty by default');
  258. $this->object->setId('NewID');
  259. $this->assertEquals('NewID', $this->object->getId());
  260. }
  261. /**
  262. * Test for Theme::getImgPath
  263. *
  264. * @return void
  265. */
  266. public function testGetSetImgPath()
  267. {
  268. $this->assertEmpty(
  269. $this->object->getImgPath(),
  270. 'ImgPath is empty by default'
  271. );
  272. $this->object->setImgPath('/new/path');
  273. $this->assertEquals('/new/path', $this->object->getImgPath());
  274. }
  275. /**
  276. * Test for getPrintPreview().
  277. *
  278. * @return void
  279. */
  280. public function testPrintPreview()
  281. {
  282. $this->assertEquals(
  283. $this->object->getPrintPreview(),
  284. '<div class="theme_preview"><h2> (0.0.0.0) </h2><p><a class="take_'
  285. . 'theme" name="" href="index.php?set_theme=&amp;server=99&amp;lang=en'
  286. . '&amp;collation_connection=utf-8'
  287. . '&amp;token=token">No preview available.[ <strong>take it</strong> ]'
  288. . '</a></p></div>'
  289. );
  290. }
  291. /**
  292. * Test for getCssIEClearFilter
  293. *
  294. * @return void
  295. */
  296. public function testGetCssIEClearFilter()
  297. {
  298. $this->assertEquals(
  299. $this->object->getCssIEClearFilter(),
  300. ''
  301. );
  302. }
  303. /**
  304. * Test for getFontSize
  305. *
  306. * @return void
  307. */
  308. public function testGetFontSize()
  309. {
  310. $this->assertEquals(
  311. $this->object->getFontSize(),
  312. '82%'
  313. );
  314. $GLOBALS['PMA_Config']->set('fontsize', '12px');
  315. $this->assertEquals(
  316. $this->object->getFontSize(),
  317. '12px'
  318. );
  319. }
  320. /**
  321. * Test for getCssGradient
  322. *
  323. * @return void
  324. */
  325. public function testgetCssGradient()
  326. {
  327. $this->assertEquals(
  328. $this->object->getCssGradient('12345', '54321'),
  329. 'background-image: url(./themes/svg_gradient.php?from=12345&to=54321);'
  330. . "\n" . 'background-size: 100% 100%;'
  331. . "\n" . 'background: -webkit-gradient(linear, left top, left bottom, '
  332. . 'from(#12345), to(#54321));'
  333. . "\n" . 'background: -webkit-linear-gradient(top, #12345, #54321);'
  334. . "\n" . 'background: -moz-linear-gradient(top, #12345, #54321);'
  335. . "\n" . 'background: -ms-linear-gradient(top, #12345, #54321);'
  336. . "\n" . 'background: -o-linear-gradient(top, #12345, #54321);'
  337. );
  338. }
  339. /**
  340. * Test for getImgPath
  341. *
  342. * @param string $file file name for image
  343. * @param string $output expected output
  344. *
  345. * @return void
  346. *
  347. * @dataProvider providerForGetImgPath
  348. */
  349. public function testGetImgPath($file, $output)
  350. {
  351. $this->assertEquals(
  352. $this->object->getImgPath($file),
  353. $output
  354. );
  355. }
  356. /**
  357. * Provider for testGetImgPath
  358. *
  359. * @return array
  360. */
  361. public function providerForGetImgPath()
  362. {
  363. return array(
  364. array(
  365. null,
  366. ''
  367. ),
  368. array(
  369. 'screen.png',
  370. './themes/pmahomme/img/screen.png'
  371. ),
  372. array(
  373. 'arrow_ltr.png',
  374. './themes/pmahomme/img/arrow_ltr.png'
  375. )
  376. );
  377. }
  378. }