Skip to content

Commit 5450d52

Browse files
committed
Merge branch 'develop' into develop-pr4
2 parents a80b107 + bd22a2c commit 5450d52

File tree

33 files changed

+645
-184
lines changed

33 files changed

+645
-184
lines changed

app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/AbstractModifierTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ protected function setUp()
5656
$this->productMock = $this->getMockBuilder(ProductInterface::class)
5757
->setMethods([
5858
'getId',
59+
'getTypeId',
5960
'getStoreId',
6061
'getResource',
6162
'getData',

app/code/Magento/CatalogInventory/Model/Stock.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Stock extends AbstractExtensibleModel implements StockInterface
3232
*
3333
* @var string
3434
*/
35-
protected $eventObject = 'stock';
35+
protected $_eventObject = 'stock';
3636

3737
const BACKORDERS_NO = 0;
3838

app/code/Magento/CatalogInventory/Model/Stock/Item.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class Item extends AbstractExtensibleModel implements StockItemInterface
4343
*
4444
* @var string
4545
*/
46-
protected $eventObject = 'item';
46+
protected $_eventObject = 'item';
4747

4848
/**
4949
* Store model manager

app/code/Magento/CatalogInventory/Test/Unit/Model/Stock/ItemTest.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -477,33 +477,37 @@ public function getQtyIncrementsDataProvider()
477477
*
478478
* @param $eventName
479479
* @param $methodName
480+
* @param $objectName
480481
*
481482
* @dataProvider eventsDataProvider
482483
*/
483-
public function testDispatchEvents($eventName, $methodName)
484+
public function testDispatchEvents($eventName, $methodName, $objectName)
484485
{
485486
$isCalledWithRightPrefix = 0;
487+
$isObjectNameRight = 0;
486488
$this->eventDispatcher->expects($this->any())->method('dispatch')->with(
487489
$this->callback(function ($arg) use (&$isCalledWithRightPrefix, $eventName) {
488490
$isCalledWithRightPrefix |= ($arg === $eventName);
489491
return true;
490492
}),
491-
$this->anything()
493+
$this->callback(function ($data) use (&$isObjectNameRight, $objectName) {
494+
$isObjectNameRight |= isset($data[$objectName]);
495+
return true;
496+
})
492497
);
493498

494499
$this->item->$methodName();
495-
$this->assertEquals(
496-
1,
497-
(int) $isCalledWithRightPrefix,
498-
sprintf("Event %s doesn't dispatched", $eventName)
500+
$this->assertTrue(
501+
($isCalledWithRightPrefix && $isObjectNameRight),
502+
sprintf('Event "%s" with object name "%s" doesn\'t dispatched properly', $eventName, $objectName)
499503
);
500504
}
501505

502506
public function eventsDataProvider()
503507
{
504508
return [
505-
['cataloginventory_stock_item_save_before', 'beforeSave'],
506-
['cataloginventory_stock_item_save_after', 'afterSave'],
509+
['cataloginventory_stock_item_save_before', 'beforeSave', 'item'],
510+
['cataloginventory_stock_item_save_after', 'afterSave', 'item'],
507511
];
508512
}
509513
}

app/code/Magento/CatalogInventory/Test/Unit/Model/StockTest.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,33 +100,37 @@ public function setUp()
100100
*
101101
* @param $eventName
102102
* @param $methodName
103+
* @param $objectName
103104
*
104105
* @dataProvider eventsDataProvider
105106
*/
106-
public function testDispatchEvents($eventName, $methodName)
107+
public function testDispatchEvents($eventName, $methodName, $objectName)
107108
{
108109
$isCalledWithRightPrefix = 0;
110+
$isObjectNameRight = 0;
109111
$this->eventDispatcher->expects($this->any())->method('dispatch')->with(
110112
$this->callback(function ($arg) use (&$isCalledWithRightPrefix, $eventName) {
111113
$isCalledWithRightPrefix |= ($arg === $eventName);
112114
return true;
113115
}),
114-
$this->anything()
116+
$this->callback(function ($data) use (&$isObjectNameRight, $objectName) {
117+
$isObjectNameRight |= isset($data[$objectName]);
118+
return true;
119+
})
115120
);
116121

117122
$this->stockModel->$methodName();
118-
$this->assertEquals(
119-
1,
120-
(int) $isCalledWithRightPrefix,
121-
sprintf("Event %s doesn't dispatched", $eventName)
123+
$this->assertTrue(
124+
($isCalledWithRightPrefix && $isObjectNameRight),
125+
sprintf('Event "%s" with object name "%s" doesn\'t dispatched properly', $eventName, $objectName)
122126
);
123127
}
124128

125129
public function eventsDataProvider()
126130
{
127131
return [
128-
['cataloginventory_stock_save_before', 'beforeSave'],
129-
['cataloginventory_stock_save_after', 'afterSave'],
132+
['cataloginventory_stock_save_before', 'beforeSave', 'stock'],
133+
['cataloginventory_stock_save_after', 'afterSave', 'stock'],
130134
];
131135
}
132136
}

app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -315,26 +315,35 @@ protected function getMultilineFieldConfig($attributeCode, array $attributeConfi
315315
*/
316316
protected function getDefaultValue($attributeCode)
317317
{
318+
if ($attributeCode === 'country_id') {
319+
return $this->directoryHelper->getDefaultCountry();
320+
}
321+
322+
$customer = $this->getCustomer();
323+
if ($customer === null) {
324+
return null;
325+
}
326+
327+
$attributeValue = null;
318328
switch ($attributeCode) {
329+
case 'prefix':
330+
$attributeValue = $customer->getPrefix();
331+
break;
319332
case 'firstname':
320-
if ($this->getCustomer()) {
321-
return $this->getCustomer()->getFirstname();
322-
}
333+
$attributeValue = $customer->getFirstname();
323334
break;
324335
case 'middlename':
325-
if ($this->getCustomer()) {
326-
return $this->getCustomer()->getMiddlename();
327-
}
336+
$attributeValue = $customer->getMiddlename();
328337
break;
329338
case 'lastname':
330-
if ($this->getCustomer()) {
331-
return $this->getCustomer()->getLastname();
332-
}
339+
$attributeValue = $customer->getLastname();
340+
break;
341+
case 'suffix':
342+
$attributeValue = $customer->getSuffix();
333343
break;
334-
case 'country_id':
335-
return $this->directoryHelper->getDefaultCountry();
336344
}
337-
return null;
345+
346+
return $attributeValue;
338347
}
339348

340349
/**

app/code/Magento/ConfigurableProduct/Pricing/Price/LowestPriceOptionsProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function getProducts(ProductInterface $product)
6363
);
6464

6565
$this->linkedProductMap[$product->getId()] = $this->collectionFactory->create()
66-
->addAttributeToSelect(['price', 'special_price'])
66+
->addAttributeToSelect(['price', 'special_price', 'special_from_date', 'special_to_date'])
6767
->addIdFilter($productIds)
6868
->getItems();
6969
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\ConfigurableProduct\Test\Unit\Pricing\Price;
8+
9+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
10+
use Magento\Catalog\Api\Data\ProductInterface;
11+
use Magento\Catalog\Model\ResourceModel\Product\LinkedProductSelectBuilderInterface;
12+
13+
class LowestPriceOptionsProviderTest extends \PHPUnit_Framework_TestCase
14+
{
15+
/**
16+
* @var \Magento\ConfigurableProduct\Pricing\Price\LowestPriceOptionsProvider
17+
*/
18+
private $model;
19+
20+
/**
21+
* @var \Magento\Framework\App\ResourceConnection|\PHPUnit_Framework_MockObject_MockObject
22+
*/
23+
private $resourceConnection;
24+
25+
/**
26+
* @var \Magento\Framework\DB\Adapter\AdapterInterface|\PHPUnit_Framework_MockObject_MockObject
27+
*/
28+
protected $connection;
29+
30+
/**
31+
* @var LinkedProductSelectBuilderInterface|\PHPUnit_Framework_MockObject_MockObject
32+
*/
33+
private $linkedProductSelectBuilder;
34+
35+
/**
36+
* @var \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory|\PHPUnit_Framework_MockObject_MockObject
37+
*/
38+
private $collectionFactory;
39+
40+
/**
41+
* @var \Magento\Catalog\Model\ResourceModel\Product\Collection|\PHPUnit_Framework_MockObject_MockObject
42+
*/
43+
private $productCollection;
44+
45+
protected function setUp()
46+
{
47+
$this->connection = $this
48+
->getMockBuilder(\Magento\Framework\DB\Adapter\AdapterInterface::class)
49+
->getMock();
50+
$this->resourceConnection = $this
51+
->getMockBuilder(\Magento\Framework\App\ResourceConnection::class)
52+
->disableOriginalConstructor()
53+
->setMethods(['getConnection'])
54+
->getMock();
55+
$this->resourceConnection->expects($this->once())->method('getConnection')->willReturn($this->connection);
56+
$this->linkedProductSelectBuilder = $this
57+
->getMockBuilder(LinkedProductSelectBuilderInterface::class)
58+
->setMethods(['build'])
59+
->getMock();
60+
$this->productCollection = $this
61+
->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Product\Collection::class)
62+
->disableOriginalConstructor()
63+
->setMethods(['addAttributeToSelect', 'addIdFilter', 'getItems'])
64+
->getMock();
65+
$this->collectionFactory = $this
66+
->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory::class)
67+
->disableOriginalConstructor()
68+
->setMethods(['create'])
69+
->getMock();
70+
$this->collectionFactory->expects($this->once())->method('create')->willReturn($this->productCollection);
71+
72+
$objectManager = new ObjectManager($this);
73+
$this->model = $objectManager->getObject(
74+
\Magento\ConfigurableProduct\Pricing\Price\LowestPriceOptionsProvider::class,
75+
[
76+
'resourceConnection' => $this->resourceConnection,
77+
'linkedProductSelectBuilder' => $this->linkedProductSelectBuilder,
78+
'collectionFactory' => $this->collectionFactory,
79+
]
80+
);
81+
}
82+
83+
public function testGetProducts()
84+
{
85+
$productId = 1;
86+
$linkedProducts = ['some', 'linked', 'products', 'dataobjects'];
87+
$product = $this->getMockBuilder(ProductInterface::class)->disableOriginalConstructor()->getMock();
88+
$product->expects($this->any())->method('getId')->willReturn($productId);
89+
$this->linkedProductSelectBuilder->expects($this->any())->method('build')->with($productId)->willReturn([]);
90+
$this->productCollection
91+
->expects($this->once())
92+
->method('addAttributeToSelect')
93+
->with(['price', 'special_price', 'special_from_date', 'special_to_date'])
94+
->willReturnSelf();
95+
$this->productCollection->expects($this->once())->method('addIdFilter')->willReturnSelf();
96+
$this->productCollection->expects($this->once())->method('getItems')->willReturn($linkedProducts);
97+
98+
$this->assertEquals($linkedProducts, $this->model->getProducts($product));
99+
}
100+
}

app/code/Magento/ConfigurableProduct/Test/Unit/Ui/DataProvider/Product/Form/Modifier/ConfigurablePriceTest.php

Lines changed: 97 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,106 @@ class ConfigurablePriceTest extends AbstractModifierTest
1515
*/
1616
protected function createModel()
1717
{
18-
return $this->objectManager->getObject(ConfigurablePriceModifier::class);
18+
return $this->objectManager->getObject(ConfigurablePriceModifier::class, ['locator' => $this->locatorMock]);
1919
}
2020

21-
public function testModifyMeta()
21+
/**
22+
* @param array $metaInput
23+
* @param array $metaOutput
24+
* @dataProvider metaDataProvider
25+
*/
26+
public function testModifyMeta($metaInput, $metaOutput)
2227
{
23-
$meta = ['initial' => 'meta'];
28+
$this->productMock->expects($this->any())
29+
->method('getTypeId')
30+
->willReturn(\Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE);
31+
32+
$metaResult = $this->getModel()->modifyMeta($metaInput);
33+
$this->assertEquals($metaResult, $metaOutput);
34+
}
2435

25-
$this->assertArrayHasKey('initial', $this->getModel()->modifyMeta($meta));
36+
/**
37+
* @return array
38+
*/
39+
public function metaDataProvider()
40+
{
41+
return [
42+
[
43+
'metaInput' => [
44+
'pruduct-details' => [
45+
'children' => [
46+
'container_price' => [
47+
'children' => [
48+
'advanced_pricing_button' => [
49+
'arguments' => []
50+
]
51+
]
52+
]
53+
]
54+
]
55+
],
56+
'metaOutput' => [
57+
'pruduct-details' => [
58+
'children' => [
59+
'container_price' => [
60+
'children' => [
61+
'advanced_pricing_button' => [
62+
'arguments' => [
63+
'data' => [
64+
'config' => [
65+
'visible' => 0,
66+
'disabled' => 1,
67+
'componentType' => 'container'
68+
],
69+
],
70+
],
71+
],
72+
'price' => [
73+
'arguments' => [
74+
'data' => [
75+
'config' => [
76+
'component' =>
77+
'Magento_ConfigurableProduct/js/components/price-configurable'
78+
],
79+
],
80+
],
81+
],
82+
],
83+
],
84+
],
85+
]
86+
]
87+
], [
88+
'metaInput' => [
89+
'pruduct-details' => [
90+
'children' => [
91+
'container_price' => [
92+
'children' => []
93+
]
94+
]
95+
]
96+
],
97+
'metaOutput' => [
98+
'pruduct-details' => [
99+
'children' => [
100+
'container_price' => [
101+
'children' => [
102+
'price' => [
103+
'arguments' => [
104+
'data' => [
105+
'config' => [
106+
'component' =>
107+
'Magento_ConfigurableProduct/js/components/price-configurable'
108+
]
109+
]
110+
]
111+
]
112+
]
113+
]
114+
]
115+
]
116+
]
117+
]
118+
];
26119
}
27120
}

0 commit comments

Comments
 (0)