diff options
author | Bernhard Posselt <dev@bernhard-posselt.com> | 2016-07-23 21:24:54 +0200 |
---|---|---|
committer | Bernhard Posselt <dev@bernhard-posselt.com> | 2016-07-23 21:24:54 +0200 |
commit | 004fcbbcc7609ca83807f2e38967ef54f469bf72 (patch) | |
tree | 49eb99b4ea92b2045793fc567f719b31ec7f9042 /tests/Integration | |
parent | 60abc0ed4438c9b6fda245b0dc33cb483bc2aeaf (diff) |
Move to new directory structure
Diffstat (limited to 'tests/Integration')
-rw-r--r-- | tests/Integration/Db/FeedMapperTest.php | 54 | ||||
-rw-r--r-- | tests/Integration/Db/FolderMapperTest.php | 51 | ||||
-rw-r--r-- | tests/Integration/Db/ItemMapperTest.php | 297 | ||||
-rw-r--r-- | tests/Integration/Fixtures/FeedFixture.php | 50 | ||||
-rw-r--r-- | tests/Integration/Fixtures/Fixture.php | 25 | ||||
-rw-r--r-- | tests/Integration/Fixtures/FolderFixture.php | 35 | ||||
-rw-r--r-- | tests/Integration/Fixtures/ItemFixture.php | 49 | ||||
-rw-r--r-- | tests/Integration/Fixtures/data/default.php | 76 | ||||
-rw-r--r-- | tests/Integration/Fixtures/data/readitem.php | 33 | ||||
-rw-r--r-- | tests/Integration/IntegrationTest.php | 206 |
10 files changed, 876 insertions, 0 deletions
diff --git a/tests/Integration/Db/FeedMapperTest.php b/tests/Integration/Db/FeedMapperTest.php new file mode 100644 index 000000000..b72cb1203 --- /dev/null +++ b/tests/Integration/Db/FeedMapperTest.php @@ -0,0 +1,54 @@ +<?php +/** + * ownCloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright Bernhard Posselt 2015 + */ + +namespace OCA\News\Db; + +use \OCA\News\Tests\Integration\IntegrationTest; + +class FeedMapperTest extends IntegrationTest { + + + public function testFind () { + } + + + /* TBD + public function testFindAll () { + + } + + + public function testFindAllFromUser () { + + } + + + public function testFindByUrlHash () { + + } + + + public function testDelete () { + + } + + + public function testGetToDelete () { + + } + + + public function testDeleteUser () { + + }*/ + + +} diff --git a/tests/Integration/Db/FolderMapperTest.php b/tests/Integration/Db/FolderMapperTest.php new file mode 100644 index 000000000..21b6ddf41 --- /dev/null +++ b/tests/Integration/Db/FolderMapperTest.php @@ -0,0 +1,51 @@ +<?php +/** + * ownCloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright Bernhard Posselt 2015 + */ + +namespace OCA\News\Db; + +use \OCA\News\Tests\Integration\IntegrationTest; + +class FolderMapperTest extends IntegrationTest { + + + public function testFind () { + + } + + + /* TBD + public function testFindByName () { + + } + + + public function testFindAllFromUser () { + + } + + + public function testDelete () { + + } + + + public function testGetToDelete () { + + } + + + public function testDeleteUser () { + + }*/ + + + +} diff --git a/tests/Integration/Db/ItemMapperTest.php b/tests/Integration/Db/ItemMapperTest.php new file mode 100644 index 000000000..14c989cbf --- /dev/null +++ b/tests/Integration/Db/ItemMapperTest.php @@ -0,0 +1,297 @@ +<?php +/** + * ownCloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright Bernhard Posselt 2015 + */ + +namespace OCA\News\Db; + +use OCA\News\Tests\Integration\Fixtures\FeedFixture; +use OCA\News\Tests\Integration\Fixtures\ItemFixture; +use OCA\News\Tests\Integration\IntegrationTest; + +class ItemMapperTest extends IntegrationTest { + + public function testFind() { + $feed = new FeedFixture(); + $feed = $this->feedMapper->insert($feed); + + $item = new ItemFixture(['feedId' => $feed->getId()]); + + $item = $this->itemMapper->insert($item); + + $fetched = $this->itemMapper->find($item->getId(), $this->user); + + $this->assertEquals($item->getTitle(), $fetched->getTitle()); + } + + /** + * Same as whereId with easier title search + * @param $title + * @return mixed + */ + private function whereTitleId($title) { + return $this->findItemByTitle($title)->getId(); + } + + /** + * @expectedException OCP\AppFramework\Db\DoesNotExistException + */ + public function testFindNotFoundWhenDeletedFeed() { + $this->loadFixtures('default'); + + $id = $this->whereTitleId('not found feed'); + $this->itemMapper->find($id, $this->user); + } + + + /** + * @expectedException OCP\AppFramework\Db\DoesNotExistException + */ + public function testFindNotFoundWhenDeletedFolder() { + $this->loadFixtures('default'); + + + $id = $this->whereTitleId('not found folder'); + $this->itemMapper->find($id, $this->user); + } + + + private function deleteReadOlderThanThreshold() { + $this->loadFixtures('default'); + + $this->itemMapper->deleteReadOlderThanThreshold(1); + + $this->itemMapper->find($this->whereTitleId('a title1'), $this->user); + $this->itemMapper->find($this->whereTitleId('a title2'), $this->user); + $this->itemMapper->find($this->whereTitleId('a title3'), $this->user); + $this->itemMapper->find($this->whereTitleId('del3'), $this->user); + $this->itemMapper->find($this->whereTitleId('del4'), $this->user); + } + + /** + * @expectedException OCP\AppFramework\Db\DoesNotExistException + */ + public function testDeleteOlderThanThresholdOne() { + $this->loadFixtures('default'); + $id = $this->whereTitleId('del1'); + + $this->deleteReadOlderThanThreshold(); + + $this->itemMapper->find($id, $this->user); + } + + /** + * @expectedException OCP\AppFramework\Db\DoesNotExistException + */ + public function testDeleteOlderThanThresholdTwo() { + $this->loadFixtures('default'); + $id = $this->whereTitleId('del2'); + + $this->deleteReadOlderThanThreshold(); + + $this->itemMapper->find($id, $this->user); + } + + + public function testStarredCount () { + $this->loadFixtures('default'); + + $count = $this->itemMapper->starredCount($this->user); + $this->assertEquals(2, $count); + } + + + public function testReadAll () { + $this->loadFixtures('default'); + + $this->itemMapper->readAll(PHP_INT_MAX, 10, $this->user); + + $status = StatusFlag::UNREAD; + $items = $this->itemMapper->findAll( + 30, 0, $status, false, $this->user + ); + + $this->assertEquals(0, count($items)); + + $itemId = $this->whereTitleId('a title1'); + $item = $this->itemMapper->find($itemId, $this->user); + + $this->assertEquals(10, $item->getLastModified()); + + $itemId = $this->whereTitleId('a title3'); + $item = $this->itemMapper->find($itemId, $this->user); + + $this->assertEquals(10, $item->getLastModified()); + + $itemId = $this->whereTitleId('a title9'); + $item = $this->itemMapper->find($itemId, $this->user); + + $this->assertEquals(10, $item->getLastModified()); + } + + + public function testReadFolder () { + $this->loadFixtures('default'); + + $folderId = $this->findFolderByName('first folder')->getId(); + $this->itemMapper->readFolder( + $folderId, PHP_INT_MAX, 10, $this->user + ); + + $status = StatusFlag::UNREAD; + $items = $this->itemMapper->findAll( + 30, 0, $status, false, $this->user + ); + + $this->assertEquals(1, count($items)); + + $item = $this->findItemByTitle('a title1'); + $item = $this->itemMapper->find($item->getId(), $this->user); + + $this->assertEquals(10, $item->getLastModified()); + + $item = $this->findItemByTitle('a title3'); + $item = $this->itemMapper->find($item->getId(), $this->user); + + $this->assertEquals(10, $item->getLastModified()); + + $item = $this->findItemByTitle('a title9'); + $item = $this->itemMapper->find($item->getId(), $this->user); + + $this->assertTrue($item->isUnread()); + } + + + public function testReadFeed () { + $this->loadFixtures('default'); + + $feedId = $this->findFeedByTitle('third feed')->getId(); + $this->itemMapper->readFeed( + $feedId, PHP_INT_MAX, 10, $this->user + ); + + $status = StatusFlag::UNREAD; + $items = $this->itemMapper->findAll( + 30, 0, $status, false, $this->user + ); + + $this->assertEquals(2, count($items)); + + $item = $this->findItemByTitle('a title9'); + $item = $this->itemMapper->find($item->getId(), $this->user); + + $this->assertEquals(10, $item->getLastModified()); + + $item = $this->findItemByTitle('a title3'); + $item = $this->itemMapper->find($item->getId(), $this->user); + $this->assertTrue($item->isUnread()); + + + $item = $this->findItemByTitle('a title1'); + $item = $this->itemMapper->find($item->getId(), $this->user); + $this->assertTrue($item->isUnread()); + } + + + public function testDeleteUser () { + $this->loadFixtures('default'); + + $this->itemMapper->deleteUser($this->user); + $id = $this->itemMapper->getNewestItemId($this->user); + + $this->assertEquals(0, $id); + } + + public function testGetNewestItemId () { + $this->loadFixtures('default'); + + $id = $this->itemMapper->getNewestItemId($this->user); + + $itemId = $this->whereTitleId('no folder'); + $this->assertEquals($itemId, $id); + } + + public function testFindAllUnreadOrStarred () { + $this->loadFixtures('default'); + + $items = $this->itemMapper->findAllUnreadOrStarred($this->user); + $this->assertEquals(4, count($items)); + } + + + public function testReadItem() { + $this->loadFixtures('readitem'); + // assert that all items are unread + $feed = $this->feedMapper->where(['userId' => 'john'])[0]; + $items = $this->itemMapper->where(['feedId' => $feed->getId()]); + foreach ($items as $item) { + $this->assertTrue($item->isUnread()); + } + $feed = $this->feedMapper->where(['userId' => 'test'])[0]; + $items = $this->itemMapper->where(['feedId' => $feed->getId()]); + foreach ($items as $item) { + $this->assertTrue($item->isUnread()); + } + + // read an item + $duplicateItem = $this->itemMapper->where(['feedId' => $feed->getId()])[0]; + $this->itemMapper->readItem($duplicateItem->getId(), true, 1000, $this->user); + + // 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()); + } + + // assert that a different item is not read + $items = $this->itemMapper->where(['feedId' => $feed->getId(), 'title' => 'blubbs']); + foreach ($items as $item) { + $this->assertTrue($item->isUnread()); + } + + // assert that other user's same items stayed the same + $johnsFeed = $this->feedMapper->where(['userId' => 'john'])[0]; + $items = $this->itemMapper->where(['feedId' => $johnsFeed->getId()]); + foreach ($items as $item) { + $this->assertTrue($item->isUnread()); + } + } + + public function testUnreadItem() { + $this->loadFixtures('readitem'); + // unread an item + $feed = $this->feedMapper->where(['userId' => 'test'])[0]; + $duplicateItem = $this->itemMapper->where(['feedId' => $feed->getId()])[0]; + $this->itemMapper->readItem($duplicateItem->getId(), true, 1000, $this->user); + $this->itemMapper->readItem($duplicateItem->getId(), false, 1000, $this->user); + + // assert that only one item is now unread + $items = $this->itemMapper->where(['feedId' => $feed->getId(), 'title' => 'blubb']); + foreach ($items as $item) { + if ($item->getId() === $duplicateItem->getId()) { + $this->assertTrue($item->isUnread()); + } else { + $this->assertTrue($item->isRead()); + } + } + + // assert that other user's same items stayed the same + $johnsFeed = $this->feedMapper->where(['userId' => 'john'])[0]; + $items = $this->itemMapper->where(['feedId' => $johnsFeed->getId()]); + foreach ($items as $item) { + $this->assertTrue($item->isUnread()); + } + } + + protected function tearDown() { + parent::tearDown(); + $this->clearUserNewsDatabase('john'); + } + +} diff --git a/tests/Integration/Fixtures/FeedFixture.php b/tests/Integration/Fixtures/FeedFixture.php new file mode 100644 index 000000000..eafcab906 --- /dev/null +++ b/tests/Integration/Fixtures/FeedFixture.php @@ -0,0 +1,50 @@ +<?php +/** + * ownCloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright Bernhard Posselt 2015 + */ + + +namespace OCA\News\Tests\Integration\Fixtures; + + +use OCA\News\Db\Feed; + +class FeedFixture extends Feed { + + use Fixture; + + public function __construct(array $defaults=[]) { + parent::__construct(); + $defaults = array_merge([ + 'userId' => 'test', + 'urlHash' => 'urlHash', + 'url' => 'http://the.url.com', + 'title' => 'title', + 'faviconLink' => 'http://feed.com/favicon.ico', + 'added' => 3000, + 'folderId' => 0, + 'link' => 'http://feed.com/rss', + 'preventUpdate' => false, + 'deletedAt' => 0, + 'articlesPerUpdate' => 40, + 'httpLastModified' => 10, + 'httpEtag' => '', + 'location' => 'http://feed.com/rss', + 'ordering' => 0, + 'fullTextEnabled' => false, + 'pinned' => false, + 'updateMode' => 0, + 'updateErrorCount' => 0, + 'lastUpdateError' => '', + ], $defaults); + unset($defaults['items']); + $this->fillDefaults($defaults); + } + +} diff --git a/tests/Integration/Fixtures/Fixture.php b/tests/Integration/Fixtures/Fixture.php new file mode 100644 index 000000000..a5bceda17 --- /dev/null +++ b/tests/Integration/Fixtures/Fixture.php @@ -0,0 +1,25 @@ +<?php +/** + * ownCloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright Bernhard Posselt 2015 + */ + + +namespace OCA\News\Tests\Integration\Fixtures; + + +trait Fixture { + + protected function fillDefaults(array $defaults=[]) { + foreach ($defaults as $key => $value) { + $method = 'set' . ucfirst($key); + $this->$method($value); + } + } + +}
\ No newline at end of file diff --git a/tests/Integration/Fixtures/FolderFixture.php b/tests/Integration/Fixtures/FolderFixture.php new file mode 100644 index 000000000..2dc6b3a44 --- /dev/null +++ b/tests/Integration/Fixtures/FolderFixture.php @@ -0,0 +1,35 @@ +<?php +/** + * ownCloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright Bernhard Posselt 2015 + */ + + +namespace OCA\News\Tests\Integration\Fixtures; + + +use OCA\News\Db\Folder; + +class FolderFixture extends Folder { + use Fixture; + + public function __construct(array $defaults=[]) { + parent::__construct(); + $defaults = array_merge([ + 'parentId' => 0, + 'name' => 'folder', + 'userId' => 'test', + 'opened' => true, + 'deletedAt' => 0, + 'lastModified' => 9 + ], $defaults); + unset($defaults['feeds']); + $this->fillDefaults($defaults); + } + +}
\ No newline at end of file diff --git a/tests/Integration/Fixtures/ItemFixture.php b/tests/Integration/Fixtures/ItemFixture.php new file mode 100644 index 000000000..9e6e07fe2 --- /dev/null +++ b/tests/Integration/Fixtures/ItemFixture.php @@ -0,0 +1,49 @@ +<?php +/** + * ownCloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright Bernhard Posselt 2015 + */ + + +namespace OCA\News\Tests\Integration\Fixtures; + + +use OCA\News\Db\Item; + +class ItemFixture extends Item { + use Fixture; + + public function __construct(array $defaults=[]) { + parent::__construct(); + $defaults = array_merge([ + 'url' => 'http://google.de', + 'title' => 'title', + 'author' => 'my author', + 'pubDate' => 2323, + 'body' => 'this is a body', + 'enclosureMime' => 'video/mpeg', + 'enclosureLink' => 'http://google.de/web.webm', + 'feedId' => 0, + 'status' => 2, + 'lastModified' => 113, + 'rtl' => false, + ], $defaults); + + if (!array_key_exists('guid', $defaults)) { + $defaults['guid'] = $defaults['title']; + } + + if (!array_key_exists('guidHash', $defaults)) { + $defaults['guidHash'] = $defaults['guid']; + } + + $this->fillDefaults($defaults); + $this->generateSearchIndex(); + } + +} diff --git a/tests/Integration/Fixtures/data/default.php b/tests/Integration/Fixtures/data/default.php new file mode 100644 index 000000000..d1383c3f7 --- /dev/null +++ b/tests/Integration/Fixtures/data/default.php @@ -0,0 +1,76 @@ +<?php +/** + * ownCloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright Bernhard Posselt 2015 + */ + +return [ + 'folders' => [ + [ + 'name' => 'first folder', + 'feeds' => [ + [ + 'title' => 'first feed', + 'url' => 'http://google.de', + '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' => 'second feed', + 'url' => 'http://golem.de', + 'items' => [] + ], + ], + ], + [ + 'name' => 'second folder', + 'opened' => false, + 'feeds' => [ + [ + 'title' => 'third feed', + 'url' => 'http://heise.de', + 'items' => [['title' => 'a title9']] + ], + [ + 'title' => 'sixth feed', + 'url' => 'http://gremlins.de', + 'deletedAt' => 999999999, + 'items' => [['title' => 'not found feed', 'guid' => 'not found']] + ] + ], + ], + [ + 'name' => 'third folder', + 'deletedAt' => 9999999999, + 'feeds' => [ + [ + 'title' => 'fifth feed', + 'url' => 'http://prolinux.de', + 'items' => [['title' => 'not found folder', 'guid' => 'not found']] + ] + ], + ] + ], + 'feeds' => [ + [ + 'title' => 'fourth feed', + 'url' => 'http://blog.fefe.de', + 'items' => [ + ['title' => 'no folder', 'status' => 0] + ] + ] + ] +];
\ No newline at end of file diff --git a/tests/Integration/Fixtures/data/readitem.php b/tests/Integration/Fixtures/data/readitem.php new file mode 100644 index 000000000..7e3d68fad --- /dev/null +++ b/tests/Integration/Fixtures/data/readitem.php @@ -0,0 +1,33 @@ +<?php +/** + * ownCloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright Bernhard Posselt 2015 + */ + +return [ + 'feeds' => [ + [ + 'title' => 'john feed', + 'userId' => 'john', + 'items' => [ + ['title' => 'blubb', 'status' => 2], + ['title' => 'blubb', 'status' => 2] + ] + ], + [ + 'title' => 'test feed', + 'userId' => 'test', + 'items' => [ + ['title' => 'blubb', 'status' => 2], + ['title' => 'blubbs', 'status' => 2], + ['title' => 'blubb', 'status' => 2], + ['title' => 'blubb', 'status' => 2] + ] + ] + ] +]; diff --git a/tests/Integration/IntegrationTest.php b/tests/Integration/IntegrationTest.php new file mode 100644 index 000000000..1e89bd8c2 --- /dev/null +++ b/tests/Integration/IntegrationTest.php @@ -0,0 +1,206 @@ +<?php +/** + * ownCloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright Bernhard Posselt 2015 + */ + + +namespace OCA\News\Tests\Integration; + +use PHPUnit_Framework_TestCase; + +use OCA\News\Db\Feed; +use OCA\News\Db\Item; +use OCP\AppFramework\Db\Entity; +use OCP\AppFramework\IAppContainer; + +use OCP\IDb; +use OCP\IUserSession; +use OCP\IUserManager; + +use OCA\News\AppInfo\Application; +use OCA\News\Tests\Integration\Fixtures\ItemFixture; +use OCA\News\Tests\Integration\Fixtures\FeedFixture; +use OCA\News\Tests\Integration\Fixtures\FolderFixture; +use OCA\News\Db\FeedMapper; +use OCA\News\Db\ItemMapper; +use OCA\News\Db\FolderMapper; + + +abstract class IntegrationTest extends PHPUnit_Framework_TestCase { + + protected $user = 'test'; + protected $userPassword = 'test'; + + /** @var ItemMapper */ + protected $itemMapper; + + /** @var FeedMapper */ + protected $feedMapper; + + /** @var FolderMapper */ + protected $folderMapper; + + /** @var IAppContainer */ + protected $container; + + protected function setUp() { + parent::setUp(); + $app = new Application(); + $this->container = $app->getContainer(); + $this->tearDownUser($this->user); + $this->setupUser($this->user, $this->userPassword); + + // set up database layers + $this->itemMapper = $this->container->query(ItemMapper::class); + $this->feedMapper = $this->container->query(FeedMapper::class); + $this->folderMapper = $this->container->query(FolderMapper::class); + } + + protected function findItemByTitle($title) { + // db logic in app code, negligible since its a test + $items = $this->itemMapper->where(['title' => $title]); + $feeds = $this->feedMapper->where(['userId' => $this->user]); + + $feedIds = []; + foreach ($feeds as $feed) { + $feedIds[$feed->getId()] = true; + } + + $result = array_filter($items, + function (Item $item) use ($feedIds) { + return array_key_exists($item->getFeedId(), $feedIds); + }); + + // ok so this is funny: array_filter preserves indices, meaning that + // you can't use 0 as key for the first element return from it :D + $result = array_values($result)[0]; + + return $result; + } + + protected function findFolderByName($name) { + return $this->folderMapper->where([ + 'userId' => $this->user, + 'name' => $name + ])[0]; + } + + protected function findFeedByTitle($title) { + return $this->feedMapper->where([ + 'userId' => $this->user, + 'title' => $title + ])[0]; + } + + /** + * @param string $name loads fixtures from a given file + */ + protected function loadFixtures($name) { + $fixtures = include __DIR__ . '/Fixtures/data/' . $name . '.php'; + if (array_key_exists('folders', $fixtures)) { + $this->loadFolderFixtures($fixtures['folders']); + } + if (array_key_exists('feeds', $fixtures)) { + $this->loadFeedFixtures($fixtures['feeds']); + } + } + + protected function loadFolderFixtures(array $folderFixtures=[]) { + foreach ($folderFixtures as $folderFixture) { + $folder = new FolderFixture($folderFixture); + $folderId = $this->loadFixture($folder); + $this->loadFeedFixtures($folderFixture['feeds'], $folderId); + } + } + + protected function loadFeedFixtures(array $feedFixtures=[], $folderId=0) { + foreach ($feedFixtures as $feedFixture) { + $feed = new FeedFixture($feedFixture); + $feed->setFolderId($folderId); + $feedId = $this->loadFixture($feed); + $this->loadItemFixtures($feedFixture['items'], $feedId); + } + } + + protected function loadItemFixtures(array $itemFixtures=[], $feedId) { + foreach ($itemFixtures as $itemFixture) { + $item = new ItemFixture($itemFixture); + $item->setFeedId($feedId); + $this->loadFixture($item); + } + } + + /** + * Saves a fixture in a database and returns the saved result + * @param Entity $fixture + * @return int the id + */ + protected function loadFixture(Entity $fixture) { + if ($fixture instanceof FeedFixture) { + return $this->feedMapper->insert($fixture)->getId(); + } elseif ($fixture instanceof ItemFixture) { + return $this->itemMapper->insert($fixture)->getId(); + } elseif ($fixture instanceof FolderFixture) { + return $this->folderMapper->insert($fixture)->getId(); + } + + throw new \InvalidArgumentException('Invalid fixture class given'); + } + + /** + * Creates and logs in a new ownCloud user |