Skip to content

Commit

Permalink
Rewrite methods which was removed in first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Usik2203 committed Jan 30, 2020
1 parent 6e2d0c8 commit 5474b5f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
19 changes: 19 additions & 0 deletions app/code/Magento/Sales/Model/Order/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
32 changes: 32 additions & 0 deletions app/code/Magento/Sales/Test/Unit/Model/Order/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down

0 comments on commit 5474b5f

Please sign in to comment.