protected function setUp() { parent::setUp(); $this->registry = $this->getMockBuilder('Doctrine\\Common\\Persistence\\ManagerRegistry')->disableOriginalConstructor()->getMock(); $this->priceListRequestHandler = $this->getMockBuilder('OroB2B\\Bundle\\PricingBundle\\Model\\FrontendPriceListRequestHandler')->disableOriginalConstructor()->getMock(); $this->formType = new FrontendOrderLineItemType($this->registry, $this->priceListRequestHandler, self::PRICE_CLASS); $priceList = new PriceList(); $this->priceListRequestHandler->expects($this->any())->method('getPriceList')->willReturn($priceList); $this->formType->setDataClass('OroB2B\\Bundle\\OrderBundle\\Entity\\OrderLineItem'); }
/** * @dataProvider getMatchedPricesDataProvider * * @param array $productUnitQuantities * @param string $currency * @param bool $withPriceList * @param array $repositoryData * @param array $expectedData */ public function testGetMatchedPrices(array $productUnitQuantities, $currency, $withPriceList, array $repositoryData, array $expectedData) { $priceList = $this->getEntity('OroB2B\\Bundle\\PricingBundle\\Entity\\PriceList', 12); if ($withPriceList) { $this->requestHandler->expects($this->never())->method('getPriceList'); } else { $this->requestHandler->expects($this->once())->method('getPriceList')->willReturn($priceList); } $repository = $this->getMockBuilder('OroB2B\\Bundle\\PricingBundle\\Entity\\Repository\\ProductPriceRepository')->disableOriginalConstructor()->getMock(); $repository->expects($this->once())->method('getPricesBatch')->willReturn($repositoryData); $em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock(); $em->expects($this->once())->method('getRepository')->with(self::CLASS_NAME)->willReturn($repository); $this->registry->expects($this->once())->method('getManagerForClass')->with(self::CLASS_NAME)->willReturn($em); $prices = $this->provider->getMatchedPrices($productUnitQuantities, $currency, $withPriceList ? $priceList : null); $this->assertInternalType('array', $prices); $this->assertEquals(count($productUnitQuantities), count($prices)); $this->assertEquals($expectedData, $prices); }
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]); }