Skip to content

Commit

Permalink
Merge pull request magento#3868 from magento-arcticfoxes/2.3.1-qwerty-pr
Browse files Browse the repository at this point in the history
[2.3.1-qwerty] sync with 2.3.1-release
  • Loading branch information
joanhe authored Mar 7, 2019
2 parents 0048c0e + 7a4d4b8 commit f66e072
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 57 deletions.
19 changes: 4 additions & 15 deletions app/code/Magento/Newsletter/Model/Plugin/CustomerPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@
namespace Magento\Newsletter\Model\Plugin;

use Magento\Customer\Api\CustomerRepositoryInterface as CustomerRepository;
use Magento\Customer\Api\Data\CustomerExtensionInterface;
use Magento\Customer\Api\Data\CustomerInterface;
use Magento\Newsletter\Model\SubscriberFactory;
use Magento\Framework\Api\ExtensionAttributesFactory;
use Magento\Framework\App\ObjectManager;
use Magento\Newsletter\Model\ResourceModel\Subscriber;
use Magento\Newsletter\Model\SubscriberFactory;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Customer\Api\Data\CustomerExtensionInterface;

/**
* Newsletter Plugin for customer
Expand Down Expand Up @@ -41,29 +39,21 @@ class CustomerPlugin
*/
private $customerSubscriptionStatus = [];

/**
* @var StoreManagerInterface
*/
private $storeManager;

/**
* Initialize dependencies.
*
* @param SubscriberFactory $subscriberFactory
* @param ExtensionAttributesFactory $extensionFactory
* @param Subscriber $subscriberResource
* @param StoreManagerInterface|null $storeManager
*/
public function __construct(
SubscriberFactory $subscriberFactory,
ExtensionAttributesFactory $extensionFactory,
Subscriber $subscriberResource,
StoreManagerInterface $storeManager = null
Subscriber $subscriberResource
) {
$this->subscriberFactory = $subscriberFactory;
$this->extensionFactory = $extensionFactory;
$this->subscriberResource = $subscriberResource;
$this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class);
}

/**
Expand Down Expand Up @@ -164,8 +154,7 @@ public function afterDelete(CustomerRepository $subject, $result, CustomerInterf
public function afterGetById(CustomerRepository $subject, CustomerInterface $customer)
{
$extensionAttributes = $customer->getExtensionAttributes();
$storeId = $this->storeManager->getStore()->getId();
$customer->setStoreId($storeId);

if ($extensionAttributes === null) {
/** @var CustomerExtensionInterface $extensionAttributes */
$extensionAttributes = $this->extensionFactory->create(CustomerInterface::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
use Magento\Customer\Api\Data\CustomerExtensionInterface;
use Magento\Framework\Api\ExtensionAttributesFactory;
use Magento\Newsletter\Model\ResourceModel\Subscriber;
use Magento\Store\Model\Store;
use Magento\Store\Model\StoreManagerInterface;

class CustomerPluginTest extends \PHPUnit\Framework\TestCase
{
Expand Down Expand Up @@ -55,11 +53,6 @@ class CustomerPluginTest extends \PHPUnit\Framework\TestCase
*/
private $customerMock;

/**
* @var StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $storeManagerMock;

protected function setUp()
{
$this->subscriberFactory = $this->getMockBuilder(\Magento\Newsletter\Model\SubscriberFactory::class)
Expand Down Expand Up @@ -94,8 +87,6 @@ protected function setUp()
->setMethods(['getExtensionAttributes'])
->disableOriginalConstructor()
->getMockForAbstractClass();
$this->storeManagerMock = $this->createMock(StoreManagerInterface::class);

$this->subscriberFactory->expects($this->any())->method('create')->willReturn($this->subscriber);
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);

Expand All @@ -105,7 +96,6 @@ protected function setUp()
'subscriberFactory' => $this->subscriberFactory,
'extensionFactory' => $this->extensionFactoryMock,
'subscriberResource' => $this->subscriberResourceMock,
'storeManager' => $this->storeManagerMock,
]
);
}
Expand Down Expand Up @@ -216,7 +206,6 @@ public function testAfterGetByIdCreatesExtensionAttributesIfItIsNotSet(
) {
$subject = $this->createMock(\Magento\Customer\Api\CustomerRepositoryInterface::class);
$subscriber = [$subscriberStatusKey => $subscriberStatusValue];
$this->prepareStoreData();

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

$this->customerMock->expects($this->any())
->method('getExtensionAttributes')
Expand Down Expand Up @@ -279,17 +267,4 @@ public function afterGetByIdDataProvider()
[null, null, false],
];
}

/**
* Prepare store information
*
* @return void
*/
private function prepareStoreData()
{
$storeId = 1;
$storeMock = $this->createMock(Store::class);
$storeMock->expects($this->any())->method('getId')->willReturn($storeId);
$this->storeManagerMock->expects($this->any())->method('getStore')->willReturn($storeMock);
}
}
5 changes: 5 additions & 0 deletions app/code/Magento/Sales/Model/Service/InvoiceService.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ private function prepareItemsQty(Order $order, array $qtys = [])
if ($orderItem->getProductType() == Type::TYPE_BUNDLE && !$orderItem->isShipSeparately()) {
$qtys[$orderItem->getId()] = $orderItem->getQtyOrdered() - $orderItem->getQtyInvoiced();
} else {
$parentItem = $orderItem->getParentItem();
$parentItemId = $parentItem ? $parentItem->getId() : null;
if ($parentItemId && isset($qtys[$parentItemId])) {
$qtys[$orderItem->getId()] = $qtys[$parentItemId];
}
continue;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Sales\Model\Service;

use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Model\Order;
use Magento\TestFramework\Helper\Bootstrap;

/**
* Tests \Magento\Sales\Model\Service\InvoiceService
*/
class InvoiceServiceTest extends \PHPUnit\Framework\TestCase
{
/**
* @var InvoiceService
*/
private $invoiceService;

/**
* @inheritdoc
*/
protected function setUp()
{
$this->invoiceService = Bootstrap::getObjectManager()->create(InvoiceService::class);
}

/**
* @param int $invoiceQty
* @magentoDataFixture Magento/Sales/_files/order_configurable_product.php
* @return void
* @dataProvider prepareInvoiceConfigurableProductDataProvider
*/
public function testPrepareInvoiceConfigurableProduct(int $invoiceQty): void
{
/** @var OrderInterface $order */
$order = Bootstrap::getObjectManager()->create(Order::class)->load('100000001', 'increment_id');
$orderItems = $order->getItems();
foreach ($orderItems as $orderItem) {
if ($orderItem->getParentItemId()) {
$parentItemId = $orderItem->getParentItemId();
}
}
$invoice = $this->invoiceService->prepareInvoice($order, [$parentItemId => $invoiceQty]);
$invoiceItems = $invoice->getItems();
foreach ($invoiceItems as $invoiceItem) {
$this->assertEquals($invoiceQty, $invoiceItem->getQty());
}
}

public function prepareInvoiceConfigurableProductDataProvider()
{
return [
'full invoice' => [2],
'partial invoice' => [1]
];
}

/**
* @param int $invoiceQty
* @magentoDataFixture Magento/Sales/_files/order.php
* @return void
* @dataProvider prepareInvoiceSimpleProductDataProvider
*/
public function testPrepareInvoiceSimpleProduct(int $invoiceQty): void
{
/** @var OrderInterface $order */
$order = Bootstrap::getObjectManager()->create(Order::class)->load('100000001', 'increment_id');
$orderItems = $order->getItems();
$invoiceQtys = [];
foreach ($orderItems as $orderItem) {
$invoiceQtys[$orderItem->getItemId()] = $invoiceQty;
}
$invoice = $this->invoiceService->prepareInvoice($order, $invoiceQtys);
$invoiceItems = $invoice->getItems();
foreach ($invoiceItems as $invoiceItem) {
$this->assertEquals($invoiceQty, $invoiceItem->getQty());
}
}

public function prepareInvoiceSimpleProductDataProvider()
{
return [
'full invoice' => [2],
'partial invoice' => [1]
];
}
}
42 changes: 26 additions & 16 deletions setup/src/Magento/Setup/Controller/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
*/
namespace Magento\Setup\Controller;

/**
* Sets up session for setup/index.php/session/prolong or redirects to error page
*/
class Session extends \Zend\Mvc\Controller\AbstractActionController
{
/**
Expand Down Expand Up @@ -52,23 +55,28 @@ public function prolongAction()
try {
if ($this->serviceManager->get(\Magento\Framework\App\DeploymentConfig::class)->isAvailable()) {
$objectManager = $this->objectManagerProvider->get();
/** @var \Magento\Framework\App\State $adminAppState */
$adminAppState = $objectManager->get(\Magento\Framework\App\State::class);
$adminAppState->setAreaCode(\Magento\Framework\App\Area::AREA_ADMINHTML);
$sessionConfig = $objectManager->get(\Magento\Backend\Model\Session\AdminConfig::class);
/** @var \Magento\Backend\Model\Url $backendUrl */
$backendUrl = $objectManager->get(\Magento\Backend\Model\Url::class);
$urlPath = parse_url($backendUrl->getBaseUrl(), PHP_URL_PATH);
$cookiePath = $urlPath . 'setup';
$sessionConfig->setCookiePath($cookiePath);
/* @var \Magento\Backend\Model\Auth\Session $session */
$session = $objectManager->create(
\Magento\Backend\Model\Auth\Session::class,
[
'sessionConfig' => $sessionConfig,
'appState' => $adminAppState
]
);
$session = $objectManager->get(\Magento\Backend\Model\Auth\Session::class);
// check if session was already set in \Magento\Setup\Mvc\Bootstrap\InitParamListener::authPreDispatch
if (!$session->isSessionExists()) {
/** @var \Magento\Framework\App\State $adminAppState */
$adminAppState = $objectManager->get(\Magento\Framework\App\State::class);
$adminAppState->setAreaCode(\Magento\Framework\App\Area::AREA_ADMINHTML);
$sessionConfig = $objectManager->get(\Magento\Backend\Model\Session\AdminConfig::class);
/** @var \Magento\Backend\Model\Url $backendUrl */
$backendUrl = $objectManager->get(\Magento\Backend\Model\Url::class);
$urlPath = parse_url($backendUrl->getBaseUrl(), PHP_URL_PATH);
$cookiePath = $urlPath . 'setup';
$sessionConfig->setCookiePath($cookiePath);
/* @var \Magento\Backend\Model\Auth\Session $session */
$session = $objectManager->create(
\Magento\Backend\Model\Auth\Session::class,
[
'sessionConfig' => $sessionConfig,
'appState' => $adminAppState
]
);
}
$session->prolong();
return new \Zend\View\Model\JsonModel(['success' => true]);
}
Expand All @@ -78,6 +86,8 @@ public function prolongAction()
}

/**
* Unlogin action, return 401 error page
*
* @return \Zend\View\Model\ViewModel|\Zend\Http\Response
*/
public function unloginAction()
Expand Down
33 changes: 32 additions & 1 deletion setup/src/Magento/Setup/Test/Unit/Controller/SessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ public function testUnloginAction()
$this->createPartialMock(\Magento\Framework\App\DeploymentConfig::class, ['isAvailable']);
$deployConfigMock->expects($this->once())->method('isAvailable')->will($this->returnValue(true));

$sessionMock = $this->createPartialMock(
\Magento\Backend\Model\Auth\Session::class,
['prolong', 'isSessionExists']
);
$sessionMock->expects($this->once())->method('isSessionExists')->will($this->returnValue(false));

$stateMock = $this->createPartialMock(\Magento\Framework\App\State::class, ['setAreaCode']);
$stateMock->expects($this->once())->method('setAreaCode');

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

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

$sessionMock = $this->createPartialMock(\Magento\Backend\Model\Auth\Session::class, ['prolong']);
$this->objectManager->expects($this->once())
->method('create')
->will($this->returnValue($sessionMock));
Expand All @@ -87,4 +93,29 @@ public function testIndexAction()
$viewModel = $controller->unloginAction();
$this->assertInstanceOf(\Zend\View\Model\ViewModel::class, $viewModel);
}

/**
* @covers \Magento\Setup\Controller\SystemConfig::prolongAction
*/
public function testProlongActionWithExistingSession()
{
$this->objectManagerProvider->expects($this->once())->method('get')->will(
$this->returnValue($this->objectManager)
);
$deployConfigMock =
$this->createPartialMock(\Magento\Framework\App\DeploymentConfig::class, ['isAvailable']);
$deployConfigMock->expects($this->once())->method('isAvailable')->will($this->returnValue(true));
$sessionMock = $this->createPartialMock(
\Magento\Backend\Model\Auth\Session::class,
['prolong', 'isSessionExists']
);
$sessionMock->expects($this->once())->method('isSessionExists')->will($this->returnValue(true));

$this->serviceManager->expects($this->once())->method('get')->will($this->returnValue($deployConfigMock));
$this->objectManager->expects($this->once())
->method('get')
->will($this->returnValue($sessionMock));
$controller = new Session($this->serviceManager, $this->objectManagerProvider);
$this->assertEquals(new \Zend\View\Model\JsonModel(['success' => true]), $controller->prolongAction());
}
}

0 comments on commit f66e072

Please sign in to comment.