Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertIntegrationResourcesPopup.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Integration\Test\Fixture\Integration;
10 use Magento\Integration\Test\Page\Adminhtml\IntegrationIndex;
11 use Magento\Mtf\Constraint\AbstractConstraint;
12 
16 class AssertIntegrationResourcesPopup extends AbstractConstraint
17 {
27  public function processAssert(IntegrationIndex $integrationIndex, Integration $integration, $resourceDepth = null)
28  {
29  $fixtureResources = is_array($integration->getResources())
30  ? $integration->getResources()
31  : [$integration->getResources()];
32  $formResources = $integrationIndex->getIntegrationGrid()->getResourcesPopup()->getStructure($resourceDepth);
33  $result = $this->verifyResources($formResources, $fixtureResources);
34  \PHPUnit\Framework\Assert::assertEmpty(
35  $result,
36  "Integration resources is not correct.\nLog:\n" . $result
37  );
38  $integrationIndex->getIntegrationGrid()->getResourcesPopup()->clickAllowButton();
39  }
40 
48  protected function verifyResources(array $formResources, array $fixtureResources)
49  {
50  $errorMessage = '';
51  $topFormResources = [];
52 
53  foreach ($fixtureResources as $fixtureResource) {
54  foreach ($formResources as $formResource) {
55  if (preg_match('|^' . preg_quote($fixtureResource) . '|', $formResource)) {
56  $topFormResources[] = $formResource;
57  }
58  }
59  }
60  $diff = array_diff($formResources, $topFormResources);
61  if (!empty($diff)) {
62  $errorMessage = sprintf(
63  "Resources are not equal.\nExpected: %s\nActual: %s",
64  implode(",\n", $formResources),
65  implode(",\n", $topFormResources)
66  );
67  }
68 
69  return $errorMessage;
70  }
71 
77  public function toString()
78  {
79  return 'Resources in popup window are shown correctly.';
80  }
81 }
processAssert(IntegrationIndex $integrationIndex, Integration $integration, $resourceDepth=null)