@@ -40,11 +40,18 @@ class FeedTest extends \PHPUnit_Framework_TestCase
40
40
/** @var \Magento\Framework\App\DeploymentConfig|\PHPUnit_Framework_MockObject_MockObject */
41
41
protected $ deploymentConfig ;
42
42
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
+
43
49
protected function setUp ()
44
50
{
45
51
$ this ->inboxFactory = $ this ->getMock ('Magento\AdminNotification\Model\InboxFactory ' , ['create ' ], [], '' , false );
46
52
$ 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 ();
48
55
$ this ->appState = $ this ->getMock ('\Magento\Framework\App\State ' , ['getInstallDate ' ], [], '' , false );
49
56
$ this ->inboxModel = $ this ->getMock (
50
57
'\Magento\AdminNotification\Model\Inbox ' ,
@@ -78,6 +85,10 @@ protected function setUp()
78
85
$ this ->deploymentConfig = $ this ->getMockBuilder ('\Magento\Framework\App\DeploymentConfig ' )
79
86
->disableOriginalConstructor ()->getMock ();
80
87
$ 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
+
81
92
$ this ->feed = $ this ->objectManagerHelper ->getObject (
82
93
'Magento\AdminNotification\Model\Feed ' ,
83
94
[
@@ -87,6 +98,8 @@ protected function setUp()
87
98
'appState ' => $ this ->appState ,
88
99
'curlFactory ' => $ this ->curlFactory ,
89
100
'deploymentConfig ' => $ this ->deploymentConfig ,
101
+ 'productMetadata ' => $ this ->productMetadata ,
102
+ 'urlBuilder ' => $ this ->urlBuilder
90
103
]
91
104
);
92
105
}
@@ -98,14 +111,31 @@ protected function setUp()
98
111
*/
99
112
public function testCheckUpdate ($ callInbox , $ curlRequest )
100
113
{
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 )));
102
132
$ 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 ));
104
135
$ this ->backendConfig ->expects ($ this ->at (0 ))->method ('getValue ' )->will ($ this ->returnValue ('1 ' ));
105
136
$ this ->backendConfig ->expects ($ this ->once ())->method ('isSetFlag ' )->will ($ this ->returnValue (false ));
106
137
$ this ->backendConfig ->expects ($ this ->at (1 ))->method ('getValue ' )
107
138
->will ($ this ->returnValue ('http://feed.magento.com ' ));
108
- $ this ->cacheManager ->expects ($ this ->once ())->method ('load ' )->will (($ this ->returnValue ($ lastUpdate )));
109
139
$ this ->deploymentConfig ->expects ($ this ->once ())->method ('get ' )
110
140
->with ('install/date ' )->will ($ this ->returnValue ('Sat, 6 Sep 2014 16:46:11 UTC ' ));
111
141
if ($ callInbox ) {
0 commit comments