aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLukas Reschke <lukas@statuscode.ch>2017-01-02 15:32:09 +0100
committerGitHub <noreply@github.com>2017-01-02 15:32:09 +0100
commite2e467750103b14664917be052a0ef0ab05badda (patch)
treea661421d187f541e1ee03425d3dfa7b9b6e2c6e5 /tests
parent60a8a1a84484fd0f3ae8a7f46212850cd43b6c5c (diff)
parent5679f04cb1a7fb761590b3a6b501044ddeeebc01 (diff)
downloadnextcloud-server-e2e467750103b14664917be052a0ef0ab05badda.tar.gz
nextcloud-server-e2e467750103b14664917be052a0ef0ab05badda.zip
Merge pull request #2911 from nextcloud/rebrand-to-nextcloud-server-crawler
Rebrand to "Nextcloud" and add 100% coverage
Diffstat (limited to 'tests')
-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');
+ }
}