public function testOnWidgetRender() { $priceList = $this->getPriceList(42); $currencies = ['UAH']; $showTierPrices = false; /** @var \PHPUnit_Framework_MockObject_MockObject|ProductGridWidgetRenderEvent $event */ $event = $this->getMockBuilder('OroB2B\\Bundle\\ProductBundle\\Event\\ProductGridWidgetRenderEvent')->disableOriginalConstructor()->getMock(); $event->expects($this->once())->method('getWidgetRouteParameters')->willReturn([]); $this->priceListRequestHandler->expects($this->once())->method('getPriceList')->willReturn($priceList); $this->priceListRequestHandler->expects($this->once())->method('getPriceListSelectedCurrencies')->willReturn($currencies); $this->priceListRequestHandler->expects($this->once())->method('getShowTierPrices')->willReturn($showTierPrices); $event->expects($this->once())->method('setWidgetRouteParameters')->with($this->logicalAnd($this->isType('array'), $this->arrayHasKey('priceListId'), $this->arrayHasKey('priceCurrencies'), $this->arrayHasKey('showTierPrices'), $this->contains($priceList->getId()), $this->contains($currencies), $this->contains($showTierPrices))); $this->listener->onWidgetRender($event); }
/** * @param int|null $priceListId * @param array $priceCurrencies * @param array $sourceResults * @param ProductPrice[] $prices * @param array $expectedResults * @dataProvider onResultAfterDataProvider */ public function testOnResultAfter($priceListId = null, array $priceCurrencies = [], array $sourceResults = [], array $prices = [], array $expectedResults = []) { $priceRepository = $this->getMockBuilder('OroB2B\\Bundle\\PricingBundle\\Entity\\Repository\\ProductPriceRepository')->disableOriginalConstructor()->getMock(); $this->doctrineHelper->expects($this->any())->method('getEntityRepository')->with('OroB2BPricingBundle:ProductPrice')->willReturn($priceRepository); $sourceResultRecords = []; $productIds = []; foreach ($sourceResults as $sourceResult) { $sourceResultRecords[] = new ResultRecord($sourceResult); $productIds[] = $sourceResult['id']; } if ($priceListId && $priceCurrencies) { $this->priceListRequestHandler->expects($this->any())->method('getPriceList')->willReturn($this->getPriceList($priceListId)); $this->priceListRequestHandler->expects($this->any())->method('getPriceListSelectedCurrencies')->will($this->returnCallback(function () use($priceCurrencies) { return array_intersect(['USD', 'EUR'], $priceCurrencies); })); $this->priceListRequestHandler->expects($this->any())->method('getShowTierPrices')->willReturn(true); $priceRepository->expects($this->any())->method('findByPriceListIdAndProductIds')->with($priceListId, $productIds)->willReturn($prices); } /** @var \PHPUnit_Framework_MockObject_MockObject|DatagridInterface $datagrid */ $datagrid = $this->getMock('Oro\\Bundle\\DataGridBundle\\Datagrid\\DatagridInterface'); $event = new OrmResultAfter($datagrid, $sourceResultRecords); $this->listener->onResultAfter($event); $actualResults = $event->getRecords(); $this->assertSameSize($expectedResults, $actualResults); foreach ($expectedResults as $key => $expectedResult) { $actualResult = $actualResults[$key]; foreach ($expectedResult as $name => $value) { $this->assertEquals($value, $actualResult->getValue($name)); } } }