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) { if(\OC::$server->getConfig()->getSystemValue('updatechecker', true) === true) {
$updater = new \OC\Updater\VersionCheck( $updater = new \OC\Updater\VersionCheck(
\OC::$server->getHTTPHelper(), \OC::$server->getHTTPClientService(),
\OC::$server->getConfig() \OC::$server->getConfig()
); );
$updateChecker = new \OCA\UpdateNotification\UpdateChecker( $updateChecker = new \OCA\UpdateNotification\UpdateChecker(

View File

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

View File

@ -33,28 +33,27 @@
namespace OC\Updater; namespace OC\Updater;
use OC\Hooks\BasicEmitter;
use OC\HTTPHelper;
use OC_Util; use OC_Util;
use OCP\Http\Client\IClientService;
use OCP\IConfig; use OCP\IConfig;
use OC\Setup; use OC\Setup;
use OCP\Util; use OCP\Util;
class VersionCheck { class VersionCheck {
/** @var \OC\HTTPHelper $helper */ /** @var IClientService */
private $httpHelper; private $clientService;
/** @var IConfig */ /** @var IConfig */
private $config; private $config;
/** /**
* @param HTTPHelper $httpHelper * @param IClientService $clientService
* @param IConfig $config * @param IConfig $config
*/ */
public function __construct(HTTPHelper $httpHelper, public function __construct(IClientService $clientService,
IConfig $config) { IConfig $config) {
$this->httpHelper = $httpHelper; $this->clientService = $clientService;
$this->config = $config; $this->config = $config;
} }
@ -94,7 +93,7 @@ class VersionCheck {
$url = $updaterUrl . '?version=' . $versionString; $url = $updaterUrl . '?version=' . $versionString;
$tmp = []; $tmp = [];
$xml = $this->httpHelper->getUrlContent($url); $xml = $this->getUrlContent($url);
if ($xml) { if ($xml) {
$loadEntities = libxml_disable_entity_loader(true); $loadEntities = libxml_disable_entity_loader(true);
$data = @simplexml_load_string($xml); $data = @simplexml_load_string($xml);
@ -115,5 +114,20 @@ class VersionCheck {
$this->config->setAppValue('core', 'lastupdateResult', json_encode($data)); $this->config->setAppValue('core', 'lastupdateResult', json_encode($data));
return $tmp; 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 { class VersionCheckTest extends \Test\TestCase {
/** @var IConfig| \PHPUnit_Framework_MockObject_MockObject */ /** @var IConfig| \PHPUnit_Framework_MockObject_MockObject */
private $config; private $config;
/** @var HTTPHelper | \PHPUnit_Framework_MockObject_MockObject*/ /** @var VersionCheck | \PHPUnit_Framework_MockObject_MockObject*/
private $httpHelper;
/** @var VersionCheck */
private $updater; private $updater;
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
$this->config = $this->getMockBuilder('\\OCP\\IConfig') $this->config = $this->getMockBuilder('\OCP\IConfig')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$this->httpHelper = $this->getMockBuilder('\\OC\\HTTPHelper') $clientService = $this->getMockBuilder('\OCP\Http\Client\IClientService')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$this->updater = new VersionCheck( $this->updater = $this->getMock('\OC\Updater\VersionCheck',
$this->httpHelper, ['getUrlContent'], [$clientService, $this->config]);
$this->config
);
} }
/** /**
@ -118,7 +114,7 @@ class VersionCheckTest extends \Test\TestCase {
<url>https://download.owncloud.org/community/owncloud-8.0.4.zip</url> <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> <web>http://doc.owncloud.org/server/8.0/admin_manual/maintenance/upgrade.html</web>
</owncloud>'; </owncloud>';
$this->httpHelper $this->updater
->expects($this->once()) ->expects($this->once())
->method('getUrlContent') ->method('getUrlContent')
->with($this->buildUpdateUrl('https://updates.owncloud.com/server/')) ->with($this->buildUpdateUrl('https://updates.owncloud.com/server/'))
@ -153,7 +149,7 @@ class VersionCheckTest extends \Test\TestCase {
->with('core', 'lastupdateResult', 'false'); ->with('core', 'lastupdateResult', 'false');
$updateXml = 'Invalid XML Response!'; $updateXml = 'Invalid XML Response!';
$this->httpHelper $this->updater
->expects($this->once()) ->expects($this->once())
->method('getUrlContent') ->method('getUrlContent')
->with($this->buildUpdateUrl('https://updates.owncloud.com/server/')) ->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> <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> <web>http://doc.owncloud.org/server/8.0/admin_manual/maintenance/upgrade.html</web>
</owncloud>'; </owncloud>';
$this->httpHelper $this->updater
->expects($this->once()) ->expects($this->once())
->method('getUrlContent') ->method('getUrlContent')
->with($this->buildUpdateUrl('https://myupdater.com/')) ->with($this->buildUpdateUrl('https://myupdater.com/'))
@ -245,7 +241,7 @@ class VersionCheckTest extends \Test\TestCase {
<url></url> <url></url>
<web></web> <web></web>
</owncloud>'; </owncloud>';
$this->httpHelper $this->updater
->expects($this->once()) ->expects($this->once())
->method('getUrlContent') ->method('getUrlContent')
->with($this->buildUpdateUrl('https://updates.owncloud.com/server/')) ->with($this->buildUpdateUrl('https://updates.owncloud.com/server/'))
@ -282,7 +278,7 @@ class VersionCheckTest extends \Test\TestCase {
->with('core', 'lastupdateResult', json_encode($expectedResult)); ->with('core', 'lastupdateResult', json_encode($expectedResult));
$updateXml = ''; $updateXml = '';
$this->httpHelper $this->updater
->expects($this->once()) ->expects($this->once())
->method('getUrlContent') ->method('getUrlContent')
->with($this->buildUpdateUrl('https://updates.owncloud.com/server/')) ->with($this->buildUpdateUrl('https://updates.owncloud.com/server/'))