Skip to content

Commit

Permalink
⏫ Forwardport of #11397 to 2.3-develop branch
Browse files Browse the repository at this point in the history
Applied pull request patch https://github.com/magento/magento2/pull/11397.patch (created by @michielgerritsen) based on commit(s):
  1. 9ee464c
  2. 8e843ad
  3. 69ef9da
  4. 4660956
  5. 567b331
  6. 1ad99bc
  7. 0784f58

Fixed GitHub Issues in 2.3-develop branch:
  - #9566: Status label is wrong in admin (reported by @darkogoles1)
  • Loading branch information
magento-engcom-team committed Jan 23, 2018
1 parent 8e77e2f commit 88a3ad0
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 6 deletions.
10 changes: 8 additions & 2 deletions app/code/Magento/Sales/Model/Order/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,14 @@ public function getStateDefaultStatus($state)
*/
public function getStatusLabel($code)
{
$code = $this->maskStatusForArea($this->state->getAreaCode(), $code);
$area = $this->state->getAreaCode();
$code = $this->maskStatusForArea($area, $code);
$status = $this->orderStatusFactory->create()->load($code);

if ($area == 'adminhtml') {
return $status->getLabel();
}

return $status->getStoreLabel();
}

Expand Down Expand Up @@ -211,7 +217,7 @@ public function getStateStatuses($state, $addLabels = true)
foreach ($collection as $item) {
$status = $item->getData('status');
if ($addLabels) {
$statuses[$status] = $item->getStoreLabel();
$statuses[$status] = $this->getStatusLabel($status);
} else {
$statuses[] = $status;
}
Expand Down
45 changes: 42 additions & 3 deletions app/code/Magento/Sales/Test/Unit/Model/Order/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,41 @@ class ConfigTest extends \PHPUnit\Framework\TestCase
*/
protected $orderStatusCollectionFactoryMock;

/**
* @var \Magento\Sales\Model\Order\StatusFactory|\PHPUnit_Framework_MockObject_MockObject
*/
protected $statusFactoryMock;

/**
* @var \Magento\Sales\Model\Order\Status
*/
protected $orderStatusModel;

/**
* @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $storeManagerMock;

protected function setUp()
{
$orderStatusFactory = $this->createMock(\Magento\Sales\Model\Order\StatusFactory::class);
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);

$this->storeManagerMock = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
$this->orderStatusModel = $objectManager->getObject(\Magento\Sales\Model\Order\Status::class, [
'storeManager' => $this->storeManagerMock,
]);
$this->statusFactoryMock = $this->getMockBuilder(\Magento\Sales\Model\Order\StatusFactory::class)
->setMethods(['load', 'create'])
->getMock();
$this->orderStatusCollectionFactoryMock = $this->createPartialMock(
\Magento\Sales\Model\ResourceModel\Order\Status\CollectionFactory::class,
['create']
);
$this->salesConfig = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))
$this->salesConfig = $objectManager
->getObject(
\Magento\Sales\Model\Order\Config::class,
[
'orderStatusFactory' => $orderStatusFactory,
'orderStatusFactory' => $this->statusFactoryMock,
'orderStatusCollectionFactory' => $this->orderStatusCollectionFactoryMock
]
);
Expand Down Expand Up @@ -147,6 +170,22 @@ public function testGetStatuses($state, $joinLabels, $collectionData, $expectedR
->method('joinStates')
->will($this->returnValue($collectionData));

$this->statusFactoryMock->method('create')
->willReturnSelf();

$this->statusFactoryMock->method('load')
->willReturn($this->orderStatusModel);

$storeMock = $this->createMock(\Magento\Store\Api\Data\StoreInterface::class);
$storeMock->method('getId')
->willReturn(1);

$this->storeManagerMock->method('getStore')
->with($this->anything())
->willReturn($storeMock);

$this->orderStatusModel->setData('store_labels', [1 => 'Pending label']);

$result = $this->salesConfig->getStateStatuses($state, $joinLabels);
$this->assertSame($expectedResult, $result);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

// @codingStandardsIgnoreFile

/** @var \Magento\Sales\Block\Adminhtml\Order\View\History $block */
?>
<div id="order_history_block" class="edit-order-comments">
<?php if ($block->canAddComment()):?>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Sales\Model\Order;

/**
* Class ShipmentTest
* @package Magento\Sales\Model\Order
*/
class StatusTest extends \PHPUnit\Framework\TestCase
{
public function theCorrectLabelIsUsedDependingOnTheAreaProvider()
{
return [
'backend label' => [
'adminhtml',
'Example',
],
'store view label' => [
'frontend',
'Store view example',
],
];
}

/**
* In the backend the regular label must be showed.
*
* @param $area
* @param $result
*
* @magentoDataFixture Magento/Sales/_files/order_status.php
* @dataProvider theCorrectLabelIsUsedDependingOnTheAreaProvider
*/
public function testTheCorrectLabelIsUsedDependingOnTheArea($area, $result)
{
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$objectManager->get(\Magento\Framework\App\State::class)->setAreaCode($area);

/** @var \Magento\Sales\Model\Order $order */
$order = $objectManager->create(\Magento\Sales\Model\Order::class);
$order->loadByIncrementId('100000001');

$this->assertEquals($result, $order->getStatusLabel());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

require __DIR__ . '/order.php';

$orderStatus = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Sales\Model\Order\Status::class
);

$data = [
'status' => 'example',
'label' => 'Example',
'store_labels' => [
1 => 'Store view example',
]
];

$orderStatus->setData($data)->setStatus('example');
$orderStatus->save();

$order->setStatus('example');
$order->save();

0 comments on commit 88a3ad0

Please sign in to comment.