Skip to content

Commit 32764b1

Browse files
committed
MC-6273: Mysql url_rewrite select make on product view page 170+ times per request
- fixed unit tests
1 parent 34a5218 commit 32764b1

File tree

1 file changed

+33
-37
lines changed
  • lib/internal/Magento/Framework/View/Test/Unit/Element/Html

1 file changed

+33
-37
lines changed

lib/internal/Magento/Framework/View/Test/Unit/Element/Html/LinkTest.php

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77

88
class LinkTest extends \PHPUnit\Framework\TestCase
99
{
10+
private $objectManager;
11+
12+
protected function setUp()
13+
{
14+
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
15+
}
16+
1017
/**
1118
* @var array
1219
*/
@@ -24,24 +31,8 @@ class LinkTest extends \PHPUnit\Framework\TestCase
2431
*/
2532
protected $link;
2633

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()
3435
{
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-
4536
$escaperMock = $this->getMockBuilder(\Magento\Framework\Escaper::class)
4637
->setMethods(['escapeHtml'])->disableOriginalConstructor()->getMock();
4738

@@ -54,13 +45,19 @@ public function getLinkAttributesDataProvider()
5445

5546
$urlBuilderMock->expects($this->any())
5647
->method('getUrl')
57-
->will($this->returnArgument('http://site.com/link.html'));
48+
->willReturn('http://site.com/link.html');
5849

5950
$validtorMock = $this->getMockBuilder(\Magento\Framework\View\Element\Template\File\Validator::class)
6051
->setMethods(['isValid'])->disableOriginalConstructor()->getMock();
52+
$validtorMock->expects($this->any())
53+
->method('isValid')
54+
->willReturn(false);
6155

6256
$scopeConfigMock = $this->getMockBuilder(\Magento\Framework\App\Config::class)
6357
->setMethods(['isSetFlag'])->disableOriginalConstructor()->getMock();
58+
$scopeConfigMock->expects($this->any())
59+
->method('isSetFlag')
60+
->willReturn(true);
6461

6562
$resolverMock = $this->getMockBuilder(\Magento\Framework\View\Element\Template\File\Resolver::class)
6663
->setMethods([])->disableOriginalConstructor()->getMock();
@@ -72,48 +69,47 @@ public function getLinkAttributesDataProvider()
7269

7370
$contextMock->expects($this->any())
7471
->method('getValidator')
75-
->will($this->returnValue($validtorMock));
72+
->willReturn($validtorMock);
7673

7774
$contextMock->expects($this->any())
7875
->method('getResolver')
79-
->will($this->returnValue($resolverMock));
76+
->willReturn($resolverMock);
8077

8178
$contextMock->expects($this->any())
8279
->method('getEscaper')
83-
->will($this->returnValue($escaperMock));
80+
->willReturn($escaperMock);
8481

8582
$contextMock->expects($this->any())
8683
->method('getUrlBuilder')
87-
->will($this->returnValue($urlBuilderMock));
84+
->willReturn($urlBuilderMock);
8885

8986
$contextMock->expects($this->any())
9087
->method('getScopeConfig')
91-
->will($this->returnValue($scopeConfigMock));
88+
->willReturn($scopeConfigMock);
9289

9390
/** @var \Magento\Framework\View\Element\Html\Link $linkWithAttributes */
94-
$linkWithAttributes = $objectManagerHelper->getObject(
91+
$linkWithAttributes = $this->objectManager->getObject(
9592
\Magento\Framework\View\Element\Html\Link::class,
9693
['context' => $contextMock]
9794
);
95+
96+
$this->assertEquals(
97+
'href="http://site.com/link.html"',
98+
$linkWithAttributes->getLinkAttributes()
99+
);
100+
98101
/** @var \Magento\Framework\View\Element\Html\Link $linkWithoutAttributes */
99-
$linkWithoutAttributes = $objectManagerHelper->getObject(
102+
$linkWithoutAttributes = $this->objectManager->getObject(
100103
\Magento\Framework\View\Element\Html\Link::class,
101104
['context' => $contextMock]
102105
);
103-
104106
foreach ($this->allowedAttributes as $attribute) {
105-
$linkWithAttributes->setDataUsingMethod($attribute, $attribute);
107+
$linkWithoutAttributes->setDataUsingMethod($attribute, $attribute);
106108
}
107109

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+
);
118114
}
119115
}

0 commit comments

Comments
 (0)