7
7
8
8
class LinkTest extends \PHPUnit \Framework \TestCase
9
9
{
10
+ private $ objectManager ;
11
+
12
+ protected function setUp ()
13
+ {
14
+ $ this ->objectManager = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
15
+ }
16
+
10
17
/**
11
18
* @var array
12
19
*/
@@ -24,24 +31,8 @@ class LinkTest extends \PHPUnit\Framework\TestCase
24
31
*/
25
32
protected $ link ;
26
33
27
- /**
28
- * @param \Magento\Framework\View\Element\Html\Link $link
29
- * @param string $expected
30
- *
31
- * @dataProvider getLinkAttributesDataProvider
32
- */
33
- public function testGetLinkAttributes ($ link , $ expected )
34
+ public function testGetLinkAttributes ()
34
35
{
35
- $ this ->assertEquals ($ expected , $ link ->getLinkAttributes ());
36
- }
37
-
38
- /**
39
- * @return array
40
- */
41
- public function getLinkAttributesDataProvider ()
42
- {
43
- $ objectManagerHelper = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
44
-
45
36
$ escaperMock = $ this ->getMockBuilder (\Magento \Framework \Escaper::class)
46
37
->setMethods (['escapeHtml ' ])->disableOriginalConstructor ()->getMock ();
47
38
@@ -54,13 +45,19 @@ public function getLinkAttributesDataProvider()
54
45
55
46
$ urlBuilderMock ->expects ($ this ->any ())
56
47
->method ('getUrl ' )
57
- ->will ( $ this -> returnArgument ( 'http://site.com/link.html ' ) );
48
+ ->willReturn ( 'http://site.com/link.html ' );
58
49
59
50
$ validtorMock = $ this ->getMockBuilder (\Magento \Framework \View \Element \Template \File \Validator::class)
60
51
->setMethods (['isValid ' ])->disableOriginalConstructor ()->getMock ();
52
+ $ validtorMock ->expects ($ this ->any ())
53
+ ->method ('isValid ' )
54
+ ->willReturn (false );
61
55
62
56
$ scopeConfigMock = $ this ->getMockBuilder (\Magento \Framework \App \Config::class)
63
57
->setMethods (['isSetFlag ' ])->disableOriginalConstructor ()->getMock ();
58
+ $ scopeConfigMock ->expects ($ this ->any ())
59
+ ->method ('isSetFlag ' )
60
+ ->willReturn (true );
64
61
65
62
$ resolverMock = $ this ->getMockBuilder (\Magento \Framework \View \Element \Template \File \Resolver::class)
66
63
->setMethods ([])->disableOriginalConstructor ()->getMock ();
@@ -72,48 +69,47 @@ public function getLinkAttributesDataProvider()
72
69
73
70
$ contextMock ->expects ($ this ->any ())
74
71
->method ('getValidator ' )
75
- ->will ( $ this -> returnValue ( $ validtorMock) );
72
+ ->willReturn ( $ validtorMock );
76
73
77
74
$ contextMock ->expects ($ this ->any ())
78
75
->method ('getResolver ' )
79
- ->will ( $ this -> returnValue ( $ resolverMock) );
76
+ ->willReturn ( $ resolverMock );
80
77
81
78
$ contextMock ->expects ($ this ->any ())
82
79
->method ('getEscaper ' )
83
- ->will ( $ this -> returnValue ( $ escaperMock) );
80
+ ->willReturn ( $ escaperMock );
84
81
85
82
$ contextMock ->expects ($ this ->any ())
86
83
->method ('getUrlBuilder ' )
87
- ->will ( $ this -> returnValue ( $ urlBuilderMock) );
84
+ ->willReturn ( $ urlBuilderMock );
88
85
89
86
$ contextMock ->expects ($ this ->any ())
90
87
->method ('getScopeConfig ' )
91
- ->will ( $ this -> returnValue ( $ scopeConfigMock) );
88
+ ->willReturn ( $ scopeConfigMock );
92
89
93
90
/** @var \Magento\Framework\View\Element\Html\Link $linkWithAttributes */
94
- $ linkWithAttributes = $ objectManagerHelper ->getObject (
91
+ $ linkWithAttributes = $ this -> objectManager ->getObject (
95
92
\Magento \Framework \View \Element \Html \Link::class,
96
93
['context ' => $ contextMock ]
97
94
);
95
+
96
+ $ this ->assertEquals (
97
+ 'href="http://site.com/link.html" ' ,
98
+ $ linkWithAttributes ->getLinkAttributes ()
99
+ );
100
+
98
101
/** @var \Magento\Framework\View\Element\Html\Link $linkWithoutAttributes */
99
- $ linkWithoutAttributes = $ objectManagerHelper ->getObject (
102
+ $ linkWithoutAttributes = $ this -> objectManager ->getObject (
100
103
\Magento \Framework \View \Element \Html \Link::class,
101
104
['context ' => $ contextMock ]
102
105
);
103
-
104
106
foreach ($ this ->allowedAttributes as $ attribute ) {
105
- $ linkWithAttributes ->setDataUsingMethod ($ attribute , $ attribute );
107
+ $ linkWithoutAttributes ->setDataUsingMethod ($ attribute , $ attribute );
106
108
}
107
109
108
- return [
109
- 'full ' => [
110
- 'link ' => $ linkWithAttributes ,
111
- 'expected ' => 'shape="shape" tabindex="tabindex" onfocus="onfocus" onblur="onblur" id="id" ' ,
112
- ],
113
- 'empty ' => [
114
- 'link ' => $ linkWithoutAttributes ,
115
- 'expected ' => '' ,
116
- ],
117
- ];
110
+ $ this ->assertEquals (
111
+ 'href="http://site.com/link.html" shape="shape" tabindex="tabindex" onfocus="onfocus" onblur="onblur" id="id" ' ,
112
+ $ linkWithoutAttributes ->getLinkAttributes ()
113
+ );
118
114
}
119
115
}
0 commit comments