From 906b6b7337b7cd8922c0b1287f25bf03fff5c471 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thomas=20M=C3=BCller?= Date: Mon, 13 Apr 2015 09:43:45 +0200 Subject: [PATCH] Prevent php message: "Trying to get property of non-object at /xxx/lib/private/ocsclient.php#282" --- lib/private/ocsclient.php | 3 ++ .../{OCSClientTest.php => ocsclienttest.php} | 45 +++++++++++++++++++ 2 files changed, 48 insertions(+) rename tests/lib/{OCSClientTest.php => ocsclienttest.php} (95%) diff --git a/lib/private/ocsclient.php b/lib/private/ocsclient.php index 84469cb5e0d..b00772fb799 100644 --- a/lib/private/ocsclient.php +++ b/lib/private/ocsclient.php @@ -262,6 +262,9 @@ class OCSClient { } $tmp = $data->data->content; + if (is_null($tmp)) { + return null; + } $app = []; $app['id'] = (int)$tmp->id; diff --git a/tests/lib/OCSClientTest.php b/tests/lib/ocsclienttest.php similarity index 95% rename from tests/lib/OCSClientTest.php rename to tests/lib/ocsclienttest.php index fa3f1fe7848..f4bf1536291 100644 --- a/tests/lib/OCSClientTest.php +++ b/tests/lib/ocsclienttest.php @@ -773,6 +773,51 @@ class OCSClientTest extends \Test\TestCase { ]; $this->assertSame($expected, $this->ocsClient->getApplication('MyId')); } + public function testGetApplicationEmptyXml() { + $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(' + + + ok + 100 + + + + ')); + + $client = $this->getMock('\OCP\Http\Client\IClient'); + $client + ->expects($this->once()) + ->method('get') + ->with( + 'https://api.owncloud.com/v1/content/data/MyId', + [ + 'timeout' => 5, + ] + ) + ->will($this->returnValue($response)); + + $this->clientService + ->expects($this->once()) + ->method('newClient') + ->will($this->returnValue($client)); + + $this->assertSame(null, $this->ocsClient->getApplication('MyId')); + } public function testGetApplicationDownloadDisabledAppStore() { $this->config -- 2.39.5