diff options
Diffstat (limited to 'tests/Integration')
-rw-r--r-- | tests/Integration/Db/FeedMapperTest.php | 192 | ||||
-rw-r--r-- | tests/Integration/Db/ItemMapperTest.php | 13 | ||||
-rw-r--r-- | tests/Integration/Fixtures/ItemFixture.php | 3 | ||||
-rw-r--r-- | tests/Integration/Fixtures/data/default.php | 14 | ||||
-rw-r--r-- | tests/Integration/Fixtures/data/readitem.php | 12 | ||||
-rw-r--r-- | tests/Integration/IntegrationTest.php | 5 |
6 files changed, 211 insertions, 28 deletions
diff --git a/tests/Integration/Db/FeedMapperTest.php b/tests/Integration/Db/FeedMapperTest.php index 0c13280f5..b429149a4 100644 --- a/tests/Integration/Db/FeedMapperTest.php +++ b/tests/Integration/Db/FeedMapperTest.php @@ -6,49 +6,231 @@ * later. See the COPYING file. * * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @author Daniel Opitz <dev@copynpaste.de> * @copyright Bernhard Posselt 2015 + * @copyright Daniel Opitz 2017 */ namespace OCA\News\Db; -use \OCA\News\Tests\Integration\IntegrationTest; +use OCA\News\Tests\Integration\Fixtures\FeedFixture; +use OCA\News\Tests\Integration\IntegrationTest; class FeedMapperTest extends IntegrationTest { - public function testFind () { + $feed = new FeedFixture(); + $feed = $this->feedMapper->insert($feed); + + $fetched = $this->feedMapper->find($feed->getId(), $this->user); + + $this->assertInstanceOf(Feed::class, $fetched); + $this->assertEquals($feed->getLink(), $fetched->getLink()); + } + + /** + * @expectedException OCP\AppFramework\Db\DoesNotExistException + */ + public function testFindNotExisting () { + $this->feedMapper->find(0, $this->user); } - /* TBD public function testFindAll () { + $feeds = [ + [ + 'userId' => $this->user, + 'items' => [] + ], + [ + 'userId' => 'john', + 'items' => [] + ] + ]; + $this->loadFeedFixtures($feeds); + + $fetched = $this->feedMapper->findAll(); + + $this->assertInternalType('array', $fetched); + $this->assertCount(2, $fetched); + $this->assertContainsOnlyInstancesOf(Feed::class, $fetched); + + $this->tearDownUser('john'); + } + public function testFindAllEmpty () { + $feeds = $this->feedMapper->findAll(); + + $this->assertInternalType('array', $feeds); + $this->assertCount(0, $feeds); } public function testFindAllFromUser () { + $feeds = [ + [ + 'userId' => $this->user, + 'items' => [] + ], + [ + 'userId' => 'john', + 'items' => [] + ] + ]; + $this->loadFeedFixtures($feeds); + + $fetched = $this->feedMapper->findAllFromUser($this->user); + + $this->assertInternalType('array', $fetched); + $this->assertCount(1, $fetched); + $this->assertContainsOnlyInstancesOf(Feed::class, $fetched); + + $this->tearDownUser('john'); + } + + public function testFindAllFromUserNotExisting () { + $fetched = $this->feedMapper->findAllFromUser('notexistinguser'); + + $this->assertInternalType('array', $fetched); + $this->assertCount(0, $fetched); } public function testFindByUrlHash () { + $feed = new FeedFixture([ + 'urlHash' => 'someTestHash', + 'title' => 'Some Test Title' + ]); + $feed = $this->feedMapper->insert($feed); + + $fetched = $this->feedMapper->findByUrlHash($feed->getUrlHash(), $this->user); + $this->assertInstanceOf(Feed::class, $fetched); + $this->assertEquals($feed->getTitle(), $fetched->getTitle()); } + /** + * @expectedException OCP\AppFramework\Db\MultipleObjectsReturnedException + */ + public function testFindByUrlHashMoreThanOneResult () { + $feed1 = $this->feedMapper->insert(new FeedFixture([ + 'urlHash' => 'someTestHash' + ])); + $feed2 = $this->feedMapper->insert(new FeedFixture([ + 'urlHash' => 'someTestHash' + ])); + + $this->feedMapper->findByUrlHash($feed1->getUrlHash(), $this->user); + } - public function testDelete () { + /** + * @expectedException OCP\AppFramework\Db\DoesNotExistException + */ + public function testFindByUrlHashNotExisting () { + $this->feedMapper->findByUrlHash('some random hash', $this->user); } + public function testDelete () { + $this->loadFixtures('default'); + + $feeds = $this->feedMapper->findAllFromUser($this->user); + $this->assertCount(4, $feeds); + + $feed = reset($feeds); + + $items = $this->itemMapper->findAllFeed( + $feed->getId(), 100, 0, true, false, $this->user + ); + $this->assertCount(7, $items); + + $this->feedMapper->delete($feed); + + $this->assertCount(3, $this->feedMapper->findAllFromUser($this->user)); + + $items = $this->itemMapper->findAllFeed( + $feed->getId(), 100, 0, true, false, $this->user + ); + $this->assertCount(0, $items); + } + public function testGetToDelete () { + $this->loadFeedFixtures([ + ['deletedAt' => 1], + ['deletedAt' => 0], + ['deletedAt' => 1, 'userId' => 'john'], + ['deletedAt' => 1000] + ]); + + $fetched = $this->feedMapper->getToDelete(); + + $this->assertInternalType('array', $fetched); + $this->assertCount(3, $fetched); + $this->assertContainsOnlyInstancesOf(Feed::class, $fetched); + + $this->tearDownUser('john'); + } + + public function testGetToDeleteOlderThan () { + $this->loadFeedFixtures([ + ['deletedAt' => 1], + ['deletedAt' => 0], + ['deletedAt' => 1, 'userId' => 'john'], + ['deletedAt' => 1000] + ]); + + $fetched = $this->feedMapper->getToDelete(1000); + + $this->assertInternalType('array', $fetched); + $this->assertCount(2, $fetched); + $this->assertContainsOnlyInstancesOf(Feed::class, $fetched); + + $this->tearDownUser('john'); + } + public function testGetToDeleteUser () { + $this->loadFeedFixtures([ + ['deletedAt' => 1], + ['deletedAt' => 0], + ['deletedAt' => 1, 'userId' => 'john'], + ['deletedAt' => 1000] + ]); + + $fetched = $this->feedMapper->getToDelete(2000, $this->user); + + $this->assertInternalType('array', $fetched); + $this->assertCount(2, $fetched); + $this->assertContainsOnlyInstancesOf(Feed::class, $fetched); + + $this->tearDownUser('john'); } + public function testGetToDeleteEmpty () { + $fetched = $this->feedMapper->getToDelete(); + + $this->assertInternalType('array', $fetched); + $this->assertCount(0, $fetched); + } public function testDeleteUser () { + $this->loadFixtures('default'); - }*/ + $this->assertCount(4, $this->feedMapper->findAllFromUser($this->user)); + $items = $this->itemMapper->findAll(100, 0, 0, true, false, $this->user); + $this->assertCount(9, $items); + $this->feedMapper->deleteUser($this->user); + + $this->assertCount(0, $this->feedMapper->findAllFromUser($this->user)); + + $items = $this->itemMapper->findAll(100, 0, 0, true, false, $this->user); + $this->assertCount(0, $items); + } + + public function testDeleteUserNotExisting () { + $this->feedMapper->deleteUser('notexistinguser'); + } } diff --git a/tests/Integration/Db/ItemMapperTest.php b/tests/Integration/Db/ItemMapperTest.php index 6b621e070..fa9cc7d25 100644 --- a/tests/Integration/Db/ItemMapperTest.php +++ b/tests/Integration/Db/ItemMapperTest.php @@ -112,9 +112,8 @@ class ItemMapperTest extends IntegrationTest { $this->itemMapper->readAll(PHP_INT_MAX, 10, $this->user); - $status = StatusFlag::UNREAD; $items = $this->itemMapper->findAll( - 30, 0, $status, false, $this->user + 30, 0, 0, false, false, $this->user ); $this->assertEquals(0, count($items)); @@ -144,9 +143,8 @@ class ItemMapperTest extends IntegrationTest { $folderId, PHP_INT_MAX, 10, $this->user ); - $status = StatusFlag::UNREAD; $items = $this->itemMapper->findAll( - 30, 0, $status, false, $this->user + 30, 0, 0, false, false, $this->user ); $this->assertEquals(1, count($items)); @@ -176,9 +174,8 @@ class ItemMapperTest extends IntegrationTest { $feedId, PHP_INT_MAX, 10, $this->user ); - $status = StatusFlag::UNREAD; $items = $this->itemMapper->findAll( - 30, 0, $status, false, $this->user + 30, 0, 0, false, false, $this->user ); $this->assertEquals(2, count($items)); @@ -246,7 +243,7 @@ class ItemMapperTest extends IntegrationTest { // assert that all test user's same items are read $items = $this->itemMapper->where(['feedId' => $feed->getId(), 'title' => 'blubb']); foreach ($items as $item) { - $this->assertTrue($item->isRead()); + $this->assertFalse($item->isUnread()); } // assert that a different item is not read @@ -277,7 +274,7 @@ class ItemMapperTest extends IntegrationTest { if ($item->getId() === $duplicateItem->getId()) { $this->assertTrue($item->isUnread()); } else { - $this->assertTrue($item->isRead()); + $this->assertFalse($item->isUnread()); } } diff --git a/tests/Integration/Fixtures/ItemFixture.php b/tests/Integration/Fixtures/ItemFixture.php index 2dfe79c28..0832b0ef4 100644 --- a/tests/Integration/Fixtures/ItemFixture.php +++ b/tests/Integration/Fixtures/ItemFixture.php @@ -29,7 +29,8 @@ class ItemFixture extends Item { 'enclosureMime' => 'video/mpeg', 'enclosureLink' => 'http://google.de/web.webm', 'feedId' => 0, - 'status' => 2, + 'unread' => true, + 'starred' => false, 'lastModified' => 113, 'rtl' => false, ], $defaults); diff --git a/tests/Integration/Fixtures/data/default.php b/tests/Integration/Fixtures/data/default.php index d87bb1e6f..862515b12 100644 --- a/tests/Integration/Fixtures/data/default.php +++ b/tests/Integration/Fixtures/data/default.php @@ -20,12 +20,12 @@ return [ 'articlesPerUpdate' => 1, 'items' => [ ['title' => 'a title1', 'guid' => 'abc'], - ['title' => 'a title2', 'status' => 4, 'guid' => 'def'], - ['title' => 'a title3', 'status' => 6, 'guid' => 'gih'], - ['title' => 'del1', 'status' => 0], - ['title' => 'del2', 'status' => 0], - ['title' => 'del3', 'status' => 0], - ['title' => 'del4', 'status' => 0] + ['title' => 'a title2', 'unread' => false, 'starred' => true, 'guid' => 'def'], + ['title' => 'a title3', 'unread' => true, 'starred' => true, 'guid' => 'gih'], + ['title' => 'del1', 'unread' => false, 'starred' => false], + ['title' => 'del2', 'unread' => false, 'starred' => false], + ['title' => 'del3', 'unread' => false, 'starred' => false], + ['title' => 'del4', 'unread' => false, 'starred' => false] ] ], [ @@ -69,7 +69,7 @@ return [ 'title' => 'fourth feed', 'url' => 'http://blog.fefe.de', 'items' => [ - ['title' => 'no folder', 'status' => 0] + ['title' => 'no folder', 'unread' => false, 'starred' => false] ] ] ] diff --git a/tests/Integration/Fixtures/data/readitem.php b/tests/Integration/Fixtures/data/readitem.php index 0a587bad7..8f953a845 100644 --- a/tests/Integration/Fixtures/data/readitem.php +++ b/tests/Integration/Fixtures/data/readitem.php @@ -15,18 +15,18 @@ return [ 'title' => 'john feed', 'userId' => 'john', 'items' => [ - ['title' => 'blubb', 'status' => 2], - ['title' => 'blubb', 'status' => 2] + ['title' => 'blubb', 'unread' => true, 'starred' => false], + ['title' => 'blubb', 'unread' => true, 'starred' => false] ] ], [ 'title' => 'test feed', 'userId' => 'test', 'items' => [ - ['title' => 'blubb', 'status' => 2], - ['title' => 'blubbs', 'status' => 2], - ['title' => 'blubb', 'status' => 2], - ['title' => 'blubb', 'status' => 2] + ['title' => 'blubb', 'unread' => true, 'starred' => false], + ['title' => 'blubbs', 'unread' => true, 'starred' => false], + ['title' => 'blubb', 'unread' => true, 'starred' => false], + ['title' => 'blubb', 'unread' => true, 'starred' => false] ] ] ] diff --git a/tests/Integration/IntegrationTest.php b/tests/Integration/IntegrationTest.php index c14d3007a..f14a1263b 100644 --- a/tests/Integration/IntegrationTest.php +++ b/tests/Integration/IntegrationTest.php @@ -124,7 +124,10 @@ abstract class IntegrationTest extends \Test\TestCase { $feed = new FeedFixture($feedFixture); $feed->setFolderId($folderId); $feedId = $this->loadFixture($feed); - $this->loadItemFixtures($feedFixture['items'], $feedId); + + if (!empty($feedFixture['items'])) { + $this->loadItemFixtures($feedFixture['items'], $feedId); + } } } |