summaryrefslogtreecommitdiffstats
path: root/tests/lib
diff options
context:
space:
mode:
authorBjörn Schießle <bjoern@schiessle.org>2015-05-26 12:23:57 +0200
committerBjörn Schießle <bjoern@schiessle.org>2015-05-26 12:23:57 +0200
commitf70c309c2d8044d46ee3daa74d1a53f48f11d53f (patch)
tree241d8121d9af66af675fb947c3d3e0f4ffc1b6d0 /tests/lib
parentf1fc7b155c6386ad41800e75472cf9e80d0fefe1 (diff)
parentdff361dc5ce4501396974785b2be22287b15b895 (diff)
downloadnextcloud-server-f70c309c2d8044d46ee3daa74d1a53f48f11d53f.tar.gz
nextcloud-server-f70c309c2d8044d46ee3daa74d1a53f48f11d53f.zip
Merge pull request #16561 from owncloud/add-default-timeout-back
Add connection timeout to default POST options
Diffstat (limited to 'tests/lib')
-rw-r--r--tests/lib/httphelper.php75
1 files changed, 73 insertions, 2 deletions
diff --git a/tests/lib/httphelper.php b/tests/lib/httphelper.php
index e8472ab553a..1d0981ba51b 100644
--- a/tests/lib/httphelper.php
+++ b/tests/lib/httphelper.php
@@ -12,15 +12,17 @@ class TestHTTPHelper extends \Test\TestCase {
private $config;
/** @var \OC\HTTPHelper */
private $httpHelperMock;
+ /** @var \OCP\Http\Client\IClientService */
+ private $clientService;
protected function setUp() {
parent::setUp();
$this->config = $this->getMockBuilder('\OCP\IConfig')
->disableOriginalConstructor()->getMock();
- $clientService = $this->getMock('\OCP\Http\Client\IClientService');
+ $this->clientService = $this->getMock('\OCP\Http\Client\IClientService');
$this->httpHelperMock = $this->getMockBuilder('\OC\HTTPHelper')
- ->setConstructorArgs(array($this->config, $clientService))
+ ->setConstructorArgs(array($this->config, $this->clientService))
->setMethods(array('getHeaders'))
->getMock();
}
@@ -44,4 +46,73 @@ class TestHTTPHelper extends \Test\TestCase {
public function testIsHTTP($url, $expected) {
$this->assertSame($expected, $this->httpHelperMock->isHTTPURL($url));
}
+
+ public function testPostSuccess() {
+ $client = $this->getMockBuilder('\OCP\Http\Client\IClient')
+ ->disableOriginalConstructor()->getMock();
+ $this->clientService
+ ->expects($this->once())
+ ->method('newClient')
+ ->will($this->returnValue($client));
+ $response = $this->getMockBuilder('\OCP\Http\Client\IResponse')
+ ->disableOriginalConstructor()->getMock();
+ $client
+ ->expects($this->once())
+ ->method('post')
+ ->with(
+ 'https://owncloud.org',
+ [
+ 'body' => [
+ 'Foo' => 'Bar',
+ ],
+ 'connect_timeout' => 10,
+
+ ]
+ )
+ ->will($this->returnValue($response));
+ $response
+ ->expects($this->once())
+ ->method('getBody')
+ ->will($this->returnValue('Body of the requested page'));
+
+
+ $response = $this->httpHelperMock->post('https://owncloud.org', ['Foo' => 'Bar']);
+ $expected = [
+ 'success' => true,
+ 'result' => 'Body of the requested page'
+ ];
+ $this->assertSame($expected, $response);
+ }
+
+ public function testPostException() {
+ $client = $this->getMockBuilder('\OCP\Http\Client\IClient')
+ ->disableOriginalConstructor()->getMock();
+ $this->clientService
+ ->expects($this->once())
+ ->method('newClient')
+ ->will($this->returnValue($client));
+ $client
+ ->expects($this->once())
+ ->method('post')
+ ->with(
+ 'https://owncloud.org',
+ [
+ 'body' => [
+ 'Foo' => 'Bar',
+ ],
+ 'connect_timeout' => 10,
+
+ ]
+ )
+ ->will($this->throwException(new \Exception('Something failed')));
+
+
+ $response = $this->httpHelperMock->post('https://owncloud.org', ['Foo' => 'Bar']);
+ $expected = [
+ 'success' => false,
+ 'result' => 'Something failed'
+ ];
+ $this->assertSame($expected, $response);
+ }
+
}