123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Sales\Test\Unit\Model\ResourceModel\Order;
- /**
- * Class StatusTest
- *
- * @package Magento\Sales\Model\ResourceModel
- */
- class StatusTest extends \PHPUnit\Framework\TestCase
- {
- /**
- * @var \Magento\Sales\Model\ResourceModel\Order\Status
- */
- protected $model;
- /**
- * @var \Magento\Framework\App\ResourceConnection|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $resourceMock;
- /**
- * @var \Magento\Eav\Model\Config|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $configMock;
- /**
- * @var \Magento\Framework\DB\Adapter\Pdo\Mysql|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $connectionMock;
- /**
- * @var \Magento\Framework\DB\Select
- */
- protected $selectMock;
- protected function setUp()
- {
- $this->selectMock = $this->createMock(\Magento\Framework\DB\Select::class);
- $this->selectMock->expects($this->any())->method('from')->will($this->returnSelf());
- $this->selectMock->expects($this->any())->method('where');
- $this->connectionMock = $this->createPartialMock(
- \Magento\Framework\DB\Adapter\Pdo\Mysql::class,
- ['update', 'insertOnDuplicate', 'select']
- );
- $this->connectionMock->expects($this->any())->method('select')->will($this->returnValue($this->selectMock));
- $this->resourceMock = $this->createMock(\Magento\Framework\App\ResourceConnection::class);
- $tableName = 'sales_order_status_state';
- $this->resourceMock->expects($this->at(1))
- ->method('getTableName')
- ->with($this->equalTo($tableName))
- ->will($this->returnValue($tableName));
- $this->resourceMock->expects($this->any())
- ->method('getConnection')
- ->will(
- $this->returnValue($this->connectionMock)
- );
- $this->configMock = $this->createPartialMock(\Magento\Eav\Model\Config::class, ['getConnectionName']);
- $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
- $this->model = $objectManager->getObject(
- \Magento\Sales\Model\ResourceModel\Order\Status::class,
- ['resource' => $this->resourceMock]
- );
- }
- public function testAssignState()
- {
- $state = 'processing';
- $status = 'processing';
- $isDefault = 1;
- $visibleOnFront = 1;
- $tableName = 'sales_order_status_state';
- $this->connectionMock->expects($this->once())
- ->method('update')
- ->with(
- $this->equalTo($tableName),
- $this->equalTo(['is_default' => 0]),
- $this->equalTo(['state = ?' => $state])
- );
- $this->connectionMock->expects($this->once())
- ->method('insertOnDuplicate')
- ->with(
- $this->equalTo($tableName),
- $this->equalTo(
- [
- 'status' => $status,
- 'state' => $state,
- 'is_default' => $isDefault,
- 'visible_on_front' => $visibleOnFront,
- ]
- )
- );
- $this->model->assignState($status, $state, $isDefault, $visibleOnFront);
- }
- }
|