Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for #9566: Show the correct label in the admin #11397

Merged
merged 7 commits into from
Nov 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can have I test + dataPorviderer instead of 2 similar tests

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@okorshenko are you happy with this updated test?

{
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();