OverviewTest.php 2.48 KB
Newer Older
Ketan's avatar
Ketan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

namespace Magento\Multishipping\Block\Checkout;

/**
 * @magentoDataFixture Magento/Catalog/_files/product_simple.php
 */
class OverviewTest extends \PHPUnit\Framework\TestCase
{
    /**
     * @var \Magento\Multishipping\Block\Checkout\Overview
     */
    protected $_block;

    /**
     * @var \Magento\Framework\ObjectManagerInterface
     */
    protected $_objectManager;

    protected function setUp()
    {
        \Magento\TestFramework\Helper\Bootstrap::getInstance()->loadArea(\Magento\Framework\App\Area::AREA_FRONTEND);
        $this->_objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
        $this->_block = $this->_objectManager->get(\Magento\Framework\View\LayoutInterface::class)
            ->createBlock(
                \Magento\Multishipping\Block\Checkout\Overview::class,
                'checkout_overview',
                [
                    'data' => [
                        'renderer_template' => 'Magento_Multishipping::checkout/item/default.phtml',
                        'row_renderer_template' => 'Magento_Multishipping::checkout/overview/item.phtml',
                    ],
                ]
            );

        $this->_block->addChild('renderer.list', \Magento\Framework\View\Element\RendererList::class);
        $this->_block->getChildBlock(
            'renderer.list'
        )->addChild(
            'default',
            \Magento\Checkout\Block\Cart\Item\Renderer::class,
            ['template' => 'cart/item/default.phtml']
        );
    }

    public function testGetRowItemHtml()
    {
        /** @var $item \Magento\Quote\Model\Quote\Item */
        $item = $this->_objectManager->create(\Magento\Quote\Model\Quote\Item::class);
        /** @var $product \Magento\Catalog\Model\Product */
        $product = $this->_objectManager->create(\Magento\Catalog\Model\Product::class);
        $product->load(1);
        $item->setProduct($product);
        /** @var $quote \Magento\Quote\Model\Quote */
        $quote = $this->_objectManager->create(\Magento\Quote\Model\Quote::class);
        $item->setQuote($quote);
        // assure that default renderer was obtained
        $this->assertEquals(
            1,
            \Magento\TestFramework\Helper\Xpath::getElementsCountForXpath(
                '//*[contains(@class,"product") and contains(@class,"name")]/a',
                $this->_block->getRowItemHtml($item)
            )
        );
    }
}