This commit is contained in:
Bernhard Posselt 2013-05-02 21:03:33 +02:00
Родитель 2b42d8bd9e
Коммит ec8394eda1
2 изменённых файлов: 89 добавлений и 7 удалений

30
external/itemapi.php поставляемый
Просмотреть файл

@ -75,17 +75,41 @@ class ItemAPI extends Controller {
public function getUpdated() {
$result = array(
'items' => array()
);
$userId = $this->api->getUserId();
$lastModified = (int) $this->params('lastModified', 0);
$type = (int) $this->params('type');
$id = (int) $this->params('id');
$items = $this->itemBusinessLayer->findAllNew(
$id,
$type,
$lastModified,
true,
$userId
);
foreach ($items as $item) {
array_push($result['items'], $item->toAPI());
}
return new NewsAPIResult($result);
}
public function get() {
private function setRead($isRead) {
$userId = $this->api->getUserId();
$itemId = $this->params('itemId');
$this->itemBusinessLayer->read($itemId, $isRead, $userId);
}
public function read() {
$this->setRead(true);
return new NewsAPIResult();
}

66
tests/unit/external/ItemAPITest.php поставляемый
Просмотреть файл

@ -54,12 +54,15 @@ class ItemAPITest extends \PHPUnit_Framework_TestCase {
'\OCA\News\BusinessLayer\ItemBusinessLayer')
->disableOriginalConstructor()
->getMock();
$this->user = 'tom';
$this->api->expects($this->once())
->method('getUserId')
->will($this->returnValue($this->user));
$this->itemAPI = new ItemAPI(
$this->api,
$this->request,
$this->itemBusinessLayer
);
$this->user = 'tom';
}
@ -80,9 +83,6 @@ class ItemAPITest extends \PHPUnit_Framework_TestCase {
$this->itemBusinessLayer
);
$this->api->expects($this->once())
->method('getUserId')
->will($this->returnValue($this->user));
$this->itemBusinessLayer->expects($this->once())
->method('findAll')
->with(
@ -103,5 +103,63 @@ class ItemAPITest extends \PHPUnit_Framework_TestCase {
}
public function testGetUpdated() {
$items = array(
new Item()
);
$request = new Request(array('params' => array(
'lastModified' => 30,
'type' => 1,
'id' => 2,
)));
$this->itemAPI = new ItemAPI(
$this->api,
$request,
$this->itemBusinessLayer
);
$this->itemBusinessLayer->expects($this->once())
->method('findAllNew')
->with(
$this->equalTo(2),
$this->equalTo(1),
$this->equalTo(30),
$this->equalTo(true),
$this->equalTo($this->user)
)
->will($this->returnValue($items));
$response = $this->itemAPI->getUpdated();
$this->assertEquals(array(
'items' => array($items[0]->toAPI())
), $response->getData());
}
public function testRead() {
$request = new Request(array('urlParams' => array(
'itemId' => 2
)));
$this->itemAPI = new ItemAPI(
$this->api,
$request,
$this->itemBusinessLayer
);
$this->itemBusinessLayer->expects($this->once())
->method('read')
->with(
$this->equalTo(2),
$this->equalTo(true),
$this->equalTo($this->user)
);
$response = $this->itemAPI->read();
$this->assertNull($response->getData());
$this->assertNull($response->getMessage());
$this->assertEquals(NewsAPIResult::OK, $response->getStatusCode());
}
}