2016-12-29 21:45:09 +01:00
< ? php
2016-12-30 00:04:56 +01:00
use JsonRPC\Client ;
2016-12-29 21:45:09 +01:00
require_once __DIR__ . '/../../app/common.php' ;
abstract class BaseApiTest extends PHPUnit_Framework_TestCase
{
protected $adminUser = array ();
2016-12-30 00:04:56 +01:00
public static function setUpBeforeClass ()
2016-12-29 21:45:09 +01:00
{
if ( DB_DRIVER === 'postgres' ) {
$pdo = new PDO ( 'pgsql:host=' . DB_HOSTNAME , DB_USERNAME , DB_PASSWORD );
2016-12-30 00:04:56 +01:00
$pdo -> exec ( " SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = ' " . DB_NAME . " ' AND pid <> pg_backend_pid() " );
$pdo -> exec ( 'DROP DATABASE ' . DB_NAME );
2016-12-29 21:45:09 +01:00
$pdo -> exec ( 'CREATE DATABASE ' . DB_NAME . ' WITH OWNER ' . DB_USERNAME );
2016-12-30 00:04:56 +01:00
$pdo = null ;
} else if ( file_exists ( DB_FILENAME )) {
unlink ( DB_FILENAME );
2016-12-29 21:45:09 +01:00
}
2016-12-30 00:04:56 +01:00
}
2016-12-29 21:45:09 +01:00
2016-12-30 00:04:56 +01:00
public function setUp ()
{
2016-12-29 21:45:09 +01:00
$db = Miniflux\Database\get_connection ();
$this -> adminUser = $db -> table ( Miniflux\Model\User\TABLE ) -> eq ( 'username' , 'admin' ) -> findOne ();
}
2016-12-30 00:04:56 +01:00
protected function getApiClient ( array $user = array ())
{
if ( empty ( $user )) {
$user = $this -> adminUser ;
}
$apiUserClient = new Client ( API_URL );
$apiUserClient -> authentication ( $user [ 'username' ], $user [ 'api_token' ]);
return $apiUserClient ;
}
2016-12-29 21:45:09 +01:00
}