From e3c203ad5fb0693c55cd3abc383ef6baa43e8b10 Mon Sep 17 00:00:00 2001 From: Oleh Usik Date: Tue, 28 Jan 2020 23:26:52 +0200 Subject: [PATCH 1/6] Fixed wrong state title --- .../Sales/Block/Status/Grid/Column/State.php | 6 ++-- app/code/Magento/Sales/Model/Order/Config.php | 19 ----------- .../Test/Unit/Model/Order/ConfigTest.php | 32 ------------------- 3 files changed, 3 insertions(+), 54 deletions(-) diff --git a/app/code/Magento/Sales/Block/Status/Grid/Column/State.php b/app/code/Magento/Sales/Block/Status/Grid/Column/State.php index d2163fae72428..85e32d53c4b72 100644 --- a/app/code/Magento/Sales/Block/Status/Grid/Column/State.php +++ b/app/code/Magento/Sales/Block/Status/Grid/Column/State.php @@ -53,9 +53,9 @@ public function getFrameCallback() */ public function decorateState($value, $row, $column, $isExport) { - $status = $row->getStatus(); - if ($value) { - $cell = $value . '[' . $this->_config->getStateLabelByStateAndStatus($value, $status) . ']'; + $states = $this->_config->getStates(); + if (isset($states[$value])) { + $cell = $value . '[' . $states[$value] . ']'; } else { $cell = $value; } diff --git a/app/code/Magento/Sales/Model/Order/Config.php b/app/code/Magento/Sales/Model/Order/Config.php index 92681f3ecf181..7dbddcd0a16c4 100644 --- a/app/code/Magento/Sales/Model/Order/Config.php +++ b/app/code/Magento/Sales/Model/Order/Config.php @@ -300,23 +300,4 @@ protected function _getStatuses($visibility) } return $this->statuses[(bool) $visibility]; } - - /** - * Retrieve label by state and status - * - * @param string $state - * @param string $status - * @return \Magento\Framework\Phrase|string - * @since 100.2.0 - */ - public function getStateLabelByStateAndStatus($state, $status) - { - foreach ($this->_getCollection() as $item) { - if ($item->getData('state') == $state && $item->getData('status') == $status) { - $label = $item->getData('label'); - return __($label); - } - } - return $state; - } } diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/ConfigTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/ConfigTest.php index feee2816b2cd4..c1a271ef2b591 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/ConfigTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/ConfigTest.php @@ -116,38 +116,6 @@ public function testGetInvisibleOnFrontStatuses() $this->assertSame($expectedResult, $result); } - /** - * @return void - */ - public function testGetStateLabelByStateAndStatus() - { - $statuses = [ - new DataObject( - [ - 'status' => 'fraud', - 'state' => 'processing', - 'label' => 'Suspected Fraud', - ] - ), - new DataObject( - [ - 'status' => 'processing', - 'state' => 'processing', - 'label' => 'Processing', - ] - ) - ]; - $collectionMock = $this->createPartialMock(Collection::class, ['create', 'joinStates']); - $this->orderStatusCollectionFactoryMock->expects($this->once()) - ->method('create') - ->will($this->returnValue($collectionMock)); - $collectionMock->expects($this->once()) - ->method('joinStates') - ->will($this->returnValue($statuses)); - $result = $this->salesConfig->getStateLabelByStateAndStatus('processing', 'fraud'); - $this->assertSame('Suspected Fraud', $result->getText()); - } - /** * Test get statuses * From 4e94687ae0c753d9d8d936b9917a8bd65aad001a Mon Sep 17 00:00:00 2001 From: Oleh Usik Date: Wed, 29 Jan 2020 15:18:34 +0200 Subject: [PATCH 2/6] fixed minor code style issues --- app/code/Magento/Sales/Block/Status/Grid/Column/State.php | 2 ++ app/code/Magento/Sales/Test/Unit/Model/Order/ConfigTest.php | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Sales/Block/Status/Grid/Column/State.php b/app/code/Magento/Sales/Block/Status/Grid/Column/State.php index 85e32d53c4b72..51d9886c79b67 100644 --- a/app/code/Magento/Sales/Block/Status/Grid/Column/State.php +++ b/app/code/Magento/Sales/Block/Status/Grid/Column/State.php @@ -6,6 +6,8 @@ namespace Magento\Sales\Block\Status\Grid\Column; /** + * Column State class + * * @api * @since 100.0.2 */ diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/ConfigTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/ConfigTest.php index c1a271ef2b591..2dcc3c2a9fd24 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/ConfigTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/ConfigTest.php @@ -9,7 +9,7 @@ use Magento\Sales\Model\ResourceModel\Order\Status\Collection; /** - * Class ConfigTest + * Test for Magento\Sales\Model\Order\Config class */ class ConfigTest extends \PHPUnit\Framework\TestCase { From 1000bcd1bfe1380c613b0486e1557e1acec18958 Mon Sep 17 00:00:00 2001 From: Oleh Usik Date: Wed, 29 Jan 2020 19:48:33 +0200 Subject: [PATCH 3/6] Fix issue related with UnitTest --- .../Magento/Sales/Block/Status/Grid/Column/State.php | 10 ++++++---- .../Test/Unit/Block/Status/Grid/Column/StateTest.php | 4 +++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Sales/Block/Status/Grid/Column/State.php b/app/code/Magento/Sales/Block/Status/Grid/Column/State.php index 51d9886c79b67..7639bde75898c 100644 --- a/app/code/Magento/Sales/Block/Status/Grid/Column/State.php +++ b/app/code/Magento/Sales/Block/Status/Grid/Column/State.php @@ -57,10 +57,12 @@ public function decorateState($value, $row, $column, $isExport) { $states = $this->_config->getStates(); if (isset($states[$value])) { - $cell = $value . '[' . $states[$value] . ']'; - } else { - $cell = $value; + return sprintf("%s[%s]", + $value, + $states[$value] + ); } - return $cell; + + return $value; } } diff --git a/app/code/Magento/Sales/Test/Unit/Block/Status/Grid/Column/StateTest.php b/app/code/Magento/Sales/Test/Unit/Block/Status/Grid/Column/StateTest.php index 86e0c561ca5ee..76ebeb2487ef3 100644 --- a/app/code/Magento/Sales/Test/Unit/Block/Status/Grid/Column/StateTest.php +++ b/app/code/Magento/Sales/Test/Unit/Block/Status/Grid/Column/StateTest.php @@ -55,6 +55,7 @@ public function testDecorateState() [ 'status' => 'fraud', 'state' => 'processing', + 'is_default' => '0', 'label' => 'Suspected Fraud', ] ), @@ -62,6 +63,7 @@ public function testDecorateState() [ 'status' => 'processing', 'state' => 'processing', + 'is_default' => '1', 'label' => 'Processing', ] ) @@ -78,6 +80,6 @@ public function testDecorateState() ->will($this->returnValue($statuses)); $result = $this->stateColumn->decorateState('processing', $rowMock, $columnMock, false); - $this->assertSame('processing[Suspected Fraud]', $result); + $this->assertSame('processing[Processing]', $result); } } From ad184d23efcea17cd1d5fe84849b38ed9f1b6636 Mon Sep 17 00:00:00 2001 From: Oleh Usik Date: Wed, 29 Jan 2020 21:49:08 +0200 Subject: [PATCH 4/6] fix code style issue --- app/code/Magento/Sales/Block/Status/Grid/Column/State.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/code/Magento/Sales/Block/Status/Grid/Column/State.php b/app/code/Magento/Sales/Block/Status/Grid/Column/State.php index 7639bde75898c..b66587eef5831 100644 --- a/app/code/Magento/Sales/Block/Status/Grid/Column/State.php +++ b/app/code/Magento/Sales/Block/Status/Grid/Column/State.php @@ -59,8 +59,7 @@ public function decorateState($value, $row, $column, $isExport) if (isset($states[$value])) { return sprintf("%s[%s]", $value, - $states[$value] - ); + $states[$value]); } return $value; From 6e2d0c841cb716fefd831fe1667acd2013e00c28 Mon Sep 17 00:00:00 2001 From: Oleh Usik Date: Wed, 29 Jan 2020 22:43:58 +0200 Subject: [PATCH 5/6] fixed codeStyle issues --- app/code/Magento/Sales/Block/Status/Grid/Column/State.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Sales/Block/Status/Grid/Column/State.php b/app/code/Magento/Sales/Block/Status/Grid/Column/State.php index b66587eef5831..10f8edb524c34 100644 --- a/app/code/Magento/Sales/Block/Status/Grid/Column/State.php +++ b/app/code/Magento/Sales/Block/Status/Grid/Column/State.php @@ -57,9 +57,11 @@ public function decorateState($value, $row, $column, $isExport) { $states = $this->_config->getStates(); if (isset($states[$value])) { - return sprintf("%s[%s]", + return sprintf( + "%s[%s]", $value, - $states[$value]); + $states[$value] + ); } return $value; From 5474b5f90a853378ac673f296047da09a0e510d5 Mon Sep 17 00:00:00 2001 From: Oleh Usik Date: Thu, 30 Jan 2020 11:33:52 +0200 Subject: [PATCH 6/6] Rewrite methods which was removed in first commit --- app/code/Magento/Sales/Model/Order/Config.php | 19 +++++++++++ .../Test/Unit/Model/Order/ConfigTest.php | 32 +++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/app/code/Magento/Sales/Model/Order/Config.php b/app/code/Magento/Sales/Model/Order/Config.php index 7dbddcd0a16c4..92681f3ecf181 100644 --- a/app/code/Magento/Sales/Model/Order/Config.php +++ b/app/code/Magento/Sales/Model/Order/Config.php @@ -300,4 +300,23 @@ protected function _getStatuses($visibility) } return $this->statuses[(bool) $visibility]; } + + /** + * Retrieve label by state and status + * + * @param string $state + * @param string $status + * @return \Magento\Framework\Phrase|string + * @since 100.2.0 + */ + public function getStateLabelByStateAndStatus($state, $status) + { + foreach ($this->_getCollection() as $item) { + if ($item->getData('state') == $state && $item->getData('status') == $status) { + $label = $item->getData('label'); + return __($label); + } + } + return $state; + } } diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/ConfigTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/ConfigTest.php index 2dcc3c2a9fd24..0bd20150cd450 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/ConfigTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/ConfigTest.php @@ -116,6 +116,38 @@ public function testGetInvisibleOnFrontStatuses() $this->assertSame($expectedResult, $result); } + /** + * @return void + */ + public function testGetStateLabelByStateAndStatus() + { + $statuses = [ + new DataObject( + [ + 'status' => 'fraud', + 'state' => 'processing', + 'label' => 'Suspected Fraud', + ] + ), + new DataObject( + [ + 'status' => 'processing', + 'state' => 'processing', + 'label' => 'Processing', + ] + ) + ]; + $collectionMock = $this->createPartialMock(Collection::class, ['create', 'joinStates']); + $this->orderStatusCollectionFactoryMock->expects($this->once()) + ->method('create') + ->will($this->returnValue($collectionMock)); + $collectionMock->expects($this->once()) + ->method('joinStates') + ->will($this->returnValue($statuses)); + $result = $this->salesConfig->getStateLabelByStateAndStatus('processing', 'fraud'); + $this->assertSame('Suspected Fraud', $result->getText()); + } + /** * Test get statuses *