2019-05-22 15:38:19 +02:00
|
|
|
<?php
|
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
use GuzzleHttp\Exception\GuzzleException;
|
|
|
|
|
2019-05-22 15:38:19 +02:00
|
|
|
require_once(__DIR__ . "/../lib/UloggerAPITestCase.php");
|
|
|
|
|
|
|
|
class SetupTest extends UloggerAPITestCase {
|
|
|
|
private $script = "/scripts/setup.php";
|
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
/**
|
|
|
|
* @throws GuzzleException
|
|
|
|
*/
|
|
|
|
public function testPrePhase(): void {
|
2019-05-22 15:38:19 +02:00
|
|
|
$response = $this->http->get($this->script);
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
|
2019-05-22 15:38:19 +02:00
|
|
|
$body = (string) $response->getBody();
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertStringContainsString("<input type=\"hidden\" name=\"command\" value=\"setup\">", $body);
|
2019-05-22 15:38:19 +02:00
|
|
|
}
|
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
/**
|
|
|
|
* @throws GuzzleException
|
|
|
|
*/
|
|
|
|
public function testSetupPhase(): void {
|
2019-05-22 15:38:19 +02:00
|
|
|
$options = [
|
|
|
|
"http_errors" => false,
|
|
|
|
"form_params" => [ "command" => "setup" ]
|
|
|
|
];
|
|
|
|
$response = $this->http->post($this->script, $options);
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
|
2019-05-22 15:38:19 +02:00
|
|
|
$body = (string) $response->getBody();
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertStringContainsString("<input type=\"hidden\" name=\"command\" value=\"adduser\">", $body);
|
2019-05-22 15:38:19 +02:00
|
|
|
}
|
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
/**
|
|
|
|
* @throws GuzzleException
|
|
|
|
*/
|
|
|
|
public function testAdduserPhase(): void {
|
2019-05-22 15:38:19 +02:00
|
|
|
$options = [
|
|
|
|
"http_errors" => false,
|
|
|
|
"form_params" => [
|
|
|
|
"command" => "adduser",
|
|
|
|
"login" => $this->testUser,
|
|
|
|
"pass" => $this->testPass,
|
|
|
|
"pass2" => $this->testPass
|
|
|
|
]
|
|
|
|
];
|
|
|
|
$response = $this->http->post($this->script, $options);
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
|
2019-05-22 15:38:19 +02:00
|
|
|
$body = (string) $response->getBody();
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertStringContainsString("<span class=\"ok\">", $body);
|
|
|
|
self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count");
|
2020-02-19 18:42:44 +01:00
|
|
|
$expected = [ "id" => 2, "login" => $this->testUser, "admin" => 1 ];
|
|
|
|
$actual = $this->getConnection()->createQueryTable("users", "SELECT id, login, admin FROM users WHERE id = 2");
|
2019-05-22 15:38:19 +02:00
|
|
|
$this->assertTableContains($expected, $actual, "Wrong actual table data");
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertTrue(password_verify($this->testPass, $this->pdoGetColumn("SELECT password FROM users WHERE id = 2")), "Wrong actual password hash");
|
2019-05-22 15:38:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|