summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2016-04-18 17:28:10 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2016-04-18 17:28:10 +0200
commit1626850fc98d619e502eb114d5f26baf06c1e183 (patch)
treef09987520080ec232019d54e22685f58abac87e3
parent5c3183cedd9672025199a1298853834df1c1320f (diff)
downloadnextcloud-server-1626850fc98d619e502eb114d5f26baf06c1e183.tar.gz
nextcloud-server-1626850fc98d619e502eb114d5f26baf06c1e183.zip
Remove deprecated HTTPHelper
-rw-r--r--apps/updatenotification/appinfo/app.php2
-rw-r--r--apps/updatenotification/appinfo/application.php2
-rw-r--r--lib/private/updater/versioncheck.php30
-rw-r--r--tests/lib/updater/versioncheck.php24
4 files changed, 34 insertions, 24 deletions
diff --git a/apps/updatenotification/appinfo/app.php b/apps/updatenotification/appinfo/app.php
index 54bef81305e..a88861c0942 100644
--- a/apps/updatenotification/appinfo/app.php
+++ b/apps/updatenotification/appinfo/app.php
@@ -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(
diff --git a/apps/updatenotification/appinfo/application.php b/apps/updatenotification/appinfo/application.php
index e0e8dad3d75..08ff4abf766 100644
--- a/apps/updatenotification/appinfo/application.php
+++ b/apps/updatenotification/appinfo/application.php
@@ -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(
diff --git a/lib/private/updater/versioncheck.php b/lib/private/updater/versioncheck.php
index 2c93952fed6..e42a1e2a40c 100644
--- a/lib/private/updater/versioncheck.php
+++ b/lib/private/updater/versioncheck.php
@@ -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;
+ }
+ }
}
diff --git a/tests/lib/updater/versioncheck.php b/tests/lib/updater/versioncheck.php
index 76afe893a7a..4613581a75f 100644
--- a/tests/lib/updater/versioncheck.php
+++ b/tests/lib/updater/versioncheck.php
@@ -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/'))