123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Cms\Test\Unit\Block\Widget\Page;
- class LinkTest extends \PHPUnit\Framework\TestCase
- {
- /**
- * @var \Magento\Cms\Block\Widget\Page\Link
- */
- protected $linkElement;
- /**
- * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
- */
- protected $objectManager;
- /**
- * @var \Magento\Cms\Helper\Page|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $mockCmsPage;
- /**
- * @var \Magento\Cms\Model\ResourceModel\Page|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $mockResourcePage;
- protected function setUp()
- {
- $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
- $this->mockCmsPage = $this->createMock(\Magento\Cms\Helper\Page::class);
- $this->mockResourcePage = $this->createMock(\Magento\Cms\Model\ResourceModel\Page::class);
- $this->linkElement = $this->objectManager->getObject(
- \Magento\Cms\Block\Widget\Page\Link::class,
- [
- 'cmsPage' => $this->mockCmsPage,
- 'resourcePage' => $this->mockResourcePage,
- ]
- );
- }
- protected function tearDown()
- {
- $this->linkElement = null;
- }
- public function testGetHrefEmpty()
- {
- $this->assertEmpty($this->linkElement->getHref());
- }
- public function testGetHref()
- {
- $href = 'localhost';
- $this->linkElement->setData('href', $href);
- $this->assertEquals($href, $this->linkElement->getHref());
- }
- public function testGetHrefByPageId()
- {
- $href = 'pagelink';
- $this->mockCmsPage->expects($this->once())
- ->method('getPageUrl')
- ->willReturn($href);
- $this->linkElement->setData('page_id', 1);
- $this->assertEquals($href, $this->linkElement->getHref());
- }
- public function testGetTitleEmpty()
- {
- $this->assertEmpty($this->linkElement->getTitle());
- }
- public function testGetTitle()
- {
- $title = 'Title';
- $this->linkElement->setData('title', $title);
- $this->assertEquals($title, $this->linkElement->getTitle());
- }
- public function testGetTitleByPageId()
- {
- $pageId = 1;
- $title = 'Title by page id';
- $this->mockResourcePage->expects($this->once())
- ->method('getCmsPageTitleById')
- ->with($pageId)
- ->willReturn($title);
- $this->linkElement->setData('page_id', $pageId);
- $this->assertEquals($title, $this->linkElement->getTitle());
- }
- public function testGetTitleByHref()
- {
- $href = 'localhost';
- $title = 'Title by href';
- $this->mockResourcePage->expects($this->once())
- ->method('setStore')
- ->willReturnSelf();
- $this->mockResourcePage->expects($this->once())
- ->method('getCmsPageTitleByIdentifier')
- ->with($href)
- ->willReturn($title);
- $this->linkElement->setData('href', $href);
- $this->assertEquals($title, $this->linkElement->getTitle());
- }
- public function testGetLabelByAnchorText()
- {
- $label = 'Test label';
- $this->linkElement->setData('anchor_text', $label);
- $this->assertEquals($label, $this->linkElement->getLabel());
- }
- public function testGetLabelLikeTitle()
- {
- $label = 'Test title';
- $this->linkElement->setData('title', $label);
- $this->assertEquals($label, $this->linkElement->getLabel());
- }
- public function testGetLabelByHref()
- {
- $href = 'localhost';
- $label = 'Label by href';
- $this->mockResourcePage->expects($this->once())
- ->method('setStore')
- ->willReturnSelf();
- $this->mockResourcePage->expects($this->once())
- ->method('getCmsPageTitleByIdentifier')
- ->with($href)
- ->willReturn($label);
- $this->linkElement->setData('href', $href);
- $this->assertEquals($label, $this->linkElement->getLabel());
- }
- public function testGetLabelByPageId()
- {
- $pageId = 1;
- $label = 'Label by page id';
- $this->mockResourcePage->expects($this->once())
- ->method('getCmsPageTitleById')
- ->with($pageId)
- ->willReturn($label);
- $this->linkElement->setData('page_id', $pageId);
- $this->assertEquals($label, $this->linkElement->getLabel());
- }
- public function testGetLabelEmpty()
- {
- $this->assertEmpty($this->linkElement->getLabel());
- }
- }
|