示例#1
0
 /**
  * @param array $data
  * @param string $priceCode
  * @param array $cssClasses
  * @dataProvider toHtmlDataProvider
  */
 public function testToHtml($data, $priceCode, $cssClasses)
 {
     $this->price->expects($this->once())->method('getPriceCode')->will($this->returnValue($priceCode));
     $priceBox = $this->objectManager->getObject('Magento\\Framework\\Pricing\\Render\\PriceBox', ['context' => $this->context, 'saleableItem' => $this->saleable, 'price' => $this->price, 'rendererPool' => $this->rendererPool, 'data' => $data]);
     $priceBox->toHtml();
     $this->assertEquals($cssClasses, $priceBox->getData('css_classes'));
 }
示例#2
0
 protected function setUp()
 {
     $this->product = $this->getMock('Magento\\Catalog\\Model\\Product', ['getPriceInfo', '__wakeup', 'getCanShowPrice'], [], '', false);
     $this->priceInfo = $this->getMock('Magento\\Framework\\Pricing\\PriceInfo', ['getPrice'], [], '', false);
     $this->product->expects($this->any())->method('getPriceInfo')->will($this->returnValue($this->priceInfo));
     $eventManager = $this->getMock('Magento\\Framework\\Event\\Test\\Unit\\ManagerStub', [], [], '', false);
     $config = $this->getMock('Magento\\Store\\Model\\Store\\Config', [], [], '', false);
     $this->layout = $this->getMock('Magento\\Framework\\View\\Layout', [], [], '', false);
     $this->priceBox = $this->getMock('Magento\\Framework\\Pricing\\Render\\PriceBox', [], [], '', false);
     $this->logger = $this->getMock('Psr\\Log\\LoggerInterface');
     $this->layout->expects($this->any())->method('getBlock')->will($this->returnValue($this->priceBox));
     $cacheState = $this->getMockBuilder(\Magento\Framework\App\Cache\StateInterface::class)->getMockForAbstractClass();
     $scopeConfigMock = $this->getMockForAbstractClass('Magento\\Framework\\App\\Config\\ScopeConfigInterface');
     $context = $this->getMock('Magento\\Framework\\View\\Element\\Template\\Context', [], [], '', false);
     $context->expects($this->any())->method('getEventManager')->will($this->returnValue($eventManager));
     $context->expects($this->any())->method('getStoreConfig')->will($this->returnValue($config));
     $context->expects($this->any())->method('getLayout')->will($this->returnValue($this->layout));
     $context->expects($this->any())->method('getLogger')->will($this->returnValue($this->logger));
     $context->expects($this->any())->method('getScopeConfig')->will($this->returnValue($scopeConfigMock));
     $context->expects($this->any())->method('getCacheState')->will($this->returnValue($cacheState));
     $this->rendererPool = $this->getMockBuilder('Magento\\Framework\\Pricing\\Render\\RendererPool')->disableOriginalConstructor()->getMock();
     $this->price = $this->getMock('Magento\\Framework\\Pricing\\Price\\PriceInterface');
     $this->price->expects($this->any())->method('getPriceCode')->will($this->returnValue(\Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE));
     $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->object = $objectManager->getObject('Magento\\Catalog\\Pricing\\Render\\FinalPriceBox', ['context' => $context, 'saleableItem' => $this->product, 'rendererPool' => $this->rendererPool, 'price' => $this->price, 'data' => ['zone' => 'test_zone']]);
 }
 /**
  * Create amount renderer
  *
  * @param AmountInterface $amount
  * @param SaleableInterface $saleableItem
  * @param PriceInterface $price
  * @param array $data
  * @return AmountRenderInterface
  * @throws \InvalidArgumentException
  */
 public function createAmountRender(AmountInterface $amount, SaleableInterface $saleableItem = null, PriceInterface $price = null, array $data = [])
 {
     $type = self::DEFAULT_PRICE_GROUP_TYPE;
     if ($saleableItem) {
         $type = $saleableItem->getTypeId();
     }
     $priceCode = null;
     $renderClassName = self::AMOUNT_RENDERER_DEFAULT;
     if ($price) {
         $priceCode = $price->getPriceCode();
         // implement class resolving fallback
         $pattern = [$type . '/prices/' . $priceCode . '/amount_render_class', $type . '/default_amount_render_class', 'default/prices/' . $priceCode . '/amount_render_class', 'default/default_amount_render_class'];
         $renderClassName = $this->findDataByPattern($pattern);
         if (!$renderClassName) {
             throw new \InvalidArgumentException('There is no amount render class for price code "' . $priceCode . '"');
         }
     }
     $arguments['data'] = $data;
     $arguments['rendererPool'] = $this;
     $arguments['amount'] = $amount;
     if ($saleableItem) {
         $arguments['saleableItem'] = $saleableItem;
         if ($price) {
             $arguments['price'] = $price;
         }
     }
     /** @var \Magento\Framework\View\Element\Template $amountBlock */
     $amountBlock = $this->getLayout()->createBlock($renderClassName, '', $arguments);
     if (!$amountBlock instanceof AmountRenderInterface) {
         throw new \InvalidArgumentException('Block "' . $renderClassName . '" must implement \\Magento\\Framework\\Pricing\\Render\\AmountRenderInterface');
     }
     $amountBlock->setTemplate($this->getAmountRenderBlockTemplate($type, $priceCode));
     return $amountBlock;
 }
 public function testGetAmount()
 {
     $resultPrice = rand(1, 9);
     $this->price->expects($this->once())->method('getValue')->willReturn($resultPrice);
     $this->priceInfo->expects($this->once())->method('getPrice')->with(BasePrice::PRICE_CODE)->willReturn($this->price);
     $this->calculator->expects($this->once())->method('getAmount')->with($resultPrice, $this->saleableItem)->willReturn($resultPrice);
     $this->assertEquals($resultPrice, $this->model->getAmount());
 }
 public function testSetLayout()
 {
     $layoutMock = $this->getMockBuilder('Magento\\Framework\\View\\LayoutInterface')->getMockForAbstractClass();
     $this->price->expects($this->once())->method('setItem')->with($this->item)->willReturnSelf();
     $this->assertInstanceOf('Magento\\Wishlist\\Pricing\\Render\\ConfiguredPriceBox', $this->model->setLayout($layoutMock));
 }