Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertHttpUsedOnFrontend.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Mtf\Constraint\AbstractConstraint;
10 use Magento\Mtf\Client\BrowserInterface;
12 use Magento\Customer\Test\TestStep\LoginCustomerOnFrontendStep as LogInCustomerOnStorefront;
13 use Magento\Customer\Test\TestStep\LogoutCustomerOnFrontendStep as LogOutCustomerOnStorefront;
14 
18 class AssertHttpUsedOnFrontend extends AbstractConstraint
19 {
25  const SCHEME_HTTP = 'http';
26 
32  protected $browser;
33 
39  protected $customer;
40 
48  public function processAssert(BrowserInterface $browser, Customer $customer)
49  {
50  $this->browser = $browser;
51  $this->customer = $customer;
52  $this->customer->persist();
53 
54  // Log in to Customer Account on Storefront to assert that http is used indeed.
55  $this->objectManager->create(LogInCustomerOnStorefront::class, ['customer' => $this->customer])->run();
56  $this->assertUsedProtocol(self::SCHEME_HTTP);
57 
58  // Log out from Customer Account on Storefront to assert that JS is deployed validly as a part of statics.
59  $this->objectManager->create(LogOutCustomerOnStorefront::class)->run();
60  $this->assertUsedProtocol(self::SCHEME_HTTP);
61  }
62 
69  protected function assertUsedProtocol($expectedProtocol)
70  {
71  if (substr($expectedProtocol, -3) !== "://") {
72  $expectedProtocol .= '://';
73  }
74 
75  \PHPUnit\Framework\Assert::assertStringStartsWith(
76  $expectedProtocol,
77  $this->browser->getUrl(),
78  "$expectedProtocol is not used."
79  );
80  }
81 
87  public function toString()
88  {
89  return 'Unsecured URLs are used for Storefront pages.';
90  }
91 }
processAssert(BrowserInterface $browser, Customer $customer)