miniflux-legacy/tests/functional/BaseApiTest.php

51 lines
1.8 KiB
PHP
Raw Permalink Normal View History

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 (DB_DRIVER === 'mysql') {
$pdo = new PDO('mysql:host='.DB_HOSTNAME, DB_USERNAME, DB_PASSWORD);
$stmt = $pdo->query("SELECT information_schema.processlist.id FROM information_schema.processlist WHERE information_schema.processlist.DB = '".DB_NAME."' AND id <> connection_id()");
2017-01-12 02:08:39 +01:00
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$pdo->exec('KILL '.$row['id']);
}
$pdo->exec('DROP DATABASE '.DB_NAME);
$pdo->exec('CREATE DATABASE '.DB_NAME);
$pdo = null;
2016-12-30 00:04:56 +01:00
} 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
}