From 143272b1743109aab016fc0e02705176aab1e18d Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Thu, 6 Nov 2014 22:30:39 +0100 Subject: more integration tests --- tests/integration/bootstrap.php | 10 +- tests/integration/db/FeedMapperTest.php | 46 +++++++++ tests/integration/db/FolderMapperTest.php | 42 +++++++++ tests/integration/db/ItemMapperTest.php | 151 ++++++++++++++++++++++++++++++ tests/integration/fixtures/items.json | 28 ++++++ 5 files changed, 273 insertions(+), 4 deletions(-) create mode 100644 tests/integration/db/FeedMapperTest.php create mode 100644 tests/integration/db/FolderMapperTest.php (limited to 'tests') diff --git a/tests/integration/bootstrap.php b/tests/integration/bootstrap.php index c8d7cc719..1fa6d08b8 100644 --- a/tests/integration/bootstrap.php +++ b/tests/integration/bootstrap.php @@ -86,10 +86,12 @@ class NewsIntegrationTest extends \PHPUnit_Framework_TestCase { } // feeds in no folders - if (array_key_exists('no feed', $feeds)) { - foreach ($feeds['no feed'] as $feed) { + if (array_key_exists('no folder', $feeds)) { + foreach ($feeds['no folder'] as $feed) { + $feed['folderId'] = 0; - $this->feeds[] = $this->createFeed($feed); + $newFeed = $this->createFeed($feed); + $this->feeds[] = $newFeed; if (array_key_exists($feed['title'], $items)) { foreach ($items[$feed['title']] as $item) { @@ -186,7 +188,7 @@ class NewsIntegrationTest extends \PHPUnit_Framework_TestCase { protected function tearDown() { - $this->cleanUp(); + //$this->cleanUp(); } diff --git a/tests/integration/db/FeedMapperTest.php b/tests/integration/db/FeedMapperTest.php new file mode 100644 index 000000000..c8de68281 --- /dev/null +++ b/tests/integration/db/FeedMapperTest.php @@ -0,0 +1,46 @@ +itemMapper->starredCount($this->userId); + $this->assertEquals(2, $count); + } + + + public function testReadAll () { + $this->itemMapper->readAll(PHP_INT_MAX, 10, $this->userId); + + $status = StatusFlag::UNREAD; + $items = $this->itemMapper->findAll( + 30, 0, $status, false, $this->userId + ); + + $this->assertEquals(0, count($items)); + + $item = $this->items['a title1']; + $item = $this->itemMapper->find($item->getId(), $this->userId); + + $this->assertEquals(10, $item->getLastModified()); + + $item = $this->items['a title3']; + $item = $this->itemMapper->find($item->getId(), $this->userId); + + $this->assertEquals(10, $item->getLastModified()); + + $item = $this->items['a title9']; + $item = $this->itemMapper->find($item->getId(), $this->userId); + + $this->assertEquals(10, $item->getLastModified()); + } + + + public function testReadFolder () { + $folderId = $this->folders['first folder']->getId(); + $this->itemMapper->readFolder( + $folderId, PHP_INT_MAX, 10, $this->userId + ); + + $status = StatusFlag::UNREAD; + $items = $this->itemMapper->findAll( + 30, 0, $status, false, $this->userId + ); + + $this->assertEquals(1, count($items)); + + $item = $this->items['a title1']; + $item = $this->itemMapper->find($item->getId(), $this->userId); + + $this->assertEquals(10, $item->getLastModified()); + + $item = $this->items['a title3']; + $item = $this->itemMapper->find($item->getId(), $this->userId); + + $this->assertEquals(10, $item->getLastModified()); + + $item = $this->items['a title9']; + $item = $this->itemMapper->find($item->getId(), $this->userId); + + $this->assertTrue($item->isUnread()); + } + + + public function testReadFeed () { + $feedId = $this->feeds['third feed']->getId(); + $this->itemMapper->readFeed( + $feedId, PHP_INT_MAX, 10, $this->userId + ); + + $status = StatusFlag::UNREAD; + $items = $this->itemMapper->findAll( + 30, 0, $status, false, $this->userId + ); + + $this->assertEquals(2, count($items)); + + $item = $this->items['a title9']; + $item = $this->itemMapper->find($item->getId(), $this->userId); + + $this->assertEquals(10, $item->getLastModified()); + + $item = $this->items['a title3']; + $item = $this->itemMapper->find($item->getId(), $this->userId); + $this->assertTrue($item->isUnread()); + + + $item = $this->items['a title1']; + $item = $this->itemMapper->find($item->getId(), $this->userId); + $this->assertTrue($item->isUnread()); + } + + + public function testDeleteUser () { + $this->itemMapper->deleteUser($this->userId); + $id = $this->itemMapper->getNewestItemId(); + + $this->assertEquals(0, $id); + } + + + public function testGetNewestItemId () { + $id = $this->itemMapper->getNewestItemId($this->userId); + + $item = $this->items['no folder']; + $this->assertEquals($item->getId(), $id); + } + + + public function testFindByGuidHash () { + $item = $this->items['no folder']; + + $fetchedItem = $this->itemMapper->findByGuidHash( + 'no folder', $item->getFeedId(), $this->userId + ); + + $this->assertEquals($item->getId(), $fetchedItem->getId()); + } + + + public function testFindAllUnreadOrStarred () { + $items = $this->itemMapper->findAllUnreadOrStarred($this->userId); + $this->assertEquals(4, count($items)); + } + + + /* TBD + public function testFindAllFolder () { + + } + + + public function testFindAllFeed () { + + } + + + public function testFindAllNew () { + + } + + + public function testFindAllNewFolder () { + + } + + + public function testFindAllNewFeed () { + + } + + */ } \ No newline at end of file diff --git a/tests/integration/fixtures/items.json b/tests/integration/fixtures/items.json index 7f6b6c9c4..5396fde9b 100644 --- a/tests/integration/fixtures/items.json +++ b/tests/integration/fixtures/items.json @@ -85,6 +85,34 @@ "enclosureLink": "http://google.de/web.webm" } ], + "third feed": [ + { + "status": 2, + "body": "this is a body", + "title": "a title9", + "author": "my author", + "guid": "a title9", + "url": "http://google.de", + "pubDate": 2323, + "lastModified": 113, + "enclosureMime": "video/mpeg", + "enclosureLink": "http://google.de/web.webm" + } + ], + "fourth feed": [ + { + "status": 0, + "body": "this is a body", + "title": "no folder", + "author": "my author", + "guid": "no folder", + "url": "http://google.de", + "pubDate": 2323, + "lastModified": 113, + "enclosureMime": "video/mpeg", + "enclosureLink": "http://google.de/web.webm" + } + ], "fifth feed": [ { "status": 2, -- cgit v1.2.3