Skip to content

Commit 0ad9891

Browse files
authored
Merge pull request #1241 from magento-tsg/2.1.8-develop-pr20
[TSG] Backporting for 2.1 (pr20) (2.1.8)
2 parents 6dd8451 + 0893439 commit 0ad9891

File tree

15 files changed

+621
-46
lines changed

15 files changed

+621
-46
lines changed

app/code/Magento/Eav/Model/Entity/Attribute/Backend/ArrayBackend.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,16 @@ public function beforeSave($object)
3838
*/
3939
public function validate($object)
4040
{
41-
$attributeCode = $this->getAttribute()->getAttributeCode();
41+
$attribute = $this->getAttribute();
42+
$attributeCode = $attribute->getAttributeCode();
4243
$data = $object->getData($attributeCode);
44+
$assigned = $object->hasData($attributeCode);
4345
if (is_array($data)) {
4446
$object->setData($attributeCode, implode(',', array_filter($data)));
45-
} elseif (empty($data)) {
47+
} elseif (empty($data) && $assigned) {
4648
$object->setData($attributeCode, null);
4749
}
50+
4851
return parent::validate($object);
4952
}
5053
}

app/code/Magento/Swatches/Helper/Data.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,14 @@ private function getAllSizeImages(ModelProduct $product, $imageFile)
346346
*/
347347
private function getSwatchAttributes(Product $product)
348348
{
349-
$swatchAttributes = $this->swatchAttributesProvider->provide($product);
350-
return $swatchAttributes;
349+
$attributes = $this->swatchAttributesProvider->provide($product) ?: [];
350+
foreach ($attributes as $attribute) {
351+
if (!$attribute->hasData(Swatch::SWATCH_INPUT_TYPE_KEY)) {
352+
$this->populateAdditionalDataEavAttribute($attribute);
353+
}
354+
}
355+
356+
return $attributes;
351357
}
352358

353359
/**

app/code/Magento/Swatches/Test/Unit/Helper/DataTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,10 @@ public function testGetSwatchAttributesAsArray($optionsArray, $attributeData, $e
552552
$storeMock->method('getId')->willReturn($storeId);
553553
$this->storeManagerMock->method('getStore')->willReturn($storeMock);
554554

555-
$this->attributeMock->method('getData')->with('')->willReturn($attributeData);
555+
$this->attributeMock
556+
->method('getData')
557+
->withConsecutive(['additional_data'], [''])
558+
->will($this->onConsecutiveCalls('', $attributeData));
556559

557560
$sourceMock = $this->getMock(
558561
\Magento\Eav\Model\Entity\Attribute\Source\AbstractSource::class,

app/code/Magento/Tax/Setup/InstallData.php

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace Magento\Tax\Setup;
88

9+
use Magento\Directory\Model\ResourceModel\Region\CollectionFactory;
910
use Magento\Framework\Setup\InstallDataInterface;
1011
use Magento\Framework\Setup\ModuleContextInterface;
1112
use Magento\Framework\Setup\ModuleDataSetupInterface;
@@ -22,14 +23,32 @@ class InstallData implements InstallDataInterface
2223
*/
2324
private $taxSetupFactory;
2425

26+
/**
27+
* Region collection factory.
28+
*
29+
* @var \Magento\Directory\Model\ResourceModel\Region\CollectionFactory
30+
*/
31+
private $regionCollectionFactory;
32+
33+
/**
34+
* Region collection.
35+
*
36+
* @var \Magento\Directory\Model\ResourceModel\Region\Collection
37+
*/
38+
private $regionCollection;
39+
2540
/**
2641
* Init
2742
*
2843
* @param TaxSetupFactory $taxSetupFactory
44+
* @param CollectionFactory $collectionFactory
2945
*/
30-
public function __construct(TaxSetupFactory $taxSetupFactory)
31-
{
46+
public function __construct(
47+
TaxSetupFactory $taxSetupFactory,
48+
CollectionFactory $collectionFactory
49+
) {
3250
$this->taxSetupFactory = $taxSetupFactory;
51+
$this->regionCollectionFactory = $collectionFactory;
3352
}
3453

3554
/**
@@ -101,22 +120,48 @@ public function install(ModuleDataSetupInterface $setup, ModuleContextInterface
101120
[
102121
'tax_calculation_rate_id' => 1,
103122
'tax_country_id' => 'US',
104-
'tax_region_id' => 12,
123+
'tax_region_id' => $this->getRegionId('CA'),
105124
'tax_postcode' => '*',
106125
'code' => 'US-CA-*-Rate 1',
107126
'rate' => '8.2500',
108127
],
109128
[
110129
'tax_calculation_rate_id' => 2,
111130
'tax_country_id' => 'US',
112-
'tax_region_id' => 43,
131+
'tax_region_id' => $this->getRegionId('NY'),
113132
'tax_postcode' => '*',
114133
'code' => 'US-NY-*-Rate 1',
115134
'rate' => '8.3750'
116135
],
117136
];
137+
118138
foreach ($data as $row) {
119139
$setup->getConnection()->insertForce($setup->getTable('tax_calculation_rate'), $row);
120140
}
121141
}
142+
143+
/**
144+
* Return region id by code.
145+
*
146+
* @param string $regionCode
147+
* @return string
148+
*/
149+
private function getRegionId($regionCode)
150+
{
151+
if ($this->regionCollection === null) {
152+
/** @var \Magento\Directory\Model\ResourceModel\Region\Collection $regionCollection */
153+
$this->regionCollection = $this->regionCollectionFactory->create();
154+
$this->regionCollection->addCountryFilter('US')
155+
->addRegionCodeOrNameFilter(['CA', 'NY']);
156+
}
157+
158+
$regionId = '';
159+
/** @var \Magento\Directory\Model\Region $item */
160+
$item = $this->regionCollection->getItemByColumnValue('code', $regionCode);
161+
if ($item) {
162+
$regionId = $item->getId();
163+
}
164+
165+
return $regionId;
166+
}
122167
}

dev/tests/functional/tests/app/Magento/Backend/Test/Fixture/Source/Date.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@
66

77
namespace Magento\Backend\Test\Fixture\Source;
88

9-
use Magento\Framework\App\ObjectManager;
109
use Magento\Mtf\Fixture\DataSource;
1110

1211
/**
1312
* Class Date.
1413
*
1514
* Data keys:
1615
* - pattern (Format a local time/date with delta, e.g. 'm/d/Y -3 days' = current day - 3 days)
17-
* - apply_timezone (true if it is needed to apply timezone)
1816
*/
1917
class Date extends DataSource
2018
{
@@ -37,17 +35,7 @@ public function __construct(array $params, $data = [])
3735
if (!$timestamp) {
3836
throw new \Exception('Invalid date format for "' . $this->params['attribute_code'] . '" field');
3937
}
40-
if (isset($data['apply_timezone']) && $data['apply_timezone'] === true) {
41-
42-
$timezone = ObjectManager::getInstance()
43-
->get(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::class);
44-
$date = new \DateTime();
45-
$date->setTimestamp($timestamp);
46-
$date->setTimezone(new \DateTimeZone($timezone->getConfigTimezone()));
47-
$date = $date->format(str_replace($delta, '', $data['pattern']));
48-
} else {
49-
$date = date(str_replace($delta, '', $data['pattern']), $timestamp);
50-
}
38+
$date = date(str_replace($delta, '', $data['pattern']), $timestamp);
5139
if (!$date) {
5240
$date = date('m/d/Y');
5341
}

dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Grid.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ class Grid extends DataGrid
7676
*/
7777
protected $firstRowSelector = '//tbody/tr[1]/td[contains(@class,"data-grid-actions-cell")]/a';
7878

79+
/**
80+
* Global seach block selector.
81+
*
82+
* @var string
83+
*/
84+
private $globalSearch = '.search-global';
85+
7986
/**
8087
* Start to create new order.
8188
*
@@ -106,4 +113,33 @@ public function getPurchasePointStoreGroups()
106113

107114
return $result;
108115
}
116+
117+
/**
118+
* {@inheritdoc}
119+
*/
120+
public function selectItems(array $items, $isSortable = true)
121+
{
122+
if ($isSortable) {
123+
$this->sortGridByField('ID');
124+
}
125+
foreach ($items as $item) {
126+
//Hover on search block is made to avoid click on invisible element currentPage
127+
$searchBlock = $this->browser->find($this->globalSearch);
128+
$searchBlock->hover();
129+
$this->_rootElement->find($this->currentPage, Locator::SELECTOR_XPATH)->setValue('');
130+
$this->waitLoader();
131+
$selectItem = $this->getRow($item)->find($this->selectItem);
132+
do {
133+
if ($selectItem->isVisible()) {
134+
if (!$selectItem->isSelected()) {
135+
$selectItem->click();
136+
}
137+
break;
138+
}
139+
} while ($this->nextPage());
140+
if (!$selectItem->isVisible()) {
141+
throw new \Exception("Searched item was not found\n" . print_r($item, true));
142+
}
143+
}
144+
}
109145
}

dev/tests/functional/tests/app/Magento/Ui/Test/Block/Adminhtml/DataGrid.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,23 @@ public function selectMassAction($massActionSelection)
346346
public function selectAction($action)
347347
{
348348
$actionType = is_array($action) ? key($action) : $action;
349-
$this->getGridHeaderElement()->find($this->actionButton)->click();
350-
$this->getGridHeaderElement()
351-
->find(sprintf($this->actionList, $actionType), Locator::SELECTOR_XPATH)
352-
->click();
349+
// Find Action button (dropdown actually)
350+
$actionButton = $this->getGridHeaderElement()->find($this->actionButton);
351+
// Click it to show options (actions)
352+
$actionButton->click();
353+
// Find needed element (action) to click on
354+
$actionElement = $this->getGridHeaderElement()
355+
->find(sprintf($this->actionList, $actionType), Locator::SELECTOR_XPATH);
356+
// Scroll to show it (action option) on viewport. It can be out of viewport because of small window height.
357+
$actionElement->hover();
358+
// In case of small window after scroll to action element it may became hidden
359+
// It because of appearance special top-stick panel of actions
360+
// So we need to click action button again to show list of actions
361+
if (!$actionElement->isVisible()) {
362+
$actionButton->click();
363+
}
364+
// Click on action element to run appropriate command
365+
$actionElement->click();
353366
if (is_array($action)) {
354367
$this->getGridHeaderElement()
355368
->find(sprintf($this->actionList, end($action)), Locator::SELECTOR_XPATH)

dev/tests/functional/tests/app/Magento/Ui/Test/Constraint/AssertAdminUrlNoAccess.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,10 @@ class AssertAdminUrlNoAccess extends AbstractConstraint
2828
*
2929
* @var array
3030
*/
31-
private $urls = [
31+
protected $urls = [
3232
'mui/index/render/?namespace=cms_block_listing&search=&filters%5Bplaceholder%5D=true'
3333
. '&paging%5BpageSize%5D=20&paging%5Bcurrent%5D=1&sorting%5Bfield%5D=block_id'
3434
. '&sorting%5Bdirection%5D=asc&isAjax=true',
35-
'mui/index/render/handle/bulk_bulk_details_modal/buttons/1/?namespace=support_report_listing'
36-
. '&filters%5Bplaceholder%5D=true&paging%5BpageSize%5D=20&paging%5Bcurrent%5D=1&sorting%5Bfield%5D=report_id'
37-
. '&sorting%5Bdirection%5D=asc&isAjax=true',
3835
'mui/index/render/?namespace=customer_listing&search=&filters%5Bplaceholder%5D=true'
3936
. '&paging%5BpageSize%5D=20&paging%5Bcurrent%5D=1&sorting%5Bfield%5D=entity_id&sorting%5Bdirection%5D=asc'
4037
. '&isAjax=true',

dev/tests/functional/tests/app/Magento/Webapi/Test/Constraint/AssertWebapiNoAccessByCookie.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@ public function processAssert(
4141
) {
4242
// Create and login a customer on frontend
4343
$customer->persist();
44-
$this->objectManager->create(
45-
'Magento\Customer\Test\TestStep\LoginCustomerOnFrontendStep',
44+
/** @var \Magento\Customer\Test\TestStep\LoginCustomerOnFrontendStep $customerLoginStep */
45+
$customerLoginStep = $this->objectManager->create(
46+
\Magento\Customer\Test\TestStep\LoginCustomerOnFrontendStep::class,
4647
['customer' => $customer]
47-
)->run();
48+
);
49+
$customerLoginStep->run();
4850

4951
// Go to cms page with form as logged in customer and submit request
5052
$browser->open($_ENV['app_frontend_url'] . $cms->getIdentifier());
@@ -55,6 +57,8 @@ public function processAssert(
5557
$browser->getHtmlSource(),
5658
'Customer should not have customer webapi access through cookies.'
5759
);
60+
61+
$customerLoginStep->cleanup();
5862
}
5963

6064
/**

dev/tests/functional/tests/app/Magento/Webapi/Test/TestCase/CustomerWebapisPermissionTest.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,28 +82,33 @@ public function __inject(
8282
\Magento\Config\Test\TestStep\SetupConfigurationStep::class,
8383
['configData' => 'wysiwyg_disabled']
8484
)->run();
85+
8586
return ['cmsOriginal' => $cmsOriginal];
8687
}
8788

8889
/**
8990
* Construct cms page with a form that contains webapi request and 'Submit Request' button.
9091
*
9192
* @param CmsPage $cmsOriginal
93+
* @param string $url
94+
* @param string $method
9295
* @return array
9396
*/
94-
public function test(CmsPage $cmsOriginal)
97+
public function test(CmsPage $cmsOriginal, $url, $method = 'POST')
9598
{
9699
$this->cmsPageIndex->open();
97100
$this->cmsPageIndex->getCmsPageGridBlock()->searchAndOpen(['title' => $cmsOriginal->getTitle()]);
98101
$data = $cmsOriginal->getData();
99-
$content = '<p><form action="'
100-
. $_ENV['app_frontend_url']
101-
. 'rest/V1/carts/mine/balance/apply" method="POST">'
102-
. '<input type="submit" value="Submit Request" /></form></p>';
102+
$content = <<<HTML
103+
<form action="$url" method="$method" >
104+
<input type="submit" value="Submit Request" />
105+
</form>
106+
HTML;
103107
$data['content'] = ['content' => $content];
104108
$cms = $this->factory->createByCode('cmsPage', ['data' => $data]);
105109
$this->cmsPageNew->getPageForm()->fill($cms);
106110
$this->cmsPageNew->getPageMainActions()->save();
111+
107112
return ['cms' => $cms];
108113
}
109114
}

0 commit comments

Comments
 (0)