TaxTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Weee\Test\Unit\Model\ResourceModel;
  7. class TaxTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \Magento\Weee\Model\ResourceModel\Tax
  11. */
  12. protected $model;
  13. /**
  14. * @var \PHPUnit_Framework_MockObject_MockObject
  15. */
  16. protected $resourceMock;
  17. /**
  18. * @var \PHPUnit_Framework_MockObject_MockObject
  19. */
  20. protected $storeManagerMock;
  21. /**
  22. * @var \PHPUnit_Framework_MockObject_MockObject
  23. */
  24. protected $connectionMock;
  25. /**
  26. * @var \PHPUnit_Framework_MockObject_MockObject
  27. */
  28. protected $selectMock;
  29. protected function setUp()
  30. {
  31. $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  32. $this->storeManagerMock = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
  33. $this->selectMock = $this->createMock(\Magento\Framework\DB\Select::class);
  34. $this->connectionMock = $this->createMock(\Magento\Framework\DB\Adapter\AdapterInterface::class);
  35. $this->connectionMock->expects($this->once())
  36. ->method('select')
  37. ->willReturn($this->selectMock);
  38. $this->resourceMock = $this->createMock(\Magento\Framework\App\ResourceConnection::class);
  39. $this->resourceMock->expects($this->any())
  40. ->method('getConnection')
  41. ->willReturn($this->connectionMock);
  42. $this->resourceMock->expects($this->atLeastOnce())
  43. ->method('getTableName')
  44. ->willReturn('table_name');
  45. $contextMock = $this->createMock(\Magento\Framework\Model\ResourceModel\Db\Context::class);
  46. $contextMock->expects($this->any())->method('getResources')->willReturn($this->resourceMock);
  47. $this->model = $this->objectManager->getObject(
  48. \Magento\Weee\Model\ResourceModel\Tax::class,
  49. [
  50. 'context' => $contextMock,
  51. ]
  52. );
  53. }
  54. public function testInWeeeLocation()
  55. {
  56. $this->selectMock->expects($this->at(1))
  57. ->method('where')
  58. ->with('website_id IN(?)', [1, 0])
  59. ->willReturn($this->selectMock);
  60. $this->selectMock->expects($this->at(2))
  61. ->method('where')
  62. ->with('country = ?', 'US')
  63. ->willReturn($this->selectMock);
  64. $this->selectMock->expects($this->at(3))
  65. ->method('where')
  66. ->with('state = ?', 0)
  67. ->willReturn($this->selectMock);
  68. $this->selectMock->expects($this->any())
  69. ->method('from')
  70. ->with('table_name', 'value')
  71. ->willReturn($this->selectMock);
  72. $this->model->isWeeeInLocation('US', 0, 1);
  73. }
  74. public function testFetchWeeeTaxCalculationsByEntity()
  75. {
  76. $this->selectMock->expects($this->any())
  77. ->method('where')
  78. ->willReturn($this->selectMock);
  79. $this->selectMock->expects($this->any())
  80. ->method('from')
  81. ->with(
  82. ['eavTable' => 'table_name'],
  83. [
  84. 'eavTable.attribute_code',
  85. 'eavTable.attribute_id',
  86. 'eavTable.frontend_label'
  87. ]
  88. )->willReturn($this->selectMock);
  89. $this->selectMock->expects($this->any())
  90. ->method('joinLeft')
  91. ->willReturn($this->selectMock);
  92. $this->selectMock->expects($this->any())
  93. ->method('joinInner')
  94. ->willReturn($this->selectMock);
  95. $this->model->fetchWeeeTaxCalculationsByEntity('US', 0, 1, 3, 4);
  96. }
  97. }