Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ReferentialTest.php
Go to the documentation of this file.
1 <?php
9 
10 class ReferentialTest extends \PHPUnit\Framework\TestCase
11 {
15  protected static $_usedGroups = [];
16 
18  protected static $_registeredGroups = [];
19 
20  public static function setUpBeforeClass()
21  {
22  self::_populateUsedGroups();
23  self::_populateRegisteredGroups();
24  }
25 
29  private static function _populateUsedGroups()
30  {
34  $configFiles = \Magento\Framework\App\Utility\Files::init()->getConfigFiles('config.xml', [], false);
38  foreach ($configFiles as $file) {
42  $dom = new \DOMDocument();
43  $dom->loadXML(file_get_contents($file));
44 
45  $xpath = new \DOMXPath($dom);
46  foreach ($xpath->query('/config/*/payment/*/group') as $group) {
47  if (!in_array($group->nodeValue, self::$_usedGroups)) {
48  self::$_usedGroups[] = $group->nodeValue;
49  }
50  }
51  }
52  }
53 
57  private static function _populateRegisteredGroups()
58  {
62  $configFiles = \Magento\Framework\App\Utility\Files::init()->getConfigFiles('payment.xml', [], false);
66  foreach ($configFiles as $file) {
70  $dom = new \DOMDocument();
71  $dom->loadXML(file_get_contents($file));
72 
73  $xpath = new \DOMXPath($dom);
74  foreach ($xpath->query('/payment/groups/group') as $group) {
75  $id = $group->attributes->getNamedItem('id')->nodeValue;
76  if (!in_array($id, self::$_registeredGroups)) {
77  self::$_registeredGroups[] = $id;
78  }
79  }
80  }
81  }
82 
83  public function testGroupsExists()
84  {
85  $missing = array_diff(self::$_usedGroups, self::$_registeredGroups);
86 
87  if (!empty($missing)) {
88  $message = sprintf(
89  "The groups, referenced in store configuration for the payment, " .
90  "don't correspond to any payment group declared in payment.xml: %s",
91  implode(', ', $missing)
92  );
93  $this->fail($message);
94  }
95  }
96 }
$id
Definition: fieldset.phtml:14
$group
Definition: sections.phtml:16
$message