StatusTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Test\Unit\Model\ResourceModel\Order;
  7. /**
  8. * Class StatusTest
  9. *
  10. * @package Magento\Sales\Model\ResourceModel
  11. */
  12. class StatusTest extends \PHPUnit\Framework\TestCase
  13. {
  14. /**
  15. * @var \Magento\Sales\Model\ResourceModel\Order\Status
  16. */
  17. protected $model;
  18. /**
  19. * @var \Magento\Framework\App\ResourceConnection|\PHPUnit_Framework_MockObject_MockObject
  20. */
  21. protected $resourceMock;
  22. /**
  23. * @var \Magento\Eav\Model\Config|\PHPUnit_Framework_MockObject_MockObject
  24. */
  25. protected $configMock;
  26. /**
  27. * @var \Magento\Framework\DB\Adapter\Pdo\Mysql|\PHPUnit_Framework_MockObject_MockObject
  28. */
  29. protected $connectionMock;
  30. /**
  31. * @var \Magento\Framework\DB\Select
  32. */
  33. protected $selectMock;
  34. protected function setUp()
  35. {
  36. $this->selectMock = $this->createMock(\Magento\Framework\DB\Select::class);
  37. $this->selectMock->expects($this->any())->method('from')->will($this->returnSelf());
  38. $this->selectMock->expects($this->any())->method('where');
  39. $this->connectionMock = $this->createPartialMock(
  40. \Magento\Framework\DB\Adapter\Pdo\Mysql::class,
  41. ['update', 'insertOnDuplicate', 'select']
  42. );
  43. $this->connectionMock->expects($this->any())->method('select')->will($this->returnValue($this->selectMock));
  44. $this->resourceMock = $this->createMock(\Magento\Framework\App\ResourceConnection::class);
  45. $tableName = 'sales_order_status_state';
  46. $this->resourceMock->expects($this->at(1))
  47. ->method('getTableName')
  48. ->with($this->equalTo($tableName))
  49. ->will($this->returnValue($tableName));
  50. $this->resourceMock->expects($this->any())
  51. ->method('getConnection')
  52. ->will(
  53. $this->returnValue($this->connectionMock)
  54. );
  55. $this->configMock = $this->createPartialMock(\Magento\Eav\Model\Config::class, ['getConnectionName']);
  56. $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  57. $this->model = $objectManager->getObject(
  58. \Magento\Sales\Model\ResourceModel\Order\Status::class,
  59. ['resource' => $this->resourceMock]
  60. );
  61. }
  62. public function testAssignState()
  63. {
  64. $state = 'processing';
  65. $status = 'processing';
  66. $isDefault = 1;
  67. $visibleOnFront = 1;
  68. $tableName = 'sales_order_status_state';
  69. $this->connectionMock->expects($this->once())
  70. ->method('update')
  71. ->with(
  72. $this->equalTo($tableName),
  73. $this->equalTo(['is_default' => 0]),
  74. $this->equalTo(['state = ?' => $state])
  75. );
  76. $this->connectionMock->expects($this->once())
  77. ->method('insertOnDuplicate')
  78. ->with(
  79. $this->equalTo($tableName),
  80. $this->equalTo(
  81. [
  82. 'status' => $status,
  83. 'state' => $state,
  84. 'is_default' => $isDefault,
  85. 'visible_on_front' => $visibleOnFront,
  86. ]
  87. )
  88. );
  89. $this->model->assignState($status, $state, $isDefault, $visibleOnFront);
  90. }
  91. }