2016-08-18 03:06:43 +02:00
|
|
|
<?php
|
|
|
|
|
2016-12-26 15:44:53 +01:00
|
|
|
use Miniflux\Model;
|
|
|
|
use Miniflux\Session\SessionStorage;
|
|
|
|
use PicoDb\Database;
|
|
|
|
use PicoFeed\Parser\Feed;
|
|
|
|
use PicoFeed\Parser\Item;
|
|
|
|
|
|
|
|
require_once __DIR__.'/../../app/common.php';
|
2016-08-18 03:06:43 +02:00
|
|
|
|
|
|
|
abstract class BaseTest extends PHPUnit_Framework_TestCase
|
|
|
|
{
|
2016-08-18 04:05:11 +02:00
|
|
|
public function setUp()
|
|
|
|
{
|
2016-12-26 21:07:18 +01:00
|
|
|
if (DB_DRIVER === 'postgres') {
|
|
|
|
$pdo = new PDO('pgsql:host='.DB_HOSTNAME, DB_USERNAME, DB_PASSWORD);
|
|
|
|
$pdo->exec('DROP DATABASE '.DB_NAME);
|
|
|
|
$pdo->exec('CREATE DATABASE '.DB_NAME.' WITH OWNER '.DB_USERNAME);
|
|
|
|
$pdo = null;
|
|
|
|
}
|
2016-12-26 15:44:53 +01:00
|
|
|
|
|
|
|
PicoDb\Database::setInstance('db', function () {
|
2016-12-26 21:07:18 +01:00
|
|
|
return Miniflux\Database\get_connection();
|
2016-12-26 15:44:53 +01:00
|
|
|
});
|
2016-12-26 21:07:18 +01:00
|
|
|
|
|
|
|
SessionStorage::getInstance()->flush();
|
2016-12-26 15:44:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function tearDown()
|
|
|
|
{
|
|
|
|
Database::getInstance('db')->closeConnection();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildItem($itemId)
|
|
|
|
{
|
|
|
|
$item = new Item();
|
|
|
|
$item->setId($itemId);
|
|
|
|
$item->setTitle('Item #1');
|
|
|
|
$item->setUrl('some url');
|
|
|
|
$item->setContent('some content');
|
|
|
|
$item->setDate(new DateTime());
|
|
|
|
return $item;
|
|
|
|
}
|
|
|
|
|
2016-12-26 22:54:44 +01:00
|
|
|
public function buildFeed($feedUrl = 'feed url')
|
2016-12-26 15:44:53 +01:00
|
|
|
{
|
|
|
|
$items = array();
|
|
|
|
|
|
|
|
$item = new Item();
|
|
|
|
$item->setId('ID 1');
|
|
|
|
$item->setTitle('Item #1');
|
|
|
|
$item->setUrl('some url');
|
|
|
|
$item->setContent('some content');
|
|
|
|
$item->setDate(new DateTime());
|
|
|
|
$items[] = $item;
|
|
|
|
|
|
|
|
$item = new Item();
|
|
|
|
$item->setId('ID 2');
|
|
|
|
$item->setTitle('Item #2');
|
|
|
|
$item->setUrl('some url');
|
|
|
|
$item->setDate(new DateTime());
|
|
|
|
$items[] = $item;
|
|
|
|
|
|
|
|
$feed = new Feed();
|
|
|
|
$feed->setTitle('My feed');
|
2016-12-26 22:54:44 +01:00
|
|
|
$feed->setFeedUrl($feedUrl);
|
2016-12-26 15:44:53 +01:00
|
|
|
$feed->setSiteUrl('site url');
|
|
|
|
$feed->setItems($items);
|
|
|
|
|
|
|
|
return $feed;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function assertCreateFeed(Feed $feed)
|
|
|
|
{
|
2016-12-26 22:54:44 +01:00
|
|
|
$this->assertNotFalse(Model\Feed\create(1, $feed, 'etag', 'last modified'));
|
2016-08-18 04:05:11 +02:00
|
|
|
}
|
2016-08-18 03:06:43 +02:00
|
|
|
}
|