예제 #1
0
 public function testAssignedProducts()
 {
     $categoryId = 3;
     $productPosition = 1;
     $productId = $categoryId + 6;
     $productSku = "sku{$productId}";
     $productDto = $this->getMockBuilder('Magento\\Catalog\\Service\\V1\\Data\\Eav\\Category\\ProductLink')->disableOriginalConstructor()->getMock();
     /** @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject $productObject */
     $productObject = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock();
     $productObject->expects($this->once())->method('getSku')->will($this->returnValue($productSku));
     /** @var \Magento\Framework\Data\Collection\Db|\PHPUnit_Framework_MockObject_MockObject $productCollection */
     $productCollection = $this->getMockBuilder('Magento\\Framework\\Data\\Collection\\Db')->disableOriginalConstructor()->getMock();
     $productCollection->expects($this->any())->method('getItems')->will($this->returnValue([$productId => $productObject]));
     $this->category->expects($this->once())->method('load')->with($this->equalTo($categoryId));
     $this->category->expects($this->once())->method('getId')->will($this->returnValue(true));
     $this->category->expects($this->once())->method('getProductsPosition')->will($this->returnValue([$productId => $productPosition]));
     $this->category->expects($this->once())->method('getProductCollection')->will($this->returnValue($productCollection));
     $this->productLinkBuilder->expects($this->any())->method('populateWithArray')->with($this->equalTo([ProductLink::SKU => $productSku, ProductLink::POSITION => $productPosition]))->will($this->returnValue($this->productLinkBuilder));
     $this->assertEquals([$productDto], $this->model->assignedProducts($categoryId));
 }
예제 #2
0
 /**
  * @expectedException \Magento\Framework\Exception\NoSuchEntityException
  */
 public function testGetCategoryNoSuchEntityException()
 {
     $categoryId = 3;
     $productId = $categoryId + 6;
     /** @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject $productObject */
     $productObject = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock();
     /** @var \Magento\Framework\Data\Collection\Db|\PHPUnit_Framework_MockObject_MockObject $productCollection */
     $productCollection = $this->getMockBuilder('Magento\\Framework\\Data\\Collection\\Db')->disableOriginalConstructor()->getMock();
     $productCollection->expects($this->any())->method('getItems')->will($this->returnValue([$productId => $productObject]));
     $this->category->expects($this->once())->method('load')->with($this->equalTo($categoryId));
     $this->category->expects($this->once())->method('getId')->will($this->returnValue(0));
     $this->model->assignedProducts($categoryId);
 }