summaryrefslogtreecommitdiffstats
path: root/tests/lib
diff options
context:
space:
mode:
authorLukas Reschke <lukas@owncloud.com>2015-03-16 11:28:23 +0100
committerLukas Reschke <lukas@owncloud.com>2015-03-25 16:04:41 +0100
commit5f044ebf1bc6f45acec2e79dc05185acd0405f42 (patch)
tree8bc8797ef55588d3aab1b160acb3e2f5576d460f /tests/lib
parent13904a7f8979a87492ac765e05017eb1e4b69588 (diff)
downloadnextcloud-server-5f044ebf1bc6f45acec2e79dc05185acd0405f42.tar.gz
nextcloud-server-5f044ebf1bc6f45acec2e79dc05185acd0405f42.zip
Add wrapper for Guzzle
Diffstat (limited to 'tests/lib')
-rw-r--r--tests/lib/app/infoparser.php6
-rw-r--r--tests/lib/http/client/clientservicetest.php25
-rw-r--r--tests/lib/http/client/clienttest.php110
-rw-r--r--tests/lib/http/client/responsetest.php37
-rw-r--r--tests/lib/httphelper.php23
-rw-r--r--tests/lib/updater.php4
6 files changed, 179 insertions, 26 deletions
diff --git a/tests/lib/app/infoparser.php b/tests/lib/app/infoparser.php
index 762a3584cd2..fb4ffe8af94 100644
--- a/tests/lib/app/infoparser.php
+++ b/tests/lib/app/infoparser.php
@@ -21,10 +21,10 @@ class InfoParser extends \PHPUnit_Framework_TestCase {
public function setUp() {
$config = $this->getMockBuilder('\OCP\IConfig')
->disableOriginalConstructor()->getMock();
- $certificateManager = $this->getMock('\OCP\ICertificateManager');
+ $clientService = $this->getMock('\OCP\Http\Client\IClientService');
$httpHelper = $this->getMockBuilder('\OC\HTTPHelper')
- ->setConstructorArgs(array($config, $certificateManager))
- ->setMethods(array('getHeaders'))
+ ->setConstructorArgs([$config, $clientService])
+ ->setMethods(['getHeaders'])
->getMock();
$urlGenerator = $this->getMockBuilder('\OCP\IURLGenerator')
->disableOriginalConstructor()
diff --git a/tests/lib/http/client/clientservicetest.php b/tests/lib/http/client/clientservicetest.php
new file mode 100644
index 00000000000..6d7acea0be7
--- /dev/null
+++ b/tests/lib/http/client/clientservicetest.php
@@ -0,0 +1,25 @@
+<?php
+/**
+ * Copyright (c) 2015 Lukas Reschke <lukas@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\Http\Client;
+
+use GuzzleHttp\Client as GuzzleClient;
+
+/**
+ * Class ClientServiceTest
+ */
+class ClientServiceTest extends \Test\TestCase {
+ public function testNewClient() {
+ $config = $this->getMock('\OCP\IConfig');
+ $certificateManager = $this->getMock('\OCP\ICertificateManager');
+
+ $expected = new Client($config, $certificateManager, new GuzzleClient());
+ $clientService = new ClientService($config, $certificateManager);
+ $this->assertEquals($expected, $clientService->newClient());
+ }
+}
diff --git a/tests/lib/http/client/clienttest.php b/tests/lib/http/client/clienttest.php
new file mode 100644
index 00000000000..bd909769b09
--- /dev/null
+++ b/tests/lib/http/client/clienttest.php
@@ -0,0 +1,110 @@
+<?php
+/**
+ * Copyright (c) 2015 Lukas Reschke <lukas@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\Http\Client;
+
+use GuzzleHttp\Message\Response;
+use OCP\IConfig;
+
+/**
+ * Class ClientTest
+ */
+class ClientTest extends \Test\TestCase {
+ /** @var \GuzzleHttp\Client */
+ private $guzzleClient;
+ /** @var Client */
+ private $client;
+ /** @var IConfig */
+ private $config;
+
+ public function setUp() {
+ parent::setUp();
+ $this->config = $this->getMock('\OCP\IConfig');
+ $this->guzzleClient = $this->getMockBuilder('\GuzzleHttp\Client')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $certificateManager = $this->getMock('\OCP\ICertificateManager');
+ $this->client = new Client(
+ $this->config,
+ $certificateManager,
+ $this->guzzleClient
+ );
+ }
+
+ public function testGetProxyUri() {
+ $this->config
+ ->expects($this->at(0))
+ ->method('getSystemValue')
+ ->with('proxy', null)
+ ->willReturn(null);
+ $this->config
+ ->expects($this->at(1))
+ ->method('getSystemValue')
+ ->with('proxyuserpwd', null)
+ ->willReturn(null);
+ $this->assertSame('', \Test_Helper::invokePrivate($this->client, 'getProxyUri'));
+ }
+
+ public function testGetProxyUriProxyHostEmptyPassword() {
+ $this->config
+ ->expects($this->at(0))
+ ->method('getSystemValue')
+ ->with('proxy', null)
+ ->willReturn('foo');
+ $this->config
+ ->expects($this->at(1))
+ ->method('getSystemValue')
+ ->with('proxyuserpwd', null)
+ ->willReturn(null);
+ $this->assertSame('foo', \Test_Helper::invokePrivate($this->client, 'getProxyUri'));
+ }
+
+ public function testGetProxyUriProxyHostWithPassword() {
+ $this->config
+ ->expects($this->at(0))
+ ->method('getSystemValue')
+ ->with('proxy', null)
+ ->willReturn('foo');
+ $this->config
+ ->expects($this->at(1))
+ ->method('getSystemValue')
+ ->with('proxyuserpwd', null)
+ ->willReturn('username:password');
+ $this->assertSame('username:password@foo', \Test_Helper::invokePrivate($this->client, 'getProxyUri'));
+ }
+
+ public function testGet() {
+ $this->guzzleClient->method('get')
+ ->willReturn(new Response(1337));
+ $this->assertEquals(1337, $this->client->get('http://localhost/', [])->getStatusCode());
+ }
+
+ public function testPost() {
+ $this->guzzleClient->method('post')
+ ->willReturn(new Response(1337));
+ $this->assertEquals(1337, $this->client->post('http://localhost/', [])->getStatusCode());
+ }
+
+ public function testPut() {
+ $this->guzzleClient->method('put')
+ ->willReturn(new Response(1337));
+ $this->assertEquals(1337, $this->client->put('http://localhost/', [])->getStatusCode());
+ }
+
+ public function testDelete() {
+ $this->guzzleClient->method('delete')
+ ->willReturn(new Response(1337));
+ $this->assertEquals(1337, $this->client->delete('http://localhost/', [])->getStatusCode());
+ }
+
+ public function testOptions() {
+ $this->guzzleClient->method('options')
+ ->willReturn(new Response(1337));
+ $this->assertEquals(1337, $this->client->options('http://localhost/', [])->getStatusCode());
+ }
+}
diff --git a/tests/lib/http/client/responsetest.php b/tests/lib/http/client/responsetest.php
new file mode 100644
index 00000000000..d9b181a8e28
--- /dev/null
+++ b/tests/lib/http/client/responsetest.php
@@ -0,0 +1,37 @@
+<?php
+/**
+ * Copyright (c) 2015 Lukas Reschke <lukas@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\Http\Client;
+
+use Guzzle\Stream\Stream;
+use GuzzleHttp\Message\Response as GuzzleResponse;
+
+/**
+ * Class ResponseTest
+ */
+class ResponseTest extends \Test\TestCase {
+ /** @var Response */
+ private $response;
+ /** @var GuzzleResponse */
+ private $guzzleResponse;
+
+ public function setUp() {
+ parent::setUp();
+ $this->guzzleResponse = new GuzzleResponse(1337);
+ $this->response = new Response($this->guzzleResponse);
+ }
+
+ public function testGetStatusCode() {
+ $this->assertEquals(1337, $this->response->getStatusCode());
+ }
+
+ public function testGetHeader() {
+ $this->guzzleResponse->setHeader('bar', 'foo');
+ $this->assertEquals('foo', $this->response->getHeader('bar'));
+ }
+}
diff --git a/tests/lib/httphelper.php b/tests/lib/httphelper.php
index fe76f984258..e8472ab553a 100644
--- a/tests/lib/httphelper.php
+++ b/tests/lib/httphelper.php
@@ -12,17 +12,15 @@ class TestHTTPHelper extends \Test\TestCase {
private $config;
/** @var \OC\HTTPHelper */
private $httpHelperMock;
- /** @var \OC\Security\CertificateManager */
- private $certificateManager;
protected function setUp() {
parent::setUp();
$this->config = $this->getMockBuilder('\OCP\IConfig')
->disableOriginalConstructor()->getMock();
- $this->certificateManager = $this->getMock('\OCP\ICertificateManager');
+ $clientService = $this->getMock('\OCP\Http\Client\IClientService');
$this->httpHelperMock = $this->getMockBuilder('\OC\HTTPHelper')
- ->setConstructorArgs(array($this->config, $this->certificateManager))
+ ->setConstructorArgs(array($this->config, $clientService))
->setMethods(array('getHeaders'))
->getMock();
}
@@ -46,21 +44,4 @@ class TestHTTPHelper extends \Test\TestCase {
public function testIsHTTP($url, $expected) {
$this->assertSame($expected, $this->httpHelperMock->isHTTPURL($url));
}
-
- /**
- * @dataProvider postParameters
- */
- public function testAssemblePostParameters($parameterList, $expectedResult) {
- $helper = \OC::$server->getHTTPHelper();
- $result = \Test_Helper::invokePrivate($helper, 'assemblePostParameters', array($parameterList));
- $this->assertSame($expectedResult, $result);
- }
-
- public function postParameters() {
- return array(
- array(array('k1' => 'v1'), 'k1=v1'),
- array(array('k1' => 'v1', 'k2' => 'v2'), 'k1=v1&k2=v2'),
- array(array(), ''),
- );
- }
}
diff --git a/tests/lib/updater.php b/tests/lib/updater.php
index 7a1bc48e1a8..13b45b3d8e7 100644
--- a/tests/lib/updater.php
+++ b/tests/lib/updater.php
@@ -93,9 +93,9 @@ class UpdaterTest extends \Test\TestCase {
->getMock()
;
- $certificateManager = $this->getMock('\OCP\ICertificateManager');
+ $clientService = $this->getMock('\OCP\Http\Client\IClientService');
$mockedHTTPHelper = $this->getMockBuilder('\OC\HTTPHelper')
- ->setConstructorArgs(array(\OC::$server->getConfig(), $certificateManager))
+ ->setConstructorArgs([\OC::$server->getConfig(), $clientService])
->getMock()
;