123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Sales\Test\Unit\Model\Order;
- use Magento\Framework\DataObject;
- use Magento\Sales\Model\ResourceModel\Order\Status\Collection;
- /**
- * Class ConfigTest
- */
- class ConfigTest extends \PHPUnit\Framework\TestCase
- {
- /**
- * @var \Magento\Sales\Model\Order\Config
- */
- protected $salesConfig;
- /**
- * @var \Magento\Sales\Model\ResourceModel\Order\Status\CollectionFactory|\PHPUnit_Framework_MockObject_MockObject
- */
- 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;
- /**
- * @return void
- */
- protected function setUp()
- {
- $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)
- ->disableOriginalConstructor()
- ->setMethods(['load', 'create'])
- ->getMock();
- $this->orderStatusCollectionFactoryMock = $this->createPartialMock(
- \Magento\Sales\Model\ResourceModel\Order\Status\CollectionFactory::class,
- ['create']
- );
- $this->salesConfig = $objectManager
- ->getObject(
- \Magento\Sales\Model\Order\Config::class,
- [
- 'orderStatusFactory' => $this->statusFactoryMock,
- 'orderStatusCollectionFactory' => $this->orderStatusCollectionFactoryMock
- ]
- );
- }
- /**
- * @return void
- */
- public function testGetInvisibleOnFrontStatuses()
- {
- $statuses = [
- new DataObject(
- [
- 'status' => 'canceled',
- 'is_default' => 1,
- 'visible_on_front' => 1,
- ]
- ),
- new DataObject(
- [
- 'status' => 'complete',
- 'is_default' => 1,
- 'visible_on_front' => 0,
- ]
- ),
- new DataObject(
- [
- 'status' => 'processing',
- 'is_default' => 1,
- 'visible_on_front' => 1,
- ]
- ),
- new DataObject(
- [
- 'status' => 'pending_payment',
- 'is_default' => 1,
- 'visible_on_front' => 0,
- ]
- ),
- ];
- $expectedResult = ['complete', 'pending_payment'];
- $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->getInvisibleOnFrontStatuses();
- $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
- *
- * @dataProvider getStatusesDataProvider
- *
- * @param string $state
- * @param bool $joinLabels
- * @param DataObject[] $collectionData
- * @param array $expectedResult
- */
- public function testGetStatuses($state, $joinLabels, $collectionData, $expectedResult)
- {
- $collectionMock = $this->createPartialMock(
- Collection::class,
- ['create', 'joinStates', 'addStateFilter', 'orderByLabel']
- );
- $this->orderStatusCollectionFactoryMock->expects($this->any())
- ->method('create')
- ->will($this->returnValue($collectionMock));
- $collectionMock->expects($this->once())
- ->method('addStateFilter')
- ->will($this->returnSelf());
- $collectionMock->expects($this->once())
- ->method('orderByLabel')
- ->will($this->returnValue($collectionData));
- $collectionMock->expects($this->once())
- ->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);
- // checking data cached in private property
- $this->assertSame($result, $this->salesConfig->getStateStatuses($state, $joinLabels));
- }
- /**
- * Data provider for testGetStatuses
- *
- * @return array
- */
- public function getStatusesDataProvider()
- {
- return [
- 'processing state' => [
- 'state' => 'processing',
- 'joinLabels' => false,
- 'collectionData' => [
- new DataObject(
- [
- 'status' => 'fraud',
- 'state' => 'processing',
- 'store_label' => 'Suspected Fraud',
- ]
- ),
- new DataObject(
- [
- 'status' => 'processing',
- 'state' => 'processing',
- 'store_label' => 'Processing',
- ]
- ),
- ],
- 'expectedResult' => [
- 0 => 'fraud',
- 1 => 'processing'
- ],
- ],
- 'pending state' => [
- 'state' => 'pending',
- 'joinLabels' => true,
- 'collectionData' => [
- new DataObject(
- [
- 'status' => 'pending_status',
- 'state' => 'pending',
- 'store_label' => 'Pending label',
- ]
- ),
- ],
- 'expectedResult' => [
- 'pending_status' => 'Pending label'
- ],
- ],
- ];
- }
- }
|