Skip to content

Commit cacfb38

Browse files
committed
Merge branch '2.3.1-release' into MQE-1436-2.3.1
2 parents 4a7d8b1 + b4f5427 commit cacfb38

File tree

6 files changed

+159
-57
lines changed

6 files changed

+159
-57
lines changed

app/code/Magento/Newsletter/Model/Plugin/CustomerPlugin.php

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66
namespace Magento\Newsletter\Model\Plugin;
77

88
use Magento\Customer\Api\CustomerRepositoryInterface as CustomerRepository;
9-
use Magento\Customer\Api\Data\CustomerExtensionInterface;
109
use Magento\Customer\Api\Data\CustomerInterface;
10+
use Magento\Newsletter\Model\SubscriberFactory;
1111
use Magento\Framework\Api\ExtensionAttributesFactory;
12-
use Magento\Framework\App\ObjectManager;
1312
use Magento\Newsletter\Model\ResourceModel\Subscriber;
14-
use Magento\Newsletter\Model\SubscriberFactory;
15-
use Magento\Store\Model\StoreManagerInterface;
13+
use Magento\Customer\Api\Data\CustomerExtensionInterface;
1614

1715
/**
1816
* Newsletter Plugin for customer
@@ -41,29 +39,21 @@ class CustomerPlugin
4139
*/
4240
private $customerSubscriptionStatus = [];
4341

44-
/**
45-
* @var StoreManagerInterface
46-
*/
47-
private $storeManager;
48-
4942
/**
5043
* Initialize dependencies.
5144
*
5245
* @param SubscriberFactory $subscriberFactory
5346
* @param ExtensionAttributesFactory $extensionFactory
5447
* @param Subscriber $subscriberResource
55-
* @param StoreManagerInterface|null $storeManager
5648
*/
5749
public function __construct(
5850
SubscriberFactory $subscriberFactory,
5951
ExtensionAttributesFactory $extensionFactory,
60-
Subscriber $subscriberResource,
61-
StoreManagerInterface $storeManager = null
52+
Subscriber $subscriberResource
6253
) {
6354
$this->subscriberFactory = $subscriberFactory;
6455
$this->extensionFactory = $extensionFactory;
6556
$this->subscriberResource = $subscriberResource;
66-
$this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class);
6757
}
6858

6959
/**
@@ -164,8 +154,7 @@ public function afterDelete(CustomerRepository $subject, $result, CustomerInterf
164154
public function afterGetById(CustomerRepository $subject, CustomerInterface $customer)
165155
{
166156
$extensionAttributes = $customer->getExtensionAttributes();
167-
$storeId = $this->storeManager->getStore()->getId();
168-
$customer->setStoreId($storeId);
157+
169158
if ($extensionAttributes === null) {
170159
/** @var CustomerExtensionInterface $extensionAttributes */
171160
$extensionAttributes = $this->extensionFactory->create(CustomerInterface::class);

app/code/Magento/Newsletter/Test/Unit/Model/Plugin/CustomerPluginTest.php

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
use Magento\Customer\Api\Data\CustomerExtensionInterface;
1111
use Magento\Framework\Api\ExtensionAttributesFactory;
1212
use Magento\Newsletter\Model\ResourceModel\Subscriber;
13-
use Magento\Store\Model\Store;
14-
use Magento\Store\Model\StoreManagerInterface;
1513

1614
class CustomerPluginTest extends \PHPUnit\Framework\TestCase
1715
{
@@ -55,11 +53,6 @@ class CustomerPluginTest extends \PHPUnit\Framework\TestCase
5553
*/
5654
private $customerMock;
5755

58-
/**
59-
* @var StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
60-
*/
61-
private $storeManagerMock;
62-
6356
protected function setUp()
6457
{
6558
$this->subscriberFactory = $this->getMockBuilder(\Magento\Newsletter\Model\SubscriberFactory::class)
@@ -94,8 +87,6 @@ protected function setUp()
9487
->setMethods(['getExtensionAttributes'])
9588
->disableOriginalConstructor()
9689
->getMockForAbstractClass();
97-
$this->storeManagerMock = $this->createMock(StoreManagerInterface::class);
98-
9990
$this->subscriberFactory->expects($this->any())->method('create')->willReturn($this->subscriber);
10091
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
10192

@@ -105,7 +96,6 @@ protected function setUp()
10596
'subscriberFactory' => $this->subscriberFactory,
10697
'extensionFactory' => $this->extensionFactoryMock,
10798
'subscriberResource' => $this->subscriberResourceMock,
108-
'storeManager' => $this->storeManagerMock,
10999
]
110100
);
111101
}
@@ -216,7 +206,6 @@ public function testAfterGetByIdCreatesExtensionAttributesIfItIsNotSet(
216206
) {
217207
$subject = $this->createMock(\Magento\Customer\Api\CustomerRepositoryInterface::class);
218208
$subscriber = [$subscriberStatusKey => $subscriberStatusValue];
219-
$this->prepareStoreData();
220209

221210
$this->extensionFactoryMock->expects($this->any())
222211
->method('create')
@@ -244,7 +233,6 @@ public function testAfterGetByIdSetsIsSubscribedFlagIfItIsNotSet()
244233
{
245234
$subject = $this->createMock(\Magento\Customer\Api\CustomerRepositoryInterface::class);
246235
$subscriber = ['subscriber_id' => 1, 'subscriber_status' => 1];
247-
$this->prepareStoreData();
248236

249237
$this->customerMock->expects($this->any())
250238
->method('getExtensionAttributes')
@@ -279,17 +267,4 @@ public function afterGetByIdDataProvider()
279267
[null, null, false],
280268
];
281269
}
282-
283-
/**
284-
* Prepare store information
285-
*
286-
* @return void
287-
*/
288-
private function prepareStoreData()
289-
{
290-
$storeId = 1;
291-
$storeMock = $this->createMock(Store::class);
292-
$storeMock->expects($this->any())->method('getId')->willReturn($storeId);
293-
$this->storeManagerMock->expects($this->any())->method('getStore')->willReturn($storeMock);
294-
}
295270
}

app/code/Magento/Sales/Model/Service/InvoiceService.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,11 @@ private function prepareItemsQty(Order $order, array $qtys = [])
190190
if ($orderItem->getProductType() == Type::TYPE_BUNDLE && !$orderItem->isShipSeparately()) {
191191
$qtys[$orderItem->getId()] = $orderItem->getQtyOrdered() - $orderItem->getQtyInvoiced();
192192
} else {
193+
$parentItem = $orderItem->getParentItem();
194+
$parentItemId = $parentItem ? $parentItem->getId() : null;
195+
if ($parentItemId && isset($qtys[$parentItemId])) {
196+
$qtys[$orderItem->getId()] = $qtys[$parentItemId];
197+
}
193198
continue;
194199
}
195200
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Sales\Model\Service;
9+
10+
use Magento\Sales\Api\Data\OrderInterface;
11+
use Magento\Sales\Model\Order;
12+
use Magento\TestFramework\Helper\Bootstrap;
13+
14+
/**
15+
* Tests \Magento\Sales\Model\Service\InvoiceService
16+
*/
17+
class InvoiceServiceTest extends \PHPUnit\Framework\TestCase
18+
{
19+
/**
20+
* @var InvoiceService
21+
*/
22+
private $invoiceService;
23+
24+
/**
25+
* @inheritdoc
26+
*/
27+
protected function setUp()
28+
{
29+
$this->invoiceService = Bootstrap::getObjectManager()->create(InvoiceService::class);
30+
}
31+
32+
/**
33+
* @param int $invoiceQty
34+
* @magentoDataFixture Magento/Sales/_files/order_configurable_product.php
35+
* @return void
36+
* @dataProvider prepareInvoiceConfigurableProductDataProvider
37+
*/
38+
public function testPrepareInvoiceConfigurableProduct(int $invoiceQty): void
39+
{
40+
/** @var OrderInterface $order */
41+
$order = Bootstrap::getObjectManager()->create(Order::class)->load('100000001', 'increment_id');
42+
$orderItems = $order->getItems();
43+
foreach ($orderItems as $orderItem) {
44+
if ($orderItem->getParentItemId()) {
45+
$parentItemId = $orderItem->getParentItemId();
46+
}
47+
}
48+
$invoice = $this->invoiceService->prepareInvoice($order, [$parentItemId => $invoiceQty]);
49+
$invoiceItems = $invoice->getItems();
50+
foreach ($invoiceItems as $invoiceItem) {
51+
$this->assertEquals($invoiceQty, $invoiceItem->getQty());
52+
}
53+
}
54+
55+
public function prepareInvoiceConfigurableProductDataProvider()
56+
{
57+
return [
58+
'full invoice' => [2],
59+
'partial invoice' => [1]
60+
];
61+
}
62+
63+
/**
64+
* @param int $invoiceQty
65+
* @magentoDataFixture Magento/Sales/_files/order.php
66+
* @return void
67+
* @dataProvider prepareInvoiceSimpleProductDataProvider
68+
*/
69+
public function testPrepareInvoiceSimpleProduct(int $invoiceQty): void
70+
{
71+
/** @var OrderInterface $order */
72+
$order = Bootstrap::getObjectManager()->create(Order::class)->load('100000001', 'increment_id');
73+
$orderItems = $order->getItems();
74+
$invoiceQtys = [];
75+
foreach ($orderItems as $orderItem) {
76+
$invoiceQtys[$orderItem->getItemId()] = $invoiceQty;
77+
}
78+
$invoice = $this->invoiceService->prepareInvoice($order, $invoiceQtys);
79+
$invoiceItems = $invoice->getItems();
80+
foreach ($invoiceItems as $invoiceItem) {
81+
$this->assertEquals($invoiceQty, $invoiceItem->getQty());
82+
}
83+
}
84+
85+
public function prepareInvoiceSimpleProductDataProvider()
86+
{
87+
return [
88+
'full invoice' => [2],
89+
'partial invoice' => [1]
90+
];
91+
}
92+
}

setup/src/Magento/Setup/Controller/Session.php

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
*/
66
namespace Magento\Setup\Controller;
77

8+
/**
9+
* Sets up session for setup/index.php/session/prolong or redirects to error page
10+
*/
811
class Session extends \Zend\Mvc\Controller\AbstractActionController
912
{
1013
/**
@@ -52,23 +55,28 @@ public function prolongAction()
5255
try {
5356
if ($this->serviceManager->get(\Magento\Framework\App\DeploymentConfig::class)->isAvailable()) {
5457
$objectManager = $this->objectManagerProvider->get();
55-
/** @var \Magento\Framework\App\State $adminAppState */
56-
$adminAppState = $objectManager->get(\Magento\Framework\App\State::class);
57-
$adminAppState->setAreaCode(\Magento\Framework\App\Area::AREA_ADMINHTML);
58-
$sessionConfig = $objectManager->get(\Magento\Backend\Model\Session\AdminConfig::class);
59-
/** @var \Magento\Backend\Model\Url $backendUrl */
60-
$backendUrl = $objectManager->get(\Magento\Backend\Model\Url::class);
61-
$urlPath = parse_url($backendUrl->getBaseUrl(), PHP_URL_PATH);
62-
$cookiePath = $urlPath . 'setup';
63-
$sessionConfig->setCookiePath($cookiePath);
6458
/* @var \Magento\Backend\Model\Auth\Session $session */
65-
$session = $objectManager->create(
66-
\Magento\Backend\Model\Auth\Session::class,
67-
[
68-
'sessionConfig' => $sessionConfig,
69-
'appState' => $adminAppState
70-
]
71-
);
59+
$session = $objectManager->get(\Magento\Backend\Model\Auth\Session::class);
60+
// check if session was already set in \Magento\Setup\Mvc\Bootstrap\InitParamListener::authPreDispatch
61+
if (!$session->isSessionExists()) {
62+
/** @var \Magento\Framework\App\State $adminAppState */
63+
$adminAppState = $objectManager->get(\Magento\Framework\App\State::class);
64+
$adminAppState->setAreaCode(\Magento\Framework\App\Area::AREA_ADMINHTML);
65+
$sessionConfig = $objectManager->get(\Magento\Backend\Model\Session\AdminConfig::class);
66+
/** @var \Magento\Backend\Model\Url $backendUrl */
67+
$backendUrl = $objectManager->get(\Magento\Backend\Model\Url::class);
68+
$urlPath = parse_url($backendUrl->getBaseUrl(), PHP_URL_PATH);
69+
$cookiePath = $urlPath . 'setup';
70+
$sessionConfig->setCookiePath($cookiePath);
71+
/* @var \Magento\Backend\Model\Auth\Session $session */
72+
$session = $objectManager->create(
73+
\Magento\Backend\Model\Auth\Session::class,
74+
[
75+
'sessionConfig' => $sessionConfig,
76+
'appState' => $adminAppState
77+
]
78+
);
79+
}
7280
$session->prolong();
7381
return new \Zend\View\Model\JsonModel(['success' => true]);
7482
}
@@ -78,6 +86,8 @@ public function prolongAction()
7886
}
7987

8088
/**
89+
* Unlogin action, return 401 error page
90+
*
8191
* @return \Zend\View\Model\ViewModel|\Zend\Http\Response
8292
*/
8393
public function unloginAction()

setup/src/Magento/Setup/Test/Unit/Controller/SessionTest.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ public function testUnloginAction()
4848
$this->createPartialMock(\Magento\Framework\App\DeploymentConfig::class, ['isAvailable']);
4949
$deployConfigMock->expects($this->once())->method('isAvailable')->will($this->returnValue(true));
5050

51+
$sessionMock = $this->createPartialMock(
52+
\Magento\Backend\Model\Auth\Session::class,
53+
['prolong', 'isSessionExists']
54+
);
55+
$sessionMock->expects($this->once())->method('isSessionExists')->will($this->returnValue(false));
56+
5157
$stateMock = $this->createPartialMock(\Magento\Framework\App\State::class, ['setAreaCode']);
5258
$stateMock->expects($this->once())->method('setAreaCode');
5359

@@ -57,6 +63,7 @@ public function testUnloginAction()
5763
$urlMock = $this->createMock(\Magento\Backend\Model\Url::class);
5864

5965
$returnValueMap = [
66+
[\Magento\Backend\Model\Auth\Session::class, $sessionMock],
6067
[\Magento\Framework\App\State::class, $stateMock],
6168
[\Magento\Backend\Model\Session\AdminConfig::class, $sessionConfigMock],
6269
[\Magento\Backend\Model\Url::class, $urlMock]
@@ -68,7 +75,6 @@ public function testUnloginAction()
6875
->method('get')
6976
->will($this->returnValueMap($returnValueMap));
7077

71-
$sessionMock = $this->createPartialMock(\Magento\Backend\Model\Auth\Session::class, ['prolong']);
7278
$this->objectManager->expects($this->once())
7379
->method('create')
7480
->will($this->returnValue($sessionMock));
@@ -87,4 +93,29 @@ public function testIndexAction()
8793
$viewModel = $controller->unloginAction();
8894
$this->assertInstanceOf(\Zend\View\Model\ViewModel::class, $viewModel);
8995
}
96+
97+
/**
98+
* @covers \Magento\Setup\Controller\SystemConfig::prolongAction
99+
*/
100+
public function testProlongActionWithExistingSession()
101+
{
102+
$this->objectManagerProvider->expects($this->once())->method('get')->will(
103+
$this->returnValue($this->objectManager)
104+
);
105+
$deployConfigMock =
106+
$this->createPartialMock(\Magento\Framework\App\DeploymentConfig::class, ['isAvailable']);
107+
$deployConfigMock->expects($this->once())->method('isAvailable')->will($this->returnValue(true));
108+
$sessionMock = $this->createPartialMock(
109+
\Magento\Backend\Model\Auth\Session::class,
110+
['prolong', 'isSessionExists']
111+
);
112+
$sessionMock->expects($this->once())->method('isSessionExists')->will($this->returnValue(true));
113+
114+
$this->serviceManager->expects($this->once())->method('get')->will($this->returnValue($deployConfigMock));
115+
$this->objectManager->expects($this->once())
116+
->method('get')
117+
->will($this->returnValue($sessionMock));
118+
$controller = new Session($this->serviceManager, $this->objectManagerProvider);
119+
$this->assertEquals(new \Zend\View\Model\JsonModel(['success' => true]), $controller->prolongAction());
120+
}
90121
}

0 commit comments

Comments
 (0)