PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/dev/tests/static/testsuite/Integrity/ConfigTest.php

https://bitbucket.org/sunil_nextbits/magento2
PHP | 120 lines | 56 code | 2 blank | 62 comment | 1 complexity | 3309491ba40758b912b84cf60d422ee2 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 tests
  22. * @package static
  23. * @subpackage Legacy
  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. class Integrity_ConfigTest extends PHPUnit_Framework_TestCase
  28. {
  29. /**
  30. * @var array
  31. */
  32. private static $_brokenModules = array('Social_Facebook');
  33. /**
  34. * @return array
  35. */
  36. public function testDeclaredLocales()
  37. {
  38. $verifiedFiles = array();
  39. foreach ($this->_getConfigFilesPerModule() as $configFile => $moduleName) {
  40. $config = simplexml_load_file($configFile);
  41. $nodes = $config->xpath("/config/*/translate/modules/{$moduleName}/files/*") ?: array();
  42. foreach ($nodes as $node) {
  43. $localeFile = dirname($configFile) . '/../locale/en_US/' . (string)$node;
  44. $this->assertFileExists($localeFile);
  45. $verifiedFiles[realpath($localeFile)] = $moduleName;
  46. }
  47. }
  48. return $verifiedFiles;
  49. }
  50. /**
  51. * @depends testDeclaredLocales
  52. */
  53. public function testExistingFilesDeclared($verifiedFiles)
  54. {
  55. $root = Utility_Files::init()->getPathToSource();
  56. $failures = array();
  57. foreach (glob("{$root}/app/code/*/*/*", GLOB_ONLYDIR) as $modulePath) {
  58. $localeFiles = glob("{$modulePath}/locale/*/*.csv");
  59. foreach ($localeFiles as $file) {
  60. $file = realpath($file);
  61. $assertFile = dirname(dirname($file)) . DIRECTORY_SEPARATOR . 'en_US' . DIRECTORY_SEPARATOR
  62. . basename($file);
  63. if (!isset($verifiedFiles[$assertFile])) {
  64. $failures[] = $file;
  65. }
  66. }
  67. }
  68. $this->assertEmpty($failures,
  69. 'Translation files exist, but not declared in configuration:' . "\n" . var_export($failures, 1)
  70. );
  71. }
  72. /**
  73. * Verify whether all payment methods are declared in appropriate modules
  74. *
  75. * @dataProvider paymentMethodsDataProvider
  76. */
  77. public function testPaymentMethods($configFile, $moduleName)
  78. {
  79. $config = simplexml_load_file($configFile);
  80. $nodes = $config->xpath('/config/default/payment/*/model') ?: array();
  81. foreach ($nodes as $node) {
  82. $this->assertStringStartsWith($moduleName . '_Model_', (string)$node,
  83. "'$node' payment method is declared in '$configFile' module, but doesn't belong to '$moduleName' module"
  84. );
  85. }
  86. }
  87. public function paymentMethodsDataProvider()
  88. {
  89. $data = array();
  90. foreach ($this->_getConfigFilesPerModule() as $configFile => $moduleName) {
  91. $data[] = array($configFile, $moduleName);
  92. }
  93. return $data;
  94. }
  95. /**
  96. * Get list of configuration files associated with modules
  97. *
  98. * @return array
  99. */
  100. protected function _getConfigFilesPerModule()
  101. {
  102. $configFiles = Utility_Files::init()->getConfigFiles('config.xml', array(), false);
  103. $data = array();
  104. foreach ($configFiles as $configFile) {
  105. preg_match('#/([^/]+?/[^/]+?)/etc/config\.xml$#', $configFile, $moduleName);
  106. $moduleName = str_replace('/', '_', $moduleName[1]);
  107. if (in_array($moduleName, self::$_brokenModules)) {
  108. continue;
  109. }
  110. $data[$configFile] = $moduleName;
  111. }
  112. return $data;
  113. }
  114. }