Skip to content

Commit 7ddb990

Browse files
committed
Merge branch 'develop' of github.com:magento-eqp/magento2ce into MM-2551-EQP-Sniffs-To-Magento
2 parents ddd5c03 + ec81bc3 commit 7ddb990

File tree

29 files changed

+633
-143
lines changed

29 files changed

+633
-143
lines changed

app/code/Magento/OfflineShipping/Model/ResourceModel/Carrier/Tablerate.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Magento\OfflineShipping\Model\ResourceModel\Carrier;
1313

1414
use Magento\Framework\Filesystem;
15-
use Magento\Framework\Filesystem\DirectoryList;
1615
use Magento\OfflineShipping\Model\ResourceModel\Carrier\Tablerate\Import;
1716
use Magento\OfflineShipping\Model\ResourceModel\Carrier\Tablerate\RateQuery;
1817
use Magento\OfflineShipping\Model\ResourceModel\Carrier\Tablerate\RateQueryFactory;
@@ -321,9 +320,13 @@ public function getConditionName(\Magento\Framework\DataObject $object)
321320
*/
322321
private function getCsvFile($filePath)
323322
{
324-
$tmpDirectory = $this->filesystem->getDirectoryRead(DirectoryList::SYS_TMP);
325-
$path = $tmpDirectory->getRelativePath($filePath);
326-
return $tmpDirectory->openFile($path);
323+
$pathInfo = pathInfo($filePath);
324+
$dirName = isset($pathInfo['dirname']) ? $pathInfo['dirname'] : '';
325+
$fileName = isset($pathInfo['basename']) ? $pathInfo['basename'] : '';
326+
327+
$directoryRead = $this->filesystem->getDirectoryReadByPath($dirName);
328+
329+
return $directoryRead->openFile($fileName);
327330
}
328331

329332
/**
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\OfflineShipping\Test\Unit\Model\ResourceModel\Carrier;
8+
9+
use Magento\OfflineShipping\Model\ResourceModel\Carrier\Tablerate;
10+
use Magento\OfflineShipping\Model\ResourceModel\Carrier\Tablerate\Import;
11+
use Magento\OfflineShipping\Model\ResourceModel\Carrier\Tablerate\RateQueryFactory;
12+
13+
/**
14+
* Unit test for Magento\OfflineShipping\Model\ResourceModel\Carrier\Tablerate
15+
*
16+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
17+
*/
18+
class TablerateTest extends \PHPUnit\Framework\TestCase
19+
{
20+
/**
21+
* @var Tablerate
22+
*/
23+
private $model;
24+
25+
/**
26+
* @var \PHPUnit_Framework_MockObject_MockObject
27+
*/
28+
private $storeManagerMock;
29+
30+
/**
31+
* @var \PHPUnit_Framework_MockObject_MockObject
32+
*/
33+
private $filesystemMock;
34+
35+
/**
36+
* @var \PHPUnit_Framework_MockObject_MockObject
37+
*/
38+
private $resource;
39+
40+
/**
41+
* @var \PHPUnit_Framework_MockObject_MockObject
42+
*/
43+
private $importMock;
44+
45+
protected function setUp()
46+
{
47+
$contextMock = $this->createMock(\Magento\Framework\Model\ResourceModel\Db\Context::class);
48+
$loggerMock = $this->createMock(\Psr\Log\LoggerInterface::class);
49+
$coreConfigMock = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
50+
$this->storeManagerMock = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
51+
$carrierTablerateMock = $this->createMock(\Magento\OfflineShipping\Model\Carrier\Tablerate::class);
52+
$this->filesystemMock = $this->createMock(\Magento\Framework\Filesystem::class);
53+
$this->importMock = $this->createMock(Import::class);
54+
$rateQueryFactoryMock = $this->createMock(RateQueryFactory::class);
55+
$this->resource = $this->createMock(\Magento\Framework\App\ResourceConnection::class);
56+
57+
$contextMock->expects($this->once())->method('getResources')->willReturn($this->resource);
58+
59+
$this->model = new Tablerate(
60+
$contextMock,
61+
$loggerMock,
62+
$coreConfigMock,
63+
$this->storeManagerMock,
64+
$carrierTablerateMock,
65+
$this->filesystemMock,
66+
$this->importMock,
67+
$rateQueryFactoryMock
68+
);
69+
}
70+
71+
public function testUploadAndImport()
72+
{
73+
$_FILES['groups']['tmp_name']['tablerate']['fields']['import']['value'] = 'some/path/to/file';
74+
$object = $this->createPartialMock(
75+
\Magento\OfflineShipping\Model\Config\Backend\Tablerate::class,
76+
['getScopeId']
77+
);
78+
79+
$websiteMock = $this->createMock(\Magento\Store\Api\Data\WebsiteInterface::class);
80+
$directoryReadMock = $this->createMock(\Magento\Framework\Filesystem\Directory\ReadInterface::class);
81+
$fileReadMock = $this->createMock(\Magento\Framework\Filesystem\File\ReadInterface::class);
82+
$connectionMock = $this->createMock(\Magento\Framework\DB\Adapter\AdapterInterface::class);
83+
84+
$this->storeManagerMock->expects($this->once())->method('getWebsite')->willReturn($websiteMock);
85+
$object->expects($this->once())->method('getScopeId')->willReturn(1);
86+
$websiteMock->expects($this->once())->method('getId')->willReturn(1);
87+
88+
$this->filesystemMock->expects($this->once())->method('getDirectoryReadByPath')
89+
->with('some/path/to')->willReturn($directoryReadMock);
90+
$directoryReadMock->expects($this->once())->method('openFile')
91+
->with('file')->willReturn($fileReadMock);
92+
93+
$this->resource->expects($this->once())->method('getConnection')->willReturn($connectionMock);
94+
95+
$connectionMock->expects($this->once())->method('beginTransaction');
96+
$connectionMock->expects($this->once())->method('delete');
97+
$connectionMock->expects($this->once())->method('commit');
98+
99+
$this->importMock->expects($this->once())->method('getColumns')->willReturn([]);
100+
$this->importMock->expects($this->once())->method('getData')->willReturn([]);
101+
102+
$this->model->uploadAndImport($object);
103+
unset($_FILES['groups']);
104+
}
105+
}

app/code/Magento/Quote/Setup/UpgradeSchema.php

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Quote\Setup;
77

8+
use Magento\Framework\DB\Ddl\Table;
89
use Magento\Framework\Setup\UpgradeSchemaInterface;
910
use Magento\Framework\Setup\ModuleContextInterface;
1011
use Magento\Framework\Setup\SchemaSetupInterface;
@@ -40,7 +41,7 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
4041
'street',
4142
'street',
4243
[
43-
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
44+
'type' => Table::TYPE_TEXT,
4445
'length' => 255,
4546
'comment' => 'Street'
4647
]
@@ -61,7 +62,7 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
6162
$setup->getTable('quote_address'),
6263
'shipping_method',
6364
[
64-
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
65+
'type' => Table::TYPE_TEXT,
6566
'length' => 120
6667
]
6768
);
@@ -72,33 +73,53 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
7273
$setup->getTable('quote_address', self::$connectionName),
7374
'firstname',
7475
[
75-
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
76+
'type' => Table::TYPE_TEXT,
7677
'length' => 255,
7778
]
7879
)->modifyColumn(
7980
$setup->getTable('quote_address', self::$connectionName),
8081
'middlename',
8182
[
82-
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
83+
'type' => Table::TYPE_TEXT,
8384
'length' => 40,
8485
]
8586
)->modifyColumn(
8687
$setup->getTable('quote_address', self::$connectionName),
8788
'lastname',
8889
[
89-
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
90+
'type' => Table::TYPE_TEXT,
9091
'length' => 255,
9192
]
9293
)->modifyColumn(
9394
$setup->getTable('quote', self::$connectionName),
9495
'updated_at',
9596
[
96-
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
97+
'type' => Table::TYPE_TIMESTAMP,
9798
'nullable' => false,
98-
'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT_UPDATE,
99+
'default' => Table::TIMESTAMP_INIT_UPDATE,
99100
]
100101
);
101102
}
103+
if (version_compare($context->getVersion(), '2.0.7', '<')) {
104+
$connection = $setup->getConnection(self::$connectionName);
105+
$connection->modifyColumn(
106+
$setup->getTable('quote_address', self::$connectionName),
107+
'telephone',
108+
['type' => Table::TYPE_TEXT, 'length' => 255]
109+
)->modifyColumn(
110+
$setup->getTable('quote_address', self::$connectionName),
111+
'fax',
112+
['type' => Table::TYPE_TEXT, 'length' => 255]
113+
)->modifyColumn(
114+
$setup->getTable('quote_address', self::$connectionName),
115+
'region',
116+
['type' => Table::TYPE_TEXT, 'length' => 255]
117+
)->modifyColumn(
118+
$setup->getTable('quote_address', self::$connectionName),
119+
'city',
120+
['type' => Table::TYPE_TEXT, 'length' => 255]
121+
);
122+
}
102123
$setup->endSetup();
103124
}
104125
}

app/code/Magento/Quote/etc/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
9-
<module name="Magento_Quote" setup_version="2.0.6">
9+
<module name="Magento_Quote" setup_version="2.0.7">
1010
</module>
1111
</config>

app/code/Magento/Swatches/Model/Plugin/EavAttribute.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,17 @@ protected function setProperOptionsArray(Attribute $attribute)
130130
$swatchesArray = $attribute->getData('swatchtext');
131131
}
132132
if ($canReplace == true) {
133-
$attribute->setData('option', $optionsArray);
134-
$attribute->setData('default', $defaultValue);
135-
$attribute->setData('swatch', $swatchesArray);
133+
if (!empty($optionsArray)) {
134+
$attribute->setData('option', $optionsArray);
135+
}
136+
if (!empty($defaultValue)) {
137+
$attribute->setData('default', $defaultValue);
138+
} else {
139+
$attribute->setData('default', [0 => $attribute->getDefaultValue()]);
140+
}
141+
if (!empty($swatchesArray)) {
142+
$attribute->setData('swatch', $swatchesArray);
143+
}
136144
}
137145
}
138146

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
8181
false
8282
);
8383
}
84-
if (version_compare($context->getVersion(), '2.0.2', '<')) {
84+
if (version_compare($context->getVersion(), '2.0.3', '<')) {
8585
//Update the tax_region_id
8686
$taxRateList = $this->taxRateRepository->getList($this->searchCriteriaFactory->create());
8787
/** @var \Magento\Tax\Api\Data\TaxRateInterface $taxRateData */
@@ -91,6 +91,9 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
9191
/** @var \Magento\Directory\Model\Region $region */
9292
$region = $this->directoryRegionFactory->create();
9393
$region->loadByCode($regionCode, $taxRateData->getTaxCountryId());
94+
if ($taxRateData->getTaxPostcode() === null) {
95+
$taxRateData->setTaxPostcode('*');
96+
}
9497
$taxRateData->setTaxRegionId($region->getRegionId());
9598
$this->taxRateRepository->save($taxRateData);
9699
}

app/code/Magento/Tax/etc/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
9-
<module name="Magento_Tax" setup_version="2.0.2">
9+
<module name="Magento_Tax" setup_version="2.0.3">
1010
<sequence>
1111
<module name="Magento_Catalog"/>
1212
<module name="Magento_Checkout"/>

app/code/Magento/Weee/Ui/DataProvider/Product/Form/Modifier/Manager/Website.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function getWebsites(ProductInterface $product, EavAttribute $eavAttribut
6868
if ($storeId = $this->locator->getStore()->getId()) {
6969
/** @var WebsiteInterface $website */
7070
$website = $this->storeManager->getStore($storeId)->getWebsite();
71-
$websites[$website->getId()] = [
71+
$websites[] = [
7272
'value' => $website->getId(),
7373
'label' => $this->formatLabel(
7474
$website->getName(),
@@ -81,7 +81,7 @@ public function getWebsites(ProductInterface $product, EavAttribute $eavAttribut
8181
if (!in_array($website->getId(), $product->getWebsiteIds())) {
8282
continue;
8383
}
84-
$websites[$website->getId()] = [
84+
$websites[] = [
8585
'value' => $website->getId(),
8686
'label' => $this->formatLabel(
8787
$website->getName(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Api;
7+
8+
use Magento\Eav\Api\Data\AttributeOptionInterface;
9+
use Magento\Eav\Api\Data\AttributeOptionLabelInterface;
10+
use Magento\TestFramework\TestCase\WebapiAbstract;
11+
12+
class ProductSwatchAttributeOptionManagementInterfaceTest extends WebapiAbstract
13+
{
14+
const SERVICE_NAME = 'catalogProductAttributeOptionManagementV1';
15+
const SERVICE_VERSION = 'V1';
16+
const RESOURCE_PATH = '/V1/products/attributes';
17+
18+
/**
19+
* @magentoApiDataFixture Magento/Swatches/_files/swatch_attribute.php
20+
* @dataProvider addDataProvider
21+
*/
22+
public function testAdd($optionData)
23+
{
24+
$testAttributeCode = 'color_swatch';
25+
$serviceInfo = [
26+
'rest' => [
27+
'resourcePath' => self::RESOURCE_PATH . '/' . $testAttributeCode . '/options',
28+
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST,
29+
],
30+
'soap' => [
31+
'service' => self::SERVICE_NAME,
32+
'serviceVersion' => self::SERVICE_VERSION,
33+
'operation' => self::SERVICE_NAME . 'add',
34+
],
35+
];
36+
37+
$response = $this->_webApiCall(
38+
$serviceInfo,
39+
[
40+
'attributeCode' => $testAttributeCode,
41+
'option' => $optionData,
42+
]
43+
);
44+
45+
$this->assertTrue($response);
46+
$updatedData = $this->getAttributeOptions($testAttributeCode);
47+
$lastOption = array_pop($updatedData);
48+
$this->assertEquals(
49+
$optionData[AttributeOptionInterface::STORE_LABELS][0][AttributeOptionLabelInterface::LABEL],
50+
$lastOption['label']
51+
);
52+
}
53+
54+
/**
55+
* @return array
56+
*/
57+
public function addDataProvider()
58+
{
59+
$optionPayload = [
60+
AttributeOptionInterface::LABEL => 'new color',
61+
AttributeOptionInterface::SORT_ORDER => 100,
62+
AttributeOptionInterface::IS_DEFAULT => true,
63+
AttributeOptionInterface::STORE_LABELS => [
64+
[
65+
AttributeOptionLabelInterface::LABEL => 'DE label',
66+
AttributeOptionLabelInterface::STORE_ID => 1,
67+
],
68+
],
69+
AttributeOptionInterface::VALUE => ''
70+
];
71+
72+
return [
73+
'option_without_value_node' => [
74+
$optionPayload
75+
],
76+
'option_with_value_node_that_starts_with_text' => [
77+
array_merge($optionPayload, [AttributeOptionInterface::VALUE => 'some_text'])
78+
],
79+
'option_with_value_node_that_starts_with_a_number' => [
80+
array_merge($optionPayload, [AttributeOptionInterface::VALUE => '123_some_text'])
81+
],
82+
83+
];
84+
}
85+
86+
/**
87+
* @param $testAttributeCode
88+
* @return array|bool|float|int|string
89+
*/
90+
private function getAttributeOptions($testAttributeCode)
91+
{
92+
$serviceInfo = [
93+
'rest' => [
94+
'resourcePath' => self::RESOURCE_PATH . '/' . $testAttributeCode . '/options',
95+
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET,
96+
],
97+
'soap' => [
98+
'service' => self::SERVICE_NAME,
99+
'serviceVersion' => self::SERVICE_VERSION,
100+
'operation' => self::SERVICE_NAME . 'getItems',
101+
],
102+
];
103+
return $this->_webApiCall($serviceInfo, ['attributeCode' => $testAttributeCode]);
104+
}
105+
}

0 commit comments

Comments
 (0)