/dev/tests/integration/testsuite/integrity/theme/XmlFilesTest.php
PHP | 140 lines | 69 code | 8 blank | 63 comment | 0 complexity | 0ebed00f57592704a2002d2ae5fa99e5 MD5 | raw file
- <?php
- /**
- * Magento
- *
- * NOTICE OF LICENSE
- *
- * This source file is subject to the Open Software License (OSL 3.0)
- * that is bundled with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://opensource.org/licenses/osl-3.0.php
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@magentocommerce.com so we can send you a copy immediately.
- *
- * DISCLAIMER
- *
- * Do not edit or add to this file if you wish to upgrade Magento to newer
- * versions in the future. If you wish to customize Magento for your
- * needs please refer to http://www.magentocommerce.com for more information.
- *
- * @category Magento
- * @package Mage_Core
- * @subpackage integration_tests
- * @copyright Copyright (c) 2012 X.commerce, Inc. (http://www.magentocommerce.com)
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
- */
- /**
- * @group integrity
- */
- class Integrity_Theme_XmlFilesTest extends PHPUnit_Framework_TestCase
- {
- /**
- * @param string $file
- * @dataProvider viewConfigFileDataProvider
- */
- public function testViewConfigFile($file)
- {
- $this->_validateConfigFile($file, Mage::getBaseDir('lib') . '/Magento/Config/view.xsd');
- }
- /**
- * @return array
- */
- public function viewConfigFileDataProvider()
- {
- $result = array();
- foreach (glob(Mage::getBaseDir('design') . '/*/*/*/view.xml') as $file) {
- $result[$file] = array($file);
- }
- return $result;
- }
- /**
- * @param string $themeDir
- * @dataProvider themeConfigFileExistsDataProvider
- */
- public function testThemeConfigFileExists($themeDir)
- {
- $this->assertFileExists($themeDir . '/theme.xml');
- }
- /**
- * @return array
- */
- public function themeConfigFileExistsDataProvider()
- {
- $result = array();
- foreach (glob(Mage::getBaseDir('design') . '/*/*/*', GLOB_ONLYDIR) as $themeDir) {
- $result[$themeDir] = array($themeDir);
- }
- return $result;
- }
- /**
- * @param string $file
- * @dataProvider themeConfigFileDataProvider
- */
- public function testThemeConfigFileSchema($file)
- {
- $this->_validateConfigFile($file, Mage::getBaseDir('lib') . '/Magento/Config/theme.xsd');
- }
- /**
- * Configuration should declare a single package/theme that corresponds to the file system directories
- *
- * @param string $file
- * @dataProvider themeConfigFileDataProvider
- */
- public function testThemeConfigFilePackageTheme($file)
- {
- list($expectedPackage, $expectedTheme) = array_slice(preg_split('[\\/]', $file), -3, 2);
- /** @var $configXml SimpleXMLElement */
- $configXml = simplexml_load_file($file);
- $actualPackages = $configXml->xpath('/design/package');
- $this->assertCount(1, $actualPackages, 'Single design package declaration is expected.');
- $this->assertEquals(
- $expectedPackage,
- $actualPackages[0]['code'],
- 'Design package code does not correspond to the directory name.'
- );
- $actualThemes = $configXml->xpath('/design/package/theme');
- $this->assertCount(1, $actualThemes, 'Single theme declaration is expected.');
- $this->assertEquals(
- $expectedTheme,
- $actualThemes[0]['code'],
- 'Theme code does not correspond to the directory name.'
- );
- }
- /**
- * @return array
- */
- public function themeConfigFileDataProvider()
- {
- $result = array();
- foreach (glob(Mage::getBaseDir('design') . '/*/*/*/theme.xml') as $file) {
- $result[$file] = array($file);
- }
- return $result;
- }
- /**
- * Perform test whether a configuration file is valid
- *
- * @param string $file
- * @param string $schemaFile
- * @throws PHPUnit_Framework_AssertionFailedError if file is invalid
- */
- protected function _validateConfigFile($file, $schemaFile)
- {
- $domConfig = new Magento_Config_Dom(file_get_contents($file));
- $result = $domConfig->validate($schemaFile, $errors);
- $message = "Invalid XML-file: {$file}\n";
- foreach ($errors as $error) {
- $message .= "{$error->message} Line: {$error->line}\n";
- }
- $this->assertTrue($result, $message);
- }
- }