Skip to content

Commit adab7bb

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-95371' into 2.1.18-develop-pr68
2 parents 51b0c9e + 4bc54c7 commit adab7bb

File tree

2 files changed

+54
-8
lines changed

2 files changed

+54
-8
lines changed

app/code/Magento/Tax/Model/System/Message/Notifications.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Tax\Model\System\Message;
77

8+
use Magento\Framework\App\ObjectManager;
9+
810
/**
911
* Notifications class
1012
*/
@@ -57,22 +59,30 @@ class Notifications implements \Magento\Framework\Notification\MessageInterface
5759
*/
5860
private $notifications = [];
5961

62+
/**
63+
* @var \Magento\Framework\Escaper
64+
*/
65+
private $escaper;
66+
6067
/**
6168
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
6269
* @param \Magento\Framework\UrlInterface $urlBuilder
6370
* @param \Magento\Tax\Model\Config $taxConfig
6471
* @param NotificationInterface[] $notifications
72+
* @param \Magento\Framework\Escaper|null $escaper
6573
*/
6674
public function __construct(
6775
\Magento\Store\Model\StoreManagerInterface $storeManager,
6876
\Magento\Framework\UrlInterface $urlBuilder,
6977
\Magento\Tax\Model\Config $taxConfig,
70-
$notifications = []
78+
$notifications = [],
79+
\Magento\Framework\Escaper $escaper = null
7180
) {
7281
$this->storeManager = $storeManager;
7382
$this->urlBuilder = $urlBuilder;
7483
$this->taxConfig = $taxConfig;
7584
$this->notifications = $notifications;
85+
$this->escaper = $escaper ?: ObjectManager::getInstance()->get(\Magento\Framework\Escaper::class);
7686
}
7787

7888
/**
@@ -134,13 +144,13 @@ public function getSeverity()
134144
}
135145

136146
/**
137-
* Get URL for the tax notification documentation.
147+
* Get URL for the tax notification documentation
138148
*
139149
* @return string
140150
*/
141151
public function getInfoUrl()
142152
{
143-
return $this->taxConfig->getInfoUrl();
153+
return $this->escaper->escapeUrl($this->taxConfig->getInfoUrl());
144154
}
145155

146156
/**

app/code/Magento/Tax/Test/Unit/Model/System/Message/NotificationsTest.php

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace Magento\Tax\Test\Unit\Model\System\Message;
88

9+
use Magento\Framework\Escaper;
910
use Magento\Tax\Model\Config as TaxConfig;
1011
use Magento\Tax\Model\System\Message\Notifications;
1112
use Magento\Store\Model\StoreManagerInterface;
@@ -14,7 +15,7 @@
1415
use Magento\Tax\Model\System\Message\NotificationInterface;
1516

1617
/**
17-
* Test class for @see \Magento\Tax\Model\System\Message\Notifications
18+
* Test class for @see \Magento\Tax\Model\System\Message\Notifications.
1819
*/
1920
class NotificationsTest extends \PHPUnit_Framework_TestCase
2021
{
@@ -43,21 +44,29 @@ class NotificationsTest extends \PHPUnit_Framework_TestCase
4344
*/
4445
private $notificationMock;
4546

47+
/**
48+
* @var Escaper|\PHPUnit_Framework_MockObject_MockObject
49+
*/
50+
private $escaperMock;
51+
52+
/**
53+
* @inheritdoc
54+
*/
4655
protected function setUp()
4756
{
48-
parent::setUp();
49-
5057
$this->storeManagerMock = $this->getMock(StoreManagerInterface::class, [], [], '', false);
5158
$this->urlBuilderMock = $this->getMock(UrlInterface::class, [], [], '', false);
5259
$this->taxConfigMock = $this->getMock(TaxConfig::class, [], [], '', false);
5360
$this->notificationMock = $this->getMock(NotificationInterface::class, [], [], '', false);
61+
$this->escaperMock = $this->getMock(Escaper::class);
5462
$this->notifications = (new ObjectManager($this))->getObject(
5563
Notifications::class,
5664
[
5765
'storeManager' => $this->storeManagerMock,
5866
'urlBuilder' => $this->urlBuilderMock,
5967
'taxConfig' => $this->taxConfigMock,
60-
'notifications' => [$this->notificationMock]
68+
'notifications' => [$this->notificationMock],
69+
'escaper' => $this->escaperMock,
6170
]
6271
);
6372
}
@@ -84,17 +93,44 @@ public function dataProviderIsDisplayed()
8493
];
8594
}
8695

96+
/**
97+
* Unit test for getText method.
98+
*
99+
* @return void
100+
*/
87101
public function testGetText()
88102
{
103+
$url = 'http://info-url';
89104
$this->notificationMock->expects($this->once())->method('getText')->willReturn('Notification Text.');
90-
$this->taxConfigMock->expects($this->once())->method('getInfoUrl')->willReturn('http://info-url');
105+
$this->taxConfigMock->expects($this->once())->method('getInfoUrl')->willReturn($url);
91106
$this->urlBuilderMock->expects($this->once())->method('getUrl')
92107
->with('adminhtml/system_config/edit/section/tax')->willReturn('http://tax-config-url');
108+
$this->escaperMock->expects($this->once())
109+
->method('escapeUrl')
110+
->with($url)
111+
->willReturn($url);
93112

94113
$this->assertEquals(
95114
'Notification Text.<p>Please see <a href="http://info-url">documentation</a> for more details. '
96115
. 'Click here to go to <a href="http://tax-config-url">Tax Configuration</a> and change your settings.</p>',
97116
$this->notifications->getText()
98117
);
99118
}
119+
120+
/**
121+
* Unit test for getInfoUrl method.
122+
*
123+
* @return void
124+
*/
125+
public function testGetInfoUrl()
126+
{
127+
$url = 'http://info-url';
128+
$this->taxConfigMock->expects($this->once())->method('getInfoUrl')->willReturn($url);
129+
$this->escaperMock->expects($this->once())
130+
->method('escapeUrl')
131+
->with($url)
132+
->willReturn($url);
133+
134+
$this->assertEquals($url, $this->notifications->getInfoUrl());
135+
}
100136
}

0 commit comments

Comments
 (0)