Skip to content

Commit 3d404bb

Browse files
author
Bohdan Korablov
committed
MAGETWO-37720: Cover Tango modules w. unit tests S2 (+0.7% from current 13.6%)
1 parent 55337d2 commit 3d404bb

File tree

1 file changed

+156
-0
lines changed
  • app/code/Magento/Cms/Test/Unit/Block/Widget/Page

1 file changed

+156
-0
lines changed
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Cms\Test\Unit\Block\Widget\Page;
7+
8+
class LinkTest extends \PHPUnit_Framework_TestCase
9+
{
10+
/**
11+
* @var \Magento\Cms\Block\Widget\Page\Link
12+
*/
13+
protected $linkElement;
14+
15+
/**
16+
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
17+
*/
18+
protected $objectManager;
19+
20+
/**
21+
* @var \Magento\Cms\Helper\Page|\PHPUnit_Framework_MockObject_MockObject
22+
*/
23+
protected $mockCmsPage;
24+
25+
/**
26+
* @var \Magento\Cms\Model\Resource\Page|\PHPUnit_Framework_MockObject_MockObject
27+
*/
28+
protected $mockResourcePage;
29+
30+
protected function setUp()
31+
{
32+
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
33+
$this->mockCmsPage = $this->getMock('Magento\Cms\Helper\Page', [], [], '', false, false);
34+
$this->mockResourcePage = $this->getMock('Magento\Cms\Model\Resource\Page', [], [], '', false, false);
35+
36+
$this->linkElement = $this->objectManager->getObject(
37+
'Magento\Cms\Block\Widget\Page\Link',
38+
[
39+
'cmsPage' => $this->mockCmsPage,
40+
'resourcePage' => $this->mockResourcePage,
41+
]
42+
);
43+
}
44+
45+
protected function tearDown()
46+
{
47+
$this->linkElement == null;
48+
}
49+
50+
public function testGetHrefEmpty()
51+
{
52+
$this->assertEmpty($this->linkElement->getHref());
53+
}
54+
55+
public function testGetHref()
56+
{
57+
$href = 'localhost';
58+
$this->linkElement->setData('href', $href);
59+
$this->assertEquals($href, $this->linkElement->getHref());
60+
}
61+
62+
public function testGetHrefByPageId()
63+
{
64+
$href = 'pagelink';
65+
$this->mockCmsPage->expects($this->once())
66+
->method('getPageUrl')
67+
->willReturn($href);
68+
$this->linkElement->setData('page_id', 1);
69+
$this->assertEquals($href, $this->linkElement->getHref());
70+
}
71+
72+
public function testGetTitleEmpty()
73+
{
74+
$this->assertEmpty($this->linkElement->getTitle());
75+
}
76+
77+
public function testGetTitle()
78+
{
79+
$title = 'Title';
80+
$this->linkElement->setData('title', $title);
81+
$this->assertEquals($title, $this->linkElement->getTitle());
82+
}
83+
84+
public function testGetTitleByPageId()
85+
{
86+
$page_id = 1;
87+
$title = 'Title by page id';
88+
$this->mockResourcePage->expects($this->once())
89+
->method('getCmsPageTitleById')
90+
->with($page_id)
91+
->willReturn($title);
92+
$this->linkElement->setData('page_id', $page_id);
93+
$this->assertEquals($title, $this->linkElement->getTitle());
94+
}
95+
96+
public function testGetTitleByHref()
97+
{
98+
$href = 'localhost';
99+
$title = 'Title by href';
100+
$this->mockResourcePage->expects($this->once())
101+
->method('setStore')
102+
->willReturnSelf();
103+
$this->mockResourcePage->expects($this->once())
104+
->method('getCmsPageTitleByIdentifier')
105+
->with($href)
106+
->willReturn($title);
107+
$this->linkElement->setData('href', $href);
108+
$this->assertEquals($title, $this->linkElement->getTitle());
109+
}
110+
111+
public function testGetLabelByAnchorText()
112+
{
113+
$label = 'Test label';
114+
$this->linkElement->setData('anchor_text', $label);
115+
$this->assertEquals($label, $this->linkElement->getLabel());
116+
}
117+
118+
public function testGetLabelLikeTitle()
119+
{
120+
$label = 'Test title';
121+
$this->linkElement->setData('title', $label);
122+
$this->assertEquals($label, $this->linkElement->getLabel());
123+
}
124+
125+
public function testGetLabelByHref()
126+
{
127+
$href = 'localhost';
128+
$label = 'Label by href';
129+
$this->mockResourcePage->expects($this->once())
130+
->method('setStore')
131+
->willReturnSelf();
132+
$this->mockResourcePage->expects($this->once())
133+
->method('getCmsPageTitleByIdentifier')
134+
->with($href)
135+
->willReturn($label);
136+
$this->linkElement->setData('href', $href);
137+
$this->assertEquals($label, $this->linkElement->getLabel());
138+
}
139+
140+
public function testGetLabelByPageId()
141+
{
142+
$page_id = 1;
143+
$label = 'Label by page id';
144+
$this->mockResourcePage->expects($this->once())
145+
->method('getCmsPageTitleById')
146+
->with($page_id)
147+
->willReturn($label);
148+
$this->linkElement->setData('page_id', $page_id);
149+
$this->assertEquals($label, $this->linkElement->getLabel());
150+
}
151+
152+
public function testGetLabelEmpty()
153+
{
154+
$this->assertEmpty($this->linkElement->getLabel());
155+
}
156+
}

0 commit comments

Comments
 (0)