From 27bd54058050a70bd1c9ec8cfcdf42d38541f1b0 Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Sat, 26 Dec 2020 13:09:41 +0100 Subject: Remove PHPunit integration tests Signed-off-by: Sean Molenaar --- .github/workflows/integration-tests.yml | 3 - CHANGELOG.md | 3 + Makefile | 6 - phpunit.integration.xml | 7 - tests/Integration/Db/FeedMapperTest.php | 258 ------------------------ tests/Integration/Db/ItemMapperTest.php | 285 --------------------------- tests/Integration/Fixtures/FeedFixture.php | 54 ----- tests/Integration/Fixtures/Fixture.php | 26 --- tests/Integration/Fixtures/FolderFixture.php | 40 ---- tests/Integration/Fixtures/ItemFixture.php | 56 ------ tests/Integration/Fixtures/data/default.php | 76 ------- tests/Integration/Fixtures/data/readitem.php | 33 ---- tests/Integration/IntegrationTest.php | 225 --------------------- 13 files changed, 3 insertions(+), 1069 deletions(-) delete mode 100644 phpunit.integration.xml delete mode 100644 tests/Integration/Db/FeedMapperTest.php delete mode 100644 tests/Integration/Db/ItemMapperTest.php delete mode 100644 tests/Integration/Fixtures/FeedFixture.php delete mode 100644 tests/Integration/Fixtures/Fixture.php delete mode 100644 tests/Integration/Fixtures/FolderFixture.php delete mode 100644 tests/Integration/Fixtures/ItemFixture.php delete mode 100644 tests/Integration/Fixtures/data/default.php delete mode 100644 tests/Integration/Fixtures/data/readitem.php delete mode 100644 tests/Integration/IntegrationTest.php diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index 5843149e9..a3d70337b 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -135,9 +135,6 @@ jobs: - name: Prep PHP tests working-directory: ../server/apps/news run: make php-test-dependencies - - name: Integration tests - working-directory: ../server/apps/news - run: make integration-test - name: Feed tests working-directory: ../server/apps/news run: make feed-test diff --git a/CHANGELOG.md b/CHANGELOG.md index df1055b7e..6874d02f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ The format is almost based on [Keep a Changelog](https://keepachangelog.com/en/1 ## [15.1.1] - 2020-12-27 +### Changed +- Remove PHPunit based integration tests + ### Fixed - Argument 2 passed to OCA\News\Db\FeedMapper::find() must be of the type int, string given #996 diff --git a/Makefile b/Makefile index 434b5c3eb..1da8c697b 100644 --- a/Makefile +++ b/Makefile @@ -194,18 +194,12 @@ php-test-dependencies: unit-test: ./vendor/phpunit/phpunit/phpunit -c phpunit.xml --coverage-clover build/php-unit.clover -# \Test\TestCase is only allowed to access the db if TRAVIS environment variable is set -.PHONY: integration-test -integration-test: - env TRAVIS=1 ./vendor/phpunit/phpunit/phpunit -c phpunit.integration.xml - # Command for running JS and PHP tests. Works for package.json files in the js/ # and root directory. If phpunit is not installed systemwide, a copy is fetched # from the internet .PHONY: test test: php-test-dependencies $(MAKE) unit-test - $(MAKE) integration-test $(MAKE) phpcs $(MAKE) phpstan $(MAKE) js-test diff --git a/phpunit.integration.xml b/phpunit.integration.xml deleted file mode 100644 index eae19f133..000000000 --- a/phpunit.integration.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - ./tests/Integration - - - diff --git a/tests/Integration/Db/FeedMapperTest.php b/tests/Integration/Db/FeedMapperTest.php deleted file mode 100644 index 803e9260b..000000000 --- a/tests/Integration/Db/FeedMapperTest.php +++ /dev/null @@ -1,258 +0,0 @@ - - * @author Daniel Opitz - * @copyright Bernhard Posselt 2015 - * @copyright Daniel Opitz 2017 - */ - -namespace OCA\News\Tests\Integration\Db; - -use OCA\News\Db\Feed; -use OCA\News\Tests\Integration\IntegrationTest; -use OCA\News\Tests\Integration\Fixtures\FeedFixture; - -class FeedMapperTest extends IntegrationTest -{ - - public function testFind() - { - $feed = new FeedFixture(); - $feed = $this->feedMapper->insert($feed); - - $fetched = $this->feedMapper->find($this->user, $feed->getId()); - - $this->assertInstanceOf(Feed::class, $fetched); - $this->assertEquals($feed->getLink(), $fetched->getLink()); - } - - public function testFindNotExisting() - { - $this->expectException('OCP\AppFramework\Db\DoesNotExistException'); - $this->feedMapper->find($this->user, 0); - } - - - public function testFindAll() - { - $feeds = [ - [ - 'userId' => $this->user, - 'items' => [] - ], - [ - 'userId' => 'john', - 'items' => [] - ] - ]; - $this->loadFeedFixtures($feeds); - - $fetched = $this->feedMapper->findAll(); - - $this->assertIsArray($fetched); - $this->assertCount(2, $fetched); - $this->assertContainsOnlyInstancesOf(Feed::class, $fetched); - - $this->tearDownUser('john'); - } - - public function testFindAllEmpty() - { - $feeds = $this->feedMapper->findAll(); - - $this->assertIsArray($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->assertIsArray($fetched); - $this->assertCount(1, $fetched); - $this->assertContainsOnlyInstancesOf(Feed::class, $fetched); - - $this->tearDownUser('john'); - } - - - public function testFindAllFromUserNotExisting() - { - $fetched = $this->feedMapper->findAllFromUser('notexistinguser'); - - $this->assertIsArray($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()); - } - - public function testFindByUrlHashMoreThanOneResult() - { - $this->expectException('OCP\AppFramework\Db\MultipleObjectsReturnedException'); - $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 testFindByUrlHashNotExisting() - { - $this->expectException('OCP\AppFramework\Db\DoesNotExistException'); - $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->assertIsArray($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->assertIsArray($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->assertIsArray($fetched); - $this->assertCount(2, $fetched); - $this->assertContainsOnlyInstancesOf(Feed::class, $fetched); - - $this->tearDownUser('john'); - } - - public function testGetToDeleteEmpty() - { - $fetched = $this->feedMapper->getToDelete(); - - $this->assertIsArray($fetched); - $this->assertCount(0, $fetched); - } - - public function testDeleteUser() - { - $this->loadFixtures('default'); - - $this->assertCount(4, $this->feedMapper->findAllFromUser($this->user)); - - $items = $this->itemMapper->findAllItems(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->findAllItems(100, 0, 0, true, false, $this->user); - $this->assertCount(0, $items); - } -} diff --git a/tests/Integration/Db/ItemMapperTest.php b/tests/Integration/Db/ItemMapperTest.php deleted file mode 100644 index ea7f306df..000000000 --- a/tests/Integration/Db/ItemMapperTest.php +++ /dev/null @@ -1,285 +0,0 @@ - - * @copyright Bernhard Posselt 2015 - */ - -namespace OCA\News\Tests\Integration\Db; - -use OCA\News\Tests\Integration\IntegrationTest; -use OCA\News\Tests\Integration\Fixtures\FeedFixture; -use OCA\News\Tests\Integration\Fixtures\ItemFixture; - -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($this->user, $item->getId()); - - $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->expectException('OCP\AppFramework\Db\DoesNotExistException'); - $this->loadFixtures('default'); - - $id = $this->whereTitleId('not found feed'); - $this->itemMapper->find($this->user, $id); - } - - - /** - * @expectedException \OCP\AppFramework\Db\DoesNotExistException - */ - public function testFindNotFoundWhenDeletedFolder() - { - $this->expectException('OCP\AppFramework\Db\DoesNotExistException'); - $this->loadFixtures('default'); - - - $id = $this->whereTitleId('not found folder'); - $this->itemMapper->find($this->user, $id); - } - - - private function deleteReadOlderThanThreshold() - { - $this->loadFixtures('default'); - - $this->itemMapper->deleteReadOlderThanThreshold(1); - - $this->itemMapper->find($this->user, $this->whereTitleId('a title1')); - $this->itemMapper->find($this->user, $this->whereTitleId('a title2')); - $this->itemMapper->find($this->user, $this->whereTitleId('a title3')); - $this->itemMapper->find($this->user, $this->whereTitleId('del3')); - $this->itemMapper->find($this->user, $this->whereTitleId('del4')); - } - - /** - * @expectedException \OCP\AppFramework\Db\DoesNotExistException - */ - public function testDeleteOlderThanThresholdOne() - { - $this->expectException('OCP\AppFramework\Db\DoesNotExistException'); - $this->loadFixtures('default'); - $id = $this->whereTitleId('del1'); - - $this->deleteReadOlderThanThreshold(); - - $this->itemMapper->find($this->user, $id); - } - - /** - * @expectedException \OCP\AppFramework\Db\DoesNotExistException - */ - public function testDeleteOlderThanThresholdTwo() - { - $this->expectException('OCP\AppFramework\Db\DoesNotExistException'); - $this->loadFixtures('default'); - $id = $this->whereTitleId('del2'); - - $this->deleteReadOlderThanThreshold(); - - $this->itemMapper->find($this->user, $id); - } - - - 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); - - $items = $this->itemMapper->findAllItems( - 30, 0, 0, false, false, $this->user - ); - - $this->assertEquals(0, count($items)); - - $itemId = $this->whereTitleId('a title1'); - $item = $this->itemMapper->find($this->user, $itemId); - - $this->assertEquals(10, $item->getLastModified()); - - $itemId = $this->whereTitleId('a title3'); - $item = $this->itemMapper->find($this->user, $itemId); - - $this->assertEquals(10, $item->getLastModified()); - - $itemId = $this->whereTitleId('a title9'); - $item = $this->itemMapper->find($this->user, $itemId); - - $this->assertEquals(10, $item->getLastModified()); - } - - - public function testReadFeed() - { - $this->loadFixtures('default'); - - $feedId = $this->findFeedByTitle('third feed')->getId(); - $this->itemMapper->readFeed( - $feedId, PHP_INT_MAX, 10, $this->user - ); - - $items = $this->itemMapper->findAllItems( - 30, 0, 0, false, false, $this->user - ); - - $this->assertEquals(2, count($items)); - - $item = $this->findItemByTitle('a title9'); - $item = $this->itemMapper->find($this->user, $item->getId()); - - $this->assertEquals(10, $item->getLastModified()); - - $item = $this->findItemByTitle('a title3'); - $item = $this->itemMapper->find($this->user, $item->getId()); - $this->assertTrue($item->isUnread()); - - - $item = $this->findItemByTitle('a title1'); - $item = $this->itemMapper->find($this->user, $item->getId()); - $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->assertFalse($item->isUnread()); - } - - // 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->assertFalse($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()); - } - } - - protected function tearDown(): void - { - parent::tearDown(); - $this->clearUserNewsDatabase('john'); - } - -} diff --git a/tests/Integration/Fixtures/FeedFixture.php b/tests/Integration/Fixtures/FeedFixture.php deleted file mode 100644 index 0c1e31af9..000000000 --- a/tests/Integration/Fixtures/FeedFixture.php +++ /dev/null @@ -1,54 +0,0 @@ - - * @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' => null, - '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 366c93228..000000000 --- a/tests/Integration/Fixtures/Fixture.php +++ /dev/null @@ -1,26 +0,0 @@ - - * @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 ffd6042c0..000000000 --- a/tests/Integration/Fixtures/FolderFixture.php +++ /dev/null @@ -1,40 +0,0 @@ - - * @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' => null, - '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 978b12b55..000000000 --- a/tests/Integration/Fixtures/ItemFixture.php +++ /dev/null @@ -1,56 +0,0 @@ - - * @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', - 'mediaThumbnail' => 'https://i3.ytimg.com/vi/Zgge1O9wdPY/hqdefault.jpg', - 'mediaDescription' => 'The best video ever', - 'feedId' => 0, - 'unread' => true, - 'starred' => false, - '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 deleted file mode 100644 index 41935b5c6..000000000 --- a/tests/Integration/Fixtures/data/default.php +++ /dev/null @@ -1,76 +0,0 @@ - - * @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', '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] - ] - ], - [ - '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', 'unread' => false, 'starred' => false] - ] - ] - ] -]; \ 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 425492741..000000000 --- a/tests/Integration/Fixtures/data/readitem.php +++ /dev/null @@ -1,33 +0,0 @@ - - * @copyright Bernhard Posselt 2015 - */ - -return [ - 'feeds' => [ - [ - 'title' => 'john feed', - 'userId' => 'john', - 'items' => [ - ['title' => 'blubb', 'unread' => true, 'starred' => false], - ['title' => 'blubb', 'unread' => true, 'starred' => false] - ] - ], - [ - 'title' => 'test feed', - 'userId' => 'test', - 'items' => [ - ['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 deleted file mode 100644 index 7c9acf170..000000000 --- a/tests/Integration/IntegrationTest.php +++ /dev/null @@ -1,225 +0,0 @@ - - * @copyright Bernhard Posselt 2015 - */ - - -namespace OCA\News\Tests\Integration; - -use OCA\News\Db\FolderMapperV2; -use OCA\News\Db\Item; -use OCP\AppFramework\Db\Entity; -use OCP\AppFramework\IAppContainer; - -use OCP\IDBConnection; -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; - -abstract class IntegrationTest extends \Test\TestCase -{ - - protected $user = 'test'; - protected $userPassword = 'test'; - - /** - * @var ItemMapper - */ - protected $itemMapper; - - /** - * @var FeedMapper - */ - protected $feedMapper; - - /** - * @var FolderMapperV2 - */ - protected $folderMapper; - - /** - * @var IAppContainer - */ - protected $container; - - protected function setUp(): void - { - 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->get(ItemMapper::class); - $this->feedMapper = $this->container->get(FeedMapper::class); - $this->folderMapper = $this->container->get(FolderMapperV2::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 findFeedByTitle($title) - { - return $this->feedMapper->where( - [ - 'userId' => $this->user, - 'title' => $title - ] - )[0]; - } - - /** - * @param string $name loads fixtures from a given file - */ - protected function loadFixtures(string $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 = null) - { - foreach ($feedFixtures as $feedFixture) { - $feed = new FeedFixture($feedFixture); - $feed->setFolderId($folderId); - $feedId = $this->loadFixture($feed); - - if (!empty($feedFixture['items'])) { - $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->get(IUserManager::class); - $userManager->createUser($user, $password); - - $this->loginAsUser($user); - } - - /** - * Removes a user and his News app database entries from the database - * - * @param $user - */ - protected function tearDownUser($user) - { - $userManager = $this->container->get(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(string $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->get(IDBConnection::class); - foreach ($sql as $query) { - $db->prepare($query)->execute([$user]); - } - } - - protected function tearDown(): void - { - parent::tearDown(); - $this->tearDownUser($this->user); - } - -} \ No newline at end of file -- cgit v1.2.3