public function testOnProductView() { $productId = 1; $product = new Product(); $templateHtml = 'template_html'; $this->listener->setRequest(new Request(['id' => $productId])); $this->doctrineHelper->expects($this->once())->method('getEntityReference')->with('OroB2BProductBundle:Product', $productId)->willReturn($product); /** @var \PHPUnit_Framework_MockObject_MockObject|\Twig_Environment $environment */ $environment = $this->getMock('\\Twig_Environment'); $environment->expects($this->once())->method('render')->with('OroB2BPricingBundle:Product:prices_view.html.twig', ['entity' => $product])->willReturn($templateHtml); $event = $this->createEvent($environment); $this->listener->onProductView($event); $scrollData = $event->getScrollData()->getData(); $this->assertScrollDataPriceBlock($scrollData, $templateHtml); }
public function testOnFrontendProductView() { $templateHtml = 'template_html'; $prices = []; /** @var Product $product */ $product = $this->getEntity('OroB2B\\Bundle\\ProductBundle\\Entity\\Product', 11); /** @var PriceList $priceList */ $priceList = $this->getEntity('OroB2B\\Bundle\\PricingBundle\\Entity\\PriceList', 42); $this->listener->setRequest(new Request(['id' => $product->getId()])); $productPriceRepository = $this->getMockBuilder('OroB2B\\Bundle\\PricingBundle\\Entity\\Repository\\ProductPriceRepository')->disableOriginalConstructor()->getMock(); $productPriceRepository->expects($this->once())->method('findByPriceListIdAndProductIds')->with($priceList->getId(), [$product->getId()])->willReturn($prices); $this->doctrineHelper->expects($this->once())->method('getEntityRepository')->with('OroB2BPricingBundle:ProductPrice')->willReturn($productPriceRepository); $this->doctrineHelper->expects($this->once())->method('getEntityReference')->with('OroB2BProductBundle:Product', $product->getId())->willReturn($product); $this->frontendPriceListRequestHandler->expects($this->once())->method('getPriceList')->willReturn($priceList); /** @var \PHPUnit_Framework_MockObject_MockObject|\Twig_Environment $environment */ $environment = $this->getMock('\\Twig_Environment'); $environment->expects($this->once())->method('render')->with('OroB2BPricingBundle:Frontend/Product:productPrice.html.twig', ['prices' => $prices])->willReturn($templateHtml); $event = $this->createEvent($environment); $this->listener->onFrontendProductView($event); $scrollData = $event->getScrollData()->getData(); $this->assertEquals([$templateHtml], $scrollData[ScrollData::DATA_BLOCKS][0][ScrollData::SUB_BLOCKS][1][ScrollData::DATA]); }