Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Reschke <lukas@statuscode.ch>2017-01-02 16:51:16 +0300
committerLukas Reschke <lukas@statuscode.ch>2017-01-02 16:51:16 +0300
commit5679f04cb1a7fb761590b3a6b501044ddeeebc01 (patch)
tree746d7774b2fef13026855ac3072c890ba86e0b41 /tests/lib/Http
parentfc02564ea6ee17f8f9522f11158c5abbceff58a1 (diff)
Rebrand to "Nextcloud" and add 100% coverage
Noticed while debugging https://github.com/nextcloud/server/issues/2910 Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
Diffstat (limited to 'tests/lib/Http')
-rw-r--r--tests/lib/Http/Client/ClientTest.php71
1 files changed, 67 insertions, 4 deletions
diff --git a/tests/lib/Http/Client/ClientTest.php b/tests/lib/Http/Client/ClientTest.php
index 4369eab3a54..1b0a51b7395 100644
--- a/tests/lib/Http/Client/ClientTest.php
+++ b/tests/lib/Http/Client/ClientTest.php
@@ -10,6 +10,7 @@ namespace Test\Http\Client;
use GuzzleHttp\Message\Response;
use OC\Http\Client\Client;
+use OC\Security\CertificateManager;
use OCP\ICertificateManager;
use OCP\IConfig;
@@ -17,11 +18,13 @@ use OCP\IConfig;
* Class ClientTest
*/
class ClientTest extends \Test\TestCase {
- /** @var \GuzzleHttp\Client */
+ /** @var \GuzzleHttp\Client|\PHPUnit_Framework_MockObject_MockObject */
private $guzzleClient;
+ /** @var CertificateManager|\PHPUnit_Framework_MockObject_MockObject */
+ private $certificateManager;
/** @var Client */
private $client;
- /** @var IConfig */
+ /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
private $config;
public function setUp() {
@@ -30,10 +33,10 @@ class ClientTest extends \Test\TestCase {
$this->guzzleClient = $this->getMockBuilder('\GuzzleHttp\Client')
->disableOriginalConstructor()
->getMock();
- $certificateManager = $this->createMock(ICertificateManager::class);
+ $this->certificateManager = $this->createMock(ICertificateManager::class);
$this->client = new Client(
$this->config,
- $certificateManager,
+ $this->certificateManager,
$this->guzzleClient
);
}
@@ -109,4 +112,64 @@ class ClientTest extends \Test\TestCase {
->willReturn(new Response(1337));
$this->assertEquals(1337, $this->client->options('http://localhost/', [])->getStatusCode());
}
+
+ public function testHead() {
+ $this->guzzleClient->method('head')
+ ->willReturn(new Response(1337));
+ $this->assertEquals(1337, $this->client->head('http://localhost/', [])->getStatusCode());
+ }
+
+ public function testSetDefaultOptionsWithNotInstalled() {
+ $this->config
+ ->expects($this->at(0))
+ ->method('getSystemValue')
+ ->with('installed', false)
+ ->willReturn(false);
+ $this->certificateManager
+ ->expects($this->once())
+ ->method('listCertificates')
+ ->willReturn([]);
+ $this->guzzleClient
+ ->expects($this->at(0))
+ ->method('setDefaultOption')
+ ->with('verify', \OC::$SERVERROOT . '/resources/config/ca-bundle.crt');
+ $this->guzzleClient
+ ->expects($this->at(1))
+ ->method('setDefaultOption')
+ ->with('headers/User-Agent', 'Nextcloud Server Crawler');
+
+ self::invokePrivate($this->client, 'setDefaultOptions');
+ }
+
+ public function testSetDefaultOptionsWithProxy() {
+ $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->certificateManager
+ ->expects($this->once())
+ ->method('getAbsoluteBundlePath')
+ ->with(null)
+ ->willReturn('/my/path.crt');
+ $this->guzzleClient
+ ->expects($this->at(0))
+ ->method('setDefaultOption')
+ ->with('verify', '/my/path.crt');
+ $this->guzzleClient
+ ->expects($this->at(1))
+ ->method('setDefaultOption')
+ ->with('headers/User-Agent', 'Nextcloud Server Crawler');
+ $this->guzzleClient
+ ->expects($this->at(2))
+ ->method('setDefaultOption')
+ ->with('proxy', 'foo');
+
+ self::invokePrivate($this->client, 'setDefaultOptions');
+ }
}