Skip to content

Commit 82317f6

Browse files
author
Serhii Bohomaz
committed
Merge branch '2.4-develop' into MC-39634
2 parents 935f4e8 + f5c5db7 commit 82317f6

File tree

13 files changed

+758
-174
lines changed

13 files changed

+758
-174
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* seeInField 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+
<actionGroup name="AssertAdminCreateOrderFormShippingAddressActionGroup">
12+
<annotations>
13+
<description>Verify shipping address inputs on admin create order page. Start on admin create new order page.</description>
14+
</annotations>
15+
<arguments>
16+
<argument name="prefix" type="string" defaultValue="{{CustomerAddressSimple.prefix}}"/>
17+
<argument name="firstname" type="string" defaultValue="{{CustomerAddressSimple.firstname}}"/>
18+
<argument name="middleName" type="string" defaultValue="{{CustomerAddressSimple.middlename}}"/>
19+
<argument name="lastname" type="string" defaultValue="{{CustomerAddressSimple.lastname}}"/>
20+
<argument name="suffix" type="string" defaultValue="{{CustomerAddressSimple.suffix}}"/>
21+
<argument name="company" type="string" defaultValue="{{CustomerAddressSimple.company}}"/>
22+
<argument name="streetLine1" type="string" defaultValue="{{CustomerAddressSimple.street[0]}}"/>
23+
<argument name="streetLine2" type="string" defaultValue="{{CustomerAddressSimple.street[1]}}"/>
24+
<argument name="city" type="string" defaultValue="{{CustomerAddressSimple.city}}"/>
25+
<argument name="countryId" type="string" defaultValue="{{CustomerAddressSimple.country_id}}"/>
26+
<argument name="state" type="string" defaultValue="{{CustomerAddressSimple.state}}"/>
27+
<argument name="province" type="string" defaultValue=""/>
28+
<argument name="postcode" type="string" defaultValue="{{CustomerAddressSimple.postcode}}"/>
29+
<argument name="telephone" type="string" defaultValue="{{CustomerAddressSimple.telephone}}"/>
30+
<argument name="fax" type="string" defaultValue="{{CustomerAddressSimple.fax}}"/>
31+
<argument name="vatNumber" type="string" defaultValue=""/>
32+
</arguments>
33+
34+
<waitForElementVisible selector="{{AdminOrderFormShippingAddressSection.NamePrefix}}" stepKey="waitForInputVisible"/>
35+
<seeInField selector="{{AdminOrderFormShippingAddressSection.NamePrefix}}" userInput="{{prefix}}" stepKey="verifyPrefix"/>
36+
<seeInField selector="{{AdminOrderFormShippingAddressSection.FirstName}}" userInput="{{firstname}}" stepKey="verifyFirstName"/>
37+
<seeInField selector="{{AdminOrderFormShippingAddressSection.MiddleName}}" userInput="{{middleName}}" stepKey="verifyMiddleName"/>
38+
<seeInField selector="{{AdminOrderFormShippingAddressSection.LastName}}" userInput="{{lastname}}" stepKey="verifyLastName"/>
39+
<seeInField selector="{{AdminOrderFormShippingAddressSection.NameSuffix}}" userInput="{{suffix}}" stepKey="verifySuffix"/>
40+
<seeInField selector="{{AdminOrderFormShippingAddressSection.Company}}" userInput="{{company}}" stepKey="verifyCompany"/>
41+
<seeInField selector="{{AdminOrderFormShippingAddressSection.StreetLine1}}" userInput="{{streetLine1}}" stepKey="verifyStreetLine1"/>
42+
<seeInField selector="{{AdminOrderFormShippingAddressSection.StreetLine2}}" userInput="{{streetLine2}}" stepKey="verifyStreetLine2"/>
43+
<seeInField selector="{{AdminOrderFormShippingAddressSection.City}}" userInput="{{city}}" stepKey="verifyCity"/>
44+
<seeInField selector="{{AdminOrderFormShippingAddressSection.Country}}" userInput="{{countryId}}" stepKey="verifyCountry"/>
45+
<seeInField selector="{{AdminOrderFormShippingAddressSection.State}}" userInput="{{state}}" stepKey="verifyState"/>
46+
<seeInField selector="{{AdminOrderFormShippingAddressSection.Province}}" userInput="{{province}}" stepKey="verifyProvince"/>
47+
<seeInField selector="{{AdminOrderFormShippingAddressSection.PostalCode}}" userInput="{{postcode}}" stepKey="verifyPostalCode"/>
48+
<seeInField selector="{{AdminOrderFormShippingAddressSection.Phone}}" userInput="{{telephone}}" stepKey="verifyPhone"/>
49+
<seeInField selector="{{AdminOrderFormShippingAddressSection.Fax}}" userInput="{{fax}}" stepKey="verifyFax"/>
50+
<seeInField selector="{{AdminOrderFormShippingAddressSection.VatNumber}}" userInput="{{vatNumber}}" stepKey="verifyVatNumber"/>
51+
</actionGroup>
52+
</actionGroups>

app/code/Magento/Sales/view/adminhtml/templates/order/create/form/address.phtml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,10 @@ endif; ?>
142142
order.bindAddressFields('{$block->escapeJs($_addressChoiceContainerId)}');
143143
144144
script;
145-
if ($block->getIsShipping() && $block->getIsAsBilling()):
146-
$scriptString .= <<<script
147-
order.disableShippingAddress(true);
145+
if ($block->getIsShipping()):
146+
$disable = $block->getIsAsBilling() ? 'true' : 'false';
147+
$scriptString .= <<<script
148+
order.disableShippingAddress({$disable});
148149
149150
script;
150151
endif;

dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductLinkRepositoryInterfaceTest.php

Lines changed: 121 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,100 +4,175 @@
44
* Copyright © Magento, Inc. All rights reserved.
55
* See COPYING.txt for license details.
66
*/
7+
declare(strict_types=1);
8+
79
namespace Magento\Catalog\Api;
810

11+
use Magento\Catalog\Model\ProductLink\Link;
12+
use Magento\Framework\ObjectManagerInterface;
13+
use Magento\Framework\Webapi\Rest\Request;
914
use Magento\TestFramework\Helper\Bootstrap;
1015
use Magento\TestFramework\TestCase\WebapiAbstract;
1116

17+
/**
18+
* Class checks product relations functionality
19+
*
20+
* @see \Magento\Catalog\Api\ProductLinkRepositoryInterface
21+
*/
1222
class ProductLinkRepositoryInterfaceTest extends WebapiAbstract
1323
{
24+
/**
25+
* @var string
26+
*/
1427
const SERVICE_NAME = 'catalogProductLinkRepositoryV1';
28+
29+
/**
30+
* @var string
31+
*/
1532
const SERVICE_VERSION = 'V1';
33+
34+
/**
35+
* @var string
36+
*/
1637
const RESOURCE_PATH = '/V1/products/';
1738

1839
/**
19-
* @var \Magento\Framework\ObjectManagerInterface
40+
* @var ObjectManagerInterface
2041
*/
21-
protected $objectManager;
42+
private $objectManager;
2243

44+
/**
45+
* @var ProductLinkManagementInterface
46+
*/
47+
private $linkManagement;
48+
49+
/**
50+
* @inheritdoc
51+
*/
2352
protected function setUp(): void
2453
{
54+
parent::setUp();
55+
2556
$this->objectManager = Bootstrap::getObjectManager();
57+
$this->linkManagement = $this->objectManager->get(ProductLinkManagementInterface::class);
2658
}
2759

2860
/**
2961
* @magentoApiDataFixture Magento/Catalog/_files/products_related_multiple.php
30-
* @magentoAppIsolation enabled
62+
*
63+
* @return void
3164
*/
32-
public function testDelete()
65+
public function testDelete(): void
3366
{
3467
$productSku = 'simple_with_cross';
35-
$linkedSku = 'simple';
3668
$linkType = 'related';
37-
$this->_webApiCall(
38-
[
39-
'rest' => [
40-
'resourcePath' => self::RESOURCE_PATH . $productSku . '/links/' . $linkType . '/' . $linkedSku,
41-
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_DELETE,
42-
],
43-
'soap' => [
44-
'service' => self::SERVICE_NAME,
45-
'serviceVersion' => self::SERVICE_VERSION,
46-
'operation' => self::SERVICE_NAME . 'DeleteById',
47-
],
48-
],
49-
[
50-
'sku' => $productSku,
51-
'type' => $linkType,
52-
'linkedProductSku' => $linkedSku
53-
]
54-
);
55-
/** @var \Magento\Catalog\Model\ProductLink\Management $linkManagement */
56-
$linkManagement = $this->objectManager->create(\Magento\Catalog\Api\ProductLinkManagementInterface::class);
57-
$linkedProducts = $linkManagement->getLinkedItemsByType($productSku, $linkType);
69+
$this->deleteApiCall($productSku, $linkType, 'simple');
70+
$linkedProducts = $this->linkManagement->getLinkedItemsByType($productSku, $linkType);
5871
$this->assertCount(1, $linkedProducts);
59-
/** @var \Magento\Catalog\Api\Data\ProductLinkInterface $product */
6072
$product = current($linkedProducts);
61-
$this->assertEquals($product->getLinkedProductSku(), 'simple_with_cross_two');
73+
$this->assertEquals('simple_with_cross_two', $product->getLinkedProductSku());
74+
}
75+
76+
/**
77+
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
78+
*
79+
* @return void
80+
*/
81+
public function testDeleteNotExistedProductLink(): void
82+
{
83+
$this->expectException(\Exception::class);
84+
$this->expectExceptionMessage((string)__("Product %1 doesn't have linked %2 as %3"));
85+
$this->deleteApiCall('simple', 'related', 'not_exists_product');
6286
}
6387

6488
/**
6589
* @magentoApiDataFixture Magento/Catalog/_files/products_related.php
90+
*
91+
* @return void
6692
*/
67-
public function testSave()
93+
public function testSave(): void
6894
{
6995
$productSku = 'simple_with_cross';
7096
$linkType = 'related';
97+
$data = [
98+
'entity' => [
99+
Link::KEY_SKU => 'simple_with_cross',
100+
Link::KEY_LINK_TYPE => 'related',
101+
Link::KEY_LINKED_PRODUCT_SKU => 'simple',
102+
Link::KEY_LINKED_PRODUCT_TYPE => 'simple',
103+
Link::KEY_POSITION => 1000,
104+
],
105+
];
106+
$this->saveApiCall($productSku, $data);
107+
$actual = $this->linkManagement->getLinkedItemsByType($productSku, $linkType);
108+
$this->assertCount(1, $actual, 'Invalid actual linked products count');
109+
$this->assertEquals(1000, $actual[0]->getPosition(), 'Product position is not updated');
110+
}
71111

72-
$serviceInfo = [
112+
/**
113+
* Get service info for api call
114+
*
115+
* @param string $resourcePath
116+
* @param string $httpMethod
117+
* @param string $operation
118+
* @return array
119+
*/
120+
private function getServiceInfo(string $resourcePath, string $httpMethod, string $operation): array
121+
{
122+
return [
73123
'rest' => [
74-
'resourcePath' => self::RESOURCE_PATH . $productSku . '/links',
75-
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT,
124+
'resourcePath' => self::RESOURCE_PATH . $resourcePath,
125+
'httpMethod' => $httpMethod,
76126
],
77127
'soap' => [
78128
'service' => self::SERVICE_NAME,
79129
'serviceVersion' => self::SERVICE_VERSION,
80-
'operation' => self::SERVICE_NAME . 'Save',
130+
'operation' => self::SERVICE_NAME . $operation,
81131
],
82132
];
133+
}
83134

84-
$this->_webApiCall(
135+
/**
136+
* Make api call to delete product link
137+
*
138+
* @param string $productSku
139+
* @param string $linkType
140+
* @param string $linkedSku
141+
* @return array|int|string|float|bool
142+
*/
143+
private function deleteApiCall(string $productSku, string $linkType, string $linkedSku)
144+
{
145+
$serviceInfo = $this->getServiceInfo(
146+
$productSku . '/links/' . $linkType . '/' . $linkedSku,
147+
Request::HTTP_METHOD_DELETE,
148+
'DeleteById'
149+
);
150+
151+
return $this->_webApiCall(
85152
$serviceInfo,
86153
[
87-
'entity' => [
88-
'sku' => 'simple_with_cross',
89-
'link_type' => 'related',
90-
'linked_product_sku' => 'simple',
91-
'linked_product_type' => 'simple',
92-
'position' => 1000,
93-
]
154+
'sku' => $productSku,
155+
'type' => $linkType,
156+
'linkedProductSku' => $linkedSku,
94157
]
95158
);
159+
}
96160

97-
/** @var \Magento\Catalog\Model\ProductLink\Management $linkManagement */
98-
$linkManagement = $this->objectManager->get(\Magento\Catalog\Api\ProductLinkManagementInterface::class);
99-
$actual = $linkManagement->getLinkedItemsByType($productSku, $linkType);
100-
$this->assertCount(1, $actual, 'Invalid actual linked products count');
101-
$this->assertEquals(1000, $actual[0]->getPosition(), 'Product position is not updated');
161+
/**
162+
* Make api call to save product link
163+
*
164+
* @param string $productSku
165+
* @param array $data
166+
* @return array|bool|float|int|string
167+
*/
168+
private function saveApiCall(string $productSku, array $data)
169+
{
170+
$serviceInfo = $this->getServiceInfo(
171+
$productSku . '/links',
172+
Request::HTTP_METHOD_PUT,
173+
'Save'
174+
);
175+
176+
return $this->_webApiCall($serviceInfo, $data);
102177
}
103178
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
namespace Magento\Catalog\Controller\Adminhtml\Category;
9+
10+
use Magento\Catalog\Helper\DefaultCategory;
11+
use Magento\TestFramework\TestCase\AbstractBackendController;
12+
13+
/**
14+
* Tests for catalog category Add controller
15+
*
16+
* @see \Magento\Catalog\Controller\Adminhtml\Category\Add
17+
*
18+
* @magentoAppArea adminhtml
19+
* @magentoDbIsolation enabled
20+
*/
21+
class AddTest extends AbstractBackendController
22+
{
23+
/**
24+
* @var DefaultCategory
25+
*/
26+
private $defaultCategoryHelper;
27+
28+
/**
29+
* @inheritdoc
30+
*/
31+
protected function setUp(): void
32+
{
33+
parent::setUp();
34+
35+
$this->defaultCategoryHelper = $this->_objectManager->get(DefaultCategory::class);
36+
}
37+
38+
/**
39+
* @return void
40+
*/
41+
public function testExecuteWithoutParams(): void
42+
{
43+
$this->dispatch('backend/catalog/category/add');
44+
$this->assertRedirect($this->stringContains('catalog/category/index'));
45+
}
46+
47+
/**
48+
* @return void
49+
*/
50+
public function testExecuteAsAjax(): void
51+
{
52+
$this->getRequest()->setQueryValue('isAjax', true);
53+
$this->getRequest()->setParam('parent', $this->defaultCategoryHelper->getId());
54+
$this->dispatch('backend/catalog/category/add');
55+
$this->assertJson($this->getResponse()->getBody());
56+
}
57+
}

0 commit comments

Comments
 (0)