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); }
public function testGetApplicationDownloadUrlSuccessful() { $this->config->expects($this->at(0))->method('getSystemValue')->with('appstoreenabled', true)->will($this->returnValue(true)); $this->config->expects($this->at(1))->method('getSystemValue')->with('appstoreurl', 'https://api.owncloud.com/v1')->will($this->returnValue('https://api.owncloud.com/v1')); $response = $this->getMock('\\OCP\\Http\\Client\\IResponse'); $response->expects($this->once())->method('getBody')->will($this->returnValue('<?xml version="1.0"?> <ocs> <meta> <status>ok</status> <statuscode>100</statuscode> <message></message> </meta> <data> <content details="download"> <downloadlink>https://apps.owncloud.com/CONTENT/content-files/166052-files_trashbin.zip</downloadlink> <mimetype>application/zip</mimetype> <gpgfingerprint></gpgfingerprint> <gpgsignature></gpgsignature> <packagename></packagename> <repository></repository> </content> </data> </ocs> ')); $client = $this->getMock('\\OCP\\Http\\Client\\IClient'); $client->expects($this->once())->method('get')->with('https://api.owncloud.com/v1/content/download/MyId/1', ['timeout' => 5, 'query' => ['version' => '8x1x0x7']])->will($this->returnValue($response)); $this->clientService->expects($this->once())->method('newClient')->will($this->returnValue($client)); $expected = ['downloadlink' => 'https://apps.owncloud.com/CONTENT/content-files/166052-files_trashbin.zip']; $this->assertSame($expected, $this->ocsClient->getApplicationDownload('MyId', [8, 1, 0, 7])); }
public function testRemoteWithInvalidRemote() { $client = $this->getMockBuilder('\\OCP\\Http\\Client\\IClient')->disableOriginalConstructor()->getMock(); $response = $this->getMockBuilder('\\OCP\\Http\\Client\\IResponse')->disableOriginalConstructor()->getMock(); $client->method('get')->will($this->onConsecutiveCalls($response, $response)); $response->expects($this->exactly(2))->method('getBody')->will($this->returnValue('Certainly not a JSON string')); $this->clientService->expects($this->exactly(2))->method('newClient')->will($this->returnValue($client)); $this->assertEquals(new DataResponse(false), $this->getExternalShareController()->testRemote('owncloud.org')); }
public function testIsBuggyNss200() { $this->checkSetupController->expects($this->once())->method('getCurlVersion')->will($this->returnValue(['ssl_version' => 'NSS/1.0.2b'])); $client = $this->getMockBuilder('\\OCP\\Http\\Client\\IClient')->disableOriginalConstructor()->getMock(); $exception = $this->getMockBuilder('\\GuzzleHttp\\Exception\\ClientException')->disableOriginalConstructor()->getMock(); $response = $this->getMockBuilder('\\GuzzleHttp\\Message\\ResponseInterface')->disableOriginalConstructor()->getMock(); $response->expects($this->once())->method('getStatusCode')->will($this->returnValue(200)); $exception->expects($this->once())->method('getResponse')->will($this->returnValue($response)); $client->expects($this->at(0))->method('get')->with('https://www.owncloud.org/', [])->will($this->throwException($exception)); $this->clientService->expects($this->once())->method('newClient')->will($this->returnValue($client)); $this->assertSame('', $this->invokePrivate($this->checkSetupController, 'isUsedTlsLibOutdated')); }
public function testCheck() { $this->config->expects($this->at(0))->method('getSystemValue')->with('has_internet_connection', true)->will($this->returnValue(true)); $this->config->expects($this->at(1))->method('getSystemValue')->with('memcache.local', null)->will($this->returnValue('SomeProvider')); $client = $this->getMockBuilder('\\OCP\\Http\\Client\\IClient')->disableOriginalConstructor()->getMock(); $client->expects($this->at(0))->method('get')->with('https://www.owncloud.org/', []); $client->expects($this->at(1))->method('get')->with('http://www.owncloud.org/', [])->will($this->throwException(new \Exception())); $this->clientService->expects($this->once())->method('newClient')->will($this->returnValue($client)); $this->util->expects($this->once())->method('isHtaccessWorking')->will($this->returnValue(true)); $this->urlGenerator->expects($this->once())->method('linkToDocs')->with('admin-performance')->willReturn('http://doc.owncloud.org/server/go.php?to=admin-performance'); $expected = new DataResponse(['serverHasInternetConnection' => false, 'dataDirectoryProtected' => true, 'isMemcacheConfigured' => true, 'memcacheDocs' => 'http://doc.owncloud.org/server/go.php?to=admin-performance']); $this->assertEquals($expected, $this->checkSetupController->check()); }