ulogger-server/.tests/lib/UloggerAPITestCase.php

57 lines
1.4 KiB
PHP
Raw Normal View History

2017-09-05 09:36:10 +02:00
<?php
use PHPUnit\Framework\TestCase;
require_once("BaseDatabaseTestCase.php");
class UloggerAPITestCase extends BaseDatabaseTestCase {
2019-05-15 12:03:55 +02:00
/**
* @var null|GuzzleHttp\Client $http
*/
2017-09-05 09:36:10 +02:00
protected $http = null;
public function setUp() {
parent::setUp();
if (file_exists(__DIR__ . '/../.env')) {
2019-02-28 11:03:41 +01:00
$dotenv = Dotenv\Dotenv::create(__DIR__ . '/..');
2017-09-05 09:36:10 +02:00
$dotenv->load();
$dotenv->required(['ULOGGER_URL']);
}
$url = getenv('ULOGGER_URL');
$this->http = new GuzzleHttp\Client([ 'base_uri' => $url, 'cookies' => true ]);
}
public function tearDown() {
parent::tearDown();
$this->http = null;
}
protected function getDataSet() {
2019-01-28 23:03:03 +01:00
$this->resetAutoincrement(2);
return $this->createFlatXMLDataSet(__DIR__ . '/../fixtures/fixture_admin.xml');
2017-09-05 09:36:10 +02:00
}
/**
* Authenticate on server
2019-05-23 10:58:57 +02:00
* @param string|null $user Login (defaults to test user)
* @param string|null $pass Optional password (defaults to test password)
2017-09-05 09:36:10 +02:00
* @return bool true on success, false otherwise
*/
public function authenticate($user = NULL, $pass = NULL) {
if (is_null($user)) { $user = $this->testAdminUser; }
if (is_null($pass)) { $pass = $this->testAdminPass; }
$options = [
'http_errors' => false,
'form_params' => [ 'action' => 'auth', 'user' => $user, 'pass' => $pass ],
];
$response = $this->http->post('/client/index.php', $options);
return ($response->getStatusCode() == 200);
}
}
?>