Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertIntegrationTokensAfterReauthorize.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\Integration\Test\Page\Adminhtml\IntegrationNew;
12 use Magento\Mtf\Constraint\AbstractConstraint;
13 
18 class AssertIntegrationTokensAfterReauthorize extends AbstractConstraint
19 {
25  protected $consumerKeys = [
26  'key',
27  'consumer_secret',
28  ];
29 
35  protected $accessTokens = [
36  'token',
37  'token_secret',
38  ];
39 
53  public function processAssert(
54  IntegrationIndex $integrationIndex,
55  IntegrationNew $integrationNew,
56  Integration $integration
57  ) {
58  $filter = ['name' => $integration->getName()];
59  $integrationIndex->open();
60  $integrationIndex->getIntegrationGrid()->searchAndOpen($filter);
61  $actualData = $integrationNew->getIntegrationForm()->getData();
62  $errors = $this->checkTokens($actualData, $integration->getData());
63 
64  \PHPUnit\Framework\Assert::assertEmpty(
65  $errors,
66  "Integration tokens was changed incorrectly.\nLog:\n" . implode(";\n", $errors)
67  );
68  }
69 
77  protected function checkTokens(array $actualData, array $tokens)
78  {
79  $errors = [];
80  foreach ($this->consumerKeys as $consumerKey) {
81  if ($actualData[$consumerKey] !== $tokens[$consumerKey]) {
82  $errors[] = "Field '" . $consumerKey . "' was changed.";
83  }
84  }
85  foreach ($this->accessTokens as $accessToken) {
86  if ($actualData[$accessToken] === $tokens[$accessToken]) {
87  $errors[] = "Field '" . $accessToken . "' was not changed.";
88  }
89  }
90  return $errors;
91  }
92 
98  public function toString()
99  {
100  return 'Access tokens were reauthorized correctly.';
101  }
102 }
processAssert(IntegrationIndex $integrationIndex, IntegrationNew $integrationNew, Integration $integration)
$errors
Definition: overview.phtml:9
$tokens
Definition: cards_list.phtml:9