inboxFactory = $this->createPartialMock(
InboxFactory::class,
['create']
);
$this->curlFactory = $this->createPartialMock(CurlFactory::class, ['create']);
$this->curl = $this->createMock(Curl::class);
$this->appState = $this->createPartialMock(State::class, []);
$this->inboxModel = $this->createPartialMock(Inbox::class, [
'__wakeup',
'parse'
]);
$this->backendConfig = $this->createPartialMock(
ConfigInterface::class,
[
'getValue',
'setValue',
'isSetFlag'
]
);
$this->cacheManager = $this->createPartialMock(
CacheInterface::class,
[
'load',
'getFrontend',
'remove',
'save',
'clean'
]
);
$this->deploymentConfig = $this->createMock(DeploymentConfig::class);
$this->objectManagerHelper = new ObjectManagerHelper($this);
$this->productMetadata = $this->createMock(ProductMetadata::class);
$this->urlBuilder = $this->getMockForAbstractClass(UrlInterface::class);
$this->feed = $this->objectManagerHelper->getObject(
Feed::class,
[
'backendConfig' => $this->backendConfig,
'cacheManager' => $this->cacheManager,
'inboxFactory' => $this->inboxFactory,
'appState' => $this->appState,
'curlFactory' => $this->curlFactory,
'deploymentConfig' => $this->deploymentConfig,
'productMetadata' => $this->productMetadata,
'urlBuilder' => $this->urlBuilder
]
);
}
/**
* @param bool $callInbox
* @param string $curlRequest
*
* @return void
* @dataProvider checkUpdateDataProvider
*/
public function testCheckUpdate(bool $callInbox, string $curlRequest): void
{
$mockName = 'Test Product Name';
$mockVersion = '0.0.0';
$mockEdition = 'Test Edition';
$mockUrl = 'http://test-url';
$this->productMetadata->expects($this->once())->method('getName')->willReturn($mockName);
$this->productMetadata->expects($this->once())->method('getVersion')->willReturn($mockVersion);
$this->productMetadata->expects($this->once())->method('getEdition')->willReturn($mockEdition);
$this->urlBuilder->expects($this->once())->method('getUrl')->with('*/*/*')->willReturn($mockUrl);
$configValues = [
'timeout' => 2,
'useragent' => $mockName . '/' . $mockVersion . ' (' . $mockEdition . ')',
'referer' => $mockUrl
];
$lastUpdate = 0;
$this->cacheManager->expects($this->once())->method('load')->willReturn($lastUpdate);
$this->curlFactory
->method('create')
->willReturn($this->curl);
$this->curl->expects($this->once())->method('setOptions')->with($configValues)->willReturnSelf();
$this->curl->expects($this->once())->method('read')->willReturn($curlRequest);
$this->backendConfig->expects($this->once())->method('isSetFlag')->willReturn(false);
$this->backendConfig
->method('getValue')
->willReturnOnConsecutiveCalls('1', 'http://feed.magento.com');
$this->deploymentConfig->expects($this->once())->method('get')
->with(ConfigOptionsListConstants::CONFIG_PATH_INSTALL_DATE)
->willReturn('Sat, 6 Sep 2014 16:46:11 UTC');
if ($callInbox) {
$this->inboxFactory->expects($this->once())->method('create')
->willReturn($this->inboxModel);
$this->inboxModel->expects($this->once())
->method('parse')
->with(
$this->callback(
function ($data) {
$fieldsToCheck = ['title', 'description', 'url'];
return array_reduce(
$fieldsToCheck,
function ($initialValue, $item) use ($data) {
$haystack = $data[0][$item] ?? false;
return $haystack
? $initialValue && !strpos($haystack, '<') && !strpos($haystack, '>')
: true;
},
true
);
}
)
)
->willReturnSelf();
} else {
$this->inboxFactory->expects($this->never())->method('create');
$this->inboxModel->expects($this->never())->method('parse');
}
$this->feed->checkUpdate();
}
/**
* @return array
*/
public function checkUpdateDataProvider(): array
{
return [
[
true,
'HEADER
MagentoCommerce
-
4
Tue, 9 Sep 2014 16:46:11 UTC
',
],
[
false,
'HEADER
MagentoCommerce
-
4
Tue, 1 Sep 2014 16:46:11 UTC
'
],
[
true,
// @codingStandardsIgnoreStart
'HEADER
MagentoCommerce
-
alert("Hello!");Test Title]]>
alert("Hello!");]]>
4
alert("Hello!");Description]]>
Tue, 20 Jun 2017 13:14:47 UTC
'
// @codingStandardsIgnoreEnd
]
];
}
}