Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/old/vendor/magento/module-customer/Test/Unit/Block/Account/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/vendor/magento/module-customer/Test/Unit/Block/Account/NavigationTest.php
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
declare(strict_types=1);

namespace Magento\Customer\Test\Unit\Block\Account;

use Magento\Customer\Block\Account\Link as CustomerAccountLink;
use Magento\Customer\Block\Account\Navigation;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
use Magento\Framework\View\Element\Template\Context;
use Magento\Framework\View\LayoutInterface;
use Magento\Wishlist\Block\Link as WishListLink;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class NavigationTest extends TestCase
{
    /**
     * @var ObjectManagerHelper
     */
    private $objectManagerHelper;

    /**
     * @var Navigation
     */
    private $navigation;

    /**
     * @var Context|MockObject
     */
    private $contextMock;

    /**
     * @var LayoutInterface|MockObject
     */
    private $layoutMock;

    /**
     * Setup environment for test
     */
    protected function setUp(): void
    {
        $this->contextMock = $this->createMock(Context::class);
        $this->layoutMock = $this->getMockForAbstractClass(LayoutInterface::class);
        $this->contextMock->expects($this->any())
            ->method('getLayout')
            ->willReturn($this->layoutMock);
        $this->objectManagerHelper = new ObjectManagerHelper($this);
        $this->navigation = $this->objectManagerHelper->getObject(
            Navigation::class,
            [
                'context' => $this->contextMock
            ]
        );
    }

    /**
     * Test get links with block customer account link and wish list link
     *
     * @return void
     */
    public function testGetLinksWithCustomerAndWishList()
    {
        $wishListLinkMock = $this->getMockBuilder(WishListLink::class)
            ->disableOriginalConstructor()
            ->setMethods(['getSortOrder'])
            ->getMock();

        $customerAccountLinkMock = $this->getMockBuilder(CustomerAccountLink::class)
            ->disableOriginalConstructor()
            ->setMethods(['getSortOrder'])
            ->getMock();

        $wishListLinkMock->expects($this->any())
            ->method('getSortOrder')
            ->willReturn(100);

        $customerAccountLinkMock->expects($this->any())
            ->method('getSortOrder')
            ->willReturn(20);

        $nameInLayout = 'top.links';

        $blockChildren = [
            'wishListLink' => $wishListLinkMock,
            'customerAccountLink' => $customerAccountLinkMock
        ];

        $this->navigation->setNameInLayout($nameInLayout);
        $this->layoutMock->expects($this->any())
            ->method('getChildBlocks')
            ->with($nameInLayout)
            ->willReturn($blockChildren);

        /* Assertion */
        $this->assertEquals(
            [
                0 => $wishListLinkMock,
                1 => $customerAccountLinkMock
            ],
            $this->navigation->getLinks()
        );
    }
}

Spamworldpro Mini