Skip to content

Commit 2ef08da

Browse files
authored
Merge pull request #4545 from magento-obsessive-owls/MC-17701
[owls] MC-17701: Downloadable Product links
2 parents 143f7e7 + bec530e commit 2ef08da

File tree

57 files changed

+1913
-98
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1913
-98
lines changed

Diff for: app/code/Magento/Catalog/Test/Mftf/ActionGroup/AdminProductActionGroup.xml

+17
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@
6464
<see selector="{{AdminProductMessagesSection.successMessage}}" userInput="You saved the product." stepKey="seeSaveConfirmation"/>
6565
</actionGroup>
6666

67+
<!-- Save product but do not expect a success message -->
68+
<actionGroup name="SaveProductFormNoSuccessCheck" extends="saveProductForm">
69+
<remove keyForRemoval="seeSaveConfirmation"/>
70+
</actionGroup>
71+
6772
<!--Upload image for product-->
6873
<actionGroup name="addProductImage">
6974
<arguments>
@@ -283,4 +288,16 @@
283288
</arguments>
284289
<amOnPage url="{{AdminProductEditPage.url(productId)}}" stepKey="goToProduct"/>
285290
</actionGroup>
291+
292+
<!-- This action group goes to the product index page, opens the drop down and clicks the specified product type for adding a product -->
293+
<actionGroup name="GoToSpecifiedCreateProductPage">
294+
<arguments>
295+
<argument type="string" name="productType" defaultValue="simple"/>
296+
</arguments>
297+
<comment userInput="actionGroup:GoToSpecifiedCreateProductPage" stepKey="actionGroupComment"/>
298+
<amOnPage url="{{AdminProductIndexPage.url}}" stepKey="navigateToProductIndex"/>
299+
<click selector="{{AdminProductGridActionSection.addProductToggle}}" stepKey="clickAddProductDropdown"/>
300+
<click selector="{{AdminProductGridActionSection.addTypeProduct(productType)}}" stepKey="clickAddProduct"/>
301+
<waitForPageLoad stepKey="waitForFormToLoad"/>
302+
</actionGroup>
286303
</actionGroups>

Diff for: app/code/Magento/Catalog/Test/Mftf/ActionGroup/AssertProductInStorefrontProductPageActionGroup.xml

+11
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,15 @@
1919
<see userInput="{{product.name}}" selector="{{StorefrontProductInfoMainSection.productName}}" stepKey="assertProductName"/>
2020
<see userInput="{{product.sku}}" selector="{{StorefrontProductInfoMainSection.productSku}}" stepKey="assertProductSku"/>
2121
</actionGroup>
22+
<actionGroup name="AssertProductNameAndSkuInStorefrontProductPage">
23+
<arguments>
24+
<argument name="product"/>
25+
</arguments>
26+
<!-- Go to storefront product page, assert product name and sku -->
27+
<amOnPage url="{{product.urlKey}}.html" stepKey="navigateToProductPage"/>
28+
<waitForPageLoad stepKey="waitForPageLoad2"/>
29+
<seeInTitle userInput="{{product.name}}" stepKey="assertProductNameTitle"/>
30+
<see userInput="{{product.name}}" selector="{{StorefrontProductInfoMainSection.productName}}" stepKey="assertProductName"/>
31+
<see userInput="{{product.sku}}" selector="{{StorefrontProductInfoMainSection.productSku}}" stepKey="assertProductSku"/>
32+
</actionGroup>
2233
</actionGroups>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<!-- You must already be on the category page -->
12+
<actionGroup name="StorefrontCheckProductPriceInCategoryActionGroup" extends="StorefrontCheckCategorySimpleProduct">
13+
<remove keyForRemoval="AssertProductPrice"/>
14+
<see userInput="{{product.price}}" selector="{{StorefrontCategoryProductSection.ProductPriceByName(product.name)}}" stepKey="AssertProductPrice"/>
15+
</actionGroup>
16+
</actionGroups>

Diff for: app/code/Magento/Catalog/Test/Mftf/Section/AdminProductMessagesSection.xml

+1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
xsi:noNamespaceSchemaLocation="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Page/etc/SectionObject.xsd">
1111
<section name="AdminProductMessagesSection">
1212
<element name="successMessage" type="text" selector=".message-success"/>
13+
<element name="errorMessage" type="text" selector=".message.message-error.error"/>
1314
</section>
1415
</sections>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Downloadable\Api;
7+
8+
/**
9+
* Interface DomainManagerInterface
10+
* Manage downloadable domains whitelist.
11+
*/
12+
interface DomainManagerInterface
13+
{
14+
/**
15+
* Get the whitelist.
16+
*
17+
* @return array
18+
*/
19+
public function getDomains(): array;
20+
21+
/**
22+
* Add host to the whitelist.
23+
*
24+
* @param array $hosts
25+
* @return void
26+
*/
27+
public function addDomains(array $hosts);
28+
29+
/**
30+
* Remove host from the whitelist.
31+
*
32+
* @param array $hosts
33+
* @return void
34+
*/
35+
public function removeDomains(array $hosts);
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
/**
3+
*
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
namespace Magento\Downloadable\Console\Command;
8+
9+
use Symfony\Component\Console\Command\Command;
10+
use Symfony\Component\Console\Output\OutputInterface;
11+
use Symfony\Component\Console\Input\InputInterface;
12+
use Symfony\Component\Console\Input\InputArgument;
13+
use Magento\Downloadable\Api\DomainManagerInterface as DomainManager;
14+
15+
/**
16+
* Class DomainsAddCommand
17+
*
18+
* Command for adding downloadable domain to the whitelist
19+
*/
20+
class DomainsAddCommand extends Command
21+
{
22+
/**
23+
* Name of domains input argument
24+
*/
25+
const INPUT_KEY_DOMAINS = 'domains';
26+
27+
/**
28+
* @var DomainManager
29+
*/
30+
private $domainManager;
31+
32+
/**
33+
* DomainsAddCommand constructor.
34+
* @param DomainManager $domainManager
35+
*/
36+
public function __construct(
37+
DomainManager $domainManager
38+
) {
39+
$this->domainManager = $domainManager;
40+
parent::__construct();
41+
}
42+
43+
/**
44+
* @inheritdoc
45+
*/
46+
protected function configure()
47+
{
48+
$description = 'Add domains to the downloadable domains whitelist';
49+
50+
$this->setName('downloadable:domains:add')
51+
->setDescription($description)
52+
->setDefinition(
53+
[
54+
new InputArgument(
55+
self::INPUT_KEY_DOMAINS,
56+
InputArgument::IS_ARRAY,
57+
'Domains name'
58+
)
59+
]
60+
);
61+
parent::configure();
62+
}
63+
64+
/**
65+
* @inheritdoc
66+
*/
67+
protected function execute(InputInterface $input, OutputInterface $output)
68+
{
69+
try {
70+
if ($input->getArgument(self::INPUT_KEY_DOMAINS)) {
71+
$whitelistBefore = $this->domainManager->getDomains();
72+
$newDomains = $input->getArgument(self::INPUT_KEY_DOMAINS);
73+
$newDomains = array_filter(array_map('trim', $newDomains), 'strlen');
74+
75+
$this->domainManager->addDomains($newDomains);
76+
77+
foreach (array_diff($this->domainManager->getDomains(), $whitelistBefore) as $newHost) {
78+
$output->writeln(
79+
$newHost . ' was added to the whitelist.'
80+
);
81+
}
82+
}
83+
} catch (\Exception $e) {
84+
$output->writeln('<error>' . $e->getMessage() . '</error>');
85+
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
86+
$output->writeln($e->getTraceAsString());
87+
}
88+
return;
89+
}
90+
}
91+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
/**
3+
*
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
namespace Magento\Downloadable\Console\Command;
8+
9+
use Symfony\Component\Console\Command\Command;
10+
use Symfony\Component\Console\Output\OutputInterface;
11+
use Symfony\Component\Console\Input\InputInterface;
12+
use Symfony\Component\Console\Input\InputArgument;
13+
use Magento\Downloadable\Api\DomainManagerInterface as DomainManager;
14+
15+
/**
16+
* Class DomainsRemoveCommand
17+
*
18+
* Command for removing downloadable domain from the whitelist
19+
*/
20+
class DomainsRemoveCommand extends Command
21+
{
22+
/**
23+
* Name of domains input argument
24+
*/
25+
const INPUT_KEY_DOMAINS = 'domains';
26+
27+
/**
28+
* @var DomainManager
29+
*/
30+
private $domainManager;
31+
32+
/**
33+
* DomainsRemoveCommand constructor.
34+
*
35+
* @param DomainManager $domainManager
36+
*/
37+
public function __construct(
38+
DomainManager $domainManager
39+
) {
40+
$this->domainManager = $domainManager;
41+
parent::__construct();
42+
}
43+
44+
/**
45+
* @inheritdoc
46+
*/
47+
protected function configure()
48+
{
49+
$description = 'Remove domains from the downloadable domains whitelist';
50+
51+
$this->setName('downloadable:domains:remove')
52+
->setDescription($description)
53+
->setDefinition(
54+
[
55+
new InputArgument(
56+
self::INPUT_KEY_DOMAINS,
57+
InputArgument::IS_ARRAY,
58+
'Domain names'
59+
)
60+
]
61+
);
62+
parent::configure();
63+
}
64+
65+
/**
66+
* @inheritdoc
67+
*/
68+
protected function execute(InputInterface $input, OutputInterface $output)
69+
{
70+
try {
71+
if ($input->getArgument(self::INPUT_KEY_DOMAINS)) {
72+
$whitelistBefore = $this->domainManager->getDomains();
73+
$removeDomains = $input->getArgument(self::INPUT_KEY_DOMAINS);
74+
$removeDomains = array_filter(array_map('trim', $removeDomains), 'strlen');
75+
$this->domainManager->removeDomains($removeDomains);
76+
77+
foreach (array_diff($whitelistBefore, $this->domainManager->getDomains()) as $removedHost) {
78+
$output->writeln(
79+
$removedHost . ' was removed from the whitelist.'
80+
);
81+
}
82+
}
83+
} catch (\Exception $e) {
84+
$output->writeln('<error>' . $e->getMessage() . '</error>');
85+
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
86+
$output->writeln($e->getTraceAsString());
87+
}
88+
return;
89+
}
90+
}
91+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
/**
3+
*
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
namespace Magento\Downloadable\Console\Command;
8+
9+
use Symfony\Component\Console\Command\Command;
10+
use Symfony\Component\Console\Output\OutputInterface;
11+
use Symfony\Component\Console\Input\InputInterface;
12+
use Magento\Downloadable\Api\DomainManagerInterface as DomainManager;
13+
14+
/**
15+
* Class DomainsShowCommand
16+
*
17+
* Command for listing allowed downloadable domains
18+
*/
19+
class DomainsShowCommand extends Command
20+
{
21+
/**
22+
* @var DomainManager
23+
*/
24+
private $domainManager;
25+
26+
/**
27+
* DomainsShowCommand constructor.
28+
* @param DomainManager $domainManager
29+
*/
30+
public function __construct(
31+
DomainManager $domainManager
32+
) {
33+
$this->domainManager = $domainManager;
34+
parent::__construct();
35+
}
36+
37+
/**
38+
* @inheritdoc
39+
*/
40+
protected function configure()
41+
{
42+
$description = 'Display downloadable domains whitelist';
43+
44+
$this->setName('downloadable:domains:show')
45+
->setDescription($description);
46+
parent::configure();
47+
}
48+
49+
/**
50+
* @inheritdoc
51+
*/
52+
protected function execute(InputInterface $input, OutputInterface $output)
53+
{
54+
try {
55+
$whitelist = implode("\n", $this->domainManager->getDomains());
56+
$output->writeln(
57+
"Downloadable domains whitelist:\n$whitelist"
58+
);
59+
} catch (\Exception $e) {
60+
$output->writeln('<error>' . $e->getMessage() . '</error>');
61+
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
62+
$output->writeln($e->getTraceAsString());
63+
}
64+
return;
65+
}
66+
}
67+
}

0 commit comments

Comments
 (0)