From 646b5296843de0815c47fe809178613a5b4fafaa Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Sun, 29 Nov 2015 22:14:56 +0100 Subject: update fixtures to simpler array --- tests/integration/IntegrationTest.php | 50 ++++++- .../Tests/Integration/Fixtures/FolderFixture.php | 20 --- .../Tests/Integration/Fixtures/ItemFixture.php | 20 --- tests/integration/fixtures/FeedFixture.php | 1 + tests/integration/fixtures/Fixture.php | 2 +- tests/integration/fixtures/FolderFixture.php | 35 +++++ tests/integration/fixtures/ItemFixture.php | 43 ++++++ tests/integration/fixtures/data/default.php | 74 +++++++++++ tests/integration/fixtures/feeds.json | 86 ------------ tests/integration/fixtures/folders.json | 17 --- tests/integration/fixtures/items.json | 144 --------------------- 11 files changed, 197 insertions(+), 295 deletions(-) delete mode 100644 tests/integration/OCA/News/Tests/Integration/Fixtures/FolderFixture.php delete mode 100644 tests/integration/OCA/News/Tests/Integration/Fixtures/ItemFixture.php create mode 100644 tests/integration/fixtures/FolderFixture.php create mode 100644 tests/integration/fixtures/ItemFixture.php create mode 100644 tests/integration/fixtures/data/default.php delete mode 100644 tests/integration/fixtures/feeds.json delete mode 100644 tests/integration/fixtures/folders.json delete mode 100644 tests/integration/fixtures/items.json diff --git a/tests/integration/IntegrationTest.php b/tests/integration/IntegrationTest.php index 1baa31359..fda0ee1b1 100644 --- a/tests/integration/IntegrationTest.php +++ b/tests/integration/IntegrationTest.php @@ -19,7 +19,7 @@ use OCP\IUserSession; use OCP\IUserManager; use OCA\News\AppInfo\Application; -use OCA\News\Tests\Integration\Fixtures\Fixture; +use OCA\News\Tests\Integration\Fixtures\Entity; use OCA\News\Tests\Integration\Fixtures\ItemFixture; use OCA\News\Tests\Integration\Fixtures\FeedFixture; use OCA\News\Tests\Integration\Fixtures\FolderFixture; @@ -55,18 +55,54 @@ abstract class IntegrationTest extends PHPUnit_Framework_TestCase { $this->folderMapper = $this->container->query(FolderMapper::class); } + /** + * @param $name loads fixtures from a given file + */ + protected function loadFixtures($name) { + $fixtures = include __DIR__ . '/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); + $feedId = $this->loadFixture($feed); + $this->loadItemFixtures($feedFixture['items'], $feedId); + } + } + + protected function loadItemFixtures(array $itemFixtures=[], $feedId) { + foreach ($itemFixtures as $itemFixture) { + $item = new ItemFixture($itemFixture); + $this->loadFixture($item); + } + } + /** * Saves a fixture in a database and returns the saved result - * @param Fixture $fixture - * @return \OCP\AppFramework\Db\Entity + * @param Entity $fixture + * @return int the id */ - protected function loadFixture(Fixture $fixture) { + protected function loadFixture(Entity $fixture) { if ($fixture instanceof FeedFixture) { - return $this->feedMapper->insert($fixture); + return $this->feedMapper->insert($fixture)->getId(); } elseif ($fixture instanceof ItemFixture) { - return $this->itemMapper->insert($fixture); + return $this->itemMapper->insert($fixture)->getId(); } elseif ($fixture instanceof FolderFixture) { - return $this->folderMapper->insert($fixture); + return $this->folderMapper->insert($fixture)->getId(); } throw new \InvalidArgumentException('Invalid fixture class given'); diff --git a/tests/integration/OCA/News/Tests/Integration/Fixtures/FolderFixture.php b/tests/integration/OCA/News/Tests/Integration/Fixtures/FolderFixture.php deleted file mode 100644 index f934f00db..000000000 --- a/tests/integration/OCA/News/Tests/Integration/Fixtures/FolderFixture.php +++ /dev/null @@ -1,20 +0,0 @@ - - * @copyright Bernhard Posselt 2015 - */ - - -namespace OCA\News\Tests\Integration\Fixtures; - - -use OCA\News\Db\Folder; - -class FolderFixture extends Folder { - use Fixture; -} \ No newline at end of file diff --git a/tests/integration/OCA/News/Tests/Integration/Fixtures/ItemFixture.php b/tests/integration/OCA/News/Tests/Integration/Fixtures/ItemFixture.php deleted file mode 100644 index 62806f208..000000000 --- a/tests/integration/OCA/News/Tests/Integration/Fixtures/ItemFixture.php +++ /dev/null @@ -1,20 +0,0 @@ - - * @copyright Bernhard Posselt 2015 - */ - - -namespace OCA\News\Tests\Integration\Fixtures; - - -use OCA\News\Db\Item; - -class ItemFixture extends Item { - use Fixture; -} \ No newline at end of file diff --git a/tests/integration/fixtures/FeedFixture.php b/tests/integration/fixtures/FeedFixture.php index 286373c76..7b2d68c80 100644 --- a/tests/integration/fixtures/FeedFixture.php +++ b/tests/integration/fixtures/FeedFixture.php @@ -44,6 +44,7 @@ class FeedFixture extends Feed { 'updateErrorCount' => 0, 'lastUpdateError' => 'lastUpdateError', ], $defaults); + unset($defaults['items']); $this->fillDefaults($defaults); } diff --git a/tests/integration/fixtures/Fixture.php b/tests/integration/fixtures/Fixture.php index 52015ebc2..2e546c4a5 100644 --- a/tests/integration/fixtures/Fixture.php +++ b/tests/integration/fixtures/Fixture.php @@ -13,7 +13,7 @@ namespace OCA\News\Tests\Integration\Fixtures; -trait Fixture { +trait Entity { public function fillDefaults(array $defaults=[]) { foreach ($defaults as $key => $value) { diff --git a/tests/integration/fixtures/FolderFixture.php b/tests/integration/fixtures/FolderFixture.php new file mode 100644 index 000000000..872ee33b8 --- /dev/null +++ b/tests/integration/fixtures/FolderFixture.php @@ -0,0 +1,35 @@ + + * @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_combine([ + 'parentId' => 0, + 'name' => 'folder', + 'userId' => 'test', + 'opened' => true, + 'deletedAt' => 0, + + ], $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..412f1c990 --- /dev/null +++ b/tests/integration/fixtures/ItemFixture.php @@ -0,0 +1,43 @@ + + * @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_combine([ + 'guid' => 'guid', + 'url' => 'http://google.de', + 'title' => 'title', + 'author' => '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); + $this->fillDefaults($defaults); + $this->generateSearchIndex(); + $this->setGuid($this->getTitle()); + $this->setGuidHash($this->getGuid()); + } + +} \ No newline at end of file diff --git a/tests/integration/fixtures/data/default.php b/tests/integration/fixtures/data/default.php new file mode 100644 index 000000000..b314d9496 --- /dev/null +++ b/tests/integration/fixtures/data/default.php @@ -0,0 +1,74 @@ + + * @copyright Bernhard Posselt 2015 + */ + +return [ + 'folders' => [ + [ + 'name' => 'first folder', + 'feeds' => [ + [ + 'title' => 'first feed', + 'url' => 'http://google.de', + 'items' => [ + ['title' => 'a title1'], + ['title' => 'a title2', 'status' => 4], + ['title' => 'a title3', 'status' => 6], + ['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', + 'feeds' => [ + [ + 'title' => 'third feed', + 'url' => 'http://heise.de', + 'items' => [['title' => 'the title9']] + ], + [ + 'title' => 'sixth feed', + 'url' => 'http://gremlins.de', + 'deletedAt' => 999999999, + 'items' => [['title' => 'not found feed']] + ] + ], + ], + [ + 'name' => 'third folder', + 'deletedAt' => 9999999999, + 'feeds' => [ + [ + 'title' => 'fifth feed', + 'url' => 'http://prolinux.de', + 'items' => [['title' => 'not found folder']] + ] + ], + ] + ], + '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/feeds.json b/tests/integration/fixtures/feeds.json deleted file mode 100644 index 685a75396..000000000 --- a/tests/integration/fixtures/feeds.json +++ /dev/null @@ -1,86 +0,0 @@ -{ - "first folder": [ - { - "title": "first feed", - "url": "http://google.de", - "deletedAt": 0, - "location": "http://feed.com/rss", - "faviconLink": "Http://feed.com/favicon.ico", - "added": 3000, - "link": "http://feed.com/rss", - "preventUpdate": false, - "articlesPerUpdate": 1, - "lastModified": "", - "etag": "" - }, - { - "title": "second feed", - "url": "http://golem.de", - "deletedAt": 0, - "location": "http://feed.com/rss", - "faviconLink": "Http://feed.com/favicon.ico", - "added": 3000, - "link": "http://feed.com/rss", - "preventUpdate": false, - "articlesPerUpdate": 40, - "lastModified": "", - "etag": "" - } - ], - "second folder": [ - { - "title": "third feed", - "url": "http://heise.de", - "deletedAt": 0, - "location": "http://feed.com/rss", - "faviconLink": "Http://feed.com/favicon.ico", - "added": 3000, - "link": "http://feed.com/rss", - "preventUpdate": false, - "articlesPerUpdate": 40, - "lastModified": "", - "etag": "" - }, - { - "title": "sixth feed", - "url": "http://gremlins.de", - "deletedAt": 999999999, - "location": "http://feed.com/rss", - "faviconLink": "Http://feed.com/favicon.ico", - "added": 3000, - "link": "http://feed.com/rss", - "preventUpdate": false, - "articlesPerUpdate": 40, - "lastModified": "", - "etag": "" - } - ], - "no folder": [{ - "title": "fourth feed", - "url": "http://blog.fefe.de", - "deletedAt": 0, - "location": "http://feed.com/rss", - "faviconLink": "Http://feed.com/favicon.ico", - "added": 3000, - "link": "http://feed.com/rss", - "preventUpdate": false, - "articlesPerUpdate": 40, - "lastModified": "", - "etag": "" - } - ], - "third folder": [{ - "title": "fifth feed", - "url": "http://prolinux.de", - "deletedAt": 0, - "location": "http://feed.com/rss", - "faviconLink": "Http://feed.com/favicon.ico", - "added": 3000, - "link": "http://feed.com/rss", - "preventUpdate": false, - "articlesPerUpdate": 40, - "lastModified": "", - "etag": "" - } - ] -} \ No newline at end of file diff --git a/tests/integration/fixtures/folders.json b/tests/integration/fixtures/folders.json deleted file mode 100644 index 3c79ef52b..000000000 --- a/tests/integration/fixtures/folders.json +++ /dev/null @@ -1,17 +0,0 @@ -[ - { - "name": "first folder", - "deletedAt": 0, - "opened": true - }, - { - "name": "second folder", - "deletedAt": 0, - "opened": false - }, - { - "name": "third folder", - "deletedAt": 9999999999, - "opened": true - } -] \ No newline at end of file diff --git a/tests/integration/fixtures/items.json b/tests/integration/fixtures/items.json deleted file mode 100644 index 5396fde9b..000000000 --- a/tests/integration/fixtures/items.json +++ /dev/null @@ -1,144 +0,0 @@ -{ - "first feed": [ - { - "status": 4, - "body": "this is a body", - "title": "a title2", - "author": "my author", - "guid": "def", - "url": "http://google.de", - "pubDate": 2323, - "lastModified": 113, - "enclosureMime": "video/mpeg", - "enclosureLink": "http://google.de/web.webm" - }, - { - "status": 6, - "body": "this is a body", - "title": "a title3", - "author": "my author", - "guid": "gih", - "url": "http://google.de", - "pubDate": 2323, - "lastModified": 113, - "enclosureMime": "video/mpeg", - "enclosureLink": "http://google.de/web.webm" - }, - { - "status": 2, - "body": "this is a body", - "title": "a title1", - "author": "my author", - "guid": "abc", - "url": "http://google.de", - "pubDate": 2323, - "lastModified": 113, - "enclosureMime": "video/mpeg", - "enclosureLink": "http://google.de/web.webm" - }, - { - "status": 0, - "body": "this is a body", - "title": "del1", - "author": "my author", - "guid": "del1", - "url": "http://google.de", - "pubDate": 2323, - "lastModified": 113, - "enclosureMime": "video/mpeg", - "enclosureLink": "http://google.de/web.webm" - }, - { - "status": 0, - "body": "this is a body", - "title": "del2", - "author": "my author", - "guid": "del2", - "url": "http://google.de", - "pubDate": 2323, - "lastModified": 113, - "enclosureMime": "video/mpeg", - "enclosureLink": "http://google.de/web.webm" - }, - { - "status": 0, - "body": "this is a body", - "title": "del3", - "author": "my author", - "guid": "del3", - "url": "http://google.de", - "pubDate": 2323, - "lastModified": 113, - "enclosureMime": "video/mpeg", - "enclosureLink": "http://google.de/web.webm" - }, - { - "status": 0, - "body": "this is a body", - "title": "del4", - "author": "my author", - "guid": "del4", - "url": "http://google.de", - "pubDate": 2323, - "lastModified": 113, - "enclosureMime": "video/mpeg", - "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, - "body": "this is a body", - "title": "not found folder", - "author": "my author", - "guid": "not found", - "url": "http://google.de", - "pubDate": 2323, - "lastModified": 113, - "enclosureMime": "video/mpeg", - "enclosureLink": "http://google.de/web.webm" - } - ], - "sixth feed": [ - { - "status": 2, - "body": "this is a body", - "title": "not found feed", - "author": "my author", - "guid": "not found", - "url": "http://google.de", - "pubDate": 2323, - "lastModified": 113, - "enclosureMime": "video/mpeg", - "enclosureLink": "http://google.de/web.webm" - } - ] -} \ No newline at end of file -- cgit v1.2.3