Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
InventoryTest.php
Go to the documentation of this file.
1 <?php
7 
11 class InventoryTest extends \PHPUnit\Framework\TestCase
12 {
16  protected $backordersMock;
17 
22 
26  protected $contextMock;
27 
31  protected $requestMock;
32 
36  protected $inventory;
37 
43  protected function setUp()
44  {
45  $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
46 
47  $this->contextMock = $this->createPartialMock(\Magento\Backend\Block\Template\Context::class, ['getRequest']);
48  $this->backordersMock = $this->createMock(\Magento\CatalogInventory\Model\Source\Backorders::class);
49  $this->stockConfigurationMock = $this->getMockForAbstractClass(
50  \Magento\CatalogInventory\Api\StockConfigurationInterface::class,
51  [],
52  '',
53  false
54  );
55  $this->requestMock = $this->getMockForAbstractClass(
56  \Magento\Framework\App\RequestInterface::class,
57  ['getParam'],
58  '',
59  false
60  );
61 
62  $this->contextMock->expects($this->once())
63  ->method('getRequest')
64  ->will($this->returnValue($this->requestMock));
65 
66  $this->inventory = $objectManager->getObject(
67  \Magento\Catalog\Block\Adminhtml\Product\Edit\Action\Attribute\Tab\Inventory::class,
68  [
69  'context' => $this->contextMock,
70  'backorders' => $this->backordersMock,
71  'stockConfiguration' => $this->stockConfigurationMock
72  ]
73  );
74  }
75 
81  public function testGetBackordersOption()
82  {
83  $this->backordersMock->expects($this->once())
84  ->method('toOptionArray')
85  ->will($this->returnValue('return-value'));
86  $this->assertEquals('return-value', $this->inventory->getBackordersOption());
87  }
88 
94  public function testGetFieldSuffix()
95  {
96  $this->assertEquals('inventory', $this->inventory->getFieldSuffix());
97  }
98 
104  public function testGetStoreId()
105  {
106  $this->requestMock->expects($this->once())
107  ->method('getParam')
108  ->with('store')
109  ->will($this->returnValue('125'));
110 
111  $this->assertTrue(is_integer($this->inventory->getStoreId()));
112  }
113 
119  public function testGetDefaultConfigValue()
120  {
121  $this->stockConfigurationMock->expects($this->once())
122  ->method('getDefaultConfigValue')
123  ->with('field-name')
124  ->will($this->returnValue('return-value'));
125 
126  $this->assertEquals('return-value', $this->inventory->getDefaultConfigValue('field-name'));
127  }
128 
134  public function testGetTabLabel()
135  {
136  $this->assertEquals('Advanced Inventory', $this->inventory->getTabLabel());
137  }
138 
144  public function testGetTabTitle()
145  {
146  $this->assertEquals('Advanced Inventory', $this->inventory->getTabLabel());
147  }
148 
154  public function testCanShowTab()
155  {
156  $this->assertTrue($this->inventory->canShowTab());
157  }
158 
164  public function testIsHidden()
165  {
166  $this->assertFalse($this->inventory->isHidden());
167  }
168 
174  public function testIsEnabled()
175  {
176  $this->assertEquals(true, $this->inventory->isAvailable('field'));
177  }
178 }
$objectManager
Definition: bootstrap.php:17