summaryrefslogtreecommitdiffstats
path: root/tests/integration
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2016-07-23 21:24:54 +0200
committerBernhard Posselt <dev@bernhard-posselt.com>2016-07-23 21:24:54 +0200
commit004fcbbcc7609ca83807f2e38967ef54f469bf72 (patch)
tree49eb99b4ea92b2045793fc567f719b31ec7f9042 /tests/integration
parent60abc0ed4438c9b6fda245b0dc33cb483bc2aeaf (diff)
Move to new directory structure
Diffstat (limited to 'tests/integration')
-rw-r--r--tests/integration/db/FeedMapperTest.php54
-rw-r--r--tests/integration/db/FolderMapperTest.php51
-rw-r--r--tests/integration/db/ItemMapperTest.php297
-rw-r--r--tests/integration/fixtures/data/default.php76
-rw-r--r--tests/integration/fixtures/data/readitem.php33
-rw-r--r--tests/integration/fixtures/feedfixture.php50
-rw-r--r--tests/integration/fixtures/fixture.php25
-rw-r--r--tests/integration/fixtures/folderfixture.php35
-rw-r--r--tests/integration/fixtures/itemfixture.php49
-rw-r--r--tests/integration/integrationtest.php206
10 files changed, 0 insertions, 876 deletions
diff --git a/tests/integration/db/FeedMapperTest.php b/tests/integration/db/FeedMapperTest.php
deleted file mode 100644
index b72cb1203..000000000
--- a/tests/integration/db/FeedMapperTest.php
+++ /dev/null
@@ -1,54 +0,0 @@
-<?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
deleted file mode 100644
index 21b6ddf41..000000000
--- a/tests/integration/db/FolderMapperTest.php
+++ /dev/null
@@ -1,51 +0,0 @@
-<?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
deleted file mode 100644
index 14c989cbf..000000000
--- a/tests/integration/db/ItemMapperTest.php
+++ /dev/null
@@ -1,297 +0,0 @@
-<?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/data/default.php b/tests/integration/fixtures/data/default.php
deleted file mode 100644
index d1383c3f7..000000000
--- a/tests/integration/fixtures/data/default.php
+++ /dev/null
@@ -1,76 +0,0 @@
-<?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
deleted file mode 100644
index 7e3d68fad..000000000
--- a/tests/integration/fixtures/data/readitem.php
+++ /dev/null
@@ -1,33 +0,0 @@
-<?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/fixtures/feedfixture.php b/tests/integration/fixtures/feedfixture.php
deleted file mode 100644
index eafcab906..000000000
--- a/tests/integration/fixtures/feedfixture.php
+++ /dev/null
@@ -1,50 +0,0 @@
-<?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
deleted file mode 100644
index a5bceda17..000000000
--- a/tests/integration/fixtures/fixture.php
+++ /dev/null
@@ -1,25 +0,0 @@
-<?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
deleted file mode 100644
index 2dc6b3a44..000000000
--- a/tests/integration/fixtures/folderfixture.php
+++ /dev/null
@@ -1,35 +0,0 @@
-<?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
deleted file mode 100644
index 9e6e07fe2..000000000
--- a/tests/integration/fixtures/itemfixture.php
+++ /dev/null
@@ -1,49 +0,0 @@
-<?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/integrationtest.php b/tests/integration/integrationtest.php
deleted file mode 100644
index 50c172705..000000000
--- a/tests/integration/integrationtest.php
+++ /dev/null
@@ -1,206 +0,0 @@
-<?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
- * @param $user
- * @param $password
- */
- protected function setupUser($user, $password) {
- $userManager = $this->container->query(IUserManager::class);
- $userManager->createUser($user, $password);
-
- $session = $this->container->query(IUserSession::class);
- $session->login($user, $password);
- }
-
- /**
- * Removes a user and his News app database entries from the database
- * @param $user
- */
- protected function tearDownUser($user) {
- $userManager = $this->container->query(IUserManager::class);
-
- if ($userManager->userExists($user)) {
- $userManager->get($user)->delete();
- }
-
- $this->clearUserNewsDatabase($user);
- }
-
- /**
- * Deletes all news entries of a given user
- * @param string $user
- */
- protected function clearUserNewsDatabase($user) {
- $sql = [
- 'DELETE FROM `*PREFIX*news_items` WHERE `feed_id` IN
- (SELECT `id` FROM `*PREFIX*news_feeds` WHERE `user_id` = ?)',
- 'DELETE FROM `*PREFIX*news_feeds` WHERE `user_id` = ?',
- 'DELETE FROM `*PREFIX*news_folders` WHERE `user_id` = ?'
- ];
-
- $db = $this->container->query(IDb::class);
- foreach ($sql as $query) {
- $db->prepareQuery($query)->execute([$user]);
- }
- }
-
- protected function tearDown() {
- parent::tearDown();
- $this->tearDownUser($this->user);
- }
-
-} \ No newline at end of file