miniflux-legacy/tests/unit/FeedModelTest.php
Frederic Guillot 82df35a59b Change the database structure to have a single database
This is a major change for the next release of Miniflux.

- There is now only one database that can supports multiple users
- There is no automated schema migration for this release
- A migration procedure is available in the ChangeLog file
2016-12-26 09:51:38 -05:00

163 lines
5.4 KiB
PHP

<?php
use Miniflux\Model;
use PicoFeed\Parser\Feed;
use PicoFeed\Parser\Item;
require_once __DIR__.'/BaseTest.php';
class FeedModelTest extends BaseTest
{
public function testCreate()
{
$feed = new Feed();
$feed->setTitle('My feed');
$feed->setFeedUrl('feed url');
$feed->setSiteUrl('site url');
$this->assertEquals(1, Model\Feed\create(1, $feed, 'etag', 'last modified'));
$this->assertEquals(-1, Model\Feed\create(1, $feed, 'etag', 'last modified'));
$subscription = Model\Feed\get_feed(1, 1);
$this->assertNotEmpty($subscription);
$this->assertEquals('1', $subscription['user_id']);
$this->assertEquals('My feed', $subscription['title']);
$this->assertEquals('site url', $subscription['site_url']);
$this->assertEquals('feed url', $subscription['feed_url']);
$this->assertEquals('etag', $subscription['etag']);
$this->assertEquals('last modified', $subscription['last_modified']);
$this->assertEquals('0', $subscription['download_content']);
$this->assertEquals('0', $subscription['rtl']);
$this->assertEquals('0', $subscription['cloak_referrer']);
$this->assertEquals('1', $subscription['enabled']);
}
public function testGetAll()
{
$feed = new Feed();
$feed->setTitle('My feed');
$feed->setFeedUrl('feed url');
$feed->setSiteUrl('site url');
$this->assertEquals(1, Model\Feed\create(1, $feed, 'etag', 'last modified'));
$feed = new Feed();
$feed->setTitle('Some feed');
$feed->setFeedUrl('another feed url');
$feed->setSiteUrl('site url');
$this->assertEquals(2, Model\Feed\create(1, $feed, 'etag', 'last modified'));
$feeds = Model\Feed\get_feeds(1);
$this->assertCount(2, $feeds);
}
public function testGetFeedIds()
{
$feed = new Feed();
$feed->setTitle('My feed');
$feed->setFeedUrl('feed url');
$feed->setSiteUrl('site url');
$this->assertEquals(1, Model\Feed\create(1, $feed, 'etag', 'last modified'));
$feed = new Feed();
$feed->setTitle('Some feed');
$feed->setFeedUrl('another feed url');
$feed->setSiteUrl('site url');
$this->assertEquals(2, Model\Feed\create(1, $feed, 'etag', 'last modified'));
$feed_ids = Model\Feed\get_feed_ids(1);
$this->assertEquals(array(1, 2), $feed_ids);
$feed_ids = Model\Feed\get_feed_ids(1, 1);
$this->assertEquals(array(1), $feed_ids);
}
public function testGetFeedWithItemsCount()
{
$item = new Item();
$item->setId('ID 1');
$item->setTitle('Item #1');
$item->setUrl('some url');
$item->setDate(new DateTime());
$feed = new Feed();
$feed->setTitle('My feed');
$feed->setFeedUrl('feed url');
$feed->setSiteUrl('site url');
$feed->setItems(array($item));
$this->assertEquals(1, Model\Feed\create(1, $feed, 'etag', 'last modified'));
$feed = new Feed();
$feed->setTitle('Some feed');
$feed->setFeedUrl('another feed url');
$feed->setSiteUrl('site url');
$this->assertEquals(2, Model\Feed\create(1, $feed, 'etag', 'last modified'));
$feeds = Model\Feed\get_feeds_with_items_count(1);
$this->assertCount(2, $feeds);
$this->assertEquals(1, $feeds[0]['items_unread']);
$this->assertEquals(1, $feeds[0]['items_total']);
$this->assertEquals(0, $feeds[1]['items_unread']);
$this->assertEquals(0, $feeds[1]['items_total']);
}
public function testUpdate()
{
$feed = new Feed();
$feed->setTitle('My feed');
$feed->setFeedUrl('feed url');
$feed->setSiteUrl('site url');
$this->assertEquals(1, Model\Feed\create(1, $feed, 'etag', 'last modified'));
$this->assertTrue(Model\Feed\update_feed(1, 1, array('title' => 'new title')));
$subscription = Model\Feed\get_feed(1, 1);
$this->assertNotEmpty($subscription);
$this->assertEquals('1', $subscription['user_id']);
$this->assertEquals('new title', $subscription['title']);
}
public function testChangeStatus()
{
$feed = new Feed();
$feed->setTitle('My feed');
$feed->setFeedUrl('feed url');
$feed->setSiteUrl('site url');
$this->assertEquals(1, Model\Feed\create(1, $feed, 'etag', 'last modified'));
$this->assertTrue(Model\Feed\change_feed_status(1, 1, Model\Feed\STATUS_INACTIVE));
$subscription = Model\Feed\get_feed(1, 1);
$this->assertEquals(0, $subscription['enabled']);
}
public function testRemoveFeed()
{
$feed = new Feed();
$feed->setTitle('My feed');
$feed->setFeedUrl('feed url');
$feed->setSiteUrl('site url');
$this->assertEquals(1, Model\Feed\create(1, $feed, 'etag', 'last modified'));
$this->assertTrue(Model\Feed\remove_feed(1, 1));
$this->assertNull(Model\Feed\get_feed(1, 1));
}
public function testPeopleCanHaveSameFeed()
{
$feed = new Feed();
$feed->setTitle('My feed');
$feed->setFeedUrl('feed url');
$feed->setSiteUrl('site url');
$this->assertEquals(2, Model\User\create_user('foobar', 'test'));
$this->assertEquals(1, Model\Feed\create(1, $feed, 'etag', 'last modified'));
$this->assertEquals(2, Model\Feed\create(2, $feed, 'etag', 'last modified'));
}
}