15 class FeedTest extends \PHPUnit\Framework\TestCase
55 $this->inboxFactory = $this->createPartialMock(
56 \
Magento\AdminNotification\Model\InboxFactory::class,
59 $this->curlFactory = $this->createPartialMock(\
Magento\Framework\HTTP\Adapter\CurlFactory::class, [
'create']);
60 $this->curl = $this->getMockBuilder(\
Magento\Framework\HTTP\Adapter\Curl::class)
61 ->disableOriginalConstructor()->getMock();
62 $this->appState = $this->createPartialMock(\
Magento\Framework\
App\State::class, [
'getInstallDate']);
63 $this->inboxModel = $this->createPartialMock(\
Magento\AdminNotification\Model\Inbox::class, [
67 $this->backendConfig = $this->createPartialMock(
75 $this->cacheManager = $this->createPartialMock(
86 $this->deploymentConfig = $this->getMockBuilder(\
Magento\Framework\
App\DeploymentConfig::class)
87 ->disableOriginalConstructor()->getMock();
89 $this->objectManagerHelper =
new ObjectManagerHelper($this);
91 $this->productMetadata = $this->getMockBuilder(\
Magento\Framework\
App\ProductMetadata::class)
92 ->disableOriginalConstructor()->getMock();
94 $this->urlBuilder = $this->createMock(\
Magento\Framework\UrlInterface::class);
96 $this->feed = $this->objectManagerHelper->getObject(
97 \
Magento\AdminNotification\Model\Feed::class,
99 'backendConfig' => $this->backendConfig,
100 'cacheManager' => $this->cacheManager,
101 'inboxFactory' => $this->inboxFactory,
102 'appState' => $this->appState,
103 'curlFactory' => $this->curlFactory,
104 'deploymentConfig' => $this->deploymentConfig,
105 'productMetadata' => $this->productMetadata,
106 'urlBuilder' => $this->urlBuilder
118 $mockName =
'Test Product Name';
119 $mockVersion =
'0.0.0';
120 $mockEdition =
'Test Edition';
121 $mockUrl =
'http://test-url';
123 $this->productMetadata->expects($this->once())->method(
'getName')->willReturn($mockName);
124 $this->productMetadata->expects($this->once())->method(
'getVersion')->willReturn($mockVersion);
125 $this->productMetadata->expects($this->once())->method(
'getEdition')->willReturn($mockEdition);
126 $this->urlBuilder->expects($this->once())->method(
'getUrl')->with(
'*/*/*')->willReturn($mockUrl);
130 'useragent' => $mockName .
'/' . $mockVersion .
' (' . $mockEdition .
')',
131 'referer' => $mockUrl
135 $this->cacheManager->expects($this->once())->method(
'load')->will(($this->returnValue($lastUpdate)));
136 $this->curlFactory->expects($this->at(0))->method(
'create')->will($this->returnValue($this->curl));
137 $this->curl->expects($this->once())->method(
'setConfig')->with($configValues)->willReturnSelf();
138 $this->curl->expects($this->once())->method(
'read')->will($this->returnValue($curlRequest));
139 $this->backendConfig->expects($this->at(0))->method(
'getValue')->will($this->returnValue(
'1'));
140 $this->backendConfig->expects($this->once())->method(
'isSetFlag')->will($this->returnValue(
false));
141 $this->backendConfig->expects($this->at(1))->method(
'getValue')
142 ->will($this->returnValue(
'http://feed.magento.com'));
143 $this->deploymentConfig->expects($this->once())->method(
'get')
145 ->will($this->returnValue(
'Sat, 6 Sep 2014 16:46:11 UTC'));
147 $this->inboxFactory->expects($this->once())->method(
'create')
148 ->will($this->returnValue($this->inboxModel));
149 $this->inboxModel->expects($this->once())
154 $fieldsToCheck = [
'title',
'description',
'url'];
160 ? $initialValue && !strpos($haystack,
'<') && !strpos($haystack,
'>')
168 ->will($this->returnSelf());
170 $this->inboxFactory->expects($this->never())->method(
'create');
171 $this->inboxModel->expects($this->never())->method(
'parse');
174 $this->feed->checkUpdate();
187 <?xml version="1.0" encoding="utf-8" ?> 188 <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> 190 <title>MagentoCommerce</title> 192 <title><![CDATA[Test Title]]></title> 193 <link><![CDATA[http://magento.com/feed_url]]></link> 194 <severity>4</severity> 195 <description><![CDATA[Test Description]]></description> 196 <pubDate>Tue, 9 Sep 2014 16:46:11 UTC</pubDate> 205 <?xml version="1.0" encoding="utf-8" ?> 206 <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> 208 <title>MagentoCommerce</title> 210 <title><![CDATA[Test Title]]></title> 211 <link><![CDATA[http://magento.com/feed_url]]></link> 212 <severity>4</severity> 213 <description><![CDATA[Test Description]]></description> 214 <pubDate>Tue, 1 Sep 2014 16:46:11 UTC</pubDate> 224 <?xml version="1.0" encoding="utf-8" ?> 225 <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> 227 <title>MagentoCommerce</title> 229 <title><![CDATA[<script>alert("Hello!");</script>Test Title]]></title> 230 <link><![CDATA[http://magento.com/feed_url<script>alert("Hello!");</script>]]></link> 231 <severity>4</severity> 232 <description><![CDATA[Test <script>alert("Hello!");</script>Description]]></description> 233 <pubDate>Tue, 20 Jun 2017 13:14:47 UTC</pubDate> testCheckUpdate($callInbox, $curlRequest)
const CONFIG_PATH_INSTALL_DATE
checkUpdateDataProvider()