Skip to content

Commit 7eb366d

Browse files
committed
Merge remote-tracking branch 'origin/2.0.15-develop' into 2.0.15-develop-pr14
2 parents b38737c + 1e9b79a commit 7eb366d

File tree

31 files changed

+1344
-252
lines changed

31 files changed

+1344
-252
lines changed

.travis.yml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
sudo: required
2+
dist: trusty
3+
addons:
4+
apt:
5+
packages:
6+
- mysql-server-5.6
7+
- mysql-client-core-5.6
8+
- mysql-client-5.6
9+
- postfix
110
language: php
211
php:
312
- 5.5
@@ -49,15 +58,7 @@ before_script:
4958
# Install MySQL 5.6, create DB for integration tests
5059
- >
5160
sh -c "if [ '$TEST_SUITE' = 'integration_part_1' ] || [ '$TEST_SUITE' = 'integration_part_2' ] || [ '$TEST_SUITE' = 'integration_integrity' ]; then
52-
sudo apt-get remove --purge mysql-common mysql-server-5.5 mysql-server-core-5.5 mysql-client-5.5 mysql-client-core-5.5;
53-
sudo apt-get autoremove;
54-
sudo apt-get autoclean;
55-
echo 'deb http://repo.mysql.com/apt/ubuntu/ precise mysql-apt-config' | sudo tee /etc/apt/sources.list.d/mysql.list;
56-
echo 'deb http://repo.mysql.com/apt/ubuntu/ precise mysql-5.6' | sudo tee /etc/apt/sources.list.d/mysql.list;
57-
curl -s http://ronaldbradford.com/mysql/mysql.gpg | sudo apt-key add -;
58-
sudo apt-get update;
59-
sudo apt-get install -y mysql-server;
60-
mysql -uroot -e 'SET @@global.sql_mode = NO_ENGINE_SUBSTITUTION; CREATE DATABASE magento_integration_tests;';
61+
mysql -u root -e 'SET @@global.sql_mode = NO_ENGINE_SUBSTITUTION; CREATE DATABASE magento_integration_tests;';
6162
mv dev/tests/integration/etc/install-config-mysql.travis.php.dist dev/tests/integration/etc/install-config-mysql.php;
6263
fi"
6364
# Change memory_limit for travis

app/code/Magento/Catalog/Model/Product/Attribute/Backend/Media.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,10 @@ public function afterSave($object)
194194
if (!empty($image['removed'])) {
195195
if (!empty($image['value_id']) && !isset($picturesInOtherStores[$image['file']])) {
196196
$recordsToDelete[] = $image['value_id'];
197-
$filesToDelete[] = ltrim($image['file'], '/');
197+
// only delete physical files if they are not used by any other products
198+
if ($this->resourceModel->countImageUses($image['file']) <= 1) {
199+
$filesToDelete[] = ltrim($image['file'], '/');
200+
}
198201
}
199202
continue;
200203
}

app/code/Magento/Catalog/Model/ResourceModel/Product/Attribute/Backend/Media.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,4 +398,28 @@ public function loadMediaGalleryEntities($attributeId, $productId)
398398

399399
return $this->getConnection()->fetchAll($select);
400400
}
401+
402+
/**
403+
* Counts uses of the image.
404+
*
405+
* @param string $image
406+
* @return int
407+
* @deprecated 2.1.5
408+
* Added to find out if product image is used for several different products.
409+
* This method is absent in version >=2.1.0 & < 2.1.5.
410+
* In 2.1.5 version it was added in Magento\Catalog\Model\ResourceModel\Product\Gallery.
411+
*/
412+
public function countImageUses($image)
413+
{
414+
$select = $this->getConnection()->select()
415+
->from(
416+
[$this->getMainTableAlias() => $this->getMainTable()],
417+
'count(*)'
418+
)
419+
->where('value = ?', $image);
420+
421+
$countImages = $this->getConnection()->fetchOne($select);
422+
423+
return $countImages;
424+
}
401425
}

app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/Attribute/Backend/MediaTest.php

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,21 @@ class MediaTest extends \PHPUnit_Framework_TestCase
6161
public function setUp()
6262
{
6363
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
64-
$this->connection = $this->getMock('Magento\Framework\DB\Adapter\Pdo\Mysql', [], [], '', false);
65-
$resource = $this->getMock('Magento\Framework\App\ResourceConnection', [], [], '', false);
64+
$this->connection = $this->getMock(\Magento\Framework\DB\Adapter\Pdo\Mysql::class, [], [], '', false);
65+
$resource = $this->getMock(\Magento\Framework\App\ResourceConnection::class, [], [], '', false);
6666
$resource->expects($this->any())
6767
->method('getConnection')
6868
->willReturn($this->connection);
6969
$resource->expects($this->any())->method('getTableName')->willReturn('table');
7070
$this->connection->expects($this->any())->method('setCacheAdapter');
7171
$this->resource = $objectManager->getObject(
72-
'Magento\Catalog\Model\ResourceModel\Product\Attribute\Backend\Media',
72+
\Magento\Catalog\Model\ResourceModel\Product\Attribute\Backend\Media::class,
7373
['resource' => $resource]
7474
);
75-
$this->product = $this->getMock('Magento\Catalog\Model\Product', [], [], '', false);
76-
$this->model = $this->getMock('Magento\Catalog\Model\Product\Attribute\Backend\Media', [], [], '', false);
77-
$this->select = $this->getMock('Magento\Framework\DB\Select', [], [], '', false);
78-
$this->attribute = $this->getMock('Magento\Eav\Model\Entity\Attribute\AbstractAttribute', [], [], '', false);
75+
$this->product = $this->getMock(\Magento\Catalog\Model\Product::class, [], [], '', false);
76+
$this->model = $this->getMock(\Magento\Catalog\Model\Product\Attribute\Backend\Media::class, [], [], '', false);
77+
$this->select = $this->getMock(\Magento\Framework\DB\Select::class, [], [], '', false);
78+
$this->attribute = $this->getMock(\Magento\Eav\Model\Entity\Attribute\AbstractAttribute::class, [], [], '', false);
7979
}
8080

8181
public function testLoadDataFromTableByValueId()
@@ -412,4 +412,33 @@ public function testDeleteGalleryValueInStore()
412412

413413
$this->resource->deleteGalleryValueInStore($valueId, $entityId, $storeId);
414414
}
415+
416+
417+
public function testCountImageUses()
418+
{
419+
$results = [
420+
[
421+
'value_id' => '1',
422+
'attribute_id' => 90,
423+
'value' => '/d/o/download_7.jpg',
424+
'media_type' => 'image',
425+
'disabled' => '0',
426+
],
427+
];
428+
429+
$this->connection->expects($this->once())->method('select')->will($this->returnValue($this->select));
430+
$this->select->expects($this->at(0))
431+
->method('from')
432+
->with(['main' => 'table'], 'count(*)' )
433+
->willReturnSelf();
434+
$this->select->expects($this->at(1))
435+
->method('where')
436+
->with('value = ?', 1)
437+
->willReturnSelf();
438+
$this->connection->expects($this->once())
439+
->method('fetchOne')
440+
->with($this->select)
441+
->willReturn(count($results));
442+
$this->assertEquals($this->resource->countImageUses(1), count($results));
443+
}
415444
}

app/code/Magento/Catalog/view/adminhtml/web/js/options.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ define([
4242
data.intype = optionDefaultInputType;
4343
}
4444

45-
if (!this.totalItems) {
46-
data.checked = 'checked';
47-
}
4845
element = this.template({
4946
data: data
5047
});

app/code/Magento/CatalogWidget/Block/Product/Widget/Conditions.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,19 @@ public function __construct(
8282
protected function _construct()
8383
{
8484
$widget = $this->registry->registry('current_widget_instance');
85+
8586
if ($widget) {
8687
$widgetParameters = $widget->getWidgetParameters();
87-
if (isset($widgetParameters['conditions'])) {
88-
$this->rule->loadPost($widgetParameters);
88+
} else {
89+
$widgetOptions = $this->getLayout()->getBlock('wysiwyg_widget.options');
90+
if ($widgetOptions) {
91+
$widgetParameters = $widgetOptions->getWidgetValues();
8992
}
9093
}
94+
95+
if (isset($widgetParameters['conditions'])) {
96+
$this->rule->loadPost($widgetParameters);
97+
}
9198
}
9299

93100
/**
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\CatalogWidget\Test\Unit\Block\Product\Widget;
7+
8+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
9+
use Magento\CatalogWidget\Block\Product\Widget\Conditions;
10+
use Magento\Framework\Registry;
11+
use Magento\Backend\Block\Template\Context;
12+
use Magento\CatalogWidget\Model\Rule;
13+
use Magento\Framework\View\LayoutInterface;
14+
use Magento\Framework\View\Element\BlockInterface;
15+
16+
/**
17+
* Test class for \Magento\CatalogWidget\Block\Product\Widget\Conditions
18+
*/
19+
class ConditionsTest extends \PHPUnit_Framework_TestCase
20+
{
21+
/**
22+
* @var ObjectManagerHelper
23+
*/
24+
private $objectManagerHelper;
25+
26+
/**
27+
* @var Registry|\PHPUnit_Framework_MockObject_MockObject
28+
*/
29+
private $registryMock;
30+
31+
/**
32+
* @var Context|\PHPUnit_Framework_MockObject_MockObject
33+
*/
34+
private $contextMock;
35+
36+
/**
37+
* @var Rule|\PHPUnit_Framework_MockObject_MockObject
38+
*/
39+
protected $ruleMock;
40+
41+
/**
42+
* @var LayoutInterface|\PHPUnit_Framework_MockObject_MockObject
43+
*/
44+
private $layoutMock;
45+
46+
/**
47+
* @var BlockInterface|\PHPUnit_Framework_MockObject_MockObject
48+
*/
49+
private $blockMock;
50+
51+
protected function setUp()
52+
{
53+
$this->objectManagerHelper = new ObjectManagerHelper($this);
54+
$this->ruleMock = $this->getMockBuilder(Rule::class)
55+
->disableOriginalConstructor()
56+
->getMock();
57+
$this->registryMock = $this->getMockBuilder(Registry::class)
58+
->disableOriginalConstructor()
59+
->getMock();
60+
$this->layoutMock = $this->getMockForAbstractClass(LayoutInterface::class);
61+
$this->blockMock = $this->getMockBuilder(BlockInterface::class)
62+
->setMethods(['getWidgetValues'])
63+
->getMockForAbstractClass();
64+
$this->contextMock = $this->getMockBuilder(Context::class)
65+
->disableOriginalConstructor()
66+
->getMock();
67+
$this->contextMock->expects($this->once())
68+
->method('getLayout')
69+
->willReturn($this->layoutMock);
70+
}
71+
72+
public function testConstructWithEmptyData()
73+
{
74+
$this->registryMock->expects($this->once())
75+
->method('registry')
76+
->with('current_widget_instance')
77+
->willReturn(null);
78+
$this->layoutMock->expects($this->once())
79+
->method('getBlock')
80+
->with('wysiwyg_widget.options')
81+
->willReturn(null);
82+
$this->blockMock->expects($this->never())
83+
->method('getWidgetValues');
84+
$this->ruleMock->expects($this->never())
85+
->method('loadPost');
86+
87+
$this->objectManagerHelper->getObject(
88+
Conditions::class,
89+
[
90+
'context' => $this->contextMock,
91+
'registry' => $this->registryMock,
92+
'rule' => $this->ruleMock,
93+
]
94+
);
95+
}
96+
97+
public function testConstructWithWidgetInstance()
98+
{
99+
$widgetParams = ['conditions' => 'some conditions'];
100+
101+
/** @var \Magento\Widget\Model\Widget\Instance|\PHPUnit_Framework_MockObject_MockObject $widgetMock */
102+
$widgetMock = $this->getMockBuilder(\Magento\Widget\Model\Widget\Instance::class)
103+
->disableOriginalConstructor()
104+
->getMock();
105+
$widgetMock->expects($this->once())
106+
->method('getWidgetParameters')
107+
->willReturn($widgetParams);
108+
109+
$this->layoutMock->expects($this->never())
110+
->method('getBlock');
111+
$this->blockMock->expects($this->never())
112+
->method('getWidgetValues');
113+
$this->registryMock->expects($this->once())
114+
->method('registry')
115+
->with('current_widget_instance')
116+
->willReturn($widgetMock);
117+
$this->ruleMock->expects($this->once())
118+
->method('loadPost')
119+
->with($widgetParams)
120+
->willReturnSelf();
121+
122+
$this->objectManagerHelper->getObject(
123+
Conditions::class,
124+
[
125+
'context' => $this->contextMock,
126+
'registry' => $this->registryMock,
127+
'rule' => $this->ruleMock,
128+
]
129+
);
130+
}
131+
132+
public function testConstructWithParamsFromBlock()
133+
{
134+
$widgetParams = ['conditions' => 'some conditions'];
135+
136+
$this->registryMock->expects($this->once())
137+
->method('registry')
138+
->with('current_widget_instance')
139+
->willReturn(null);
140+
$this->layoutMock->expects($this->once())
141+
->method('getBlock')
142+
->with('wysiwyg_widget.options')
143+
->willReturn($this->blockMock);
144+
$this->blockMock->expects($this->once())
145+
->method('getWidgetValues')
146+
->willReturn($widgetParams);
147+
$this->ruleMock->expects($this->once())
148+
->method('loadPost')
149+
->with($widgetParams)
150+
->willReturnSelf();
151+
152+
$this->objectManagerHelper->getObject(
153+
Conditions::class,
154+
[
155+
'context' => $this->contextMock,
156+
'registry' => $this->registryMock,
157+
'rule' => $this->ruleMock,
158+
]
159+
);
160+
}
161+
}

app/code/Magento/Customer/Model/ResourceModel/CustomerRepository.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,13 @@ public function save(\Magento\Customer\Api\Data\CustomerInterface $customer, $pa
142142
$this->validate($customer);
143143

144144
$prevCustomerData = null;
145+
$prevCustomerDataArr = null;
145146
if ($customer->getId()) {
146147
$prevCustomerData = $this->getById($customer->getId());
148+
$prevCustomerDataArr = $prevCustomerData->__toArray();
147149
}
150+
/** @var $customer \Magento\Customer\Model\Data\Customer */
151+
$customerArr = $customer->__toArray();
148152
$customer = $this->imageProcessor->save(
149153
$customer,
150154
CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER,
@@ -156,7 +160,7 @@ public function save(\Magento\Customer\Api\Data\CustomerInterface $customer, $pa
156160
$customerData = $this->extensibleDataObjectConverter->toNestedArray(
157161
$customer,
158162
[],
159-
'\Magento\Customer\Api\Data\CustomerInterface'
163+
\Magento\Customer\Api\Data\CustomerInterface::class
160164
);
161165

162166
$customer->setAddresses($origAddresses);
@@ -192,6 +196,21 @@ public function save(\Magento\Customer\Api\Data\CustomerInterface $customer, $pa
192196
$customerModel->setRpToken(null);
193197
$customerModel->setRpTokenCreatedAt(null);
194198
}
199+
200+
if (!array_key_exists('default_billing', $customerArr) &&
201+
null !== $prevCustomerDataArr &&
202+
array_key_exists('default_billing', $prevCustomerDataArr)
203+
) {
204+
$customerModel->setDefaultBilling($prevCustomerDataArr['default_billing']);
205+
}
206+
207+
if (!array_key_exists('default_shipping', $customerArr) &&
208+
null !== $prevCustomerDataArr &&
209+
array_key_exists('default_shipping', $prevCustomerDataArr)
210+
) {
211+
$customerModel->setDefaultShipping($prevCustomerDataArr['default_shipping']);
212+
}
213+
195214
$customerModel->save();
196215
$this->customerRegistry->push($customerModel);
197216
$customerId = $customerModel->getId();
@@ -258,7 +277,7 @@ public function getList(SearchCriteriaInterface $searchCriteria)
258277
$searchResults->setSearchCriteria($searchCriteria);
259278
/** @var \Magento\Customer\Model\ResourceModel\Customer\Collection $collection */
260279
$collection = $this->customerFactory->create()->getCollection();
261-
$this->extensionAttributesJoinProcessor->process($collection, 'Magento\Customer\Api\Data\CustomerInterface');
280+
$this->extensionAttributesJoinProcessor->process($collection, \Magento\Customer\Api\Data\CustomerInterface::class);
262281
// This is needed to make sure all the attributes are properly loaded
263282
foreach ($this->customerMetadata->getAllAttributesMetadata() as $metadata) {
264283
$collection->addAttributeToSelect($metadata->getAttributeCode());

0 commit comments

Comments
 (0)