PageRenderTime 26ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/dev/tests/integration/testsuite/Mage/Core/Model/Design/PackageTest.php

https://bitbucket.org/jokusafet/magento2
PHP | 303 lines | 205 code | 26 blank | 72 comment | 0 complexity | 2c3435b0ad60f057d836da65915644aa MD5 | raw file
  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magentocommerce.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magentocommerce.com for more information.
  20. *
  21. * @category Magento
  22. * @package Mage_Core
  23. * @subpackage integration_tests
  24. * @copyright Copyright (c) 2012 X.commerce, Inc. (http://www.magentocommerce.com)
  25. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  26. */
  27. /**
  28. * @magentoDbIsolation enabled
  29. */
  30. class Mage_Core_Model_Design_PackageTest extends PHPUnit_Framework_TestCase
  31. {
  32. /**
  33. * @var Mage_Core_Model_Design_Package
  34. */
  35. protected $_model;
  36. protected static $_developerMode;
  37. public static function setUpBeforeClass()
  38. {
  39. Varien_Io_File::rmdirRecursive(Mage::app()->getConfig()->getOptions()->getMediaDir() . '/theme');
  40. $ioAdapter = new Varien_Io_File();
  41. $ioAdapter->cp(
  42. Mage::app()->getConfig()->getOptions()->getJsDir() . '/prototype/prototype.js',
  43. Mage::app()->getConfig()->getOptions()->getJsDir() . '/prototype/prototype.min.js'
  44. );
  45. self::$_developerMode = Mage::getIsDeveloperMode();
  46. }
  47. public static function tearDownAfterClass()
  48. {
  49. $ioAdapter = new Varien_Io_File();
  50. $ioAdapter->rm(Mage::app()->getConfig()->getOptions()->getJsDir() . '/prototype/prototype.min.js');
  51. Mage::setIsDeveloperMode(self::$_developerMode);
  52. }
  53. protected function setUp()
  54. {
  55. /** @var $themeUtility Mage_Core_Utility_Theme */
  56. $themeUtility = Mage::getModel('Mage_Core_Utility_Theme', array(
  57. dirname(__DIR__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'design',
  58. Mage::getModel('Mage_Core_Model_Design_Package')
  59. ));
  60. $themeUtility->registerThemes()->setDesignTheme('test/default', 'frontend');
  61. $this->_model = $themeUtility->getDesign();
  62. }
  63. protected function tearDown()
  64. {
  65. $this->_model = null;
  66. }
  67. public function testSetGetArea()
  68. {
  69. $this->assertEquals(Mage_Core_Model_Design_Package::DEFAULT_AREA, $this->_model->getArea());
  70. $this->_model->setArea('test');
  71. $this->assertEquals('test', $this->_model->getArea());
  72. }
  73. public function testGetTheme()
  74. {
  75. $this->assertEquals('test/default', $this->_model->getDesignTheme()->getThemePath());
  76. }
  77. public function testSetDesignTheme()
  78. {
  79. $this->_model->setDesignTheme('test/test', 'test');
  80. $this->assertEquals('test', $this->_model->getArea());
  81. $this->assertEquals(null, $this->_model->getDesignTheme()->getThemePath());
  82. }
  83. public function testGetDesignTheme()
  84. {
  85. $this->assertInstanceOf('Mage_Core_Model_Theme', $this->_model->getDesignTheme());
  86. }
  87. /**
  88. * @dataProvider getFilenameDataProvider
  89. */
  90. public function testGetFilename($file, $params)
  91. {
  92. $this->assertFileExists($this->_model->getFilename($file, $params));
  93. }
  94. /**
  95. * @return array
  96. */
  97. public function getFilenameDataProvider()
  98. {
  99. return array(
  100. array('theme_file.txt', array('module' => 'Mage_Catalog')),
  101. array('Mage_Catalog::theme_file.txt', array()),
  102. array('Mage_Catalog::theme_file_with_2_dots..txt', array()),
  103. array('Mage_Catalog::theme_file.txt', array('module' => 'Overriden_Module')),
  104. );
  105. }
  106. /**
  107. * @param string $file
  108. * @expectedException Magento_Exception
  109. * @dataProvider extractScopeExceptionDataProvider
  110. */
  111. public function testExtractScopeException($file)
  112. {
  113. $this->_model->getFilename($file, array());
  114. }
  115. public function extractScopeExceptionDataProvider()
  116. {
  117. return array(
  118. array('::no_scope.ext'),
  119. array('./file.ext'),
  120. array('../file.ext'),
  121. array('dir/./file.ext'),
  122. array('dir/../file.ext'),
  123. );
  124. }
  125. public function testGetOptimalCssUrls()
  126. {
  127. $expected = array(
  128. 'http://localhost/pub/media/theme/frontend/test/default/en_US/css/styles.css',
  129. 'http://localhost/pub/lib/mage/translate-inline.css',
  130. );
  131. $params = array(
  132. 'css/styles.css',
  133. 'mage/translate-inline.css',
  134. );
  135. $this->assertEquals($expected, $this->_model->getOptimalCssUrls($params));
  136. }
  137. /**
  138. * @param array $files
  139. * @param array $expectedFiles
  140. * @dataProvider getOptimalCssUrlsMergedDataProvider
  141. * @magentoConfigFixture current_store dev/css/merge_css_files 1
  142. */
  143. public function testGetOptimalCssUrlsMerged($files, $expectedFiles)
  144. {
  145. $this->assertEquals($expectedFiles, $this->_model->getOptimalCssUrls($files));
  146. }
  147. public function getOptimalCssUrlsMergedDataProvider()
  148. {
  149. return array(
  150. array(
  151. array('css/styles.css', 'mage/calendar.css'),
  152. array('http://localhost/pub/media/theme/_merged/dce6f2a22049cd09bbfbe344fc73b037.css')
  153. ),
  154. array(
  155. array('css/styles.css'),
  156. array('http://localhost/pub/media/theme/frontend/test/default/en_US/css/styles.css',)
  157. ),
  158. );
  159. }
  160. public function testGetOptimalJsUrls()
  161. {
  162. $expected = array(
  163. 'http://localhost/pub/media/theme/frontend/test/default/en_US/js/tabs.js',
  164. 'http://localhost/pub/lib/jquery/jquery-ui-timepicker-addon.js',
  165. 'http://localhost/pub/lib/mage/calendar.js',
  166. );
  167. $params = array(
  168. 'js/tabs.js',
  169. 'jquery/jquery-ui-timepicker-addon.js',
  170. 'mage/calendar.js',
  171. );
  172. $this->assertEquals($expected, $this->_model->getOptimalJsUrls($params));
  173. }
  174. /**
  175. * @param array $files
  176. * @param array $expectedFiles
  177. * @dataProvider getOptimalJsUrlsMergedDataProvider
  178. * @magentoConfigFixture current_store dev/js/merge_files 1
  179. */
  180. public function testGetOptimalJsUrlsMerged($files, $expectedFiles)
  181. {
  182. $this->assertEquals($expectedFiles, $this->_model->getOptimalJsUrls($files));
  183. }
  184. public function getOptimalJsUrlsMergedDataProvider()
  185. {
  186. return array(
  187. array(
  188. array('js/tabs.js', 'mage/calendar.js', 'jquery/jquery-ui-timepicker-addon.js'),
  189. array('http://localhost/pub/media/theme/_merged/51cf03344697f37c2511aa0ad3391d56.js',)
  190. ),
  191. array(
  192. array('mage/calendar.js'),
  193. array('http://localhost/pub/lib/mage/calendar.js',)
  194. ),
  195. );
  196. }
  197. public function testGetViewConfig()
  198. {
  199. $config = $this->_model->getViewConfig();
  200. $this->assertInstanceOf('Magento_Config_View', $config);
  201. $this->assertEquals(array('var1' => 'value1', 'var2' => 'value2'), $config->getVars('Namespace_Module'));
  202. }
  203. /**
  204. * @param string $file
  205. * @param string $result
  206. * @covers Mage_Core_Model_Design_Package::getViewUrl
  207. * @dataProvider getViewUrlDataProvider
  208. * @magentoConfigFixture current_store dev/static/sign 0
  209. */
  210. public function testGetViewUrl($devMode, $file, $result)
  211. {
  212. Mage::setIsDeveloperMode($devMode);
  213. $this->assertEquals($this->_model->getViewFileUrl($file), $result);
  214. }
  215. /**
  216. * @param string $file
  217. * @param string $result
  218. * @covers Mage_Core_Model_Design_Package::getSkinUrl
  219. * @dataProvider getViewUrlDataProvider
  220. * @magentoConfigFixture current_store dev/static/sign 1
  221. */
  222. public function testGetViewUrlSigned($devMode, $file, $result)
  223. {
  224. Mage::setIsDeveloperMode($devMode);
  225. $url = $this->_model->getViewFileUrl($file);
  226. $this->assertEquals(strpos($url, $result), 0);
  227. $lastModified = array();
  228. preg_match('/.*\?(.*)$/i', $url, $lastModified);
  229. $this->assertArrayHasKey(1, $lastModified);
  230. $this->assertEquals(10, strlen($lastModified[1]));
  231. $this->assertLessThanOrEqual(time(), $lastModified[1]);
  232. $this->assertGreaterThan(1970, date('Y', $lastModified[1]));
  233. }
  234. /**
  235. * @return array
  236. */
  237. public function getViewUrlDataProvider()
  238. {
  239. return array(
  240. array(
  241. false,
  242. 'Mage_Page::favicon.ico',
  243. 'http://localhost/pub/media/theme/frontend/test/default/en_US/Mage_Page/favicon.ico',
  244. ),
  245. array(
  246. true,
  247. 'prototype/prototype.js',
  248. 'http://localhost/pub/lib/prototype/prototype.js'
  249. ),
  250. array(
  251. false,
  252. 'prototype/prototype.js',
  253. 'http://localhost/pub/lib/prototype/prototype.min.js'
  254. ),
  255. array(
  256. true,
  257. 'Mage_Page::menu.js',
  258. 'http://localhost/pub/media/theme/frontend/test/default/en_US/Mage_Page/menu.js'
  259. ),
  260. array(
  261. false,
  262. 'Mage_Page::menu.js',
  263. 'http://localhost/pub/media/theme/frontend/test/default/en_US/Mage_Page/menu.js'
  264. ),
  265. array(
  266. false,
  267. 'Mage_Catalog::widgets.css',
  268. 'http://localhost/pub/media/theme/frontend/test/default/en_US/Mage_Catalog/widgets.css'
  269. ),
  270. array(
  271. true,
  272. 'Mage_Catalog::widgets.css',
  273. 'http://localhost/pub/media/theme/frontend/test/default/en_US/Mage_Catalog/widgets.css'
  274. ),
  275. );
  276. }
  277. }