mirror of
https://github.com/owncloud/bookmarks.git
synced 2024-11-28 04:24:09 +01:00
adjust unit test
This commit is contained in:
parent
1dc98e7067
commit
3428c3638a
@ -96,14 +96,41 @@ class Test_LibBookmarks_Bookmarks extends PHPUnit_Framework_TestCase {
|
||||
|
||||
$config = $this->getMockBuilder('\OCP\IConfig')
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$clientService = $this->getMock('OCP\Http\Client\IClientService');
|
||||
$httpHelperMock = $this->getMockBuilder('\OC\HTTPHelper')
|
||||
->setConstructorArgs(array($config, $clientService))
|
||||
->getMock();
|
||||
$returnAmazonDe = file_get_contents(__DIR__ . '/res/amazonHtml.file');
|
||||
$returnGolemDe = file_get_contents(__DIR__ . '/res/golemHtml.file');
|
||||
$httpHelperMock->expects($this->any())->method('getUrlContent')->with($this->anything())->will($this->onConsecutiveCalls($returnAmazonDe, $returnGolemDe));
|
||||
$this->registerHttpHelper($httpHelperMock);
|
||||
$amazonResponse = $this->getMock('OCP\Http\Client\IResponse');
|
||||
$amazonResponse->expects($this->once())
|
||||
->method('getBody')
|
||||
->will($this->returnValue(file_get_contents(__DIR__ . '/res/amazonHtml.file')));
|
||||
$amazonResponse->expects($this->once())
|
||||
->method('getHeader')
|
||||
->with('Content-Type')
|
||||
->will($this->returnValue(''));
|
||||
|
||||
$golemResponse = $this->getMock('OCP\Http\Client\IResponse');
|
||||
$golemResponse->expects($this->once())
|
||||
->method('getBody')
|
||||
->will($this->returnValue(file_get_contents(__DIR__ . '/res/golemHtml.file')));
|
||||
$golemResponse->expects($this->once())
|
||||
->method('getHeader')
|
||||
->with('Content-Type')
|
||||
->will($this->returnValue('text/html; charset=UTF-8'));
|
||||
|
||||
$clientMock = $this->getMock('OCP\Http\Client\IClient');
|
||||
$clientMock->expects($this->exactly(2))
|
||||
->method('get')
|
||||
->will($this->returnCallback(function ($page) use($amazonResponse, $golemResponse) {
|
||||
if($page === 'amazonHtml') {
|
||||
return $amazonResponse;
|
||||
} else if($page === 'golemHtml') {
|
||||
return $golemResponse;
|
||||
}
|
||||
}));
|
||||
|
||||
$clientServiceMock = $this->getMock('OCP\Http\Client\IClientService');
|
||||
$clientServiceMock->expects($this->any())
|
||||
->method('newClient')
|
||||
->will($this->returnValue($clientMock));
|
||||
|
||||
$this->registerHttpService($clientServiceMock);
|
||||
|
||||
$metadataAmazon = Bookmarks::getURLMetadata('amazonHtml');
|
||||
$this->assertTrue($metadataAmazon['url'] == 'amazonHtml');
|
||||
@ -126,13 +153,13 @@ class Test_LibBookmarks_Bookmarks extends PHPUnit_Framework_TestCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an http helper mock for testing purposes.
|
||||
* @param $httpHelper http helper mock
|
||||
* Register an http service mock for testing purposes.
|
||||
*
|
||||
* @param \OCP\Http\Client\IClientService $service
|
||||
*/
|
||||
private function registerHttpHelper($httpHelper) {
|
||||
$this->oldHttpHelper = \OC::$server->query('HTTPHelper');
|
||||
\OC::$server->registerService('HTTPHelper', function () use ($httpHelper) {
|
||||
return $httpHelper;
|
||||
private function registerHttpService($service) {
|
||||
\OC::$server->registerService('HttpClientService', function () use ($service) {
|
||||
return $service;
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user