summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2015-12-03 21:40:46 +0100
committerBernhard Posselt <dev@bernhard-posselt.com>2016-01-17 18:18:39 +0100
commit570c75db776a79294d97a05cd8ac63ac4ab39685 (patch)
treedeedd28a10628a06b9d0b53400a2719b7a659562 /tests
parente5d606d3ee7dc046e7db9eb1f94b6cc6e542ecbe (diff)
fix several integration test issues
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/db/ItemMapperTest.php12
-rw-r--r--tests/integration/fixtures/feedfixture.php3
-rw-r--r--tests/integration/fixtures/fixture.php3
-rw-r--r--tests/integration/fixtures/folderfixture.php2
-rw-r--r--tests/integration/fixtures/itemfixture.php10
-rw-r--r--tests/integration/integrationtest.php26
6 files changed, 34 insertions, 22 deletions
diff --git a/tests/integration/db/ItemMapperTest.php b/tests/integration/db/ItemMapperTest.php
index 948b843de..0f5f15318 100644
--- a/tests/integration/db/ItemMapperTest.php
+++ b/tests/integration/db/ItemMapperTest.php
@@ -11,16 +11,21 @@
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() {
- $item = new ItemFixture();
+ $feed = new FeedFixture();
+ $feed = $this->feedMapper->insert($feed);
- $created = $this->itemMapper->insert($item);
- $fetched = $this->itemMapper->find($created->getId(), $this->user);
+ $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());
}
@@ -51,6 +56,7 @@ class ItemMapperTest extends IntegrationTest {
public function testFindNotFoundWhenDeletedFolder() {
$this->loadFixtures('default');
+
$id = $this->whereTitleId('not found folder');
$this->itemMapper->find($id, $this->user);
}
diff --git a/tests/integration/fixtures/feedfixture.php b/tests/integration/fixtures/feedfixture.php
index 8c87a8efd..5394ebf6b 100644
--- a/tests/integration/fixtures/feedfixture.php
+++ b/tests/integration/fixtures/feedfixture.php
@@ -21,7 +21,7 @@ class FeedFixture extends Feed {
public function __construct(array $defaults=[]) {
parent::__construct();
- $defaults = array_combine([
+ $defaults = array_merge([
'userId' => 'test',
'urlHash' => 'urlHash',
'url' => 'http://the.url.com',
@@ -29,7 +29,6 @@ class FeedFixture extends Feed {
'faviconLink' => 'http://the.faviconLink.com',
'added' => 9,
'folderId' => 0,
- 'unreadCount' => 0,
'link' => 'http://thelink.com',
'preventUpdate' => false,
'deletedAt' => 0,
diff --git a/tests/integration/fixtures/fixture.php b/tests/integration/fixtures/fixture.php
index 52015ebc2..a5bceda17 100644
--- a/tests/integration/fixtures/fixture.php
+++ b/tests/integration/fixtures/fixture.php
@@ -15,12 +15,11 @@ namespace OCA\News\Tests\Integration\Fixtures;
trait Fixture {
- public function fillDefaults(array $defaults=[]) {
+ protected function fillDefaults(array $defaults=[]) {
foreach ($defaults as $key => $value) {
$method = 'set' . ucfirst($key);
$this->$method($value);
}
- $this->resetUpdatedFields();
}
} \ No newline at end of file
diff --git a/tests/integration/fixtures/folderfixture.php b/tests/integration/fixtures/folderfixture.php
index 872ee33b8..2c884c6ed 100644
--- a/tests/integration/fixtures/folderfixture.php
+++ b/tests/integration/fixtures/folderfixture.php
@@ -20,7 +20,7 @@ class FolderFixture extends Folder {
public function __construct(array $defaults=[]) {
parent::__construct();
- $defaults = array_combine([
+ $defaults = array_merge([
'parentId' => 0,
'name' => 'folder',
'userId' => 'test',
diff --git a/tests/integration/fixtures/itemfixture.php b/tests/integration/fixtures/itemfixture.php
index ac9191c4d..8914773dc 100644
--- a/tests/integration/fixtures/itemfixture.php
+++ b/tests/integration/fixtures/itemfixture.php
@@ -20,8 +20,7 @@ class ItemFixture extends Item {
public function __construct(array $defaults=[]) {
parent::__construct();
- $defaults = array_combine([
- 'guid' => 'guid',
+ $defaults = array_merge([
'url' => 'http://google.de',
'title' => 'title',
'author' => 'author',
@@ -34,17 +33,18 @@ class ItemFixture extends Item {
'lastModified' => 113,
'rtl' => false,
], $defaults);
- $this->fillDefaults($defaults);
if (!array_key_exists('guid', $defaults)) {
- $this->setGuid($this->getTitle());
+ $defaults['guid'] = $defaults['title'];
}
if (!array_key_exists('guidHash', $defaults)) {
- $this->setGuidHash($this->getGuid());
+ $defaults['guidHash'] = $defaults['guid'];
}
$this->generateSearchIndex();
+
+ $this->fillDefaults($defaults);
}
}
diff --git a/tests/integration/integrationtest.php b/tests/integration/integrationtest.php
index 08f146fdd..50c172705 100644
--- a/tests/integration/integrationtest.php
+++ b/tests/integration/integrationtest.php
@@ -64,18 +64,24 @@ abstract class IntegrationTest extends PHPUnit_Framework_TestCase {
protected function findItemByTitle($title) {
// db logic in app code, negligible since its a test
- $items = $this->itemMapper->where();
+ $items = $this->itemMapper->where(['title' => $title]);
$feeds = $this->feedMapper->where(['userId' => $this->user]);
- $feedIds = array_map(function (Feed $feed) {
- return $feed->getId();
- }, $feeds);
+ $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);
+ });
- return array_filter($items, function (Item $item) use ($title, $feedIds) {
- return $item->getTitle() === $title &&
- in_array($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];
- })[0];
+ return $result;
}
protected function findFolderByName($name) {
@@ -96,7 +102,7 @@ abstract class IntegrationTest extends PHPUnit_Framework_TestCase {
* @param string $name loads fixtures from a given file
*/
protected function loadFixtures($name) {
- $fixtures = include __DIR__ . '/data/' . $name . '.php';
+ $fixtures = include __DIR__ . '/fixtures/data/' . $name . '.php';
if (array_key_exists('folders', $fixtures)) {
$this->loadFolderFixtures($fixtures['folders']);
}
@@ -116,6 +122,7 @@ abstract class IntegrationTest extends PHPUnit_Framework_TestCase {
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);
}
@@ -124,6 +131,7 @@ abstract class IntegrationTest extends PHPUnit_Framework_TestCase {
protected function loadItemFixtures(array $itemFixtures=[], $feedId) {
foreach ($itemFixtures as $itemFixture) {
$item = new ItemFixture($itemFixture);
+ $item->setFeedId($feedId);
$this->loadFixture($item);
}
}
ass="w"> : "Maximum number of seconds to wait for an RSS or Atom feed to load; if it takes longer the update will be aborted", "Explore Service URL" : "Explore Service URL", "If given, this service's URL will be queried for displaying the feeds in the explore feed section. To fall back to the built in explore service, leave this input empty" : "If given, this service's URL will be queried for displaying the feeds in the explore feed section. To fall back to the built-in explore service, leave this input empty", "Saved" : "Saved", "Ajax cron mode detected! Your feeds will not be updated correctly. It is recommended to either use the operating system cron or a custom updater." : "Ajax cron mode detected! Your feeds will not be updated correctly. It is recommended to either use the operating system cron or a custom updater.", "How to set up the operating system cron" : "How to set up the operating system cron", "How to set up a custom updater (faster and no possible deadlock) " : "How to set up a custom updater (faster and no possible deadlock) ", "Subscribe" : "Subscribe", "Refresh" : "Refresh", "No articles available" : "No articles available", "No unread articles available" : "No unread articles available", "Open website" : "Open website", "Star article" : "Star article", "Unstar article" : "Unstar article", "Keep article unread" : "Keep article unread", "Remove keep article unread" : "Remove keep article unread", "by" : "by", "from" : "from", "Browser can not play media type" : "Browser cannot play media type", "Download" : "Download", "Keyboard shortcut" : "Keyboard shortcut", "Description" : "Description", "right" : "right", "Jump to next article" : "Jump to next article", "left" : "left", "Jump to previous article" : "Jump to previous article", "Toggle star article" : "Toggle star article", "Star article and jump to next one" : "Star article and jump to next one", "Toggle keep current article unread" : "Toggle keep current article unread", "Open article in new tab" : "Open article in new tab", "Toggle expand article in compact view" : "Toggle expand article in compact view", "Load next feed" : "Load next feed", "Load previous feed" : "Load previous feed", "Load next folder" : "Load next folder", "Load previous folder" : "Load previous folder", "Scroll to active navigation entry" : "Scroll to active navigation entry", "Web address" : "Web address", "Feed exists already!" : "Feed exists already!", "Folder" : "Folder", "No folder" : "No folder", "New folder" : "New folder", "Folder name" : "Folder name", "Go back" : "Go back", "Folder exists already!" : "Folder exists already!", "New Folder" : "New Folder", "Create" : "Create", "Explore" : "Explore", "Deleted feed" : "Deleted feed", "Undo delete feed" : "Undo delete feed", "Rename" : "Rename", "Menu" : "Menu", "No feed ordering" : "No feed ordering", "Reversed feed ordering" : "Reversed feed ordering", "Normal feed ordering" : "Normal feed ordering", "Rename feed" : "Rename feed", "Delete feed" : "Delete feed", "Mark all articles read" : "Mark all articles read", "Dismiss" : "Dismiss", "Collapse" : "Collapse", "Deleted folder" : "Deleted folder", "Undo delete folder" : "Undo delete folder", "Rename folder" : "Rename folder", "Delete folder" : "Delete folder", "Starred" : "Starred", "Unread articles" : "Unread articles", "All articles" : "All articles", "Settings" : "Settings", "Keyboard shortcuts" : "Keyboard shortcuts", "Compact view" : "Compact view", "Expand articles in compact view when navigating with keyboard shortcuts" : "Expand articles in compact view when navigating with keyboard shortcuts", "Show all articles" : "Show all articles", "Reverse ordering (oldest on top)" : "Reverse ordering (oldest on top)", "Disable mark read through scrolling" : "Disable mark read through scrolling", "Subscriptions (OPML)" : "Subscriptions (OPML)", "Import" : "Import", "Export" : "Export", "Error when importing: file does not contain valid OPML" : "Error when importing: file does not contain valid OPML", "Unread/Starred Articles" : "Unread/Starred Articles", "Error when importing: file does not contain valid JSON" : "Error when importing: file does not contain valid JSON" },"pluralForm" :"nplurals=2; plural=(n != 1);" }