Skip to content

Commit 2faaa50

Browse files
committed
Merge branch 'MAGETWO-31354' into develop
2 parents 895a0c3 + 8a40eac commit 2faaa50

File tree

8 files changed

+99
-19
lines changed

8 files changed

+99
-19
lines changed

app/code/Magento/AdminNotification/Model/Feed.php

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* AdminNotification Feed model
1010
*
1111
* @author Magento Core Team <core@magentocommerce.com>
12+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1213
*/
1314
class Feed extends \Magento\Framework\Model\AbstractModel
1415
{
@@ -50,16 +51,29 @@ class Feed extends \Magento\Framework\Model\AbstractModel
5051
*/
5152
protected $_deploymentConfig;
5253

54+
/**
55+
* @var \Magento\Framework\App\ProductMetadataInterface
56+
*/
57+
protected $productMetadata;
58+
59+
/**
60+
* @var \Magento\Framework\UrlInterface
61+
*/
62+
protected $urlBuilder;
63+
5364
/**
5465
* @param \Magento\Framework\Model\Context $context
5566
* @param \Magento\Framework\Registry $registry
5667
* @param \Magento\Backend\App\ConfigInterface $backendConfig
57-
* @param \Magento\AdminNotification\Model\InboxFactory $inboxFactory
58-
* @param \Magento\Framework\Model\Resource\AbstractResource $resource
68+
* @param InboxFactory $inboxFactory
69+
* @param \Magento\Framework\HTTP\Adapter\CurlFactory $curlFactory
5970
* @param \Magento\Framework\App\DeploymentConfig $deploymentConfig
71+
* @param \Magento\Framework\App\ProductMetadataInterface $productMetadata
72+
* @param \Magento\Framework\UrlInterface $urlBuilder
73+
* @param \Magento\Framework\Model\Resource\AbstractResource $resource
6074
* @param \Magento\Framework\Data\Collection\Db $resourceCollection
61-
* @param \Magento\Framework\HTTP\Adapter\curlFactory $curlFactory
6275
* @param array $data
76+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
6377
*/
6478
public function __construct(
6579
\Magento\Framework\Model\Context $context,
@@ -68,15 +82,19 @@ public function __construct(
6882
\Magento\AdminNotification\Model\InboxFactory $inboxFactory,
6983
\Magento\Framework\HTTP\Adapter\CurlFactory $curlFactory,
7084
\Magento\Framework\App\DeploymentConfig $deploymentConfig,
85+
\Magento\Framework\App\ProductMetadataInterface $productMetadata,
86+
\Magento\Framework\UrlInterface $urlBuilder,
7187
\Magento\Framework\Model\Resource\AbstractResource $resource = null,
7288
\Magento\Framework\Data\Collection\Db $resourceCollection = null,
7389
array $data = []
7490
) {
7591
parent::__construct($context, $registry, $resource, $resourceCollection, $data);
76-
$this->_backendConfig = $backendConfig;
77-
$this->_inboxFactory = $inboxFactory;
78-
$this->curlFactory = $curlFactory;
92+
$this->_backendConfig = $backendConfig;
93+
$this->_inboxFactory = $inboxFactory;
94+
$this->curlFactory = $curlFactory;
7995
$this->_deploymentConfig = $deploymentConfig;
96+
$this->productMetadata = $productMetadata;
97+
$this->urlBuilder = $urlBuilder;
8098
}
8199

82100
/**
@@ -191,7 +209,15 @@ public function setLastUpdate()
191209
public function getFeedData()
192210
{
193211
$curl = $this->curlFactory->create();
194-
$curl->setConfig(['timeout' => 2]);
212+
$curl->setConfig(
213+
[
214+
'timeout' => 2,
215+
'useragent' => $this->productMetadata->getName()
216+
. '/' . $this->productMetadata->getVersion()
217+
. ' (' . $this->productMetadata->getEdition() . ')',
218+
'referer' => $this->urlBuilder->getUrl('*/*/*')
219+
]
220+
);
195221
$curl->write(\Zend_Http_Client::GET, $this->getFeedUrl(), '1.0');
196222
$data = $curl->read();
197223
if ($data === false) {

app/code/Magento/AdminNotification/etc/config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<default>
1010
<system>
1111
<adminnotification>
12-
<feed_url>notifications.magentocommerce.com/community/notifications.rss</feed_url>
12+
<feed_url>notifications.magentocommerce.com/magento2/community/notifications.rss</feed_url>
1313
<popup_url>widgets.magentocommerce.com/notificationPopup</popup_url>
1414
<severity_icons_url>widgets.magentocommerce.com/%s/%s.gif</severity_icons_url>
1515
<use_https>0</use_https>

app/code/Magento/Version/Controller/Index/Index.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
*/
1616
class Index extends Action
1717
{
18-
const PRODUCT_NAME = "Magento";
19-
2018
/**
2119
* @var ProductMetadataInterface
2220
*/
@@ -40,7 +38,7 @@ public function __construct(Context $context, ProductMetadataInterface $productM
4038
public function execute()
4139
{
4240
$this->getResponse()->setBody(
43-
self::PRODUCT_NAME . '/' .
41+
$this->productMetadata->getName() . '/' .
4442
$this->productMetadata->getVersion() . ' (' .
4543
$this->productMetadata->getEdition() . ')'
4644
);

dev/tests/unit/testsuite/Magento/AdminNotification/Model/FeedTest.php

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,18 @@ class FeedTest extends \PHPUnit_Framework_TestCase
4040
/** @var \Magento\Framework\App\DeploymentConfig|\PHPUnit_Framework_MockObject_MockObject */
4141
protected $deploymentConfig;
4242

43+
/** @var \Magento\Framework\App\DeploymentConfig|\PHPUnit_Framework_MockObject_MockObject */
44+
protected $productMetadata;
45+
46+
/** @var \Magento\Framework\App\DeploymentConfig|\PHPUnit_Framework_MockObject_MockObject */
47+
protected $urlBuilder;
48+
4349
protected function setUp()
4450
{
4551
$this->inboxFactory = $this->getMock('Magento\AdminNotification\Model\InboxFactory', ['create'], [], '', false);
4652
$this->curlFactory = $this->getMock('\Magento\Framework\HTTP\Adapter\CurlFactory', ['create'], [], '', false);
47-
$this->curl = $this->getMock('\Magento\Framework\HTTP\Adapter\Curl', ['read']);
53+
$this->curl = $this->getMockBuilder('\Magento\Framework\HTTP\Adapter\Curl')
54+
->disableOriginalConstructor()->getMock();
4855
$this->appState = $this->getMock('\Magento\Framework\App\State', ['getInstallDate'], [], '', false);
4956
$this->inboxModel = $this->getMock(
5057
'\Magento\AdminNotification\Model\Inbox',
@@ -78,6 +85,10 @@ protected function setUp()
7885
$this->deploymentConfig = $this->getMockBuilder('\Magento\Framework\App\DeploymentConfig')
7986
->disableOriginalConstructor()->getMock();
8087
$this->objectManagerHelper = new ObjectManagerHelper($this);
88+
89+
$this->productMetadata = $this->getMock('Magento\Framework\App\ProductMetadata');
90+
$this->urlBuilder = $this->getMock('Magento\Framework\Url', [], [], '', false);
91+
8192
$this->feed = $this->objectManagerHelper->getObject(
8293
'Magento\AdminNotification\Model\Feed',
8394
[
@@ -87,6 +98,8 @@ protected function setUp()
8798
'appState' => $this->appState,
8899
'curlFactory' => $this->curlFactory,
89100
'deploymentConfig' => $this->deploymentConfig,
101+
'productMetadata' => $this->productMetadata,
102+
'urlBuilder' => $this->urlBuilder
90103
]
91104
);
92105
}
@@ -98,14 +111,31 @@ protected function setUp()
98111
*/
99112
public function testCheckUpdate($callInbox, $curlRequest)
100113
{
101-
$lastUpdate = 1410121748;
114+
$mockName = 'Test Product Name';
115+
$mockVersion = '0.42.0-beta7';
116+
$mockEdition = 'Test Edition';
117+
$mockUrl = 'http://test-url';
118+
119+
$this->productMetadata->expects($this->once())->method('getName')->willReturn($mockName);
120+
$this->productMetadata->expects($this->once())->method('getVersion')->willReturn($mockVersion);
121+
$this->productMetadata->expects($this->once())->method('getEdition')->willReturn($mockEdition);
122+
$this->urlBuilder->expects($this->once())->method('getUrl')->with('*/*/*')->willReturn($mockUrl);
123+
124+
$configValues = [
125+
'timeout' => 2,
126+
'useragent' => $mockName . '/' . $mockVersion . ' (' . $mockEdition . ')',
127+
'referer' => $mockUrl
128+
];
129+
130+
$lastUpdate = 0;
131+
$this->cacheManager->expects($this->once())->method('load')->will(($this->returnValue($lastUpdate)));
102132
$this->curlFactory->expects($this->at(0))->method('create')->will($this->returnValue($this->curl));
103-
$this->curl->expects($this->any())->method('read')->will($this->returnValue($curlRequest));
133+
$this->curl->expects($this->once())->method('setConfig')->with($configValues)->willReturnSelf();
134+
$this->curl->expects($this->once())->method('read')->will($this->returnValue($curlRequest));
104135
$this->backendConfig->expects($this->at(0))->method('getValue')->will($this->returnValue('1'));
105136
$this->backendConfig->expects($this->once())->method('isSetFlag')->will($this->returnValue(false));
106137
$this->backendConfig->expects($this->at(1))->method('getValue')
107138
->will($this->returnValue('http://feed.magento.com'));
108-
$this->cacheManager->expects($this->once())->method('load')->will(($this->returnValue($lastUpdate)));
109139
$this->deploymentConfig->expects($this->once())->method('get')
110140
->with('install/date')->will($this->returnValue('Sat, 6 Sep 2014 16:46:11 UTC'));
111141
if ($callInbox) {

dev/tests/unit/testsuite/Magento/Framework/App/ProductMetadataTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,10 @@ public function testGetEdition()
3434
$productEdition = $this->productMetadata->getEdition();
3535
$this->assertNotEmpty($productEdition, 'Empty product edition');
3636
}
37+
38+
public function testGetName()
39+
{
40+
$productName = $this->productMetadata->getName();
41+
$this->assertNotEmpty($productName, 'Empty product name');
42+
}
3743
}

lib/internal/Magento/Framework/App/ProductMetadata.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
class ProductMetadata implements ProductMetadataInterface
1313
{
1414
const EDITION_NAME = 'Community';
15+
const PRODUCT_NAME = 'Magento';
1516

1617
/**
1718
* Get Product version
@@ -32,4 +33,14 @@ public function getEdition()
3233
{
3334
return self::EDITION_NAME;
3435
}
36+
37+
/**
38+
* Get Product name
39+
*
40+
* @return string
41+
*/
42+
public function getName()
43+
{
44+
return self::PRODUCT_NAME;
45+
}
3546
}

lib/internal/Magento/Framework/App/ProductMetadataInterface.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,11 @@ public function getVersion();
2222
* @return string
2323
*/
2424
public function getEdition();
25+
26+
/**
27+
* Get Product name
28+
*
29+
* @return string
30+
*/
31+
public function getName();
2532
}

lib/internal/Magento/Framework/HTTP/Adapter/Curl.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@ class Curl implements \Zend_Http_Client_Adapter_Interface
3535
* @var array
3636
*/
3737
protected $_allowedParams = [
38-
'timeout' => CURLOPT_TIMEOUT,
38+
'timeout' => CURLOPT_TIMEOUT,
3939
'maxredirects' => CURLOPT_MAXREDIRS,
40-
'proxy' => CURLOPT_PROXY,
41-
'ssl_cert' => CURLOPT_SSLCERT,
42-
'userpwd' => CURLOPT_USERPWD,
40+
'proxy' => CURLOPT_PROXY,
41+
'ssl_cert' => CURLOPT_SSLCERT,
42+
'userpwd' => CURLOPT_USERPWD,
43+
'useragent' => CURLOPT_USERAGENT,
44+
'referer' => CURLOPT_REFERER
4345
];
4446

4547
/**

0 commit comments

Comments
 (0)