зеркало из https://github.com/nextcloud/news.git
added small result wrapper
This commit is contained in:
Родитель
d89931b22a
Коммит
d7014ce74f
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* ownCloud - News
|
||||
*
|
||||
* @author Alessandro Cosentino
|
||||
* @author Bernhard Posselt
|
||||
* @copyright 2012 Alessandro Cosentino cosenal@gmail.com
|
||||
* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\News\External;
|
||||
|
||||
class APIResult {
|
||||
|
||||
const OK = 100;
|
||||
const SERVER_ERROR = 996;
|
||||
const UNAUTHORISED = 997;
|
||||
const NOT_FOUND = 998;
|
||||
const UNKNOWN_ERROR = 999;
|
||||
|
||||
private $data;
|
||||
private $statusCode;
|
||||
|
||||
public function __construct($data, $statusCode=APIResult::OK) {
|
||||
$this->data = $data;
|
||||
$this->statusCode = $statusCode;
|
||||
}
|
||||
|
||||
|
||||
public function getData() {
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
|
||||
public function getStatusCode() {
|
||||
return $this->statusCode;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -35,7 +35,7 @@ class External {
|
|||
\Pimple $container) {
|
||||
$container['urlParams'] = $urlParams;
|
||||
$response = $container[$controllerName]->$methodName();
|
||||
return new \OC_OCS_Result($response);
|
||||
return new \OC_OCS_Result($response->getData(), $response->getStatusCode());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -72,7 +72,7 @@ class FeedAPI extends Controller {
|
|||
$this->itemBusinessLayer->getNewestItemId($userId);
|
||||
} catch(BusinessLayerException $ex) {}
|
||||
|
||||
return $result;
|
||||
return new APIResult($result);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -46,8 +46,16 @@ class FolderAPI extends Controller {
|
|||
|
||||
|
||||
public function getAll() {
|
||||
$userId = $this->api->getUserId();
|
||||
$result = array(
|
||||
'folders' => array()
|
||||
);
|
||||
|
||||
foreach ($this->folderBusinessLayer->findAll($userId) as $folder) {
|
||||
array_push($result['folders'], $folder->toAPI());
|
||||
}
|
||||
|
||||
return new APIResult($result);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* ownCloud - News
|
||||
*
|
||||
* @author Alessandro Cosentino
|
||||
* @author Bernhard Posselt
|
||||
* @copyright 2012 Alessandro Cosentino cosenal@gmail.com
|
||||
* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\News\External;
|
||||
|
||||
require_once(__DIR__ . "/../../classloader.php");
|
||||
|
||||
|
||||
class APIResultTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
|
||||
public function testGetStatusCode() {
|
||||
$result = new APIResult(null, APIResult::SERVER_ERROR);
|
||||
$this->assertEquals(996, $result->getStatusCode());
|
||||
}
|
||||
|
||||
public function testGetData() {
|
||||
$result = new APIResult('hi');
|
||||
$this->assertEquals('hi', $result->getData());
|
||||
$this->assertEquals(100, $result->getStatusCode());
|
||||
}
|
||||
|
||||
}
|
|
@ -105,7 +105,7 @@ class FeedAPITest extends \PHPUnit_Framework_TestCase {
|
|||
'feeds' => array($feeds[0]->toAPI()),
|
||||
'starredCount' => $starredCount,
|
||||
'newestItemId' => $newestItemId
|
||||
), $response);
|
||||
), $response->getData());
|
||||
}
|
||||
|
||||
|
||||
|
@ -136,7 +136,7 @@ class FeedAPITest extends \PHPUnit_Framework_TestCase {
|
|||
$this->assertEquals(array(
|
||||
'feeds' => array($feeds[0]->toAPI()),
|
||||
'starredCount' => $starredCount,
|
||||
), $response);
|
||||
), $response->getData());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* ownCloud - News
|
||||
*
|
||||
* @author Alessandro Cosentino
|
||||
* @author Bernhard Posselt
|
||||
* @copyright 2012 Alessandro Cosentino cosenal@gmail.com
|
||||
* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\News\External;
|
||||
|
||||
use \OCA\News\BusinessLayer\BusinessLayerException;
|
||||
|
||||
use \OCA\News\Db\Folder;
|
||||
use \OCA\News\Db\Feed;
|
||||
use \OCA\News\Db\Item;
|
||||
|
||||
require_once(__DIR__ . "/../../classloader.php");
|
||||
|
||||
|
||||
class FolderAPITest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
private $folderBusinessLayer;
|
||||
private $folderAPI;
|
||||
private $api;
|
||||
private $user;
|
||||
private $request;
|
||||
|
||||
protected function setUp() {
|
||||
$this->api = $this->folderBusinessLayer = $this->getMockBuilder(
|
||||
'\OCA\AppFramework\Core\API')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->request = $this->folderBusinessLayer = $this->getMockBuilder(
|
||||
'\OCA\AppFramework\Http\Request')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->folderBusinessLayer = $this->getMockBuilder(
|
||||
'\OCA\News\BusinessLayer\FolderBusinessLayer')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->feedAPI = new FolderAPI(
|
||||
$this->api,
|
||||
$this->request,
|
||||
$this->folderBusinessLayer
|
||||
);
|
||||
$this->user = 'tom';
|
||||
}
|
||||
|
||||
|
||||
public function testGetAll() {
|
||||
$folders = array(
|
||||
new Folder()
|
||||
);
|
||||
|
||||
$this->api->expects($this->once())
|
||||
->method('getUserId')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->folderBusinessLayer->expects($this->once())
|
||||
->method('findAll')
|
||||
->with($this->equalTo($this->user))
|
||||
->will($this->returnValue($folders));
|
||||
|
||||
$response = $this->feedAPI->getAll();
|
||||
|
||||
$this->assertEquals(array(
|
||||
'folders' => array($folders[0]->toAPI())
|
||||
), $response->getData());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Загрузка…
Ссылка в новой задаче