diff --git a/app/code/Magento/Reports/Test/Unit/Block/Product/ComparedTest.php b/app/code/Magento/Reports/Test/Unit/Block/Product/ComparedTest.php new file mode 100644 index 0000000000000..e8913e4adb38f --- /dev/null +++ b/app/code/Magento/Reports/Test/Unit/Block/Product/ComparedTest.php @@ -0,0 +1,66 @@ +getMockBuilder(\Magento\Catalog\Block\Product\Context::class) + ->disableOriginalConstructor() + ->getMock(); + $visibilityMock = $this->getMockBuilder(\Magento\Catalog\Model\Product\Visibility::class) + ->disableOriginalConstructor() + ->getMock(); + $this->factoryMock = $this->getMockBuilder(\Magento\Reports\Model\Product\Index\Factory::class) + ->disableOriginalConstructor() + ->setMethods(['get']) + ->getMock(); + + $this->sut = new Compared($contextMock, $visibilityMock, $this->factoryMock); + } + + /** + * Assert that getModel method throws LocalizedException + * + * @expectedException \Magento\Framework\Exception\LocalizedException + */ + public function testGetModelException() + { + $this->factoryMock->expects($this->once())->method('get')->willThrowException(new \InvalidArgumentException); + + $this->sut->getModel(); + } + + /** + * Assert that getModel method returns AbstractIndex + */ + public function testGetModel() + { + $indexMock = $this->getMockBuilder(\Magento\Reports\Model\Product\Index\AbstractIndex::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->factoryMock->expects($this->once())->method('get')->willReturn($indexMock); + + $this->assertSame($indexMock, $this->sut->getModel()); + } +} diff --git a/dev/tests/integration/testsuite/Magento/Reports/Model/ResourceModel/Product/Lowstock/CollectionTest.php b/dev/tests/integration/testsuite/Magento/Reports/Model/ResourceModel/Product/Lowstock/CollectionTest.php new file mode 100644 index 0000000000000..aa8d6c2bd65bd --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Reports/Model/ResourceModel/Product/Lowstock/CollectionTest.php @@ -0,0 +1,68 @@ +collection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( + \Magento\Reports\Model\ResourceModel\Product\Lowstock\Collection::class + ); + } + + /** + * Assert that filterByProductType method throws LocalizedException if not String or Array is passed to it + * + * @expectedException \Magento\Framework\Exception\LocalizedException + */ + public function testFilterByProductTypeException() + { + $this->collection->filterByProductType(100); + } + + /** + * Assert that String argument passed to filterByProductType method is correctly passed to attribute adder + * + * @expectedException \Magento\Framework\Exception\LocalizedException + */ + public function testFilterByProductTypeString() + { + $this->collection->filterByProductType('simple'); + $whereParts = $this->collection->getSelect()->getPart(\Zend_Db_Select::WHERE); + $this->assertContains('simple', $whereParts[0]); + } + + /** + * Assert that Array argument passed to filterByProductType method is correctly passed to attribute adder + * + * @expectedException \Magento\Framework\Exception\LocalizedException + */ + public function testFilterByProductTypeArray() + { + $this->collection->filterByProductType(['simple', 'configurable']); + $whereParts = $this->collection->getSelect()->getPart(\Zend_Db_Select::WHERE); + + $this->assertThat( + $whereParts[0], + $this->logicalAnd( + $this->stringContains('simple'), + $this->stringContains('configurable') + ) + ); + } +}