PageRenderTime 40ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/dev/tests/integration/testsuite/integrity/theme/XmlFilesTest.php

https://bitbucket.org/sunil_nextbits/magento2
PHP | 140 lines | 69 code | 8 blank | 63 comment | 0 complexity | 0ebed00f57592704a2002d2ae5fa99e5 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. * @group integrity
  29. */
  30. class Integrity_Theme_XmlFilesTest extends PHPUnit_Framework_TestCase
  31. {
  32. /**
  33. * @param string $file
  34. * @dataProvider viewConfigFileDataProvider
  35. */
  36. public function testViewConfigFile($file)
  37. {
  38. $this->_validateConfigFile($file, Mage::getBaseDir('lib') . '/Magento/Config/view.xsd');
  39. }
  40. /**
  41. * @return array
  42. */
  43. public function viewConfigFileDataProvider()
  44. {
  45. $result = array();
  46. foreach (glob(Mage::getBaseDir('design') . '/*/*/*/view.xml') as $file) {
  47. $result[$file] = array($file);
  48. }
  49. return $result;
  50. }
  51. /**
  52. * @param string $themeDir
  53. * @dataProvider themeConfigFileExistsDataProvider
  54. */
  55. public function testThemeConfigFileExists($themeDir)
  56. {
  57. $this->assertFileExists($themeDir . '/theme.xml');
  58. }
  59. /**
  60. * @return array
  61. */
  62. public function themeConfigFileExistsDataProvider()
  63. {
  64. $result = array();
  65. foreach (glob(Mage::getBaseDir('design') . '/*/*/*', GLOB_ONLYDIR) as $themeDir) {
  66. $result[$themeDir] = array($themeDir);
  67. }
  68. return $result;
  69. }
  70. /**
  71. * @param string $file
  72. * @dataProvider themeConfigFileDataProvider
  73. */
  74. public function testThemeConfigFileSchema($file)
  75. {
  76. $this->_validateConfigFile($file, Mage::getBaseDir('lib') . '/Magento/Config/theme.xsd');
  77. }
  78. /**
  79. * Configuration should declare a single package/theme that corresponds to the file system directories
  80. *
  81. * @param string $file
  82. * @dataProvider themeConfigFileDataProvider
  83. */
  84. public function testThemeConfigFilePackageTheme($file)
  85. {
  86. list($expectedPackage, $expectedTheme) = array_slice(preg_split('[\\/]', $file), -3, 2);
  87. /** @var $configXml SimpleXMLElement */
  88. $configXml = simplexml_load_file($file);
  89. $actualPackages = $configXml->xpath('/design/package');
  90. $this->assertCount(1, $actualPackages, 'Single design package declaration is expected.');
  91. $this->assertEquals(
  92. $expectedPackage,
  93. $actualPackages[0]['code'],
  94. 'Design package code does not correspond to the directory name.'
  95. );
  96. $actualThemes = $configXml->xpath('/design/package/theme');
  97. $this->assertCount(1, $actualThemes, 'Single theme declaration is expected.');
  98. $this->assertEquals(
  99. $expectedTheme,
  100. $actualThemes[0]['code'],
  101. 'Theme code does not correspond to the directory name.'
  102. );
  103. }
  104. /**
  105. * @return array
  106. */
  107. public function themeConfigFileDataProvider()
  108. {
  109. $result = array();
  110. foreach (glob(Mage::getBaseDir('design') . '/*/*/*/theme.xml') as $file) {
  111. $result[$file] = array($file);
  112. }
  113. return $result;
  114. }
  115. /**
  116. * Perform test whether a configuration file is valid
  117. *
  118. * @param string $file
  119. * @param string $schemaFile
  120. * @throws PHPUnit_Framework_AssertionFailedError if file is invalid
  121. */
  122. protected function _validateConfigFile($file, $schemaFile)
  123. {
  124. $domConfig = new Magento_Config_Dom(file_get_contents($file));
  125. $result = $domConfig->validate($schemaFile, $errors);
  126. $message = "Invalid XML-file: {$file}\n";
  127. foreach ($errors as $error) {
  128. $message .= "{$error->message} Line: {$error->line}\n";
  129. }
  130. $this->assertTrue($result, $message);
  131. }
  132. }