Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertHttpsUsedOnBackend.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Mtf\Constraint\AbstractConstraint;
10 use Magento\Mtf\Client\BrowserInterface;
11 use Magento\Backend\Test\Page\Adminhtml\Dashboard;
12 
16 class AssertHttpsUsedOnBackend extends AbstractConstraint
17 {
21  const SCHEME_HTTP = 'http';
22  const SCHEME_HTTPS = 'https';
23 
29  protected $browser;
30 
39  public function processAssert(BrowserInterface $browser, Dashboard $adminDashboardPage, $navMenuPath)
40  {
41  $this->browser = $browser;
42 
43  // Open specified Admin page using Navigation Menu to assert that JS is deployed validly as a part of statics.
44  $adminDashboardPage->open()->getMenuBlock()->navigate($navMenuPath);
45  $this->assertUsedProtocol(self::SCHEME_HTTPS);
47  }
48 
55  protected function assertUsedProtocol($expectedProtocol)
56  {
57  if (substr($expectedProtocol, -3) !== "://") {
58  $expectedProtocol .= '://';
59  }
60 
61  \PHPUnit\Framework\Assert::assertStringStartsWith(
62  $expectedProtocol,
63  $this->browser->getUrl(),
64  "$expectedProtocol is not used."
65  );
66  }
67 
73  protected function assertDirectHttpUnavailable()
74  {
75  $fakeUrl = str_replace(self::SCHEME_HTTPS, self::SCHEME_HTTP, $this->browser->getUrl());
76  $this->browser->open($fakeUrl);
77  \PHPUnit\Framework\Assert::assertStringStartsWith(
78  self::SCHEME_HTTPS,
79  $this->browser->getUrl(),
80  'Merchant is not redirected to https if tries to access the Admin panel page directly via http.'
81  );
82  }
83 
89  public function toString()
90  {
91  return 'Secured URLs are used for Admin panel pages.';
92  }
93 }
processAssert(BrowserInterface $browser, Dashboard $adminDashboardPage, $navMenuPath)