Skip to content

Commit 5eba3af

Browse files
committed
Merge branch 'develop' of https://github.com/magento/magento2ce into MPI-PR
2 parents b9ec499 + 8eb6402 commit 5eba3af

File tree

155 files changed

+3735
-1869
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

155 files changed

+3735
-1869
lines changed

app/code/Magento/Backend/App/Action/Plugin/MassactionKey.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,27 @@
77
*/
88
namespace Magento\Backend\App\Action\Plugin;
99

10+
use Magento\Framework\App\RequestInterface;
11+
use Magento\Backend\App\AbstractAction;
12+
1013
class MassactionKey
1114
{
1215
/**
1316
* Process massaction key
1417
*
15-
* @param \Magento\Backend\App\AbstractAction $subject
16-
* @param callable $proceed
17-
* @param \Magento\Framework\App\RequestInterface $request
18+
* @param AbstractAction $subject
19+
* @param RequestInterface $request
1820
*
19-
* @return mixed
21+
* @return void
2022
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
2123
*/
22-
public function aroundDispatch(
23-
\Magento\Backend\App\AbstractAction $subject,
24-
\Closure $proceed,
25-
\Magento\Framework\App\RequestInterface $request
26-
) {
24+
public function beforeDispatch(AbstractAction $subject, RequestInterface $request)
25+
{
2726
$key = $request->getPost('massaction_prepare_key');
2827
if ($key) {
2928
$postData = $request->getPost($key);
3029
$value = is_array($postData) ? $postData : explode(',', $postData);
3130
$request->setPostValue($key, $value ? $value : null);
3231
}
33-
return $proceed($request);
3432
}
3533
}

app/code/Magento/Backend/Test/Unit/App/Action/Plugin/MassactionKeyTest.php

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
namespace Magento\Backend\Test\Unit\App\Action\Plugin;
77

88
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
9+
use Magento\Backend\App\AbstractAction;
10+
use Magento\Framework\App\RequestInterface;
911

1012
class MassactionKeyTest extends \PHPUnit_Framework_TestCase
1113
{
@@ -15,17 +17,12 @@ class MassactionKeyTest extends \PHPUnit_Framework_TestCase
1517
protected $plugin;
1618

1719
/**
18-
* @var \Closure
19-
*/
20-
protected $closureMock;
21-
22-
/**
23-
* @var \PHPUnit_Framework_MockObject_MockObject
20+
* @var \PHPUnit_Framework_MockObject_MockObject|RequestInterface
2421
*/
2522
protected $requestMock;
2623

2724
/**
28-
* @var \PHPUnit_Framework_MockObject_MockObject
25+
* @var \PHPUnit_Framework_MockObject_MockObject|AbstractAction
2926
*/
3027
protected $subjectMock;
3128

@@ -35,27 +32,32 @@ protected function setUp()
3532
return 'Expected';
3633
};
3734
$this->subjectMock = $this->getMock(\Magento\Backend\App\AbstractAction::class, [], [], '', false);
38-
$this->requestMock = $this->getMock(\Magento\Framework\App\Request\Http::class, [], [], '', false);
35+
$this->requestMock = $this->getMockForAbstractClass(
36+
RequestInterface::class,
37+
[],
38+
'',
39+
false,
40+
false,
41+
true,
42+
['getPost', 'setPostValue']
43+
);
3944

4045
$objectManager = new ObjectManager($this);
4146
$this->plugin = $objectManager->getObject(
4247
\Magento\Backend\App\Action\Plugin\MassactionKey::class,
4348
[
4449
'subject' => $this->subjectMock,
45-
'closure' => $this->closureMock,
4650
'request' => $this->requestMock,
4751
]
4852
);
4953
}
5054

5155
/**
52-
* @covers \Magento\Backend\App\Action\Plugin\MassactionKey::aroundDispatch
53-
*
5456
* @param $postData array|string
5557
* @param array $convertedData
56-
* @dataProvider aroundDispatchDataProvider
58+
* @dataProvider beforeDispatchDataProvider
5759
*/
58-
public function testAroundDispatchWhenMassactionPrepareKeyRequestExists($postData, $convertedData)
60+
public function testBeforeDispatchWhenMassactionPrepareKeyRequestExists($postData, $convertedData)
5961
{
6062
$this->requestMock->expects($this->at(0))
6163
->method('getPost')
@@ -69,24 +71,18 @@ public function testAroundDispatchWhenMassactionPrepareKeyRequestExists($postDat
6971
->method('setPostValue')
7072
->with('key', $convertedData);
7173

72-
$this->assertEquals(
73-
'Expected',
74-
$this->plugin->aroundDispatch($this->subjectMock, $this->closureMock, $this->requestMock)
75-
);
74+
$this->plugin->beforeDispatch($this->subjectMock, $this->requestMock);
7675
}
7776

78-
public function aroundDispatchDataProvider()
77+
public function beforeDispatchDataProvider()
7978
{
8079
return [
8180
'post_data_is_array' => [['key'], ['key']],
8281
'post_data_is_string' => ['key, key_two', ['key', ' key_two']]
8382
];
8483
}
8584

86-
/**
87-
* @covers \Magento\Backend\App\Action\Plugin\MassactionKey::aroundDispatch
88-
*/
89-
public function testAroundDispatchWhenMassactionPrepareKeyRequestNotExists()
85+
public function testBeforeDispatchWhenMassactionPrepareKeyRequestNotExists()
9086
{
9187
$this->requestMock->expects($this->once())
9288
->method('getPost')
@@ -95,9 +91,6 @@ public function testAroundDispatchWhenMassactionPrepareKeyRequestNotExists()
9591
$this->requestMock->expects($this->never())
9692
->method('setPostValue');
9793

98-
$this->assertEquals(
99-
'Expected',
100-
$this->plugin->aroundDispatch($this->subjectMock, $this->closureMock, $this->requestMock)
101-
);
94+
$this->plugin->beforeDispatch($this->subjectMock, $this->requestMock);
10295
}
10396
}

app/code/Magento/Bundle/Model/Plugin/QuoteItem.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,34 @@
55
*/
66
namespace Magento\Bundle\Model\Plugin;
77

8-
use Closure;
8+
use Magento\Quote\Model\Quote\Item\ToOrderItem;
9+
use Magento\Sales\Api\Data\OrderItemInterface;
10+
use Magento\Quote\Model\Quote\Item\AbstractItem;
911

12+
/**
13+
* Plugin for Magento\Quote\Model\Quote\Item\ToOrderItem
14+
*/
1015
class QuoteItem
1116
{
1217
/**
1318
* Add bundle attributes to order data
1419
*
15-
* @param \Magento\Quote\Model\Quote\Item\ToOrderItem $subject
16-
* @param callable $proceed
17-
* @param \Magento\Quote\Model\Quote\Item\AbstractItem $item
18-
* @param array $additional
19-
* @return \Magento\Sales\Model\Order\Item
20+
* @param ToOrderItem $subject
21+
* @param OrderItemInterface $orderItem
22+
* @param AbstractItem $item
23+
* @param array $data
24+
* @return OrderItemInterface
25+
*
2026
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
2127
*/
22-
public function aroundConvert(
23-
\Magento\Quote\Model\Quote\Item\ToOrderItem $subject,
24-
Closure $proceed,
25-
\Magento\Quote\Model\Quote\Item\AbstractItem $item,
26-
$additional = []
27-
) {
28-
/** @var $orderItem \Magento\Sales\Model\Order\Item */
29-
$orderItem = $proceed($item, $additional);
30-
28+
public function afterConvert(ToOrderItem $subject, OrderItemInterface $orderItem, AbstractItem $item, $data = [])
29+
{
3130
if ($attributes = $item->getProduct()->getCustomOption('bundle_selection_attributes')) {
3231
$productOptions = $orderItem->getProductOptions();
3332
$productOptions['bundle_selection_attributes'] = $attributes->getValue();
3433
$orderItem->setProductOptions($productOptions);
3534
}
35+
3636
return $orderItem;
3737
}
3838
}

app/code/Magento/Bundle/Test/Unit/Model/Plugin/QuoteItemTest.php

Lines changed: 60 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,81 +5,101 @@
55
*/
66
namespace Magento\Bundle\Test\Unit\Model\Plugin;
77

8+
use Magento\Quote\Model\Quote\Item\ToOrderItem;
9+
use Magento\Sales\Api\Data\OrderItemInterface;
10+
use Magento\Quote\Model\Quote\Item\AbstractItem;
11+
use Magento\Catalog\Model\Product;
12+
813
class QuoteItemTest extends \PHPUnit_Framework_TestCase
914
{
15+
/**
16+
* @var \PHPUnit_Framework_MockObject_MockObject|Product
17+
*/
18+
private $productMock;
19+
1020
/** @var \Magento\Bundle\Model\Plugin\QuoteItem */
1121
protected $model;
1222

13-
/** @var \PHPUnit_Framework_MockObject_MockObject */
23+
/** @var \PHPUnit_Framework_MockObject_MockObject|AbstractItem */
1424
protected $quoteItemMock;
1525

16-
/** @var \PHPUnit_Framework_MockObject_MockObject */
26+
/** @var \PHPUnit_Framework_MockObject_MockObject|OrderItemInterface */
1727
protected $orderItemMock;
1828

1929
/**
20-
* @var /PHPUnit_Framework_MockObject_MockObject
30+
* @var \PHPUnit_Framework_MockObject_MockObject|ToOrderItem
2131
*/
2232
protected $subjectMock;
2333

24-
/**
25-
* @var /Closure
26-
*/
27-
protected $closureMock;
28-
2934
protected function setUp()
3035
{
31-
$this->orderItemMock = $this->getMock(\Magento\Sales\Model\Order\Item::class, [], [], '', false);
32-
$this->quoteItemMock = $this->getMock(\Magento\Quote\Model\Quote\Item::class, [], [], '', false);
33-
$orderItem = $this->orderItemMock;
34-
$this->closureMock = function () use ($orderItem) {
35-
return $orderItem;
36-
};
37-
$this->subjectMock = $this->getMock(\Magento\Quote\Model\Quote\Item\ToOrderItem::class, [], [], '', false);
36+
$this->orderItemMock = $this->getMockForAbstractClass(
37+
OrderItemInterface::class,
38+
[],
39+
'',
40+
false,
41+
false,
42+
true,
43+
['getProductOptions', 'setProductOptions']
44+
);
45+
$this->quoteItemMock = $this->getMockForAbstractClass(
46+
AbstractItem::class,
47+
[],
48+
'',
49+
false,
50+
false,
51+
true,
52+
['getProduct']
53+
);
54+
$this->subjectMock = $this->getMock(ToOrderItem::class, [], [], '', false);
55+
$this->productMock = $this->getMock(Product::class, [], [], '', false);
3856
$this->model = new \Magento\Bundle\Model\Plugin\QuoteItem();
3957
}
4058

4159
public function testAroundItemToOrderItemPositive()
4260
{
43-
$productMock = $this->getMock(\Magento\Catalog\Model\Product::class, [], [], '', false);
61+
$attributeValue = 'test_value';
62+
$productOptions = [
63+
'option_1' => 'value_1',
64+
'option_2' => 'value_2'
65+
];
66+
$expectedOptions = $productOptions + ['bundle_selection_attributes' => $attributeValue];
67+
4468
$bundleAttribute = $this->getMock(
4569
\Magento\Catalog\Model\Product\Configuration\Item\Option::class,
4670
[],
4771
[],
4872
'',
4973
false
5074
);
51-
$productMock->expects(
52-
$this->once()
53-
)->method(
54-
'getCustomOption'
55-
)->with(
56-
'bundle_selection_attributes'
57-
)->will(
58-
$this->returnValue($bundleAttribute)
59-
);
60-
$this->quoteItemMock->expects($this->once())->method('getProduct')->will($this->returnValue($productMock));
61-
$this->orderItemMock->expects($this->once())->method('setProductOptions');
75+
$bundleAttribute->expects($this->once())
76+
->method('getValue')
77+
->willReturn($attributeValue);
6278

63-
$orderItem = $this->model->aroundConvert($this->subjectMock, $this->closureMock, $this->quoteItemMock, []);
79+
$this->productMock->expects($this->once())
80+
->method('getCustomOption')
81+
->with('bundle_selection_attributes')
82+
->willReturn($bundleAttribute);
83+
$this->quoteItemMock->expects($this->once())->method('getProduct')->willReturn($this->productMock);
84+
85+
$this->orderItemMock->expects($this->once())->method('getProductOptions')->willReturn($productOptions);
86+
$this->orderItemMock->expects($this->once())->method('setProductOptions')->with($expectedOptions);
87+
88+
$orderItem = $this->model->afterConvert($this->subjectMock, $this->orderItemMock, $this->quoteItemMock);
6489
$this->assertSame($this->orderItemMock, $orderItem);
6590
}
6691

6792
public function testAroundItemToOrderItemNegative()
6893
{
69-
$productMock = $this->getMock(\Magento\Catalog\Model\Product::class, [], [], '', false);
70-
$productMock->expects(
71-
$this->once()
72-
)->method(
73-
'getCustomOption'
74-
)->with(
75-
'bundle_selection_attributes'
76-
)->will(
77-
$this->returnValue(false)
78-
);
79-
$this->quoteItemMock->expects($this->once())->method('getProduct')->will($this->returnValue($productMock));
94+
$this->productMock->expects($this->once())
95+
->method('getCustomOption')
96+
->with('bundle_selection_attributes')->willReturn(false);
97+
98+
$this->quoteItemMock->expects($this->once())->method('getProduct')
99+
->willReturn($this->productMock);
80100
$this->orderItemMock->expects($this->never())->method('setProductOptions');
81101

82-
$orderItem = $this->model->aroundConvert($this->subjectMock, $this->closureMock, $this->quoteItemMock, []);
102+
$orderItem = $this->model->afterConvert($this->subjectMock, $this->orderItemMock, $this->quoteItemMock);
83103
$this->assertSame($this->orderItemMock, $orderItem);
84104
}
85105
}

app/code/Magento/Catalog/Model/CatalogRegistry.php

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)