|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\Customer\Test\Unit\Block\Account; |
| 9 | + |
| 10 | +use PHPUnit\Framework\TestCase; |
| 11 | +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; |
| 12 | +use Magento\Customer\Block\Account\Navigation; |
| 13 | +use Magento\Framework\View\Element\Template\Context; |
| 14 | +use Magento\Framework\View\LayoutInterface; |
| 15 | +use Magento\Wishlist\Block\Link as WishListLink; |
| 16 | +use Magento\Customer\Block\Account\Link as CustomerAccountLink; |
| 17 | + |
| 18 | +class NavigationTest extends TestCase |
| 19 | +{ |
| 20 | + /** |
| 21 | + * @var ObjectManagerHelper |
| 22 | + */ |
| 23 | + private $objectManagerHelper; |
| 24 | + |
| 25 | + /** |
| 26 | + * @var Navigation |
| 27 | + */ |
| 28 | + private $navigation; |
| 29 | + |
| 30 | + /** |
| 31 | + * @var Context|\PHPUnit_Framework_MockObject_MockObject |
| 32 | + */ |
| 33 | + private $contextMock; |
| 34 | + |
| 35 | + /** |
| 36 | + * @var LayoutInterface|\PHPUnit_Framework_MockObject_MockObject |
| 37 | + */ |
| 38 | + private $layoutMock; |
| 39 | + |
| 40 | + /** |
| 41 | + * Setup environment for test |
| 42 | + */ |
| 43 | + protected function setUp() |
| 44 | + { |
| 45 | + $this->contextMock = $this->createMock(Context::class); |
| 46 | + $this->layoutMock = $this->createMock(LayoutInterface::class); |
| 47 | + $this->contextMock->expects($this->any()) |
| 48 | + ->method('getLayout') |
| 49 | + ->willReturn($this->layoutMock); |
| 50 | + $this->objectManagerHelper = new ObjectManagerHelper($this); |
| 51 | + $this->navigation = $this->objectManagerHelper->getObject( |
| 52 | + Navigation::class, |
| 53 | + [ |
| 54 | + 'context' => $this->contextMock |
| 55 | + ] |
| 56 | + ); |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * Test get links with block customer account link and wish list link |
| 61 | + * |
| 62 | + * @return void |
| 63 | + */ |
| 64 | + public function testGetLinksWithCustomerAndWishList() |
| 65 | + { |
| 66 | + $wishListLinkMock = $this->getMockBuilder(WishListLink::class) |
| 67 | + ->disableOriginalConstructor() |
| 68 | + ->setMethods(['getSortOrder']) |
| 69 | + ->getMock(); |
| 70 | + |
| 71 | + $customerAccountLinkMock = $this->getMockBuilder(CustomerAccountLink::class) |
| 72 | + ->disableOriginalConstructor() |
| 73 | + ->setMethods(['getSortOrder']) |
| 74 | + ->getMock(); |
| 75 | + |
| 76 | + $wishListLinkMock->expects($this->any()) |
| 77 | + ->method('getSortOrder') |
| 78 | + ->willReturn(100); |
| 79 | + |
| 80 | + $customerAccountLinkMock->expects($this->any()) |
| 81 | + ->method('getSortOrder') |
| 82 | + ->willReturn(20); |
| 83 | + |
| 84 | + $nameInLayout = 'top.links'; |
| 85 | + |
| 86 | + $blockChildren = [ |
| 87 | + 'wishListLink' => $wishListLinkMock, |
| 88 | + 'customerAccountLink' => $customerAccountLinkMock |
| 89 | + ]; |
| 90 | + |
| 91 | + $this->navigation->setNameInLayout($nameInLayout); |
| 92 | + $this->layoutMock->expects($this->any()) |
| 93 | + ->method('getChildBlocks') |
| 94 | + ->with($nameInLayout) |
| 95 | + ->willReturn($blockChildren); |
| 96 | + |
| 97 | + /* Assertion */ |
| 98 | + $this->assertEquals( |
| 99 | + [ |
| 100 | + 0 => $wishListLinkMock, |
| 101 | + 1 => $customerAccountLinkMock |
| 102 | + ], |
| 103 | + $this->navigation->getLinks() |
| 104 | + ); |
| 105 | + } |
| 106 | +} |
0 commit comments