CartTest.php 2.77 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 71 72 73 74 75 76 77
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

/**
 * Test class for \Magento\Checkout\Block\Cart
 */
namespace Magento\Checkout\Block;

class CartTest extends \PHPUnit\Framework\TestCase
{
    public function testGetMethods()
    {
        /** @var $layout \Magento\Framework\View\Layout */
        $layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
            \Magento\Framework\View\LayoutInterface::class
        );
        $child = $layout->createBlock(
            \Magento\Framework\View\Element\Text::class
        )->setChild(
            'child1',
            $layout->createBlock(
                \Magento\Framework\View\Element\Text::class,
                'method1'
            )
        )->setChild(
            'child2',
            $layout->createBlock(
                \Magento\Framework\View\Element\Text::class,
                'method2'
            )
        );
        /** @var $block \Magento\Checkout\Block\Cart */
        $block = $layout->createBlock(\Magento\Checkout\Block\Cart::class)->setChild('child', $child);
        $methods = $block->getMethods('child');
        $this->assertEquals(['method1', 'method2'], $methods);
    }

    public function testGetMethodsEmptyChild()
    {
        /** @var $layout \Magento\Framework\View\Layout */
        $layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
            \Magento\Framework\View\LayoutInterface::class
        );
        $childEmpty = $layout->createBlock(\Magento\Framework\View\Element\Text::class);
        /** @var $block \Magento\Checkout\Block\Cart */
        $block = $layout->createBlock(\Magento\Checkout\Block\Cart::class)->setChild('child', $childEmpty);
        $methods = $block->getMethods('child');
        $this->assertEquals([], $methods);
    }

    public function testGetMethodsNoChild()
    {
        /** @var $layout \Magento\Framework\View\Layout */
        $layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
            \Magento\Framework\View\LayoutInterface::class
        );
        /** @var $block \Magento\Checkout\Block\Cart */
        $block = $layout->createBlock(\Magento\Checkout\Block\Cart::class);
        $methods = $block->getMethods('child');
        $this->assertEquals([], $methods);
    }

    public function testGetPagerHtml()
    {
        /** @var $layout \Magento\Framework\View\Layout */
        $layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
            \Magento\Framework\View\LayoutInterface::class
        );
        /** @var $block \Magento\Checkout\Block\Cart */
        $block = $layout->createBlock(\Magento\Checkout\Block\Cart::class);
        $pager = $block->getPagerHtml();
        $this->assertEquals('', $pager);
    }
}