Skip to content

Commit b98b04c

Browse files
author
Dmytro Vilchynskyi
committed
MAGETWO-60185: Remove distinction in http/https for requirejs-config.js
- test logic automation.
1 parent d559d44 commit b98b04c

File tree

7 files changed

+475
-4
lines changed

7 files changed

+475
-4
lines changed

dev/tests/functional/lib/Magento/Mtf/Util/Command/Cli/Cache.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,16 @@ class Cache extends Cli
2929
const PARAM_CACHE_ENABLE = 'cache:enable';
3030

3131
/**
32-
* Flush cache.
32+
* Flush Cache.
33+
* If no parameters are set, all cache types are flushed.
3334
*
35+
* @param array $cacheTypes
3436
* @return void
3537
*/
36-
public function flush()
38+
public function flush(array $cacheTypes = [])
3739
{
38-
parent::execute(Cache::PARAM_CACHE_FLUSH);
40+
$options = empty($cacheTypes) ? '' : ' ' . implode(' ', $cacheTypes);
41+
parent::execute(Cache::PARAM_CACHE_FLUSH . $options);
3942
}
4043

4144
/**
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Mtf\Util\Command\Cli;
8+
9+
use Magento\Mtf\Util\Command\Cli;
10+
11+
/**
12+
* Merchant Developer deploys static view files during test executions so that Storefront UI updates are applied.
13+
*/
14+
class StaticContent extends Cli
15+
{
16+
/**
17+
* Parameter for deploy static view files.
18+
*/
19+
const PARAM_SETUP_STATIC_CONTENT_DEPLOY = 'setup:static-content:deploy';
20+
21+
/**
22+
* Deploy static view files.
23+
*
24+
* @return void
25+
*/
26+
public function deploy()
27+
{
28+
parent::execute(StaticContent::PARAM_SETUP_STATIC_CONTENT_DEPLOY);
29+
}
30+
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Backend\Test\Constraint;
8+
9+
use Magento\Mtf\ObjectManager;
10+
use Magento\Mtf\System\Event\EventManagerInterface;
11+
use Magento\Mtf\Constraint\AbstractConstraint;
12+
use Magento\Mtf\Client\BrowserInterface;
13+
use Magento\Customer\Test\Fixture\Customer;
14+
use Magento\Customer\Test\TestStep\LoginCustomerOnFrontendStep as LogInCustomerOnStorefront;
15+
use Magento\Customer\Test\TestStep\LogoutCustomerOnFrontendStep as LogOutCustomerOnStorefront;
16+
17+
/**
18+
* Assert that http is used all over the Storefront.
19+
* It would be great to assert somehow that browser console does not contain JS-related errors as well.
20+
*/
21+
class AssertHttpUsedOnFrontend extends AbstractConstraint
22+
{
23+
/**
24+
* Unsecured protocol format.
25+
*
26+
* @var string
27+
*/
28+
private $unsecuredProtocol = 'http://';
29+
30+
/**
31+
* Browser interface.
32+
*
33+
* @var BrowserInterface
34+
*/
35+
protected $browser;
36+
37+
/**
38+
* Customer account.
39+
*
40+
* @var Customer
41+
*/
42+
protected $customer;
43+
44+
/**
45+
* Prepare data for further validations execution.
46+
*
47+
* @param ObjectManager $objectManager
48+
* @param EventManagerInterface $eventManager
49+
* @param BrowserInterface $browser
50+
* @param Customer $customer
51+
* @param string $severity
52+
* @param bool $active
53+
*/
54+
public function __construct(
55+
ObjectManager $objectManager,
56+
EventManagerInterface $eventManager,
57+
BrowserInterface $browser,
58+
Customer $customer,
59+
$severity = 'low',
60+
$active = true
61+
) {
62+
parent::__construct($objectManager, $eventManager, $severity, $active);
63+
$this->browser = $browser;
64+
$this->customer = $customer;
65+
66+
$this->customer->persist();
67+
}
68+
69+
/**
70+
* Validations execution.
71+
*
72+
* @return void
73+
*/
74+
public function processAssert()
75+
{
76+
// Log in to Customer Account on Storefront to assert that http is used indeed.
77+
$this->objectManager->create(LogInCustomerOnStorefront::class, ['customer' => $this->customer])->run();
78+
$this->assertUsedProtocol($this->unsecuredProtocol);
79+
80+
// Log out from Customer Account on Storefront to assert that JS is deployed validly as a part of statics.
81+
$this->objectManager->create(LogOutCustomerOnStorefront::class)->run();
82+
$this->assertUsedProtocol($this->unsecuredProtocol);
83+
}
84+
85+
/**
86+
* Assert that specified protocol is used on current page.
87+
*
88+
* @param string $expectedProtocol
89+
* @return void
90+
*/
91+
protected function assertUsedProtocol($expectedProtocol)
92+
{
93+
\PHPUnit_Framework_Assert::assertStringStartsWith(
94+
$expectedProtocol,
95+
$this->browser->getUrl(),
96+
"$expectedProtocol is not used."
97+
);
98+
}
99+
100+
/**
101+
* Returns a string representation of the object.
102+
*
103+
* @return string
104+
*/
105+
public function toString()
106+
{
107+
return 'Unsecured URLs are used for Storefront pages.';
108+
}
109+
}
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Backend\Test\Constraint;
8+
9+
use Magento\Mtf\ObjectManager;
10+
use Magento\Mtf\System\Event\EventManagerInterface;
11+
use Magento\Mtf\Constraint\AbstractConstraint;
12+
use Magento\Mtf\Client\BrowserInterface;
13+
use Magento\Backend\Test\Page\Adminhtml\Dashboard;
14+
15+
/**
16+
* Assert that https protocol is used all over the Admin panel
17+
* It would be great if several different pages to validate are selected randomly in order to increase the coverage.
18+
* It would be great to assert somehow that browser console does not contain JS-related errors as well.
19+
*/
20+
class AssertHttpsUsedOnBackend extends AbstractConstraint
21+
{
22+
/**
23+
* Secured protocol format.
24+
*
25+
* @var string
26+
*/
27+
private $securedProtocol = 'https://';
28+
29+
/**
30+
* Unsecured protocol format.
31+
*
32+
* @var string
33+
*/
34+
private $unsecuredProtocol = 'http://';
35+
36+
/**
37+
* Browser interface.
38+
*
39+
* @var BrowserInterface
40+
*/
41+
protected $browser;
42+
43+
/**
44+
* "Dashboard" page in Admin panel.
45+
*
46+
* @var Dashboard
47+
*/
48+
protected $adminDashboardPage;
49+
50+
/**
51+
* The list of Navigation Menu paths for Admin pages to verify.
52+
*
53+
* @var array
54+
*/
55+
protected $pagesPaths;
56+
57+
/**
58+
* Prepare data for further validations execution.
59+
*
60+
* @param ObjectManager $objectManager
61+
* @param EventManagerInterface $eventManager
62+
* @param BrowserInterface $browser
63+
* @param Dashboard $adminDashboardPage
64+
* @param string $severity
65+
* @param bool $active
66+
*/
67+
public function __construct(
68+
ObjectManager $objectManager,
69+
EventManagerInterface $eventManager,
70+
BrowserInterface $browser,
71+
Dashboard $adminDashboardPage,
72+
$severity = 'low',
73+
$active = true
74+
) {
75+
parent::__construct($objectManager, $eventManager, $severity, $active);
76+
$this->browser = $browser;
77+
$this->adminDashboardPage = $adminDashboardPage;
78+
$this->pagesPaths = ['Products>Catalog', 'Marketing>Catalog Price Rule'];
79+
}
80+
81+
/**
82+
* Validations execution.
83+
*
84+
* @return void
85+
*/
86+
public function processAssert()
87+
{
88+
// Open specified Admin pages using Navigation Menu to assert that JS is deployed validly as a part of statics.
89+
foreach ($this->pagesPaths as $pagePath) {
90+
$this->adminDashboardPage->open()->getMenuBlock()->navigate($pagePath);
91+
$this->assertUsedProtocol($this->securedProtocol);
92+
$this->assertDirectHttpUnavailable();
93+
}
94+
}
95+
96+
/**
97+
* Assert that specified protocol is used on current page.
98+
*
99+
* @param string $expectedProtocol
100+
* @return void
101+
*/
102+
protected function assertUsedProtocol($expectedProtocol)
103+
{
104+
\PHPUnit_Framework_Assert::assertStringStartsWith(
105+
$expectedProtocol,
106+
$this->browser->getUrl(),
107+
"$expectedProtocol is not used."
108+
);
109+
}
110+
111+
/**
112+
*
113+
* Assert that Merchant is redirected to https if trying to access the page directly via http.
114+
*
115+
* @return void
116+
*/
117+
protected function assertDirectHttpUnavailable()
118+
{
119+
$fakeUrl = str_replace($this->securedProtocol, $this->unsecuredProtocol, $this->browser->getUrl());
120+
$this->browser->open($fakeUrl);
121+
\PHPUnit_Framework_Assert::assertStringStartsWith(
122+
$this->securedProtocol,
123+
$this->browser->getUrl(),
124+
'Merchant is not redirected to https if tries to access the Admin panel page directly via http.'
125+
);
126+
127+
}
128+
129+
/**
130+
* Returns a string representation of the object.
131+
*
132+
* @return string
133+
*/
134+
public function toString()
135+
{
136+
return 'Unsecured URLs are used for Storefront pages.';
137+
}
138+
}

dev/tests/functional/tests/app/Magento/Backend/Test/Repository/ConfigData.xml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
* See COPYING.txt for license details.
66
*/
77
-->
8-
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/Magento/Mtf/Repository/etc/repository.xsd">
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/Magento/Mtf/Repository/etc/repository.xsd">
910
<repository class="Magento\Config\Test\Repository\ConfigData">
1011
<dataset name="store_information_US">
1112
<field name="general/store_information/name" xsi:type="array">
@@ -156,12 +157,14 @@
156157
<item name="scope_id" xsi:type="number">0</item>
157158
<item name="label" xsi:type="string">Yes</item>
158159
<item name="value" xsi:type="number">1</item>
160+
<item name="inherit" xsi:type="number">1</item>
159161
</field>
160162
<field name="web/secure/use_in_adminhtml" xsi:type="array">
161163
<item name="scope" xsi:type="string">default</item>
162164
<item name="scope_id" xsi:type="number">0</item>
163165
<item name="label" xsi:type="string">Yes</item>
164166
<item name="value" xsi:type="number">1</item>
167+
<item name="inherit" xsi:type="number">1</item>
165168
</field>
166169
</dataset>
167170
<dataset name="enable_hsts">
@@ -195,6 +198,21 @@
195198
</field>
196199
</dataset>
197200

201+
<dataset name="disable_https_frontend_admin">
202+
<field name="web/secure/use_in_frontend" xsi:type="array">
203+
<item name="scope" xsi:type="string">default</item>
204+
<item name="scope_id" xsi:type="number">0</item>
205+
<item name="label" xsi:type="string">No</item>
206+
<item name="value" xsi:type="number">0</item>
207+
</field>
208+
<field name="web/secure/use_in_adminhtml" xsi:type="array">
209+
<item name="scope" xsi:type="string">default</item>
210+
<item name="scope_id" xsi:type="number">0</item>
211+
<item name="label" xsi:type="string">No</item>
212+
<item name="value" xsi:type="number">0</item>
213+
</field>
214+
</dataset>
215+
198216
<dataset name="custom_allowed_country">
199217
<field name="general/country/allow" xsi:type="array">
200218
<item name="scope" xsi:type="string">default</item>

0 commit comments

Comments
 (0)