summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2014-05-14 02:16:31 +0200
committerBernhard Posselt <dev@bernhard-posselt.com>2014-05-14 02:16:31 +0200
commitacc2df1251a1c1b9ec5ede13bdf46d516dc64b0d (patch)
treece8503baa37cc05379dfd43a65e9acf0b41e0d97 /tests
parentdb4c29e89d77955c4930731ade08816f5567fe84 (diff)
use more flexible serializer that ignores nulls, non entity values and responses
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/controller/EntityApiSerializerTest.php51
-rw-r--r--tests/unit/controller/FeedApiControllerTest.php8
2 files changed, 55 insertions, 4 deletions
diff --git a/tests/unit/controller/EntityApiSerializerTest.php b/tests/unit/controller/EntityApiSerializerTest.php
index 8153f40d6..5541cc3be 100644
--- a/tests/unit/controller/EntityApiSerializerTest.php
+++ b/tests/unit/controller/EntityApiSerializerTest.php
@@ -15,6 +15,9 @@ namespace OCA\News\Controller;
require_once(__DIR__ . "/../../classloader.php");
+
+use \OCP\AppFramework\Http\Response;
+
use \OCA\News\Db\Item;
@@ -40,6 +43,7 @@ class EntityApiSerializerTest extends \PHPUnit_Framework_TestCase {
$item2->setRead();
$serializer = new EntityApiSerializer('items');
+
$result = $serializer->serialize(array($item, $item2));
$this->assertTrue($result['items'][0]['unread']);
@@ -47,4 +51,51 @@ class EntityApiSerializerTest extends \PHPUnit_Framework_TestCase {
}
+ public function testResponseNoChange() {
+ $response = new Response();
+ $serializer = new EntityApiSerializer('items');
+
+ $result = $serializer->serialize($response);
+
+ $this->assertEquals($response, $result);
+ }
+
+
+ public function testCompleteArraysTransformed() {
+ $item = new Item();
+ $item->setUnread();
+
+ $item2 = new Item();
+ $item2->setRead();
+
+ $serializer = new EntityApiSerializer('items');
+
+ $in = array(
+ 'items' => array($item, $item2),
+ 'test' => 1
+ );
+
+ $result = $serializer->serialize($in);
+
+ $this->assertTrue($result['items'][0]['unread']);
+ $this->assertFalse($result['items'][1]['unread']);
+ $this->assertEquals(1, $result['test']);
+ }
+
+
+ public function noEntityNoChange() {
+ $serializer = new EntityApiSerializer('items');
+
+ $in = array(
+ 'items' => array('hi', '2'),
+ 'test' => 1
+ );
+
+ $result = $serializer->serialize($in);
+
+ $this->assertEquals('hi', $result['items'][0]);
+ $this->assertEquals('2', $result['items'][1]);
+ $this->assertEquals(1, $result['test']);
+ }
+
} \ No newline at end of file
diff --git a/tests/unit/controller/FeedApiControllerTest.php b/tests/unit/controller/FeedApiControllerTest.php
index 1444fa563..79c21af28 100644
--- a/tests/unit/controller/FeedApiControllerTest.php
+++ b/tests/unit/controller/FeedApiControllerTest.php
@@ -98,7 +98,7 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase {
$response = $this->feedAPI->index();
$this->assertEquals(array(
- 'feeds' => array($feeds[0]->toAPI()),
+ 'feeds' => $feeds,
'starredCount' => $starredCount,
'newestItemId' => $newestItemId
), $response);
@@ -127,7 +127,7 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase {
$response = $this->feedAPI->index();
$this->assertEquals(array(
- 'feeds' => array($feeds[0]->toAPI()),
+ 'feeds' => $feeds,
'starredCount' => $starredCount,
), $response);
}
@@ -179,7 +179,7 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase {
$response = $this->feedAPI->create('url', 3);
$this->assertEquals(array(
- 'feeds' => array($feeds[0]->toAPI()),
+ 'feeds' => $feeds,
'newestItemId' => 3
), $response);
}
@@ -207,7 +207,7 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase {
$response = $this->feedAPI->create('ho', 3);
$this->assertEquals(array(
- 'feeds' => array($feeds[0]->toAPI())
+ 'feeds' => $feeds
), $response);
}