Skip to content

Commit 7d23e3f

Browse files
authored
Merge pull request magento#4945 from magento-tsg/2.3-develop-pr82
[TSG] TESTs Fixes for 2.3 (pr82) (2.3-develop)
2 parents 9cc293e + 7907a08 commit 7d23e3f

18 files changed

+931
-32
lines changed

app/code/Magento/Sales/Test/Mftf/Test/CreateOrderFromEditCustomerPageTest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@
8787
<deleteData createDataKey="createConfigProduct" stepKey="deleteConfigurableProduct"/>
8888
<deleteData createDataKey="createConfigProductAttribute" stepKey="deleteProductAttribute"/>
8989
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>
90+
<amOnPage url="{{AdminCustomerPage.url}}" stepKey="openCustomerIndexPage"/>
91+
<actionGroup ref="clearFiltersAdminDataGrid" stepKey="clearCustomerGridFilter"/>
9092
<actionGroup ref="logout" stepKey="logout"/>
9193
</after>
9294

@@ -98,6 +100,7 @@
98100
<waitForPageLoad stepKey="waitForCustomerEditPageToLoad"/>
99101
<click selector="{{AdminCustomerMainActionsSection.createOrderBtn}}" stepKey="clickOnCreateOrderButton"/>
100102
<waitForPageLoad stepKey="waitForOrderPageToLoad"/>
103+
<conditionalClick selector="{{AdminOrderStoreScopeTreeSection.storeOption(_defaultStore.name)}}" dependentSelector="{{AdminOrderStoreScopeTreeSection.storeOption(_defaultStore.name)}}" visible="true" stepKey="selectStoreViewIfAppears"/>
101104

102105
<!--Add configurable product to order-->
103106
<actionGroup ref="addConfigurableProductToOrderFromAdmin" stepKey="addConfigurableProductToOrder">

dev/tests/integration/testsuite/Magento/Catalog/Controller/Product/ViewTest.php

Lines changed: 154 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,75 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Catalog\Controller\Product;
79

10+
use Magento\Catalog\Api\Data\ProductInterface;
11+
use Magento\Catalog\Api\ProductRepositoryInterface;
12+
use Magento\Catalog\Model\Product;
13+
use Magento\Eav\Model\AttributeSetSearchResults;
14+
use Magento\Eav\Model\Entity\Attribute\Set;
15+
use Magento\Framework\Api\SearchCriteriaBuilder;
16+
use Magento\Framework\Api\SortOrderBuilder;
17+
use Magento\Framework\Data\Collection;
18+
use Magento\Catalog\Api\AttributeSetRepositoryInterface;
19+
use Magento\Eav\Model\Entity\Type;
20+
use PHPUnit\Framework\MockObject\MockObject;
21+
use Psr\Log\LoggerInterface;
22+
use Magento\Catalog\Api\Data\ProductAttributeInterface;
23+
use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
24+
use Magento\Framework\Logger\Monolog as MagentoMonologLogger;
25+
826
/**
9-
* @magentoDataFixture Magento/Catalog/controllers/_files/products.php
10-
* @magentoDbIsolation disabled
27+
* Integration test for product view front action.
28+
*
29+
* @magentoAppArea frontend
30+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1131
*/
1232
class ViewTest extends \Magento\TestFramework\TestCase\AbstractController
1333
{
1434
/**
35+
* @var ProductRepositoryInterface $productRepository
36+
*/
37+
private $productRepository;
38+
39+
/**
40+
* @var AttributeSetRepositoryInterface $attributeSetRepository
41+
*/
42+
private $attributeSetRepository;
43+
44+
/**
45+
* @var ProductAttributeRepositoryInterface $attributeSetRepository
46+
*/
47+
private $attributeRepository;
48+
49+
/**
50+
* @var Type $productEntityType
51+
*/
52+
private $productEntityType;
53+
54+
/**
55+
* @inheritdoc
56+
*/
57+
protected function setUp()
58+
{
59+
parent::setUp();
60+
61+
$this->productRepository = $this->_objectManager->create(ProductRepositoryInterface::class);
62+
$this->attributeSetRepository = $this->_objectManager->create(AttributeSetRepositoryInterface::class);
63+
$this->attributeRepository = $this->_objectManager->create(ProductAttributeRepositoryInterface::class);
64+
$this->productEntityType = $this->_objectManager->create(Type::class)
65+
->loadByCode(Product::ENTITY);
66+
}
67+
68+
/**
69+
* @magentoDbIsolation disabled
70+
* @magentoDataFixture Magento/Catalog/controllers/_files/products.php
1571
* @magentoConfigFixture current_store catalog/seo/product_canonical_tag 1
72+
* @return void
1673
*/
17-
public function testViewActionWithCanonicalTag()
74+
public function testViewActionWithCanonicalTag(): void
1875
{
1976
$this->markTestSkipped(
2077
'MAGETWO-40724: Canonical url from tests sometimes does not equal canonical url from action'
@@ -26,4 +83,98 @@ public function testViewActionWithCanonicalTag()
2683
$this->getResponse()->getBody()
2784
);
2885
}
86+
87+
/**
88+
* View product with custom attribute when attribute removed from it.
89+
*
90+
* It tests that after changing product attribute set from Default to Custom
91+
* there are no warning messages in log in case Custom not contains attribute from Default.
92+
*
93+
* @magentoDataFixture Magento/Catalog/_files/product_simple_with_country_of_manufacture.php
94+
* @magentoDataFixture Magento/Catalog/_files/attribute_set_based_on_default_without_country_of_manufacture.php
95+
* @return void
96+
*/
97+
public function testViewActionCustomAttributeSetWithoutCountryOfManufacture(): void
98+
{
99+
/** @var MockObject|LoggerInterface $logger */
100+
$logger = $this->setupLoggerMock();
101+
102+
$product = $this->getProductBySku('simple_with_com');
103+
$attributeSetCustom = $this->getProductAttributeSetByName('custom_attribute_set_wout_com');
104+
$product->setAttributeSetId($attributeSetCustom->getAttributeSetId());
105+
$this->productRepository->save($product);
106+
107+
/** @var ProductAttributeInterface $attributeCountryOfManufacture */
108+
$attributeCountryOfManufacture = $this->attributeRepository->get('country_of_manufacture');
109+
$logger->expects($this->never())
110+
->method('warning')
111+
->with(
112+
"Attempt to load value of nonexistent EAV attribute",
113+
[
114+
'attribute_id' => $attributeCountryOfManufacture->getAttributeId(),
115+
'entity_type' => ProductInterface::class,
116+
]
117+
);
118+
119+
$this->dispatch(sprintf('catalog/product/view/id/%s/', $product->getId()));
120+
}
121+
122+
/**
123+
* Setup logger mock to check there are no warning messages logged.
124+
*
125+
* @return MockObject
126+
*/
127+
private function setupLoggerMock() : MockObject
128+
{
129+
$logger = $this->getMockBuilder(LoggerInterface::class)
130+
->disableOriginalConstructor()
131+
->getMock();
132+
$this->_objectManager->addSharedInstance($logger, MagentoMonologLogger::class);
133+
134+
return $logger;
135+
}
136+
137+
/**
138+
* Get product instance by sku.
139+
*
140+
* @param string $sku
141+
* @return Product
142+
*/
143+
private function getProductBySku(string $sku): Product
144+
{
145+
return $this->productRepository->get($sku);
146+
}
147+
148+
/**
149+
* Get product attribute set by name.
150+
*
151+
* @param string $attributeSetName
152+
* @return Set|null
153+
*/
154+
private function getProductAttributeSetByName(string $attributeSetName): ?Set
155+
{
156+
/** @var SortOrderBuilder $sortOrderBuilder */
157+
$sortOrderBuilder = $this->_objectManager->create(SortOrderBuilder::class);
158+
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
159+
$searchCriteriaBuilder = $this->_objectManager->get(SearchCriteriaBuilder::class);
160+
$searchCriteriaBuilder->addFilter('attribute_set_name', $attributeSetName);
161+
$searchCriteriaBuilder->addFilter('entity_type_id', $this->productEntityType->getId());
162+
$attributeSetIdSortOrder = $sortOrderBuilder
163+
->setField('attribute_set_id')
164+
->setDirection(Collection::SORT_ORDER_DESC)
165+
->create();
166+
$searchCriteriaBuilder->addSortOrder($attributeSetIdSortOrder);
167+
$searchCriteriaBuilder->setPageSize(1);
168+
$searchCriteriaBuilder->setCurrentPage(1);
169+
170+
/** @var AttributeSetSearchResults $searchResult */
171+
$searchResult = $this->attributeSetRepository->getList($searchCriteriaBuilder->create());
172+
$items = $searchResult->getItems();
173+
174+
if (count($items) > 0) {
175+
return reset($items);
176+
}
177+
178+
return null;
179+
}
29180
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\Catalog\Api\Data\ProductAttributeInterface;
9+
use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
10+
use Magento\Catalog\Model\Product\Attribute\Group;
11+
use Magento\Eav\Model\Entity\Attribute\Set;
12+
use Magento\Eav\Model\Entity\Type;
13+
use Magento\TestFramework\Helper\Bootstrap;
14+
15+
$objectManager = Bootstrap::getObjectManager();
16+
17+
/** @var ProductAttributeRepositoryInterface $attributeRepository */
18+
$attributeRepository = $objectManager->get(ProductAttributeRepositoryInterface::class);
19+
/** @var ProductAttributeInterface $attributeCountryOfManufacture */
20+
$attributeCountryOfManufacture = $attributeRepository->get('country_of_manufacture');
21+
22+
/** @var Magento\Eav\Model\Entity\Attribute\Set $attributeSet */
23+
$attributeSet = $objectManager->create(Set::class);
24+
/** @var Type $entityType */
25+
$entityType = $objectManager->create(Type::class)
26+
->loadByCode(Magento\Catalog\Model\Product::ENTITY);
27+
$data = [
28+
'attribute_set_name' => 'custom_attribute_set_wout_com',
29+
'entity_type_id' => $entityType->getId(),
30+
'sort_order' => 300,
31+
];
32+
33+
$attributeSet->setData($data);
34+
$attributeSet->validate();
35+
$attributeSet->save();
36+
$attributeSet->initFromSkeleton($entityType->getDefaultAttributeSetId());
37+
/** @var Group $group */
38+
foreach ($attributeSet->getGroups() as $group) {
39+
$groupAttributes = $group->getAttributes();
40+
$newAttributes = array_filter(
41+
$groupAttributes,
42+
function ($attribute) use ($attributeCountryOfManufacture) {
43+
/** @var ProductAttributeInterface $attribute */
44+
return (int)$attribute->getAttributeId() !== (int)$attributeCountryOfManufacture->getAttributeId();
45+
}
46+
);
47+
if (count($newAttributes) < count($groupAttributes)) {
48+
$group->setAttributes($newAttributes);
49+
break;
50+
}
51+
}
52+
$attributeSet->save();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\Eav\Model\AttributeSetSearchResults;
9+
use Magento\Eav\Model\Entity\Attribute\Set;
10+
use Magento\Framework\Api\SearchCriteriaBuilder;
11+
use Magento\Framework\Api\SortOrderBuilder;
12+
use Magento\Framework\Data\Collection;
13+
use Magento\Framework\Registry;
14+
use Magento\TestFramework\Helper\Bootstrap;
15+
use Magento\Catalog\Api\AttributeSetRepositoryInterface;
16+
use Magento\Eav\Model\Entity\Type;
17+
18+
$objectManager = Bootstrap::getObjectManager();
19+
20+
/** @var AttributeSetRepositoryInterface $attributeSetRepository */
21+
$attributeSetRepository = $objectManager->create(AttributeSetRepositoryInterface::class);
22+
/** @var Type $entityType */
23+
$entityType = $objectManager->create(Type::class)
24+
->loadByCode(Magento\Catalog\Model\Product::ENTITY);
25+
$sortOrderBuilder = $objectManager->create(SortOrderBuilder::class);
26+
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
27+
$searchCriteriaBuilder = $objectManager->get(SearchCriteriaBuilder::class);
28+
$searchCriteriaBuilder->addFilter('attribute_set_name', 'custom_attribute_set_wout_com');
29+
$searchCriteriaBuilder->addFilter('entity_type_id', $entityType->getId());
30+
$attributeSetIdSortOrder = $sortOrderBuilder
31+
->setField('attribute_set_id')
32+
->setDirection(Collection::SORT_ORDER_DESC)
33+
->create();
34+
$searchCriteriaBuilder->addSortOrder($attributeSetIdSortOrder);
35+
$searchCriteriaBuilder->setPageSize(1);
36+
$searchCriteriaBuilder->setCurrentPage(1);
37+
38+
/** @var AttributeSetSearchResults $searchResult */
39+
$searchResult = $attributeSetRepository->getList($searchCriteriaBuilder->create());
40+
$items = $searchResult->getItems();
41+
42+
$registry = $objectManager->get(Registry::class);
43+
$registry->unregister('isSecureArea');
44+
$registry->register('isSecureArea', true);
45+
46+
try {
47+
if (count($items) > 0) {
48+
/** @var Set $attributeSet */
49+
$attributeSet = reset($items);
50+
$attributeSetRepository->deleteById($attributeSet->getId());
51+
}
52+
} catch (\Exception $e) {
53+
// In case of test run with DB isolation there is already no object in database
54+
// since rollback fixtures called after transaction rollback.
55+
}
56+
57+
$registry->unregister('isSecureArea');
58+
$registry->register('isSecureArea', false);
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\Catalog\Api\Data\ProductInterfaceFactory;
9+
use Magento\Catalog\Api\ProductRepositoryInterface;
10+
use Magento\Catalog\Model\Product\Attribute\Source\Status;
11+
use Magento\Catalog\Model\Product\Visibility;
12+
use Magento\TestFramework\Helper\Bootstrap;
13+
14+
$objectManager = Bootstrap::getObjectManager();
15+
/** @var ProductInterfaceFactory $productFactory */
16+
$productFactory = $objectManager->get(ProductInterfaceFactory::class);
17+
/** @var ProductRepositoryInterface $productRepository */
18+
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
19+
20+
/** @var $product \Magento\Catalog\Model\Product */
21+
$product = $productFactory->create();
22+
$product->setTypeId('simple')
23+
->setAttributeSetId($product->getDefaultAttributeSetId())
24+
->setWebsiteIds([1])
25+
->setName('Simple Product Tax None')
26+
->setSku('simple-product-tax-none')
27+
->setPrice(205)
28+
->setWeight(1)
29+
->setMetaTitle('meta title')
30+
->setMetaKeyword('meta keyword')
31+
->setMetaDescription('meta description')
32+
->setVisibility(Visibility::VISIBILITY_BOTH)
33+
->setStatus(Status::STATUS_ENABLED)
34+
->setStockData(
35+
[
36+
'use_config_manage_stock' => 1,
37+
'qty' => 100,
38+
'is_in_stock' => 1
39+
]
40+
);
41+
42+
$productRepository->save($product);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\Catalog\Api\Data\ProductInterface;
9+
use Magento\Catalog\Api\ProductRepositoryInterface;
10+
use Magento\Framework\Exception\NoSuchEntityException;
11+
use Magento\TestFramework\Helper\Bootstrap;
12+
use Magento\TestFramework\ObjectManager;
13+
14+
/** @var ObjectManager $objectManager */
15+
$objectManager = Bootstrap::getObjectManager();
16+
/** @var ProductRepositoryInterface $productRepository */
17+
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
18+
/** @var \Magento\Framework\Registry $registry */
19+
$registry =$objectManager->get(\Magento\Framework\Registry::class);
20+
21+
$registry->unregister('isSecureArea');
22+
$registry->register('isSecureArea', true);
23+
24+
try {
25+
/** @var ProductInterface $product */
26+
$product = $productRepository->get('simple-product-tax-none', false, null, true);
27+
$productRepository->delete($product);
28+
} catch (NoSuchEntityException $e) {
29+
// isolation on
30+
}
31+
32+
$registry->unregister('isSecureArea');
33+
$registry->register('isSecureArea', false);

0 commit comments

Comments
 (0)