Remove deprecated HTTPHelper

This commit is contained in:
Thomas Müller 2016-04-18 17:28:10 +02:00
parent 5c3183cedd
commit 1626850fc9
No known key found for this signature in database
GPG Key ID: A943788A3BBEC44C
4 changed files with 34 additions and 24 deletions

View File

@ -21,7 +21,7 @@
if(\OC::$server->getConfig()->getSystemValue('updatechecker', true) === true) {
$updater = new \OC\Updater\VersionCheck(
\OC::$server->getHTTPHelper(),
\OC::$server->getHTTPClientService(),
\OC::$server->getConfig()
);
$updateChecker = new \OCA\UpdateNotification\UpdateChecker(

View File

@ -35,7 +35,7 @@ class Application extends App {
$container->registerService('AdminController', function(IAppContainer $c) {
$updater = new \OC\Updater\VersionCheck(
\OC::$server->getHTTPHelper(),
\OC::$server->getHTTPClientService(),
\OC::$server->getConfig()
);
return new AdminController(

View File

@ -33,28 +33,27 @@
namespace OC\Updater;
use OC\Hooks\BasicEmitter;
use OC\HTTPHelper;
use OC_Util;
use OCP\Http\Client\IClientService;
use OCP\IConfig;
use OC\Setup;
use OCP\Util;
class VersionCheck {
/** @var \OC\HTTPHelper $helper */
private $httpHelper;
/** @var IClientService */
private $clientService;
/** @var IConfig */
private $config;
/**
* @param HTTPHelper $httpHelper
* @param IClientService $clientService
* @param IConfig $config
*/
public function __construct(HTTPHelper $httpHelper,
public function __construct(IClientService $clientService,
IConfig $config) {
$this->httpHelper = $httpHelper;
$this->clientService = $clientService;
$this->config = $config;
}
@ -94,7 +93,7 @@ class VersionCheck {
$url = $updaterUrl . '?version=' . $versionString;
$tmp = [];
$xml = $this->httpHelper->getUrlContent($url);
$xml = $this->getUrlContent($url);
if ($xml) {
$loadEntities = libxml_disable_entity_loader(true);
$data = @simplexml_load_string($xml);
@ -115,5 +114,20 @@ class VersionCheck {
$this->config->setAppValue('core', 'lastupdateResult', json_encode($data));
return $tmp;
}
/**
* @codeCoverageIgnore
* @param string $url
* @return bool|resource|string
*/
protected function getUrlContent($url) {
try {
$client = $this->clientService->newClient();
$response = $client->get($url);
return $response->getBody();
} catch (\Exception $e) {
return false;
}
}
}

View File

@ -29,24 +29,20 @@ use OCP\Util;
class VersionCheckTest extends \Test\TestCase {
/** @var IConfig| \PHPUnit_Framework_MockObject_MockObject */
private $config;
/** @var HTTPHelper | \PHPUnit_Framework_MockObject_MockObject*/
private $httpHelper;
/** @var VersionCheck */
/** @var VersionCheck | \PHPUnit_Framework_MockObject_MockObject*/
private $updater;
public function setUp() {
parent::setUp();
$this->config = $this->getMockBuilder('\\OCP\\IConfig')
$this->config = $this->getMockBuilder('\OCP\IConfig')
->disableOriginalConstructor()
->getMock();
$this->httpHelper = $this->getMockBuilder('\\OC\\HTTPHelper')
$clientService = $this->getMockBuilder('\OCP\Http\Client\IClientService')
->disableOriginalConstructor()
->getMock();
$this->updater = new VersionCheck(
$this->httpHelper,
$this->config
);
$this->updater = $this->getMock('\OC\Updater\VersionCheck',
['getUrlContent'], [$clientService, $this->config]);
}
/**
@ -118,7 +114,7 @@ class VersionCheckTest extends \Test\TestCase {
<url>https://download.owncloud.org/community/owncloud-8.0.4.zip</url>
<web>http://doc.owncloud.org/server/8.0/admin_manual/maintenance/upgrade.html</web>
</owncloud>';
$this->httpHelper
$this->updater
->expects($this->once())
->method('getUrlContent')
->with($this->buildUpdateUrl('https://updates.owncloud.com/server/'))
@ -153,7 +149,7 @@ class VersionCheckTest extends \Test\TestCase {
->with('core', 'lastupdateResult', 'false');
$updateXml = 'Invalid XML Response!';
$this->httpHelper
$this->updater
->expects($this->once())
->method('getUrlContent')
->with($this->buildUpdateUrl('https://updates.owncloud.com/server/'))
@ -201,7 +197,7 @@ class VersionCheckTest extends \Test\TestCase {
<url>https://download.owncloud.org/community/owncloud-8.0.4.zip</url>
<web>http://doc.owncloud.org/server/8.0/admin_manual/maintenance/upgrade.html</web>
</owncloud>';
$this->httpHelper
$this->updater
->expects($this->once())
->method('getUrlContent')
->with($this->buildUpdateUrl('https://myupdater.com/'))
@ -245,7 +241,7 @@ class VersionCheckTest extends \Test\TestCase {
<url></url>
<web></web>
</owncloud>';
$this->httpHelper
$this->updater
->expects($this->once())
->method('getUrlContent')
->with($this->buildUpdateUrl('https://updates.owncloud.com/server/'))
@ -282,7 +278,7 @@ class VersionCheckTest extends \Test\TestCase {
->with('core', 'lastupdateResult', json_encode($expectedResult));
$updateXml = '';
$this->httpHelper
$this->updater
->expects($this->once())
->method('getUrlContent')
->with($this->buildUpdateUrl('https://updates.owncloud.com/server/'))