2017-09-05 09:36:10 +02:00
|
|
|
<?php
|
2021-04-22 19:47:52 +02:00
|
|
|
|
|
|
|
use GuzzleHttp\Exception\GuzzleException;
|
|
|
|
use PHPUnit\DbUnit\DataSet\IDataSet;
|
2017-09-05 09:36:10 +02:00
|
|
|
|
|
|
|
require_once("BaseDatabaseTestCase.php");
|
|
|
|
|
|
|
|
class UloggerAPITestCase extends BaseDatabaseTestCase {
|
|
|
|
|
2019-05-15 12:03:55 +02:00
|
|
|
/**
|
|
|
|
* @var null|GuzzleHttp\Client $http
|
|
|
|
*/
|
2021-04-22 19:47:52 +02:00
|
|
|
protected $http;
|
2017-09-05 09:36:10 +02:00
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
public function setUp(): void {
|
2017-09-05 09:36:10 +02:00
|
|
|
parent::setUp();
|
|
|
|
if (file_exists(__DIR__ . '/../.env')) {
|
2021-04-22 21:44:03 +02:00
|
|
|
$dotenv = Dotenv\Dotenv::createUnsafeImmutable(__DIR__ . '/..');
|
2017-09-05 09:36:10 +02:00
|
|
|
$dotenv->load();
|
|
|
|
$dotenv->required(['ULOGGER_URL']);
|
|
|
|
}
|
|
|
|
|
2021-04-22 21:44:03 +02:00
|
|
|
$url = getenv('ULOGGER_URL');
|
2017-09-05 09:36:10 +02:00
|
|
|
|
|
|
|
$this->http = new GuzzleHttp\Client([ 'base_uri' => $url, 'cookies' => true ]);
|
|
|
|
}
|
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
public function tearDown(): void {
|
2017-09-05 09:36:10 +02:00
|
|
|
parent::tearDown();
|
|
|
|
$this->http = null;
|
|
|
|
}
|
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
protected function getDataSet(): IDataSet {
|
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
|
2021-04-22 19:47:52 +02:00
|
|
|
* @throws GuzzleException
|
2017-09-05 09:36:10 +02:00
|
|
|
*/
|
2021-04-22 19:47:52 +02:00
|
|
|
public function authenticate(?string $user = null, ?string $pass = null): bool {
|
2017-09-05 09:36:10 +02:00
|
|
|
|
|
|
|
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);
|
2021-04-22 19:47:52 +02:00
|
|
|
return $response->getStatusCode() === 200;
|
2017-09-05 09:36:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|