Update PHP test dependencies

This commit is contained in:
Bartek Fabiszewski 2021-04-22 19:47:52 +02:00
parent 9f139c70f4
commit 72e89edd4d
21 changed files with 3008 additions and 1197 deletions

View File

@ -1,16 +1,19 @@
<?php
use PHPUnit\DbUnit\Database\Connection;
use PHPUnit\DbUnit\DataSet\IDataSet;
if (!defined("ROOT_DIR")) { define("ROOT_DIR", __DIR__ . "/../.."); }
require_once(__DIR__ . "/../../helpers/config.php");
abstract class BaseDatabaseTestCase extends PHPUnit_Extensions_Database_TestCase {
abstract class BaseDatabaseTestCase extends PHPUnit\DbUnit\TestCase {
/**
* @var PDO $pdo
*/
static private $pdo;
/**
* @var PHPUnit_Extensions_Database_DB_IDatabaseConnection $conn
* @var PHPUnit\DbUnit\Database\Connection $conn
*/
private $conn;
static private $driver = "mysql";
@ -42,24 +45,24 @@ abstract class BaseDatabaseTestCase extends PHPUnit_Extensions_Database_TestCase
// Fixes PostgreSQL: "cannot truncate a table referenced in a foreign key constraint"
protected function getSetUpOperation() {
return PHPUnit_Extensions_Database_Operation_Factory::CLEAN_INSERT(TRUE);
return PHPUnit\DbUnit\Operation\Factory::CLEAN_INSERT(true);
}
public function setUp() {
public function setUp(): void {
parent::setUp();
$this->mockConfig = new uConfig(false);
}
public static function setUpBeforeClass() {
public static function setUpBeforeClass(): void {
if (file_exists(__DIR__ . '/../.env')) {
$dotenv = Dotenv\Dotenv::create(__DIR__ . '/..');
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . '/..');
$dotenv->load();
$dotenv->required(['DB_DSN', 'DB_USER', 'DB_PASS']);
}
$db_dsn = getenv('DB_DSN');
$db_user = getenv('DB_USER');
$db_pass = getenv('DB_PASS');
$db_dsn = $_ENV['DB_DSN'];
$db_user = $_ENV['DB_USER'];
$db_pass = $_ENV['DB_PASS'];
// pdo connection
if (self::$pdo == null) {
@ -68,7 +71,7 @@ abstract class BaseDatabaseTestCase extends PHPUnit_Extensions_Database_TestCase
}
}
public static function tearDownAfterClass() {
public static function tearDownAfterClass(): void {
self::$pdo = null;
}
@ -76,9 +79,9 @@ abstract class BaseDatabaseTestCase extends PHPUnit_Extensions_Database_TestCase
* Set up database connection
* This will also override uDb class connection
*
* @return PHPUnit_Extensions_Database_DB_IDatabaseConnection
* @return Connection
*/
public function getConnection() {
public function getConnection(): Connection {
if ($this->conn === null) {
$this->conn = $this->createDefaultDBConnection(self::$pdo, getenv('DB_NAME'));
}
@ -88,14 +91,14 @@ abstract class BaseDatabaseTestCase extends PHPUnit_Extensions_Database_TestCase
/**
* Create data set from xml fixture
*
* @return PHPUnit_Extensions_Database_DataSet_IDataSet
* @return PHPUnit\DbUnit\DataSet\IDataSet
*/
protected function getDataSet() {
protected function getDataSet(): IDataSet {
$this->resetAutoincrement();
return $this->createFlatXMLDataSet(__DIR__ . '/../fixtures/fixture_empty.xml');
}
protected function resetAutoincrement($users = 1, $tracks = 1, $positions = 1, $layers = 1) {
protected function resetAutoincrement($users = 1, $tracks = 1, $positions = 1, $layers = 1): void {
if (self::$driver === "pgsql") {
self::$pdo->exec("ALTER SEQUENCE IF EXISTS users_id_seq RESTART WITH $users");
self::$pdo->exec("ALTER SEQUENCE IF EXISTS tracks_id_seq RESTART WITH $tracks");
@ -125,7 +128,7 @@ abstract class BaseDatabaseTestCase extends PHPUnit_Extensions_Database_TestCase
* Reset connection
* Fixes sqlite error when db schema changes in another connection.
*/
protected function resetConnection() {
protected function resetConnection(): void {
$this->closeConnection($this->conn);
$this->conn = null;
self::tearDownAfterClass();
@ -139,7 +142,7 @@ abstract class BaseDatabaseTestCase extends PHPUnit_Extensions_Database_TestCase
* @param array $rowsArr Array of rows
* @return int|null Last insert id if available, NULL otherwise
*/
private function pdoInsert($table, $rowsArr = []) {
private function pdoInsert(string $table, array $rowsArr = []): ?int {
$ret = NULL;
if (!empty($rowsArr)) {
$values = ':' . implode(', :', array_keys($rowsArr));
@ -160,8 +163,8 @@ abstract class BaseDatabaseTestCase extends PHPUnit_Extensions_Database_TestCase
* @param string $query Insert query
* @return int|null Last insert id if available, NULL otherwise
*/
private function pdoInsertRaw($query) {
$ret = NULL;
private function pdoInsertRaw(string $query): ?int {
$ret = null;
if (self::$pdo->exec($query) !== false) {
$ret = self::$pdo->lastInsertId();
}
@ -175,7 +178,7 @@ abstract class BaseDatabaseTestCase extends PHPUnit_Extensions_Database_TestCase
* @param int $columnNumber Optional column number (default is first column)
* @return string|bool Column or false if no data
*/
protected function pdoGetColumn($query, $columnNumber = 0) {
protected function pdoGetColumn(string $query, int $columnNumber = 0) {
$column = false;
$stmt = self::$pdo->query($query);
if ($stmt !== false) {
@ -189,12 +192,12 @@ abstract class BaseDatabaseTestCase extends PHPUnit_Extensions_Database_TestCase
* Insert user data to database
* If parameters are omitted they default test values are used
*
* @param string $user User login
* @param string $pass User password
* @param string|null $user User login
* @param string|null $pass User password
* @param bool $isAdmin User is admin
* @return int|bool User id or false on error
*/
protected function addTestUser($user = NULL, $pass = NULL, $isAdmin = false) {
protected function addTestUser(?string $user = null, ?string $pass = null, bool $isAdmin = false) {
if (is_null($user)) { $user = $this->testUser; }
if (is_null($pass)) { $pass = $this->testPass; }
$id = $this->pdoInsert('users', [ 'login' => $user, 'password' => $pass, 'admin' => (int) $isAdmin ]);
@ -208,12 +211,12 @@ abstract class BaseDatabaseTestCase extends PHPUnit_Extensions_Database_TestCase
* Insert track data to database.
* If parameters are omitted they default test values are used
*
* @param int $userId Optional track id
* @param string $trackName Optional track name
* @param string $comment Optional comment
* @param int|null $userId Optional track id
* @param string|null $trackName Optional track name
* @param string|null $comment Optional comment
* @return int|bool Track id or false on error
*/
protected function addTestTrack($userId = NULL, $trackName = NULL, $comment = NULL) {
protected function addTestTrack(?int $userId = null, ?string $trackName = null, ?string $comment = null) {
if (is_null($userId)) { $userId = $this->testUserId; }
if (is_null($trackName)) { $trackName = $this->testTrackName; }
if (is_null($comment)) { $comment = $this->testTrackComment; }
@ -228,14 +231,14 @@ abstract class BaseDatabaseTestCase extends PHPUnit_Extensions_Database_TestCase
* Insert position data to database
* If parameters are omitted they default test values are used
*
* @param int $userId
* @param int $trackId
* @param int $timeStamp
* @param double $latitude
* @param double $longitude
* @return int|bool Position id or false on error
* @param int|null $userId
* @param int|null $trackId
* @param int|null $timeStamp
* @param float|null $latitude
* @param float|null $longitude
* @return int|null Position id or false on error
*/
protected function addTestPosition($userId = NULL, $trackId = NULL, $timeStamp = NULL, $latitude = NULL, $longitude = NULL) {
protected function addTestPosition(?int $userId = null, ?int $trackId = null, ?int $timeStamp = null, ?float $latitude = null, ?float $longitude = null): ?int {
if (is_null($userId)) { $userId = $this->testUserId; }
if (is_null($trackId)) { $trackId = $this->testTrackId; }
if (is_null($timeStamp)) { $timeStamp = $this->testTimestamp; }
@ -247,33 +250,27 @@ abstract class BaseDatabaseTestCase extends PHPUnit_Extensions_Database_TestCase
return $this->pdoInsertRaw($query);
}
public function unix_timestamp($column) {
public function unix_timestamp(string $column): string {
switch (self::$driver) {
default:
case "mysql":
return "UNIX_TIMESTAMP($column)";
break;
case "pgsql":
return "EXTRACT(EPOCH FROM $column)";
break;
case "sqlite":
return "STRFTIME('%s', $column)";
break;
}
}
public function from_unixtime($column) {
public function from_unixtime(string $column): string {
switch (self::$driver) {
default:
case "mysql":
return "FROM_UNIXTIME($column)";
break;
case "pgsql":
return "TO_TIMESTAMP($column)";
break;
case "sqlite":
return "DATETIME($column, 'unixepoch')";
break;
}
}
}

View File

@ -1,5 +1,7 @@
<?php
use PHPUnit\Framework\TestCase;
use GuzzleHttp\Exception\GuzzleException;
use PHPUnit\DbUnit\DataSet\IDataSet;
require_once("BaseDatabaseTestCase.php");
@ -8,27 +10,27 @@ class UloggerAPITestCase extends BaseDatabaseTestCase {
/**
* @var null|GuzzleHttp\Client $http
*/
protected $http = null;
protected $http;
public function setUp() {
public function setUp(): void {
parent::setUp();
if (file_exists(__DIR__ . '/../.env')) {
$dotenv = Dotenv\Dotenv::create(__DIR__ . '/..');
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . '/..');
$dotenv->load();
$dotenv->required(['ULOGGER_URL']);
}
$url = getenv('ULOGGER_URL');
$url = $_ENV['ULOGGER_URL'];
$this->http = new GuzzleHttp\Client([ 'base_uri' => $url, 'cookies' => true ]);
}
public function tearDown() {
public function tearDown(): void {
parent::tearDown();
$this->http = null;
}
protected function getDataSet() {
protected function getDataSet(): IDataSet {
$this->resetAutoincrement(2);
return $this->createFlatXMLDataSet(__DIR__ . '/../fixtures/fixture_admin.xml');
}
@ -38,8 +40,9 @@ class UloggerAPITestCase extends BaseDatabaseTestCase {
* @param string|null $user Login (defaults to test user)
* @param string|null $pass Optional password (defaults to test password)
* @return bool true on success, false otherwise
* @throws GuzzleException
*/
public function authenticate($user = NULL, $pass = NULL) {
public function authenticate(?string $user = null, ?string $pass = null): bool {
if (is_null($user)) { $user = $this->testAdminUser; }
if (is_null($pass)) { $pass = $this->testAdminPass; }
@ -50,7 +53,7 @@ class UloggerAPITestCase extends BaseDatabaseTestCase {
];
$response = $this->http->post('/client/index.php', $options);
return ($response->getStatusCode() == 200);
return $response->getStatusCode() === 200;
}
}
?>

View File

@ -13,29 +13,29 @@ class UloggerDatabaseTestCase extends BaseDatabaseTestCase {
/**
* @throws ReflectionException
*/
public static function setUpBeforeClass() {
public static function setUpBeforeClass(): void {
parent::setUpBeforeClass();
if (file_exists(__DIR__ . '/../.env')) {
$dotenv = Dotenv\Dotenv::create(__DIR__ . '/..');
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . '/..');
$dotenv->load();
$dotenv->required(['DB_DSN', 'DB_USER', 'DB_PASS']);
}
$db_dsn = getenv('DB_DSN');
$db_user = getenv('DB_USER');
$db_pass = getenv('DB_PASS');
$db_dsn = $_ENV['DB_DSN'];
$db_user = $_ENV['DB_USER'];
$db_pass = $_ENV['DB_PASS'];
// uDb connection
if (self::$udb == null) {
self::$udb = new ReflectionClass("uDb");
self::$udb = new ReflectionClass('uDb');
$dbInstance = self::$udb->getProperty('instance');
$dbInstance->setAccessible(true);
$dbInstance->setValue(new uDb($db_dsn, $db_user, $db_pass));
}
}
public static function tearDownAfterClass() {
public static function tearDownAfterClass(): void {
parent::tearDownAfterClass();
self::$udb = null;
}

View File

@ -1,23 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="../vendor/autoload.php">
<testsuites>
<testsuite name="µlogger test suite">
<directory suffix=".php">tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">..</directory>
<exclude>
<directory suffix=".php">../.tests</directory>
<directory suffix=".php">../vendor</directory>
</exclude>
</whitelist>
</filter>
<logging>
<log type="coverage-text" target="php://stdout" showUncoveredFiles="false"/>
</logging>
<php>
<server name='HTTP_HOST' value='http://127.0.0.1' />
</php>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="../vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">..</directory>
</include>
<exclude>
<directory suffix=".php">../.tests</directory>
<directory suffix=".php">../vendor</directory>
</exclude>
<report>
<text outputFile="php://stdout" showUncoveredFiles="false"/>
</report>
</coverage>
<testsuites>
<testsuite name="µlogger test suite">
<directory suffix=".php">tests</directory>
</testsuite>
</testsuites>
<logging/>
<php>
<server name="HTTP_HOST" value="http://127.0.0.1"/>
</php>
</phpunit>

View File

@ -6,7 +6,7 @@ require_once(__DIR__ . "/../../helpers/config.php");
class AuthTest extends UloggerDatabaseTestCase {
public function setUp() {
public function setUp(): void {
$_SESSION = [];
parent::setUp();
}
@ -14,85 +14,85 @@ class AuthTest extends UloggerDatabaseTestCase {
/**
* @runInSeparateProcess
*/
public function testLogin() {
public function testLogin(): void {
$this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
$this->assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count");
self::assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count");
$auth = new uAuth();
$auth->checkLogin($this->testUser, $this->testPass);
$this->assertTrue($auth->isAuthenticated(), "Not authenticated");
$this->assertInstanceOf(uUser::class, $auth->user, "User variable not set");
$this->assertEquals($this->testUser, $auth->user->login, "Wrong login");
$this->assertEquals($_SESSION["user"]->login, $auth->user->login, "Wrong login");
$this->assertInstanceOf(uUser::class, $_SESSION["user"], "User not set in session");
self::assertTrue($auth->isAuthenticated(), "Not authenticated");
self::assertInstanceOf(uUser::class, $auth->user, "User variable not set");
self::assertEquals($this->testUser, $auth->user->login, "Wrong login");
self::assertEquals($_SESSION["user"]->login, $auth->user->login, "Wrong login");
self::assertInstanceOf(uUser::class, $_SESSION["user"], "User not set in session");
}
/**
* @runInSeparateProcess
*/
public function testLoginBadPass() {
public function testLoginBadPass(): void {
$this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
$this->assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count");
self::assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count");
$auth = new uAuth();
$auth->checkLogin($this->testUser, "badPass");
$this->assertFalse($auth->isAuthenticated(), "Should not be authenticated");
$this->assertInternalType('null', $auth->user, "User not null");
self::assertFalse($auth->isAuthenticated(), "Should not be authenticated");
self::assertNull($auth->user, "User not null");
}
/**
* @runInSeparateProcess
*/
public function testLoginEmptyLogin() {
public function testLoginEmptyLogin(): void {
$this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
$this->assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count");
self::assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count");
$auth = new uAuth();
$auth->checkLogin("", $this->testPass);
$this->assertFalse($auth->isAuthenticated(), "Should not be authenticated");
$this->assertInternalType('null', $auth->user, "User not null");
self::assertFalse($auth->isAuthenticated(), "Should not be authenticated");
self::assertNull($auth->user, "User not null");
}
/**
* @runInSeparateProcess
*/
public function testLoginNoFormData() {
public function testLoginNoFormData(): void {
$this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
$this->assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count");
self::assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count");
$auth = new uAuth();
$this->assertFalse($auth->isAuthenticated(), "Should not be authenticated");
$this->assertInternalType('null', $auth->user, "User not null");
self::assertFalse($auth->isAuthenticated(), "Should not be authenticated");
self::assertNull($auth->user, "User not null");
}
/**
* @runInSeparateProcess
*/
public function testSessionAuth() {
public function testSessionAuth(): void {
$this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
$this->assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count");
self::assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count");
$user = new uUser($this->testUser);
$this->assertTrue($user->isValid, "User not valid");
self::assertTrue($user->isValid, "User not valid");
session_name("ulogger");
session_start();
$_SESSION["user"] = $user;
unset($user);
@$auth = new uAuth();
$this->assertTrue($auth->isAuthenticated(), "Should be authenticated");
$this->assertEquals($this->testUser, $auth->user->login, "Wrong login");
self::assertTrue($auth->isAuthenticated(), "Should be authenticated");
self::assertEquals($this->testUser, $auth->user->login, "Wrong login");
}
/**
* @runInSeparateProcess
*/
public function testSessionAndRequest() {
public function testSessionAndRequest(): void {
$this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
$this->assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count");
self::assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count");
$user = new uUser($this->testUser);
$this->assertTrue($user->isValid, "User not valid");
self::assertTrue($user->isValid, "User not valid");
session_name("ulogger");
session_start();
$_SESSION["user"] = $user;
@ -100,35 +100,35 @@ class AuthTest extends UloggerDatabaseTestCase {
@$auth = new uAuth();
$auth->checkLogin($this->testUser, $this->testPass);
$this->assertTrue($auth->isAuthenticated(), "Should be authenticated");
$this->assertEquals($this->testUser, $auth->user->login, "Wrong login");
self::assertTrue($auth->isAuthenticated(), "Should be authenticated");
self::assertEquals($this->testUser, $auth->user->login, "Wrong login");
}
/**
* @runInSeparateProcess
*/
public function testIsNotAdmin() {
public function testIsNotAdmin(): void {
$this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
$this->assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count");
self::assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count");
@$auth = new uAuth();
$auth->checkLogin($this->testUser, $this->testPass);
$this->assertTrue($auth->isAuthenticated(), "Should be authenticated");
$this->assertFalse($auth->isAdmin(), "Should not be admin");
self::assertTrue($auth->isAuthenticated(), "Should be authenticated");
self::assertFalse($auth->isAdmin(), "Should not be admin");
}
/**
* @runInSeparateProcess
*/
public function testIsAdmin() {
public function testIsAdmin(): void {
$this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT), true);
$this->assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count");
self::assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count");
@$auth = new uAuth();
$auth->checkLogin($this->testUser, $this->testPass);
$this->assertTrue($auth->isAuthenticated(), "Should be authenticated");
$this->assertTrue($auth->isAdmin(), "Should be admin");
self::assertTrue($auth->isAuthenticated(), "Should be authenticated");
self::assertTrue($auth->isAdmin(), "Should be admin");
}
}

View File

@ -1,215 +1,253 @@
<?php
use GuzzleHttp\Exception\GuzzleException;
require_once(__DIR__ . "/../lib/UloggerAPITestCase.php");
class ClientAPITest extends UloggerAPITestCase {
public function testNoAction() {
$this->assertTrue($this->authenticate(), "Authentication failed");
/**
* @throws GuzzleException
*/
public function testNoAction(): void {
self::assertTrue($this->authenticate(), "Authentication failed");
$options = [
'http_errors' => false
];
$response = $this->http->post('/client/index.php', $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
$json = json_decode((string) $response->getBody());
$this->assertTrue($json->{'error'}, "Unexpected success");
self::assertTrue($json->{'error'}, "Unexpected success");
}
/* auth */
public function testAuthOk() {
/**
* @throws GuzzleException
*/
public function testAuthOk(): void {
$options = [
'http_errors' => false,
'form_params' => [ 'action' => 'auth', 'user' => $this->testAdminUser, 'pass' => $this->testAdminPass ],
];
$response = $this->http->post('/client/index.php', $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
$json = json_decode((string) $response->getBody());
$this->assertFalse($json->{'error'}, "Unexpected error");
self::assertFalse($json->{'error'}, "Unexpected error");
}
public function testAuthFail() {
/**
* @throws GuzzleException
*/
public function testAuthFail(): void {
$options = [
'http_errors' => false,
'form_params' => [ 'action' => 'adduser', 'user' => 'noexist', 'pass' => 'noexist' ],
];
$response = $this->http->post('/client/index.php', $options);
$this->assertEquals(401, $response->getStatusCode(), "Unexpected status code");
self::assertEquals(401, $response->getStatusCode(), "Unexpected status code");
}
/* adduser */
public function testAddUser() {
$this->assertTrue($this->authenticate(), "Authentication failed");
$this->assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count");
/**
* @throws GuzzleException
*/
public function testAddUser(): void {
self::assertTrue($this->authenticate(), "Authentication failed");
self::assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count");
$options = [
'http_errors' => false,
'form_params' => [ 'action' => 'adduser', 'login' => $this->testUser, 'password' => $this->testPass ],
];
$response = $this->http->post('/client/index.php', $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
$json = json_decode((string) $response->getBody());
$this->assertFalse($json->{'error'}, "Unexpected error");
$this->assertEquals(2, $json->{'userid'}, "Wrong user id");
$this->assertEquals(2, $this->getConnection()->getRowCount('users'), "Wrong row count");
self::assertFalse($json->{'error'}, "Unexpected error");
self::assertEquals(2, $json->{'userid'}, "Wrong user id");
self::assertEquals(2, $this->getConnection()->getRowCount('users'), "Wrong row count");
$expected = [ "id" => 2, "login" => $this->testUser ];
$actual = $this->getConnection()->createQueryTable("users", "SELECT id, login FROM users");
$this->assertTableContains($expected, $actual, "Wrong actual table data");
}
public function testAddUserExistingLogin() {
$this->assertTrue($this->authenticate(), "Authentication failed");
/**
* @throws GuzzleException
*/
public function testAddUserExistingLogin(): void {
self::assertTrue($this->authenticate(), "Authentication failed");
$this->assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count");
self::assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count");
$options = [
'http_errors' => false,
'form_params' => [ 'action' => 'adduser', 'login' => $this->testAdminUser, 'password' => $this->testPass ],
];
$response = $this->http->post('/client/index.php', $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
$json = json_decode((string) $response->getBody());
$this->assertTrue($json->{'error'}, "Unexpected success");
$this->assertFalse(isset($json->{'userid'}), "Unexpected user id");
$this->assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count");
self::assertTrue($json->{'error'}, "Unexpected success");
self::assertFalse(isset($json->{'userid'}), "Unexpected user id");
self::assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count");
}
public function testAddUserEmptyLogin() {
$this->assertTrue($this->authenticate(), "Authentication failed");
/**
* @throws GuzzleException
*/
public function testAddUserEmptyLogin(): void {
self::assertTrue($this->authenticate(), "Authentication failed");
$this->assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count");
self::assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count");
$options = [
'http_errors' => false,
'form_params' => [ 'action' => 'adduser', 'login' => '', 'password' => $this->testPass ],
];
$response = $this->http->post('/client/index.php', $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
$json = json_decode((string) $response->getBody());
$this->assertTrue($json->{'error'}, "Unexpected success");
$this->assertFalse(isset($json->{'userid'}), "Unexpected user id");
$this->assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count");
self::assertTrue($json->{'error'}, "Unexpected success");
self::assertFalse(isset($json->{'userid'}), "Unexpected user id");
self::assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count");
}
public function testAddUserEmptyPass() {
$this->assertTrue($this->authenticate(), "Authentication failed");
/**
* @throws GuzzleException
*/
public function testAddUserEmptyPass(): void {
self::assertTrue($this->authenticate(), "Authentication failed");
$this->assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count");
self::assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count");
$options = [
'http_errors' => false,
'form_params' => [ 'action' => 'adduser', 'login' => $this->testUser, 'password' => '' ],
];
$response = $this->http->post('/client/index.php', $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
$json = json_decode((string) $response->getBody());
$this->assertTrue($json->{'error'}, "Unexpected success");
$this->assertFalse(isset($json->{'userid'}), "Unexpected user id");
$this->assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count");
self::assertTrue($json->{'error'}, "Unexpected success");
self::assertFalse(isset($json->{'userid'}), "Unexpected user id");
self::assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count");
}
public function testAddUserNoParameters() {
$this->assertTrue($this->authenticate(), "Authentication failed");
/**
* @throws GuzzleException
*/
public function testAddUserNoParameters(): void {
self::assertTrue($this->authenticate(), "Authentication failed");
$this->assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count");
self::assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count");
$options = [
'http_errors' => false,
'form_params' => [ 'action' => 'adduser' ],
];
$response = $this->http->post('/client/index.php', $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
$json = json_decode((string) $response->getBody());
$this->assertTrue($json->{'error'}, "Unexpected success");
$this->assertFalse(isset($json->{'userid'}), "Unexpected user id");
$this->assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count");
self::assertTrue($json->{'error'}, "Unexpected success");
self::assertFalse(isset($json->{'userid'}), "Unexpected user id");
self::assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count");
}
public function testAddUserByNonAdmin() {
/**
* @throws GuzzleException
*/
public function testAddUserByNonAdmin(): void {
$this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
$this->assertTrue($this->authenticate($this->testUser, $this->testPass), "Authentication failed");
self::assertTrue($this->authenticate($this->testUser, $this->testPass), "Authentication failed");
$this->assertEquals(2, $this->getConnection()->getRowCount('users'), "Wrong row count");
self::assertEquals(2, $this->getConnection()->getRowCount('users'), "Wrong row count");
$options = [
'http_errors' => false,
'form_params' => [ 'action' => 'adduser', 'login' => $this->testUser2, 'password' => $this->testPass ],
];
$response = $this->http->post('/client/index.php', $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
$json = json_decode((string) $response->getBody());
$this->assertTrue($json->{'error'}, "Unexpected success");
$this->assertFalse(isset($json->{'userid'}), "Unexpected user id");
$this->assertEquals(2, $this->getConnection()->getRowCount('users'), "Wrong row count");
self::assertTrue($json->{'error'}, "Unexpected success");
self::assertFalse(isset($json->{'userid'}), "Unexpected user id");
self::assertEquals(2, $this->getConnection()->getRowCount('users'), "Wrong row count");
}
/* addtrack */
/**
* @throws GuzzleException
*/
public function testAddTrack(): void {
self::assertTrue($this->authenticate(), "Authentication failed");
public function testAddTrack() {
$this->assertTrue($this->authenticate(), "Authentication failed");
$this->assertEquals(0, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
self::assertEquals(0, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
$options = [
'http_errors' => false,
'form_params' => [ 'action' => 'addtrack', 'track' => $this->testTrackName ],
];
$response = $this->http->post('/client/index.php', $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
$json = json_decode((string) $response->getBody());
$this->assertFalse($json->{'error'}, "Unexpected error");
$this->assertEquals(1, $json->{'trackid'}, "Wrong track id");
$this->assertEquals(1, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
self::assertFalse($json->{'error'}, "Unexpected error");
self::assertEquals(1, $json->{'trackid'}, "Wrong track id");
self::assertEquals(1, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
$expected = [ "id" => 1, "user_id" => 1, "name" => $this->testTrackName ];
$actual = $this->getConnection()->createQueryTable("users", "SELECT id, user_id, name FROM tracks");
$this->assertTableContains($expected, $actual, "Wrong actual table data");
}
public function testAddTrackEmptyName() {
$this->assertTrue($this->authenticate(), "Authentication failed");
/**
* @throws GuzzleException
*/
public function testAddTrackEmptyName(): void {
self::assertTrue($this->authenticate(), "Authentication failed");
$this->assertEquals(0, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
self::assertEquals(0, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
$options = [
'http_errors' => false,
'form_params' => [ 'action' => 'addtrack', 'track' => '' ],
];
$response = $this->http->post('/client/index.php', $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
$json = json_decode((string) $response->getBody());
$this->assertTrue($json->{'error'}, "Unexpected success");
$this->assertFalse(isset($json->{'trackid'}), "Unexpected track id");
$this->assertEquals(0, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
self::assertTrue($json->{'error'}, "Unexpected success");
self::assertFalse(isset($json->{'trackid'}), "Unexpected track id");
self::assertEquals(0, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
}
public function testAddTrackNoParameters() {
$this->assertTrue($this->authenticate(), "Authentication failed");
/**
* @throws GuzzleException
*/
public function testAddTrackNoParameters(): void {
self::assertTrue($this->authenticate(), "Authentication failed");
$this->assertEquals(0, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
self::assertEquals(0, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
$options = [
'http_errors' => false,
'form_params' => [ 'action' => 'addtrack' ],
];
$response = $this->http->post('/client/index.php', $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
$json = json_decode((string) $response->getBody());
$this->assertTrue($json->{'error'}, "Unexpected success");
$this->assertFalse(isset($json->{'trackid'}), "Unexpected track id");
$this->assertEquals(0, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
self::assertTrue($json->{'error'}, "Unexpected success");
self::assertFalse(isset($json->{'trackid'}), "Unexpected track id");
self::assertEquals(0, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
}
/* addpos */
public function testAddPosition() {
$this->assertTrue($this->authenticate(), "Authentication failed");
/**
* @throws GuzzleException
*/
public function testAddPosition(): void {
self::assertTrue($this->authenticate(), "Authentication failed");
$trackId = $this->addTestTrack($this->testUserId);
$this->assertEquals(1, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
$this->assertEquals(0, $this->getConnection()->getRowCount('positions'), "Wrong row count");
self::assertEquals(1, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
self::assertEquals(0, $this->getConnection()->getRowCount('positions'), "Wrong row count");
$options = [
'http_errors' => false,
@ -228,10 +266,10 @@ class ClientAPITest extends UloggerAPITestCase {
],
];
$response = $this->http->post('/client/index.php', $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
$json = json_decode((string) $response->getBody());
$this->assertFalse($json->{'error'}, "Unexpected error");
$this->assertEquals(1, $this->getConnection()->getRowCount('positions'), "Wrong row count");
self::assertFalse($json->{'error'}, "Unexpected error");
self::assertEquals(1, $this->getConnection()->getRowCount('positions'), "Wrong row count");
$expected = [
"id" => 1,
"user_id" => $this->testUserId,
@ -254,12 +292,15 @@ class ClientAPITest extends UloggerAPITestCase {
$this->assertTableContains($expected, $actual, "Wrong actual table data");
}
public function testAddPositionWithImage() {
$this->assertTrue($this->authenticate(), "Authentication failed");
/**
* @throws GuzzleException
*/
public function testAddPositionWithImage(): void {
self::assertTrue($this->authenticate(), "Authentication failed");
$trackId = $this->addTestTrack($this->testUserId);
$this->assertEquals(1, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
$this->assertEquals(0, $this->getConnection()->getRowCount('positions'), "Wrong row count");
self::assertEquals(1, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
self::assertEquals(0, $this->getConnection()->getRowCount('positions'), "Wrong row count");
$options = [
'http_errors' => false,
@ -317,10 +358,10 @@ class ClientAPITest extends UloggerAPITestCase {
]
];
$response = $this->http->post('/client/index.php', $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
$json = json_decode((string) $response->getBody());
$this->assertFalse($json->{'error'}, "Unexpected error");
$this->assertEquals(1, $this->getConnection()->getRowCount('positions'), "Wrong row count");
self::assertFalse($json->{'error'}, "Unexpected error");
self::assertEquals(1, $this->getConnection()->getRowCount('positions'), "Wrong row count");
$expected = [
"id" => 1,
"user_id" => $this->testUserId,
@ -339,26 +380,29 @@ class ClientAPITest extends UloggerAPITestCase {
"positions",
"SELECT id, user_id, track_id, " . $this->unix_timestamp('time') . " AS time, latitude, longitude, altitude, speed, bearing, accuracy, provider, comment, image FROM positions"
);
$this->assertEquals($expected['id'], $actual->getValue(0, 'id'));
$this->assertEquals($expected['user_id'], $actual->getValue(0, 'user_id'));
$this->assertEquals($expected['track_id'], $actual->getValue(0, 'track_id'));
$this->assertEquals($expected['time'], $actual->getValue(0, 'time'));
$this->assertEquals($expected['latitude'], $actual->getValue(0, 'latitude'));
$this->assertEquals($expected['longitude'], $actual->getValue(0, 'longitude'));
$this->assertEquals($expected['altitude'], $actual->getValue(0, 'altitude'));
$this->assertEquals($expected['speed'], $actual->getValue(0, 'speed'));
$this->assertEquals($expected['bearing'], $actual->getValue(0, 'bearing'));
$this->assertEquals($expected['accuracy'], $actual->getValue(0, 'accuracy'));
$this->assertEquals($expected['provider'], $actual->getValue(0, 'provider'));
$this->assertEquals($expected['comment'], $actual->getValue(0, 'comment'));
$this->assertContains('.jpg', $actual->getValue(0, 'image'));
self::assertEquals($expected['id'], $actual->getValue(0, 'id'));
self::assertEquals($expected['user_id'], $actual->getValue(0, 'user_id'));
self::assertEquals($expected['track_id'], $actual->getValue(0, 'track_id'));
self::assertEquals($expected['time'], $actual->getValue(0, 'time'));
self::assertEquals($expected['latitude'], $actual->getValue(0, 'latitude'));
self::assertEquals($expected['longitude'], $actual->getValue(0, 'longitude'));
self::assertEquals($expected['altitude'], $actual->getValue(0, 'altitude'));
self::assertEquals($expected['speed'], $actual->getValue(0, 'speed'));
self::assertEquals($expected['bearing'], $actual->getValue(0, 'bearing'));
self::assertEquals($expected['accuracy'], $actual->getValue(0, 'accuracy'));
self::assertEquals($expected['provider'], $actual->getValue(0, 'provider'));
self::assertEquals($expected['comment'], $actual->getValue(0, 'comment'));
self::assertStringContainsString('.jpg', $actual->getValue(0, 'image'));
}
public function testAddPositionNoexistantTrack() {
$this->assertTrue($this->authenticate(), "Authentication failed");
/**
* @throws GuzzleException
*/
public function testAddPositionNoexistantTrack(): void {
self::assertTrue($this->authenticate(), "Authentication failed");
$this->assertEquals(0, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
$this->assertEquals(0, $this->getConnection()->getRowCount('positions'), "Wrong row count");
self::assertEquals(0, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
self::assertEquals(0, $this->getConnection()->getRowCount('positions'), "Wrong row count");
$options = [
'http_errors' => false,
@ -378,18 +422,21 @@ class ClientAPITest extends UloggerAPITestCase {
],
];
$response = $this->http->post('/client/index.php', $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
$json = json_decode((string) $response->getBody());
$this->assertTrue($json->{'error'}, "Unexpected success");
$this->assertEquals(0, $this->getConnection()->getRowCount('positions'), "Wrong row count");
self::assertTrue($json->{'error'}, "Unexpected success");
self::assertEquals(0, $this->getConnection()->getRowCount('positions'), "Wrong row count");
}
public function testAddPositionEmptyParameters() {
$this->assertTrue($this->authenticate(), "Authentication failed");
/**
* @throws GuzzleException
*/
public function testAddPositionEmptyParameters(): void {
self::assertTrue($this->authenticate(), "Authentication failed");
$trackId = $this->addTestTrack($this->testUserId);
$this->assertEquals(1, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
$this->assertEquals(0, $this->getConnection()->getRowCount('positions'), "Wrong row count");
self::assertEquals(1, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
self::assertEquals(0, $this->getConnection()->getRowCount('positions'), "Wrong row count");
$options = [
'http_errors' => false,
@ -414,19 +461,22 @@ class ClientAPITest extends UloggerAPITestCase {
$optCopy = $options;
$optCopy['form_params'][$parameter] = '';
$response = $this->http->post('/client/index.php', $optCopy);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
$json = json_decode((string) $response->getBody());
$this->assertTrue($json->{'error'}, "Unexpected success ($parameter)");
self::assertTrue($json->{'error'}, "Unexpected success ($parameter)");
}
$this->assertEquals(0, $this->getConnection()->getRowCount('positions'), "Wrong row count");
self::assertEquals(0, $this->getConnection()->getRowCount('positions'), "Wrong row count");
}
public function testAddPositionMissingParameters() {
$this->assertTrue($this->authenticate(), "Authentication failed");
/**
* @throws GuzzleException
*/
public function testAddPositionMissingParameters(): void {
self::assertTrue($this->authenticate(), "Authentication failed");
$trackId = $this->addTestTrack($this->testUserId);
$this->assertEquals(1, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
$this->assertEquals(0, $this->getConnection()->getRowCount('positions'), "Wrong row count");
self::assertEquals(1, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
self::assertEquals(0, $this->getConnection()->getRowCount('positions'), "Wrong row count");
$options = [
'http_errors' => false,
@ -451,11 +501,11 @@ class ClientAPITest extends UloggerAPITestCase {
$optCopy = $options;
unset($optCopy['form_params'][$parameter]);
$response = $this->http->post('/client/index.php', $optCopy);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
$json = json_decode((string) $response->getBody());
$this->assertTrue($json->{'error'}, "Unexpected success ($parameter)");
self::assertTrue($json->{'error'}, "Unexpected success ($parameter)");
}
$this->assertEquals(0, $this->getConnection()->getRowCount('positions'), "Wrong row count");
self::assertEquals(0, $this->getConnection()->getRowCount('positions'), "Wrong row count");
// optional
$optional = [ 'altitude', 'speed', 'bearing', 'accuracy', 'provider', 'comment', 'imageid' ];
@ -463,11 +513,11 @@ class ClientAPITest extends UloggerAPITestCase {
$optCopy = $options;
unset($optCopy['form_params'][$parameter]);
$response = $this->http->post('/client/index.php', $optCopy);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
$json = json_decode((string) $response->getBody());
$this->assertFalse($json->{'error'}, "Unexpected error ($parameter)");
self::assertFalse($json->{'error'}, "Unexpected error ($parameter)");
}
$this->assertEquals(count($optional), $this->getConnection()->getRowCount('positions'), "Wrong row count");
self::assertEquals(count($optional), $this->getConnection()->getRowCount('positions'), "Wrong row count");
}

View File

@ -1,5 +1,7 @@
<?php
use PHPUnit\DbUnit\DataSet\IDataSet;
if (!defined("ROOT_DIR")) { define("ROOT_DIR", __DIR__ . "/../.."); }
require_once(__DIR__ . "/../../helpers/config.php");
require_once(__DIR__ . "/../lib/UloggerDatabaseTestCase.php");
@ -26,16 +28,13 @@ class ConfigTest extends UloggerDatabaseTestCase {
private $testUrl;
private $testPriority;
public function setUp() {
public function setUp(): void {
parent::setUp();
$this->config = uConfig::getInstance();
$this->initConfigValues();
}
/**
* @throws ReflectionException
*/
protected function tearDown() {
protected function tearDown(): void {
parent::tearDown();
$configClass = new ReflectionClass("uConfig");
$configInstance = $configClass->getProperty('instance');
@ -43,7 +42,7 @@ class ConfigTest extends UloggerDatabaseTestCase {
$configInstance->setValue(null);
}
protected function getDataSet() {
protected function getDataSet(): IDataSet {
$this->initConfigValues();
$this->resetAutoincrement();
$dataset = [
@ -71,28 +70,28 @@ class ConfigTest extends UloggerDatabaseTestCase {
return $this->createArrayDataSet($dataset);
}
public function testSetFromDatabase() {
$this->assertEquals($this->mapApi, $this->config->mapApi);
$this->assertEquals($this->latitude, $this->config->initLatitude);
$this->assertEquals($this->longitude, $this->config->initLongitude);
$this->assertEquals($this->googleKey, $this->config->googleKey);
$this->assertEquals($this->requireAuth, $this->config->requireAuthentication);
$this->assertEquals($this->publicTracks, $this->config->publicTracks);
$this->assertEquals($this->passLenMin, $this->config->passLenMin);
$this->assertEquals($this->passStrength, $this->config->passStrength);
$this->assertEquals($this->interval, $this->config->interval);
$this->assertEquals($this->lang, $this->config->lang);
$this->assertEquals($this->units, $this->config->units);
$this->assertEquals($this->strokeWeight, $this->config->strokeWeight);
$this->assertEquals($this->strokeColor, $this->config->strokeColor);
$this->assertEquals($this->strokeOpacity, $this->config->strokeOpacity);
public function testSetFromDatabase(): void {
self::assertEquals($this->mapApi, $this->config->mapApi);
self::assertEquals($this->latitude, $this->config->initLatitude);
self::assertEquals($this->longitude, $this->config->initLongitude);
self::assertEquals($this->googleKey, $this->config->googleKey);
self::assertEquals($this->requireAuth, $this->config->requireAuthentication);
self::assertEquals($this->publicTracks, $this->config->publicTracks);
self::assertEquals($this->passLenMin, $this->config->passLenMin);
self::assertEquals($this->passStrength, $this->config->passStrength);
self::assertEquals($this->interval, $this->config->interval);
self::assertEquals($this->lang, $this->config->lang);
self::assertEquals($this->units, $this->config->units);
self::assertEquals($this->strokeWeight, $this->config->strokeWeight);
self::assertEquals($this->strokeColor, $this->config->strokeColor);
self::assertEquals($this->strokeOpacity, $this->config->strokeOpacity);
$this->assertEquals($this->testLayer, $this->config->olLayers[0]->name);
$this->assertEquals($this->testUrl, $this->config->olLayers[0]->url);
$this->assertEquals($this->testPriority, $this->config->olLayers[0]->priority);
self::assertEquals($this->testLayer, $this->config->olLayers[0]->name);
self::assertEquals($this->testUrl, $this->config->olLayers[0]->url);
self::assertEquals($this->testPriority, $this->config->olLayers[0]->priority);
}
public function testSave() {
public function testSave(): void {
$this->config->mapApi = 'newApi';
$this->config->initLatitude = 33.11;
$this->config->initLongitude = 22.11;
@ -129,16 +128,16 @@ class ConfigTest extends UloggerDatabaseTestCase {
"stroke_opacity" => $this->config->strokeOpacity
];
$cnt = count($expected);
$this->assertGreaterThanOrEqual($cnt, $this->getConnection()->getRowCount('config'), "Wrong row count");
self::assertGreaterThanOrEqual($cnt, $this->getConnection()->getRowCount('config'), "Wrong row count");
$actual = $this->getConnection()->createQueryTable("config", "SELECT * FROM config");
for ($i = 0; $i < $cnt; $i++) {
$row = $actual->getRow($i);
$actualValue = $row['value'];
if (isset($expected[$row['name']])) {
$this->assertEquals(serialize($expected[$row['name']]), is_resource($actualValue) ? stream_get_contents($actualValue) : $actualValue);
self::assertEquals(serialize($expected[$row['name']]), is_resource($actualValue) ? stream_get_contents($actualValue) : $actualValue);
}
}
$this->assertEquals(1, $this->getConnection()->getRowCount('ol_layers'), "Wrong row count");
self::assertEquals(1, $this->getConnection()->getRowCount('ol_layers'), "Wrong row count");
$expected = [
"id" => $this->config->olLayers[0]->id,
"name" => $this->config->olLayers[0]->name,
@ -149,7 +148,7 @@ class ConfigTest extends UloggerDatabaseTestCase {
$this->assertTableContains($expected, $actual, "Wrong actual table data: " . implode(', ', $actual->getRow(0)));
}
private function initConfigValues() {
private function initConfigValues(): void {
$this->mapApi = 'testApi';
$this->latitude = 33.33;
$this->longitude = 22.22;
@ -169,7 +168,7 @@ class ConfigTest extends UloggerDatabaseTestCase {
$this->testPriority = 5;
}
public function testPassRegex() {
public function testPassRegex(): void {
$this->config->passLenMin = 0;
$this->config->passStrength = 0;
$password0 = "password";
@ -178,49 +177,49 @@ class ConfigTest extends UloggerDatabaseTestCase {
$password3 = "PASSword1234-;";
$regex = $this->config->passRegex();
$this->assertRegExp($regex, $password0, "Regex: \"$regex\", password: \"$password0\"");
$this->assertRegExp($regex, $password1, "Regex: \"$regex\", password: \"$password1\"");
$this->assertRegExp($regex, $password2, "Regex: \"$regex\", password: \"$password2\"");
$this->assertRegExp($regex, $password3, "Regex: \"$regex\", password: \"$password3\"");
self::assertMatchesRegularExpression($regex, $password0, "Regex: \"$regex\", password: \"$password0\"");
self::assertMatchesRegularExpression($regex, $password1, "Regex: \"$regex\", password: \"$password1\"");
self::assertMatchesRegularExpression($regex, $password2, "Regex: \"$regex\", password: \"$password2\"");
self::assertMatchesRegularExpression($regex, $password3, "Regex: \"$regex\", password: \"$password3\"");
$this->config->passStrength = 1;
$regex = $this->config->passRegex();
$this->assertNotRegExp($regex, $password0, "Regex: \"$regex\", password: \"$password0\"");
$this->assertRegExp($regex, $password1, "Regex: \"$regex\", password: \"$password1\"");
$this->assertRegExp($regex, $password2, "Regex: \"$regex\", password: \"$password2\"");
$this->assertRegExp($regex, $password3, "Regex: \"$regex\", password: \"$password3\"");
self::assertDoesNotMatchRegularExpression($regex, $password0, "Regex: \"$regex\", password: \"$password0\"");
self::assertMatchesRegularExpression($regex, $password1, "Regex: \"$regex\", password: \"$password1\"");
self::assertMatchesRegularExpression($regex, $password2, "Regex: \"$regex\", password: \"$password2\"");
self::assertMatchesRegularExpression($regex, $password3, "Regex: \"$regex\", password: \"$password3\"");
$this->config->passStrength = 2;
$regex = $this->config->passRegex();
$this->assertNotRegExp($regex, $password0, "Regex: \"$regex\", password: \"$password0\"");
$this->assertNotRegExp($regex, $password1, "Regex: \"$regex\", password: \"$password1\"");
$this->assertRegExp($regex, $password2, "Regex: \"$regex\", password: \"$password2\"");
$this->assertRegExp($regex, $password3, "Regex: \"$regex\", password: \"$password3\"");
self::assertDoesNotMatchRegularExpression($regex, $password0, "Regex: \"$regex\", password: \"$password0\"");
self::assertDoesNotMatchRegularExpression($regex, $password1, "Regex: \"$regex\", password: \"$password1\"");
self::assertMatchesRegularExpression($regex, $password2, "Regex: \"$regex\", password: \"$password2\"");
self::assertMatchesRegularExpression($regex, $password3, "Regex: \"$regex\", password: \"$password3\"");
$this->config->passStrength = 3;
$regex = $this->config->passRegex();
$this->assertNotRegExp($regex, $password0, "Regex: \"$regex\", password: \"$password0\"");
$this->assertNotRegExp($regex, $password1, "Regex: \"$regex\", password: \"$password1\"");
$this->assertNotRegExp($regex, $password2, "Regex: \"$regex\", password: \"$password2\"");
$this->assertRegExp($regex, $password3, "Regex: \"$regex\", password: \"$password3\"");
self::assertDoesNotMatchRegularExpression($regex, $password0, "Regex: \"$regex\", password: \"$password0\"");
self::assertDoesNotMatchRegularExpression($regex, $password1, "Regex: \"$regex\", password: \"$password1\"");
self::assertDoesNotMatchRegularExpression($regex, $password2, "Regex: \"$regex\", password: \"$password2\"");
self::assertMatchesRegularExpression($regex, $password3, "Regex: \"$regex\", password: \"$password3\"");
$password_len5 = "12345";
$password_len10 = "1234567890";
$this->config->passLenMin = 5;
$this->config->passStrength = 0;
$regex = $this->config->passRegex();
$this->assertRegExp($regex, $password_len5, "Regex: \"$regex\", password: \"$password_len5\"");
$this->assertRegExp($regex, $password_len10, "Regex: \"$regex\", password: \"$password_len10\"");
self::assertMatchesRegularExpression($regex, $password_len5, "Regex: \"$regex\", password: \"$password_len5\"");
self::assertMatchesRegularExpression($regex, $password_len10, "Regex: \"$regex\", password: \"$password_len10\"");
$this->config->passLenMin = 7;
$regex = $this->config->passRegex();
$this->assertNotRegExp($regex, $password_len5, "Regex: \"$regex\", password: \"$password_len5\"");
$this->assertRegExp($regex, $password_len10, "Regex: \"$regex\", password: \"$password_len10\"");
self::assertDoesNotMatchRegularExpression($regex, $password_len5, "Regex: \"$regex\", password: \"$password_len5\"");
self::assertMatchesRegularExpression($regex, $password_len10, "Regex: \"$regex\", password: \"$password_len10\"");
$this->config->passLenMin = 12;
$regex = $this->config->passRegex();
$this->assertNotRegExp($regex, $password_len5, "Regex: \"$regex\", password: \"$password_len5\"");
$this->assertNotRegExp($regex, $password_len10, "Regex: \"$regex\", password: \"$password_len10\"");
self::assertDoesNotMatchRegularExpression($regex, $password_len5, "Regex: \"$regex\", password: \"$password_len5\"");
self::assertDoesNotMatchRegularExpression($regex, $password_len10, "Regex: \"$regex\", password: \"$password_len10\"");
}
}
?>

View File

@ -6,7 +6,7 @@ require_once(__DIR__ . "/../../helpers/db.php");
class DbTest extends TestCase {
public function testGetDbNameValidNames() {
public function testGetDbNameValidNames(): void {
$testDbName = "testDbName";
$defaultDSNs = [
"mysql:host=db.example.com;port=3306;dbname=$testDbName",
@ -22,11 +22,11 @@ class DbTest extends TestCase {
];
foreach ($defaultDSNs as $dsn) {
$this->assertEquals($testDbName, uDb::getDbName($dsn));
self::assertEquals($testDbName, uDb::getDbName($dsn));
}
}
public function testGetDbNameEmptyNames() {
public function testGetDbNameEmptyNames(): void {
$testDbName = "";
$defaultDSNs = [
"mysql:host=db.example.com;port=3306;dbname=",
@ -42,12 +42,12 @@ class DbTest extends TestCase {
];
foreach ($defaultDSNs as $dsn) {
$this->assertEquals($testDbName, uDb::getDbName($dsn));
self::assertEquals($testDbName, uDb::getDbName($dsn));
}
}
public function testGetDbFilename() {
public function testGetDbFilename(): void {
$testFileNames = [
"C:\\Program Files\\Database.db",
":memory:",
@ -55,11 +55,11 @@ class DbTest extends TestCase {
];
foreach ($testFileNames as $fileName) {
$this->assertEquals($fileName, uDb::getDbName("sqlite:$fileName"));
self::assertEquals($fileName, uDb::getDbName("sqlite:$fileName"));
}
}
public function testNormalizeDsn() {
public function testNormalizeDsn(): void {
$testDbName = "testDbName";
$nonSqlite = [
"mysql:host=db.example.com;port=3306;dbname=$testDbName",
@ -72,12 +72,12 @@ class DbTest extends TestCase {
];
foreach ($nonSqlite as $dsn) {
$this->assertEquals($dsn, uDb::normalizeDsn($dsn));
self::assertEquals($dsn, uDb::normalizeDsn($dsn));
}
$this->assertEquals("sqlite:" . realpath(ROOT_DIR . "/index.php"), uDb::normalizeDsn("sqlite:index.php"));
$this->assertEquals("sqlite:" . realpath(ROOT_DIR . "/index.php"), uDb::normalizeDsn("sqlite:helpers/../index.php"));
$this->assertNotEquals("sqlite:" . realpath(ROOT_DIR . "/index.php"), uDb::normalizeDsn("sqlite:../index.php"));
self::assertEquals("sqlite:" . realpath(ROOT_DIR . "/index.php"), uDb::normalizeDsn("sqlite:index.php"));
self::assertEquals("sqlite:" . realpath(ROOT_DIR . "/index.php"), uDb::normalizeDsn("sqlite:helpers/../index.php"));
self::assertNotEquals("sqlite:" . realpath(ROOT_DIR . "/index.php"), uDb::normalizeDsn("sqlite:../index.php"));
}
}

View File

@ -1,6 +1,6 @@
<?php /** @noinspection HtmlUnknownAttribute */
use Psr\Http\Message\ResponseInterface;
use GuzzleHttp\Exception\GuzzleException;
require_once(__DIR__ . "/../lib/UloggerAPITestCase.php");
if (!defined("ROOT_DIR")) { define("ROOT_DIR", __DIR__ . "/../.."); }
@ -9,19 +9,21 @@ require_once(ROOT_DIR . "/helpers/lang.php");
class ImportTest extends UloggerAPITestCase {
public function testImportGPX10() {
/**
* @throws GuzzleException
*/
public function testImportGPX10(): void {
$this->assertTrue($this->authenticate(), "Authentication failed");
self::assertTrue($this->authenticate(), "Authentication failed");
$this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
$this->assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
self::assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
self::assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
$gpx10 = '<?xml version="1.0"?>
<gpx version="1.0" creator="test software"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.topografix.com/GPX/1/0"
xsi:schemaLocation="http://www.topografix.com/GPX/1/0
http://www.topografix.com/GPX/1/0/gpx.xsd">
xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd">
<time>2017-09-19T11:00:08Z</time>
<trk>
<name>' . $this->testTrackName . '</name>
@ -52,18 +54,18 @@ class ImportTest extends UloggerAPITestCase {
],
];
$response = $this->http->post("/utils/import.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
$json = json_decode($response->getBody());
$this->assertNotNull($json, "JSON object is null");
$this->assertEquals(count($json), 1, "Wrong count of tracks");
self::assertNotNull($json, "JSON object is null");
self::assertCount(1, $json, "Wrong count of tracks");
$track = $json[0];
$this->assertEquals(1, (int) $track->id, "Wrong track id");
$this->assertEquals($this->testTrackName, $track->name, "Wrong track name");
self::assertEquals(1, (int) $track->id, "Wrong track id");
self::assertEquals($this->testTrackName, $track->name, "Wrong track name");
$this->assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
$this->assertEquals(2, $this->getConnection()->getRowCount("positions"), "Wrong row count");
self::assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
self::assertEquals(2, $this->getConnection()->getRowCount("positions"), "Wrong row count");
$expected = [
"id" => 1,
@ -116,12 +118,15 @@ class ImportTest extends UloggerAPITestCase {
$this->assertTableContains($expected, $actual, "Wrong actual table data");
}
public function testImportGPX11() {
/**
* @throws GuzzleException
*/
public function testImportGPX11(): void {
$this->assertTrue($this->authenticate(), "Authentication failed");
self::assertTrue($this->authenticate(), "Authentication failed");
$this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
$this->assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
self::assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
self::assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
$gpx11 = '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<gpx version="1.1"
@ -134,7 +139,7 @@ class ImportTest extends UloggerAPITestCase {
<desc>Track for testing ulogger</desc>
<author>
<name>Bartek Fabiszewski</name>
<link href="http://www.fabiszewski.net"><text>fabiszewski.net</text></link>
<link href="https://www.fabiszewski.net"><text>fabiszewski.net</text></link>
</author>
<time>2017-09-19T09:22:06Z</time>
<keywords>Test, ulogger</keywords>
@ -142,7 +147,7 @@ class ImportTest extends UloggerAPITestCase {
</metadata>
<trk>
<src>Crafted by Bartek Fabiszewski</src>
<link href="http://www.fabiszewski.net"><text>fabiszewski.net</text></link>
<link href="https://www.fabiszewski.net"><text>fabiszewski.net</text></link>
<trkseg>
<trkpt lat="' . $this->testLat . '" lon="' . $this->testLon . '">
<ele>' . $this->testAltitude . '</ele>
@ -169,19 +174,19 @@ class ImportTest extends UloggerAPITestCase {
],
];
$response = $this->http->post("/utils/import.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
$json = json_decode($response->getBody());
$this->assertNotNull($json, "JSON object is null");
$this->assertEquals(count($json), 1, "Wrong count of tracks");
self::assertNotNull($json, "JSON object is null");
self::assertCount(1, $json, "Wrong count of tracks");
$track = $json[0];
$this->assertEquals(1, (int) $track->id, "Wrong track id");
$this->assertEquals($this->testTrackName, $track->name, "Wrong track name");
self::assertEquals(1, (int) $track->id, "Wrong track id");
self::assertEquals($this->testTrackName, $track->name, "Wrong track name");
$this->assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
$this->assertEquals(1, $this->getConnection()->getRowCount("positions"), "Wrong row count");
self::assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
self::assertEquals(1, $this->getConnection()->getRowCount("positions"), "Wrong row count");
$expected = [
"id" => 1,
@ -217,12 +222,15 @@ class ImportTest extends UloggerAPITestCase {
$this->assertTableContains($expected, $actual, "Wrong actual table data");
}
public function testImportExtensions() {
/**
* @throws GuzzleException
*/
public function testImportExtensions(): void {
$this->assertTrue($this->authenticate(), "Authentication failed");
self::assertTrue($this->authenticate(), "Authentication failed");
$this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
$this->assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
self::assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
self::assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
$gpx = '<?xml version="1.0" encoding="UTF-8"?>
<gpx xsi:schemaLocation="http://www.topografix.com/GPX/1/1
@ -271,19 +279,19 @@ class ImportTest extends UloggerAPITestCase {
],
];
$response = $this->http->post("/utils/import.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
$json = json_decode($response->getBody());
$this->assertNotNull($json, "JSON object is null");
$this->assertEquals(count($json), 1, "Wrong count of tracks");
self::assertNotNull($json, "JSON object is null");
self::assertCount(1, $json, "Wrong count of tracks");
$track = $json[0];
$this->assertEquals(1, (int) $track->id, "Wrong track id");
$this->assertEquals($this->testTrackName, $track->name, "Wrong track name");
self::assertEquals(1, (int) $track->id, "Wrong track id");
self::assertEquals($this->testTrackName, $track->name, "Wrong track name");
$this->assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
$this->assertEquals(1, $this->getConnection()->getRowCount("positions"), "Wrong row count");
self::assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
self::assertEquals(1, $this->getConnection()->getRowCount("positions"), "Wrong row count");
$expected = [
"id" => 1,
@ -319,16 +327,18 @@ class ImportTest extends UloggerAPITestCase {
$this->assertTableContains($expected, $actual, "Wrong actual table data");
}
public function testImportNoTime() {
/**
* @throws GuzzleException
*/
public function testImportNoTime(): void {
$this->assertTrue($this->authenticate(), "Authentication failed");
self::assertTrue($this->authenticate(), "Authentication failed");
$this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
$this->assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
self::assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
self::assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
$gpx = '<?xml version="1.0" encoding="UTF-8"?>
<gpx xsi:schemaLocation="http://www.topografix.com/GPX/1/1
http://www.topografix.com/GPX/1/1/gpx.xsd"
<gpx xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.topografix.com/GPX/1/1"
creator="μlogger" version="1.1">
@ -354,19 +364,19 @@ class ImportTest extends UloggerAPITestCase {
],
];
$response = $this->http->post("/utils/import.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
$json = json_decode($response->getBody());
$this->assertNotNull($json, "JSON object is null");
$this->assertEquals(count($json), 1, "Wrong count of tracks");
self::assertNotNull($json, "JSON object is null");
self::assertCount(1, $json, "Wrong count of tracks");
$track = $json[0];
$this->assertEquals(1, (int) $track->id, "Wrong track id");
$this->assertEquals($this->testTrackName, $track->name, "Wrong track name");
self::assertEquals(1, (int) $track->id, "Wrong track id");
self::assertEquals($this->testTrackName, $track->name, "Wrong track name");
$this->assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
$this->assertEquals(1, $this->getConnection()->getRowCount("positions"), "Wrong row count");
self::assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
self::assertEquals(1, $this->getConnection()->getRowCount("positions"), "Wrong row count");
$expected = [
"id" => 1,
@ -402,12 +412,15 @@ class ImportTest extends UloggerAPITestCase {
$this->assertTableContains($expected, $actual, "Wrong actual table data");
}
public function testImportMultipleSegments() {
/**
* @throws GuzzleException
*/
public function testImportMultipleSegments(): void {
$this->assertTrue($this->authenticate(), "Authentication failed");
self::assertTrue($this->authenticate(), "Authentication failed");
$this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
$this->assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
self::assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
self::assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
$gpx = '<?xml version="1.0" encoding="UTF-8"?>
<gpx xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd"
@ -443,19 +456,19 @@ class ImportTest extends UloggerAPITestCase {
],
];
$response = $this->http->post("/utils/import.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
$json = json_decode($response->getBody());
$this->assertNotNull($json, "JSON object is null");
$this->assertEquals(count($json), 1, "Wrong count of tracks");
self::assertNotNull($json, "JSON object is null");
self::assertCount(1, $json, "Wrong count of tracks");
$track = $json[0];
$this->assertEquals(1, (int) $track->id, "Wrong track id");
$this->assertEquals($this->testTrackName, $track->name, "Wrong track name");
self::assertEquals(1, (int) $track->id, "Wrong track id");
self::assertEquals($this->testTrackName, $track->name, "Wrong track name");
$this->assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
$this->assertEquals(2, $this->getConnection()->getRowCount("positions"), "Wrong row count");
self::assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
self::assertEquals(2, $this->getConnection()->getRowCount("positions"), "Wrong row count");
$expected = [
"id" => 1,
@ -507,12 +520,15 @@ class ImportTest extends UloggerAPITestCase {
$this->assertTableContains($expected, $actual, "Wrong actual table data");
}
public function testImportMultipleTracks() {
/**
* @throws GuzzleException
*/
public function testImportMultipleTracks(): void {
$this->assertTrue($this->authenticate(), "Authentication failed");
self::assertTrue($this->authenticate(), "Authentication failed");
$this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
$this->assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
self::assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
self::assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
$gpx = '<?xml version="1.0" encoding="UTF-8"?>
<gpx xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd"
@ -550,23 +566,23 @@ class ImportTest extends UloggerAPITestCase {
],
];
$response = $this->http->post("/utils/import.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
$json = json_decode($response->getBody());
$this->assertNotNull($json, "JSON object is null");
$this->assertEquals(count($json), 2, "Wrong count of tracks");
self::assertNotNull($json, "JSON object is null");
self::assertCount(2, $json, "Wrong count of tracks");
$track = $json[0];
$this->assertEquals(2, (int) $track->id, "Wrong track id");
$this->assertEquals($this->testTrackName, $track->name, "Wrong track name");
self::assertEquals(2, (int) $track->id, "Wrong track id");
self::assertEquals($this->testTrackName, $track->name, "Wrong track name");
$track = $json[1];
$this->assertEquals(1, (int) $track->id, "Wrong track id");
$this->assertEquals($this->testTrackName, $track->name, "Wrong track name");
self::assertEquals(1, (int) $track->id, "Wrong track id");
self::assertEquals($this->testTrackName, $track->name, "Wrong track name");
$this->assertEquals(2, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
$this->assertEquals(2, $this->getConnection()->getRowCount("positions"), "Wrong row count");
self::assertEquals(2, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
self::assertEquals(2, $this->getConnection()->getRowCount("positions"), "Wrong row count");
$expected = [
"id" => 1,
@ -625,16 +641,18 @@ class ImportTest extends UloggerAPITestCase {
$this->assertTableContains($expected, $actual, "Wrong actual table data");
}
public function testImportNoLongitude() {
/**
* @throws GuzzleException
*/
public function testImportNoLongitude(): void {
$lang = (new uLang($this->mockConfig))->getStrings();
$this->assertTrue($this->authenticate(), "Authentication failed");
self::assertTrue($this->authenticate(), "Authentication failed");
$this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
$this->assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
self::assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
self::assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
$gpx = '<?xml version="1.0" encoding="UTF-8"?>
<gpx xsi:schemaLocation="http://www.topografix.com/GPX/1/1
http://www.topografix.com/GPX/1/1/gpx.xsd"
<gpx xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.topografix.com/GPX/1/1"
creator="μlogger" version="1.1">
@ -660,28 +678,30 @@ class ImportTest extends UloggerAPITestCase {
],
];
$response = $this->http->post("/utils/import.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
$json = json_decode($response->getBody());
$this->assertNotNull($json, "JSON object is null");
$this->assertEquals(1, (int) $json->error, "Wrong error status");
$this->assertEquals($lang["iparsefailure"], (string) $json->message, "Wrong error status");
self::assertNotNull($json, "JSON object is null");
self::assertEquals(1, (int) $json->error, "Wrong error status");
self::assertEquals($lang["iparsefailure"], (string) $json->message, "Wrong error status");
$this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
$this->assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
self::assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
self::assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
}
public function testImportNoLatitude() {
/**
* @throws GuzzleException
*/
public function testImportNoLatitude(): void {
$lang = (new uLang($this->mockConfig))->getStrings();
$this->assertTrue($this->authenticate(), "Authentication failed");
self::assertTrue($this->authenticate(), "Authentication failed");
$this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
$this->assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
self::assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
self::assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
$gpx = '<?xml version="1.0" encoding="UTF-8"?>
<gpx xsi:schemaLocation="http://www.topografix.com/GPX/1/1
http://www.topografix.com/GPX/1/1/gpx.xsd"
<gpx xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.topografix.com/GPX/1/1"
creator="μlogger" version="1.1">
@ -707,24 +727,27 @@ class ImportTest extends UloggerAPITestCase {
],
];
$response = $this->http->post("/utils/import.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
$json = json_decode($response->getBody());
$this->assertNotNull($json, "JSON object is null");
$this->assertEquals(1, (int) $json->error, "Wrong error status");
$this->assertEquals($lang["iparsefailure"], (string) $json->message, "Wrong error status");
self::assertNotNull($json, "JSON object is null");
self::assertEquals(1, (int) $json->error, "Wrong error status");
self::assertEquals($lang["iparsefailure"], (string) $json->message, "Wrong error status");
$this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
$this->assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
self::assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
self::assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
}
public function testImportNoGPX() {
/**
* @throws GuzzleException
*/
public function testImportNoGPX(): void {
$lang = (new uLang($this->mockConfig))->getStrings();
$this->assertTrue($this->authenticate(), "Authentication failed");
self::assertTrue($this->authenticate(), "Authentication failed");
$this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
$this->assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
self::assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
self::assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
$gpx = '<?xml version="1.0" encoding="UTF-8"?>
<trk>
@ -748,28 +771,30 @@ class ImportTest extends UloggerAPITestCase {
],
];
$response = $this->http->post("/utils/import.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
$json = json_decode($response->getBody());
$this->assertNotNull($json, "JSON object is null");
$this->assertEquals(1, (int) $json->error, "Wrong error status");
$this->assertEquals($lang["iparsefailure"], (string) $json->message, "Wrong error status");
self::assertNotNull($json, "JSON object is null");
self::assertEquals(1, (int) $json->error, "Wrong error status");
self::assertEquals($lang["iparsefailure"], (string) $json->message, "Wrong error status");
$this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
$this->assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
self::assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
self::assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
}
public function testImportCorrupt() {
/**
* @throws GuzzleException
*/
public function testImportCorrupt(): void {
$lang = (new uLang($this->mockConfig))->getStrings();
$this->assertTrue($this->authenticate(), "Authentication failed");
self::assertTrue($this->authenticate(), "Authentication failed");
$this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
$this->assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
self::assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
self::assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
$gpx = '<?xml version="1.0" encoding="UTF-8"?>
<gpx xsi:schemaLocation="http://www.topografix.com/GPX/1/1
http://www.topografix.com/GPX/1/1/gpx.xsd"
<gpx xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.topografix.com/GPX/1/1"
creator="μlogger" version="1.1">
@ -793,16 +818,16 @@ class ImportTest extends UloggerAPITestCase {
],
];
$response = $this->http->post("/utils/import.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
$json = json_decode($response->getBody());
$this->assertNotNull($json, "JSON object is null");
$this->assertEquals(1, (int) $json->error, "Wrong error status");
$this->assertEquals(0, strpos((string) $json->message, $lang["iparsefailure"]), "Wrong error status");
self::assertNotNull($json, "JSON object is null");
self::assertEquals(1, (int) $json->error, "Wrong error status");
self::assertEquals(0, strpos((string) $json->message, $lang["iparsefailure"]), "Wrong error status");
$this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
$this->assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
self::assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
self::assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
}
private function getStream($string) {

View File

@ -1,5 +1,7 @@
<?php
use GuzzleHttp\Exception\GuzzleException;
require_once(__DIR__ . "/../lib/UloggerAPITestCase.php");
if (!defined("ROOT_DIR")) { define("ROOT_DIR", __DIR__ . "/../.."); }
require_once(ROOT_DIR . "/helpers/config.php");
@ -9,7 +11,10 @@ class InternalAPITest extends UloggerAPITestCase {
/* getpositions */
public function testGetPositionsAdmin() {
/**
* @throws GuzzleException
*/
public function testGetPositionsAdmin(): void {
self::assertTrue($this->authenticate(), "Authentication failed");
@ -47,7 +52,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertEquals($this->testTrackName, (string) $position->trackname,"Wrong trackname");
}
public function testGetPositionsUser() {
/**
* @throws GuzzleException
*/
public function testGetPositionsUser(): void {
$userId = $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count");
self::assertTrue($this->authenticate($this->testUser, $this->testPass), "Authentication failed");
@ -86,7 +94,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertEquals($this->testTrackName, (string) $position->trackname,"Wrong trackname");
}
public function testGetPositionsOtherUser() {
/**
* @throws GuzzleException
*/
public function testGetPositionsOtherUser(): void {
$userId = $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
self::assertEquals(2, $userId);
self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count");
@ -110,7 +121,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertCount(0, $json, "Wrong count of positions");
}
public function testGetPositionsOtherUserByAdmin() {
/**
* @throws GuzzleException
*/
public function testGetPositionsOtherUserByAdmin(): void {
$userId = $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
self::assertEquals(2, $userId);
self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count");
@ -150,7 +164,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertEquals($this->testTrackName, (string) $position->trackname,"Wrong trackname");
}
public function testGetPositionsUserLatest() {
/**
* @throws GuzzleException
*/
public function testGetPositionsUserLatest(): void {
self::assertTrue($this->authenticate(), "Authentication failed");
$trackId = $this->addTestTrack($this->testUserId);
@ -186,7 +203,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertEquals($this->testTrackName, (string) $position->trackname,"Wrong trackname");
}
public function testGetPositionsAllUsersLatest() {
/**
* @throws GuzzleException
*/
public function testGetPositionsAllUsersLatest(): void {
self::assertTrue($this->authenticate(), "Authentication failed");
$userId = $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
@ -231,7 +251,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertEquals($trackName, (string) $position->trackname,"Wrong trackname");
}
public function testGetPositionsNoTrackId() {
/**
* @throws GuzzleException
*/
public function testGetPositionsNoTrackId(): void {
self::assertTrue($this->authenticate(), "Authentication failed");
@ -253,7 +276,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertCount(0, $json, "Wrong count of positions");
}
public function testGetPositionsNoUserId() {
/**
* @throws GuzzleException
*/
public function testGetPositionsNoUserId(): void {
self::assertTrue($this->authenticate(), "Authentication failed");
@ -275,7 +301,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertCount(0, $json, "Wrong count of positions");
}
public function testGetPositionsNoAuth() {
/**
* @throws GuzzleException
*/
public function testGetPositionsNoAuth(): void {
$trackId = $this->addTestTrack($this->testUserId);
$this->addTestPosition($this->testUserId, $trackId, $this->testTimestamp);
@ -294,7 +323,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertCount(0, $json, "Wrong count of positions");
}
public function testGetPositionsAfterId() {
/**
* @throws GuzzleException
*/
public function testGetPositionsAfterId(): void {
self::assertTrue($this->authenticate(), "Authentication failed");
@ -331,7 +363,10 @@ class InternalAPITest extends UloggerAPITestCase {
/* gettracks.php */
public function testGetTracksAdmin() {
/**
* @throws GuzzleException
*/
public function testGetTracksAdmin(): void {
self::assertTrue($this->authenticate(), "Authentication failed");
@ -360,7 +395,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertEquals($this->testTrackName, (string) $track->name,"Wrong track name");
}
public function testGetTracksUser() {
/**
* @throws GuzzleException
*/
public function testGetTracksUser(): void {
$userId = $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count");
self::assertTrue($this->authenticate($this->testUser, $this->testPass), "Authentication failed");
@ -390,7 +428,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertEquals($this->testTrackName, (string) $track->name,"Wrong track name");
}
public function testGetTracksOtherUser() {
/**
* @throws GuzzleException
*/
public function testGetTracksOtherUser(): void {
$this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count");
self::assertTrue($this->authenticate($this->testUser, $this->testPass), "Authentication failed");
@ -412,7 +453,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertCount(0, $json, "Wrong count of tracks");
}
public function testGetTracksNoUserId() {
/**
* @throws GuzzleException
*/
public function testGetTracksNoUserId(): void {
$this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count");
self::assertTrue($this->authenticate($this->testUser, $this->testPass), "Authentication failed");
@ -432,7 +476,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertCount(0, $json, "Wrong count of tracks");
}
public function testGetTracksNoAuth() {
/**
* @throws GuzzleException
*/
public function testGetTracksNoAuth(): void {
$this->addTestTrack($this->testUserId);
$this->addTestTrack($this->testUserId, $this->testTrackName . "2");
@ -454,7 +501,10 @@ class InternalAPITest extends UloggerAPITestCase {
/* changepass.php */
public function testChangePassNoAuth() {
/**
* @throws GuzzleException
*/
public function testChangePassNoAuth(): void {
$options = [
"http_errors" => false,
@ -473,7 +523,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertEquals("User not authorized", (string) $json->message, "Wrong error message");
}
public function testChangePassEmpty() {
/**
* @throws GuzzleException
*/
public function testChangePassEmpty(): void {
self::assertTrue($this->authenticate(), "Authentication failed");
$options = [
@ -489,7 +542,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertEquals("Empty password", (string) $json->message, "Wrong error message");
}
public function testChangePassUserUnknown() {
/**
* @throws GuzzleException
*/
public function testChangePassUserUnknown(): void {
self::assertTrue($this->authenticate(), "Authentication failed");
$options = [
@ -508,7 +564,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertEquals("User unknown", (string) $json->message, "Wrong error message");
}
public function testChangePassEmptyLogin() {
/**
* @throws GuzzleException
*/
public function testChangePassEmptyLogin(): void {
self::assertTrue($this->authenticate(), "Authentication failed");
$options = [
@ -526,7 +585,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertEquals("Empty login", (string) $json->message, "Wrong error message");
}
public function testChangePassWrongOldpass() {
/**
* @throws GuzzleException
*/
public function testChangePassWrongOldpass(): void {
self::assertTrue($this->authenticate(), "Authentication failed");
$options = [
@ -546,7 +608,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertEquals("Wrong old password", (string) $json->message, "Wrong error message");
}
public function testChangePassNoOldpass() {
/**
* @throws GuzzleException
*/
public function testChangePassNoOldpass(): void {
self::assertTrue($this->authenticate(), "Authentication failed");
$options = [
@ -565,7 +630,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertEquals("Wrong old password", (string) $json->message,"Wrong error message");
}
public function testChangePassSelfAdmin() {
/**
* @throws GuzzleException
*/
public function testChangePassSelfAdmin(): void {
self::assertTrue($this->authenticate(), "Authentication failed");
$newPass = "Newpass1234567890";
@ -586,7 +654,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertTrue(password_verify($newPass, $this->pdoGetColumn("SELECT password FROM users")), "Wrong actual password hash");
}
public function testChangePassSelfUser() {
/**
* @throws GuzzleException
*/
public function testChangePassSelfUser(): void {
$userId = $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
self::assertTrue($this->authenticate($this->testUser, $this->testPass), "Authentication failed");
@ -608,7 +679,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertTrue(password_verify($newPass, $this->pdoGetColumn("SELECT password FROM users WHERE id = $userId")), "Wrong actual password hash");
}
public function testChangePassOtherAdmin() {
/**
* @throws GuzzleException
*/
public function testChangePassOtherAdmin(): void {
self::assertTrue($this->authenticate(), "Authentication failed");
$userId = $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
@ -629,7 +703,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertTrue(password_verify($newPass, $this->pdoGetColumn("SELECT password FROM users WHERE id = $userId")), "Wrong actual password hash");
}
public function testChangePassOtherUser() {
/**
* @throws GuzzleException
*/
public function testChangePassOtherUser(): void {
$this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
$this->addTestUser($this->testUser2, password_hash($this->testPass, PASSWORD_DEFAULT));
self::assertTrue($this->authenticate($this->testUser, $this->testPass), "Authentication failed");
@ -654,7 +731,10 @@ class InternalAPITest extends UloggerAPITestCase {
/* handletrack.php */
public function testHandleTrackDeleteAdmin() {
/**
* @throws GuzzleException
*/
public function testHandleTrackDeleteAdmin(): void {
self::assertTrue($this->authenticate(), "Authentication failed");
$userId = $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count");
@ -676,7 +756,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertEquals($trackId2, $this->pdoGetColumn("SELECT id FROM tracks WHERE id = $trackId2"), "Wrong actual track id");
}
public function testHandleTrackDeleteSelf() {
/**
* @throws GuzzleException
*/
public function testHandleTrackDeleteSelf(): void {
$userId = $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count");
self::assertTrue($this->authenticate($this->testUser, $this->testPass), "Authentication failed");
@ -698,7 +781,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertEquals($trackId2, $this->pdoGetColumn("SELECT id FROM tracks WHERE id = $trackId2"), "Wrong actual track id");
}
public function testHandleTrackDeleteOtherUser() {
/**
* @throws GuzzleException
*/
public function testHandleTrackDeleteOtherUser(): void {
$lang = (new uLang($this->mockConfig))->getStrings();
$this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count");
@ -720,7 +806,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertEquals($lang["notauthorized"], (string) $json->message, "Wrong error message");
}
public function testHandleTrackUpdate() {
/**
* @throws GuzzleException
*/
public function testHandleTrackUpdate(): void {
$newName = "New name";
self::assertTrue($this->authenticate(), "Authentication failed");
$userId = $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
@ -760,7 +849,10 @@ class InternalAPITest extends UloggerAPITestCase {
$this->assertTableContains($row2, $actual, "Wrong actual table data");
}
public function testHandleTrackUpdateEmptyName() {
/**
* @throws GuzzleException
*/
public function testHandleTrackUpdateEmptyName(): void {
$lang = (new uLang($this->mockConfig))->getStrings();
self::assertTrue($this->authenticate(), "Authentication failed");
$userId = $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
@ -784,7 +876,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertEquals(2, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
}
public function testHandleTrackUpdateNonexistantTrack() {
/**
* @throws GuzzleException
*/
public function testHandleTrackUpdateNonexistantTrack(): void {
$lang = (new uLang($this->mockConfig))->getStrings();
$newName = "New name";
self::assertTrue($this->authenticate(), "Authentication failed");
@ -808,7 +903,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertEquals($lang["servererror"], (string) $json->message,"Wrong error message");
}
public function testHandleTrackMissingAction() {
/**
* @throws GuzzleException
*/
public function testHandleTrackMissingAction(): void {
$lang = (new uLang($this->mockConfig))->getStrings();
self::assertTrue($this->authenticate(), "Authentication failed");
@ -826,7 +924,10 @@ class InternalAPITest extends UloggerAPITestCase {
/* handleuser.php */
public function testHandleUserMissingAction() {
/**
* @throws GuzzleException
*/
public function testHandleUserMissingAction(): void {
$lang = (new uLang($this->mockConfig))->getStrings();
self::assertTrue($this->authenticate(), "Authentication failed");
@ -841,7 +942,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertEquals($lang["servererror"], (string) $json->message,"Wrong error message");
}
public function testHandleUserNonAdmin() {
/**
* @throws GuzzleException
*/
public function testHandleUserNonAdmin(): void {
$lang = (new uLang($this->mockConfig))->getStrings();
$this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count");
@ -861,7 +965,10 @@ class InternalAPITest extends UloggerAPITestCase {
}
public function testHandleUserSelf() {
/**
* @throws GuzzleException
*/
public function testHandleUserSelf(): void {
$lang = (new uLang($this->mockConfig))->getStrings();
self::assertTrue($this->authenticate(), "Authentication failed");
self::assertEquals(1, $this->getConnection()->getRowCount("users"), "Wrong row count");
@ -879,7 +986,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertEquals(1, $this->getConnection()->getRowCount("users"), "Wrong row count");
}
public function testHandleUserEmptyLogin() {
/**
* @throws GuzzleException
*/
public function testHandleUserEmptyLogin(): void {
$lang = (new uLang($this->mockConfig))->getStrings();
self::assertTrue($this->authenticate(), "Authentication failed");
self::assertEquals(1, $this->getConnection()->getRowCount("users"), "Wrong row count");
@ -897,7 +1007,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertEquals(1, $this->getConnection()->getRowCount("users"), "Wrong row count");
}
public function testHandleUserNoAuth() {
/**
* @throws GuzzleException
*/
public function testHandleUserNoAuth(): void {
$lang = (new uLang($this->mockConfig))->getStrings();
$this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count");
@ -916,7 +1029,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count");
}
public function testHandleUserAdd() {
/**
* @throws GuzzleException
*/
public function testHandleUserAdd(): void {
self::assertTrue($this->authenticate(), "Authentication failed");
self::assertEquals(1, $this->getConnection()->getRowCount("users"), "Wrong row count");
@ -940,7 +1056,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertTrue(password_verify($this->testPass, $this->pdoGetColumn("SELECT password FROM users WHERE login = '$this->testUser'")), "Wrong actual password hash");
}
public function testHandleUserAddSameLogin() {
/**
* @throws GuzzleException
*/
public function testHandleUserAddSameLogin(): void {
$lang = (new uLang($this->mockConfig))->getStrings();
self::assertTrue($this->authenticate(), "Authentication failed");
$this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
@ -959,7 +1078,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count");
}
public function testHandleUserUpdate() {
/**
* @throws GuzzleException
*/
public function testHandleUserUpdate(): void {
$newPass = $this->testPass . "new";
self::assertTrue($this->authenticate(), "Authentication failed");
$this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
@ -977,7 +1099,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertTrue(password_verify($newPass, $this->pdoGetColumn("SELECT password FROM users WHERE login = '$this->testUser'")), "Wrong actual password hash");
}
public function testHandleUserUpdateEmptyPass() {
/**
* @throws GuzzleException
*/
public function testHandleUserUpdateEmptyPass(): void {
self::assertTrue($this->authenticate(), "Authentication failed");
$this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count");
@ -993,7 +1118,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertTrue(password_verify($this->testPass, $this->pdoGetColumn("SELECT password FROM users WHERE login = '$this->testUser'")), "Wrong actual password hash");
}
public function testHandleUserDelete() {
/**
* @throws GuzzleException
*/
public function testHandleUserDelete(): void {
self::assertTrue($this->authenticate(), "Authentication failed");
$this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count");

View File

@ -10,34 +10,34 @@ class LangTest extends TestCase {
protected $mockConfig;
public function setUp() {
public function setUp(): void {
parent::setUp();
$this->mockConfig = new uConfig(false);
}
public function testGetLanguages() {
public function testGetLanguages(): void {
$languages = uLang::getLanguages();
$this->assertNotEmpty($languages);
$this->assertArrayHasKey("en", $languages);
$this->assertArrayHasKey("pl", $languages);
$this->assertEquals("English", $languages["en"]);
$this->assertEquals("Polski", $languages["pl"]);
self::assertNotEmpty($languages);
self::assertArrayHasKey("en", $languages);
self::assertArrayHasKey("pl", $languages);
self::assertEquals("English", $languages["en"]);
self::assertEquals("Polski", $languages["pl"]);
}
public function testGetStrings() {
public function testGetStrings(): void {
$lang = new uLang($this->mockConfig);
$this->assertEquals("User", $lang->getStrings()["user"]);
self::assertEquals("User", $lang->getStrings()["user"]);
$this->mockConfig->lang = "pl";
$lang = new uLang($this->mockConfig);
$this->assertEquals("Użytkownik", $lang->getStrings()["user"]);
self::assertEquals("Użytkownik", $lang->getStrings()["user"]);
}
public function testGetSetupStrings() {
public function testGetSetupStrings(): void {
$lang = new uLang($this->mockConfig);
$this->assertEquals("Congratulations!", $lang->getSetupStrings()["congratulations"]);
self::assertEquals("Congratulations!", $lang->getSetupStrings()["congratulations"]);
$this->mockConfig->lang = "pl";
$lang = new uLang($this->mockConfig);
$this->assertEquals("Gratulacje!", $lang->getSetupStrings()["congratulations"]);
self::assertEquals("Gratulacje!", $lang->getSetupStrings()["congratulations"]);
}
}
?>

View File

@ -24,42 +24,42 @@ require_once(dirname(__DIR__) . "/lib/UloggerDatabaseTestCase.php");
class MigrateTest extends UloggerDatabaseTestCase {
protected function tearDown() {
protected function tearDown(): void {
if ($this->getName() === "testUpdateSchemas") {
self::runSqlScript(dirname(__DIR__) . "/../scripts/ulogger." . $this->getDbDriverName());
}
parent::tearDown();
}
public function testUpdateSchemas() {
public function testUpdateSchemas(): void {
self::runSqlScript(dirname(__DIR__) . "/fixtures/ulogger_0_6." . $this->getDbDriverName());
$this->loadDataSet("fixture_0_6.xml");
$this->assertEquals(1, $this->getConnection()->getRowCount("users"), "Wrong row count");
$this->assertNotContains("admin", $this->getConnection()->getMetaData()->getTableColumns("users"));
$this->assertContains("image_id", $this->getConnection()->getMetaData()->getTableColumns("positions"));
$this->assertNotContains("ol_layers", $this->getConnection()->getMetaData()->getTableNames());
$this->assertNotContains("config", $this->getConnection()->getMetaData()->getTableNames());
self::assertEquals(1, $this->getConnection()->getRowCount("users"), "Wrong row count");
self::assertNotContains("admin", $this->getConnection()->getMetaData()->getTableColumns("users"));
self::assertContains("image_id", $this->getConnection()->getMetaData()->getTableColumns("positions"));
self::assertNotContains("ol_layers", $this->getConnection()->getMetaData()->getTableNames());
self::assertNotContains("config", $this->getConnection()->getMetaData()->getTableNames());
$this->setOutputCallback(static function() {});
$ret = updateSchemas();
$this->resetConnection();
$this->assertTrue($ret, "Function updateSchemas() failed");
$this->assertEquals(1, $this->getConnection()->getRowCount("users"), "Wrong row count");
$this->assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
$this->assertEquals(1, $this->getConnection()->getRowCount("positions"), "Wrong row count");
$this->assertContains("admin", $this->getConnection()->getMetaData()->getTableColumns("users"), "Missing table column");
$this->assertContains("image", $this->getConnection()->getMetaData()->getTableColumns("positions"), "Missing table column");
$this->assertContains("ol_layers", $this->getConnection()->getMetaData()->getTableNames(), "Missing table");
$this->assertContains("config", $this->getConnection()->getMetaData()->getTableNames(), "Missing table");
self::assertTrue($ret, "Function updateSchemas() failed");
self::assertEquals(1, $this->getConnection()->getRowCount("users"), "Wrong row count");
self::assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
self::assertEquals(1, $this->getConnection()->getRowCount("positions"), "Wrong row count");
self::assertContains("admin", $this->getConnection()->getMetaData()->getTableColumns("users"), "Missing table column");
self::assertContains("image", $this->getConnection()->getMetaData()->getTableColumns("positions"), "Missing table column");
self::assertContains("ol_layers", $this->getConnection()->getMetaData()->getTableNames(), "Missing table");
self::assertContains("config", $this->getConnection()->getMetaData()->getTableNames(), "Missing table");
}
public function testUpdateConfig() {
public function testUpdateConfig(): void {
$this->loadDataSet("fixture_non_admin.xml");
$this->setOutputCallback(static function() {});
$ret = updateConfig(dirname(__DIR__) . "/fixtures/config_0_6.php");
$this->assertTrue($ret, "Function updateConfig() failed");
self::assertTrue($ret, "Function updateConfig() failed");
// admin user imported from config file
$this->assertEquals(1, $this->getConnection()->getRowCount("users"), "Wrong row count");
$this->assertTrue((bool) $this->pdoGetColumn("SELECT admin FROM users WHERE login = 'admin'"), "User should be admin");
self::assertEquals(1, $this->getConnection()->getRowCount("users"), "Wrong row count");
self::assertTrue((bool) $this->pdoGetColumn("SELECT admin FROM users WHERE login = 'admin'"), "User should be admin");
// settings imported from config file
$expected = [ "config" => [
["name" => "color_extra", "value" => "s:7:\"#cccccc\";"], // default
@ -90,7 +90,7 @@ class MigrateTest extends UloggerDatabaseTestCase {
$expected = $this->createArrayDataSet($expected)->getTable("config");
self::assertTablesEqual($expected, $actual);
// layers imported from config file
$this->assertEquals(1, $this->getConnection()->getRowCount("ol_layers"), "Wrong row count");
self::assertEquals(1, $this->getConnection()->getRowCount("ol_layers"), "Wrong row count");
$expected = [ "id" => 1, "name" => "TestLayer", "url" => "https://test_tile.png", "priority" => 0 ];
$actual = $this->getConnection()->createQueryTable(
"ol_layers",
@ -99,19 +99,19 @@ class MigrateTest extends UloggerDatabaseTestCase {
$this->assertTableContains($expected, $actual, "Wrong actual table data");
}
public function testWaitForUser() {
public function testWaitForUser(): void {
$this->setOutputCallback(static function() {});
$yes = tmpfile();
fwrite($yes, "yes");
$ret = waitForUser(stream_get_meta_data($yes)['uri']);
fclose($yes);
$this->assertTrue($ret, "Wrong return status");
self::assertTrue($ret, "Wrong return status");
$no = tmpfile();
fwrite($no, "no");
$ret = waitForUser(stream_get_meta_data($no)['uri']);
fclose($no);
$this->assertFalse($ret, "Wrong return status");
self::assertFalse($ret, "Wrong return status");
}
/**
@ -120,7 +120,7 @@ class MigrateTest extends UloggerDatabaseTestCase {
* @param string $path Script path
* @throws PDOException
*/
private static function runSqlScript($path) {
private static function runSqlScript(string $path): void {
$script = file_get_contents($path);
$count = preg_match_all('/^(?:(?:DROP|CREATE) (?:TABLE|INDEX)|INSERT|PRAGMA|SET) .*?;\s*$/smi', $script, $queries);
if ($count) {
@ -146,7 +146,7 @@ class MigrateTest extends UloggerDatabaseTestCase {
return uDb::getInstance()->getAttribute(PDO::ATTR_DRIVER_NAME);
}
private function loadDataSet($name) {
private function loadDataSet($name): void {
$this->resetAutoincrement();
$dataSet = $this->createFlatXMLDataSet(dirname(__DIR__) . '/fixtures/' . $name);
$this->getDatabaseTester()->setDataSet($dataSet);

View File

@ -5,21 +5,21 @@ require_once(__DIR__ . "/../../helpers/track.php");
class PositionTest extends UloggerDatabaseTestCase {
public function testAddPosition() {
public function testAddPosition(): void {
$userId = $this->addTestUser();
$trackId = $this->addTestTrack($userId);
$this->assertEquals(1, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
self::assertEquals(1, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
$posId = uPosition::add($userId, $trackId + 1, $this->testTimestamp, $this->testLat, $this->testLon, $this->testAltitude, $this->testSpeed, $this->testBearing, $this->testAccuracy, $this->testProvider, $this->testComment, $this->testImage);
$this->assertEquals(0, $this->getConnection()->getRowCount('positions'), "Wrong row count");
$this->assertFalse($posId, "Adding position with nonexistant track should fail");
self::assertEquals(0, $this->getConnection()->getRowCount('positions'), "Wrong row count");
self::assertFalse($posId, "Adding position with nonexistant track should fail");
$posId = uPosition::add($userId + 1, $trackId, $this->testTimestamp, $this->testLat, $this->testLon, $this->testAltitude, $this->testSpeed, $this->testBearing, $this->testAccuracy, $this->testProvider, $this->testComment, $this->testImage);
$this->assertEquals(0, $this->getConnection()->getRowCount('positions'), "Wrong row count");
$this->assertFalse($posId, "Adding position with wrong user should fail");
self::assertEquals(0, $this->getConnection()->getRowCount('positions'), "Wrong row count");
self::assertFalse($posId, "Adding position with wrong user should fail");
$posId = uPosition::add($userId, $trackId, $this->testTimestamp, $this->testLat, $this->testLon, $this->testAltitude, $this->testSpeed, $this->testBearing, $this->testAccuracy, $this->testProvider, $this->testComment, $this->testImage);
$this->assertEquals(1, $this->getConnection()->getRowCount('positions'), "Wrong row count");
self::assertEquals(1, $this->getConnection()->getRowCount('positions'), "Wrong row count");
$expected = [
"id" => $posId,
"user_id" => $this->testUserId,
@ -42,21 +42,21 @@ class PositionTest extends UloggerDatabaseTestCase {
$this->assertTableContains($expected, $actual, "Wrong actual table data");
$posId = uPosition::add($userId, $trackId, NULL, $this->testLat, $this->testLon);
$this->assertFalse($posId, "Adding position with null time stamp should fail");
self::assertFalse($posId, "Adding position with null time stamp should fail");
$posId = uPosition::add($userId, $trackId, $this->testTimestamp, NULL, $this->testLon);
$this->assertFalse($posId, "Adding position with null latitude should fail");
self::assertFalse($posId, "Adding position with null latitude should fail");
$posId = uPosition::add($userId, $trackId, $this->testTimestamp, $this->testLat, NULL);
$this->assertFalse($posId, "Adding position with null longitude should fail");
self::assertFalse($posId, "Adding position with null longitude should fail");
$posId = uPosition::add($userId, $trackId, "", $this->testLat, $this->testLon);
$this->assertFalse($posId, "Adding position with empty time stamp should fail");
self::assertFalse($posId, "Adding position with empty time stamp should fail");
$posId = uPosition::add($userId, $trackId, $this->testTimestamp, "", $this->testLon);
$this->assertFalse($posId, "Adding position with empty latitude should fail");
self::assertFalse($posId, "Adding position with empty latitude should fail");
$posId = uPosition::add($userId, $trackId, $this->testTimestamp, $this->testLat, "");
$this->assertFalse($posId, "Adding position with empty longitude should fail");
self::assertFalse($posId, "Adding position with empty longitude should fail");
}
public function testDeleteAll() {
public function testDeleteAll(): void {
$userId = $this->addTestUser();
$userId2 = $this->addTestUser($this->testUser2);
$trackId = $this->addTestTrack($userId);
@ -65,14 +65,14 @@ class PositionTest extends UloggerDatabaseTestCase {
$this->addTestPosition($userId, $trackId2);
$trackId3 = $this->addTestTrack($userId2);
$this->addTestPosition($userId2, $trackId3);
$this->assertEquals(3, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
$this->assertEquals(3, $this->getConnection()->getRowCount('positions'), "Wrong row count");
self::assertEquals(3, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
self::assertEquals(3, $this->getConnection()->getRowCount('positions'), "Wrong row count");
$this->assertTrue(uPosition::deleteAll($userId), "Deleting failed");
$this->assertEquals(1, $this->getConnection()->getRowCount('positions'), "Wrong row count");
self::assertTrue(uPosition::deleteAll($userId), "Deleting failed");
self::assertEquals(1, $this->getConnection()->getRowCount('positions'), "Wrong row count");
}
public function testDeleteAllWIthTrackId() {
public function testDeleteAllWIthTrackId(): void {
$userId = $this->addTestUser();
$userId2 = $this->addTestUser($this->testUser2);
$trackId = $this->addTestTrack($userId);
@ -81,14 +81,14 @@ class PositionTest extends UloggerDatabaseTestCase {
$this->addTestPosition($userId, $trackId2);
$trackId3 = $this->addTestTrack($userId2);
$this->addTestPosition($userId2, $trackId3);
$this->assertEquals(3, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
$this->assertEquals(3, $this->getConnection()->getRowCount('positions'), "Wrong row count");
self::assertEquals(3, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
self::assertEquals(3, $this->getConnection()->getRowCount('positions'), "Wrong row count");
$this->assertTrue(uPosition::deleteAll($userId, $trackId), "Deleting failed");
$this->assertEquals(2, $this->getConnection()->getRowCount('positions'), "Wrong row count");
self::assertTrue(uPosition::deleteAll($userId, $trackId), "Deleting failed");
self::assertEquals(2, $this->getConnection()->getRowCount('positions'), "Wrong row count");
}
public function testGetLast() {
public function testGetLast(): void {
$userId = $this->addTestUser();
$userId2 = $this->addTestUser($this->testUser2);
$trackId1 = $this->addTestTrack($userId);
@ -97,15 +97,15 @@ class PositionTest extends UloggerDatabaseTestCase {
$pos2 = $this->addTestPosition($userId2, $trackId2, $this->testTimestamp + 1);
$pos3 = $this->addTestPosition($userId, $trackId1, $this->testTimestamp);
$pos4 = $this->addTestPosition($userId2, $trackId2, $this->testTimestamp + 2);
$this->assertEquals(2, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
$this->assertEquals(4, $this->getConnection()->getRowCount('positions'), "Wrong row count");
self::assertEquals(2, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
self::assertEquals(4, $this->getConnection()->getRowCount('positions'), "Wrong row count");
$lastPosition = uPosition::getLast();
$this->assertEquals($lastPosition->id, $pos1, "Wrong last position");
self::assertEquals($lastPosition->id, $pos1, "Wrong last position");
$lastPosition = uPosition::getLast($this->testUserId2);
$this->assertEquals($lastPosition->id, $pos4, "Wrong last position (user)");
self::assertEquals($lastPosition->id, $pos4, "Wrong last position (user)");
}
public function testGetLastAllUsers() {
public function testGetLastAllUsers(): void {
$userId = $this->addTestUser();
$userId2 = $this->addTestUser($this->testUser2);
$trackId1 = $this->addTestTrack($userId);
@ -114,30 +114,30 @@ class PositionTest extends UloggerDatabaseTestCase {
$pos2 = $this->addTestPosition($userId2, $trackId2, $this->testTimestamp + 1);
$pos3 = $this->addTestPosition($userId, $trackId1, $this->testTimestamp);
$pos4 = $this->addTestPosition($userId2, $trackId2, $this->testTimestamp + 2);
$this->assertEquals(2, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
$this->assertEquals(4, $this->getConnection()->getRowCount('positions'), "Wrong row count");
self::assertEquals(2, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
self::assertEquals(4, $this->getConnection()->getRowCount('positions'), "Wrong row count");
$posArr = uPosition::getLastAllUsers();
$this->assertCount(2, $posArr, "Wrong row count");
self::assertCount(2, $posArr, "Wrong row count");
foreach ($posArr as $position) {
/** @var uPosition $position */
switch ($position->id) {
case 1:
$this->assertEquals($this->testTimestamp + 3, $position->timestamp);
$this->assertEquals($userId, $position->userId);
$this->assertEquals($trackId1, $position->trackId);
self::assertEquals($this->testTimestamp + 3, $position->timestamp);
self::assertEquals($userId, $position->userId);
self::assertEquals($trackId1, $position->trackId);
break;
case 4:
$this->assertEquals($this->testTimestamp + 2, $position->timestamp);
$this->assertEquals($userId2, $position->userId);
$this->assertEquals($trackId2, $position->trackId);
self::assertEquals($this->testTimestamp + 2, $position->timestamp);
self::assertEquals($userId2, $position->userId);
self::assertEquals($trackId2, $position->trackId);
break;
default:
$this->assertTrue(false, "Unexpected position: {$position->id}");
self::assertTrue(false, "Unexpected position: $position->id");
}
}
}
public function testGetAll() {
public function testGetAll(): void {
$userId = $this->addTestUser();
$userId2 = $this->addTestUser($this->testUser2);
$userId3 = $this->addTestUser("testUser3");
@ -147,39 +147,39 @@ class PositionTest extends UloggerDatabaseTestCase {
$this->addTestPosition($userId, $trackId2);
$trackId3 = $this->addTestTrack($userId2);
$this->addTestPosition($userId2, $trackId3);
$this->assertEquals(3, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
$this->assertEquals(3, $this->getConnection()->getRowCount('positions'), "Wrong row count");
self::assertEquals(3, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
self::assertEquals(3, $this->getConnection()->getRowCount('positions'), "Wrong row count");
$posArr = uPosition::getAll();
$this->assertCount(3, $posArr, "Wrong row count");
self::assertCount(3, $posArr, "Wrong row count");
$posArr = uPosition::getAll($userId);
$this->assertCount(2, $posArr, "Wrong row count");
self::assertCount(2, $posArr, "Wrong row count");
$posArr = uPosition::getAll($userId, $trackId);
$this->assertCount(1, $posArr, "Wrong row count");
self::assertCount(1, $posArr, "Wrong row count");
$posArr = uPosition::getAll(NULL, $trackId);
$this->assertCount(1, $posArr, "Wrong row count");
self::assertCount(1, $posArr, "Wrong row count");
$posArr = uPosition::getAll($userId3);
$this->assertCount(0, $posArr, "Wrong row count");
self::assertCount(0, $posArr, "Wrong row count");
}
public function testDistanceTo() {
public function testDistanceTo(): void {
$userId = $this->addTestUser();
$trackId = $this->addTestTrack($userId);
$pos1 = $this->addTestPosition($userId, $trackId, $this->testTimestamp, 0, 0);
$pos2 = $this->addTestPosition($userId, $trackId, $this->testTimestamp, 0, 1);
$posArr = uPosition::getAll();
$this->assertCount(2, $posArr, "Wrong row count");
$this->assertEquals(111195, round($posArr[0]->distanceTo($posArr[1])), "Wrong distance");
self::assertCount(2, $posArr, "Wrong row count");
self::assertEquals(111195, round($posArr[0]->distanceTo($posArr[1])), "Wrong distance");
}
public function testSecondsTo() {
public function testSecondsTo(): void {
$userId = $this->addTestUser();
$trackId = $this->addTestTrack($userId);
$pos1 = $this->addTestPosition($userId, $trackId, $this->testTimestamp);
$pos2 = $this->addTestPosition($userId, $trackId, $this->testTimestamp + 1);
$posArr = uPosition::getAll();
$this->assertCount(2, $posArr, "Wrong row count");
$this->assertEquals(-1, $posArr[0]->secondsTo($posArr[1]), "Wrong time difference");
self::assertCount(2, $posArr, "Wrong row count");
self::assertEquals(-1, $posArr[0]->secondsTo($posArr[1]), "Wrong time difference");
}
}

View File

@ -1,29 +1,40 @@
<?php
use GuzzleHttp\Exception\GuzzleException;
require_once(__DIR__ . "/../lib/UloggerAPITestCase.php");
class SetupTest extends UloggerAPITestCase {
private $script = "/scripts/setup.php";
public function testPrePhase() {
/**
* @throws GuzzleException
*/
public function testPrePhase(): void {
$response = $this->http->get($this->script);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
$body = (string) $response->getBody();
$this->assertContains("<input type=\"hidden\" name=\"command\" value=\"setup\">", $body);
self::assertStringContainsString("<input type=\"hidden\" name=\"command\" value=\"setup\">", $body);
}
public function testSetupPhase() {
/**
* @throws GuzzleException
*/
public function testSetupPhase(): void {
$options = [
"http_errors" => false,
"form_params" => [ "command" => "setup" ]
];
$response = $this->http->post($this->script, $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
$body = (string) $response->getBody();
$this->assertContains("<input type=\"hidden\" name=\"command\" value=\"adduser\">", $body);
self::assertStringContainsString("<input type=\"hidden\" name=\"command\" value=\"adduser\">", $body);
}
public function testAdduserPhase() {
/**
* @throws GuzzleException
*/
public function testAdduserPhase(): void {
$options = [
"http_errors" => false,
"form_params" => [
@ -34,14 +45,14 @@ class SetupTest extends UloggerAPITestCase {
]
];
$response = $this->http->post($this->script, $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
$body = (string) $response->getBody();
$this->assertContains("<span class=\"ok\">", $body);
$this->assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count");
self::assertStringContainsString("<span class=\"ok\">", $body);
self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count");
$expected = [ "id" => 2, "login" => $this->testUser, "admin" => 1 ];
$actual = $this->getConnection()->createQueryTable("users", "SELECT id, login, admin FROM users WHERE id = 2");
$this->assertTableContains($expected, $actual, "Wrong actual table data");
$this->assertTrue(password_verify($this->testPass, $this->pdoGetColumn("SELECT password FROM users WHERE id = 2")), "Wrong actual password hash");
self::assertTrue(password_verify($this->testPass, $this->pdoGetColumn("SELECT password FROM users WHERE id = 2")), "Wrong actual password hash");
}
}

View File

@ -1,57 +1,56 @@
<?php
use PHPUnit\Framework\TestCase;
require_once(__DIR__ . "/../lib/UloggerDatabaseTestCase.php");
require_once(__DIR__ . "/../../helpers/track.php");
class TrackTest extends UloggerDatabaseTestCase {
public function testAddTrack() {
public function testAddTrack(): void {
$this->addTestUser();
$trackId = uTrack::add($this->testUserId, $this->testTrackName, $this->testTrackComment);
$this->assertNotFalse($trackId, "Track id should not be false");
$this->assertEquals(1, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
$this->assertEquals(1, $trackId, "Wrong track id returned");
self::assertNotFalse($trackId, "Track id should not be false");
self::assertEquals(1, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
self::assertEquals(1, $trackId, "Wrong track id returned");
$expected = [ "id" => $trackId, "user_id" => $this->testUserId, "name" => $this->testTrackName, "comment" => $this->testTrackComment ];
$actual = $this->getConnection()->createQueryTable("tracks", "SELECT id, user_id, name, comment FROM tracks");
$this->assertTableContains($expected, $actual, "Wrong actual table data");
$this->assertFalse(uTrack::add("", $this->testTrackName), "Adding track with empty user id should fail");
$this->assertFalse(uTrack::add($this->testUserId, ""), "Adding track with empty name should fail");
self::assertFalse(uTrack::add("", $this->testTrackName), "Adding track with empty user id should fail");
self::assertFalse(uTrack::add($this->testUserId, ""), "Adding track with empty name should fail");
}
public function testDeleteTrack() {
public function testDeleteTrack(): void {
$userId = $this->addTestUser();
$trackId = $this->addTestTrack($userId);
$this->addTestPosition($userId, $trackId);
$this->assertEquals(1, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
$this->assertEquals(1, $this->getConnection()->getRowCount('positions'), "Wrong row count");
self::assertEquals(1, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
self::assertEquals(1, $this->getConnection()->getRowCount('positions'), "Wrong row count");
$track = new uTrack($trackId);
$track->delete();
$this->assertEquals(0, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
$this->assertEquals(0, $this->getConnection()->getRowCount('positions'), "Wrong row count");
$this->assertFalse($track->isValid, "Deleted track should not be valid");
self::assertEquals(0, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
self::assertEquals(0, $this->getConnection()->getRowCount('positions'), "Wrong row count");
self::assertFalse($track->isValid, "Deleted track should not be valid");
}
public function testAddPosition() {
public function testAddPosition(): void {
$userId = $this->addTestUser();
$userId2 = $this->addTestUser($this->testUser2);
$trackId = $this->addTestTrack($userId);
$this->assertEquals(1, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
self::assertEquals(1, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
$track = new uTrack($trackId + 1);
$posId = $track->addPosition($userId, $this->testTimestamp, $this->testLat, $this->testLon, $this->testAltitude, $this->testSpeed, $this->testBearing, $this->testAccuracy, $this->testProvider, $this->testComment, $this->testImage);
$this->assertEquals(0, $this->getConnection()->getRowCount('positions'), "Wrong row count");
$this->assertFalse($posId, "Adding position with nonexistant track should fail");
self::assertEquals(0, $this->getConnection()->getRowCount('positions'), "Wrong row count");
self::assertFalse($posId, "Adding position with nonexistant track should fail");
$track = new uTrack($trackId);
$posId = $track->addPosition($userId2, $this->testTimestamp, $this->testLat, $this->testLon, $this->testAltitude, $this->testSpeed, $this->testBearing, $this->testAccuracy, $this->testProvider, $this->testComment, $this->testImage);
$this->assertEquals(0, $this->getConnection()->getRowCount('positions'), "Wrong row count");
$this->assertFalse($posId, "Adding position with wrong user should fail");
self::assertEquals(0, $this->getConnection()->getRowCount('positions'), "Wrong row count");
self::assertFalse($posId, "Adding position with wrong user should fail");
$posId = $track->addPosition($userId, $this->testTimestamp, $this->testLat, $this->testLon, $this->testAltitude, $this->testSpeed, $this->testBearing, $this->testAccuracy, $this->testProvider, $this->testComment, $this->testImage);
$this->assertEquals(1, $this->getConnection()->getRowCount('positions'), "Wrong row count");
self::assertEquals(1, $this->getConnection()->getRowCount('positions'), "Wrong row count");
$expected = [
"id" => $posId,
"user_id" => $this->testUserId,
@ -74,31 +73,31 @@ class TrackTest extends UloggerDatabaseTestCase {
$this->assertTableContains($expected, $actual, "Wrong actual table data");
$posId = $track->addPosition($userId, NULL, $this->testLat, $this->testLon);
$this->assertFalse($posId, "Adding position with null time stamp should fail");
self::assertFalse($posId, "Adding position with null time stamp should fail");
$posId = $track->addPosition($userId, $this->testTimestamp, NULL, $this->testLon);
$this->assertFalse($posId, "Adding position with null latitude should fail");
self::assertFalse($posId, "Adding position with null latitude should fail");
$posId = $track->addPosition($userId, $this->testTimestamp, $this->testLat, NULL);
$this->assertFalse($posId, "Adding position with null longitude should fail");
self::assertFalse($posId, "Adding position with null longitude should fail");
$posId = $track->addPosition($userId, "", $this->testLat, $this->testLon);
$this->assertFalse($posId, "Adding position with empty time stamp should fail");
self::assertFalse($posId, "Adding position with empty time stamp should fail");
$posId = $track->addPosition($userId, $this->testTimestamp, "", $this->testLon);
$this->assertFalse($posId, "Adding position with empty latitude should fail");
self::assertFalse($posId, "Adding position with empty latitude should fail");
$posId = $track->addPosition($userId, $this->testTimestamp, $this->testLat, "");
$this->assertFalse($posId, "Adding position with empty longitude should fail");
self::assertFalse($posId, "Adding position with empty longitude should fail");
}
public function testGetAll() {
public function testGetAll(): void {
$this->addTestTrack($this->addTestUser());
$this->addTestTrack($this->addTestUser($this->testUser2));
$this->assertEquals(2, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
self::assertEquals(2, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
$trackArr = uTrack::getAll();
$this->assertEquals(2, count($trackArr), "Wrong array size");
$this->assertTrue($trackArr[0] instanceof uTrack, "Wrong array member");
self::assertCount(2, $trackArr, "Wrong array size");
self::assertInstanceOf(uTrack::class, $trackArr[0], "Wrong array member");
}
public function testDeleteAll() {
public function testDeleteAll(): void {
$userId = $this->addTestUser();
$trackId = $this->addTestTrack($userId);
$this->addTestTrack($userId);
@ -108,16 +107,16 @@ class TrackTest extends UloggerDatabaseTestCase {
$trackId2 = $this->addTestTrack($userId2);
$this->addTestPosition($userId2, $trackId2);
$this->assertEquals(3, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
$this->assertEquals(2, $this->getConnection()->getRowCount('positions'), "Wrong row count");
self::assertEquals(3, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
self::assertEquals(2, $this->getConnection()->getRowCount('positions'), "Wrong row count");
uTrack::deleteAll($userId);
$this->assertEquals(1, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
$this->assertEquals(1, $this->getConnection()->getRowCount('positions'), "Wrong row count");
$this->assertFalse(uTrack::deleteAll(NULL), "User id should not be empty");
self::assertEquals(1, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
self::assertEquals(1, $this->getConnection()->getRowCount('positions'), "Wrong row count");
self::assertFalse(uTrack::deleteAll(NULL), "User id should not be empty");
}
public function testUpdate() {
public function testUpdate(): void {
$userId = $this->addTestUser();
$trackId = $this->addTestTrack($userId);
$track = new uTrack($trackId);
@ -127,16 +126,16 @@ class TrackTest extends UloggerDatabaseTestCase {
$this->assertTableContains($expected, $actual, "Wrong actual table data");
$trackInvalid = new uTrack($trackId + 1);
$this->assertFalse($trackInvalid->update("newName", "newComment"), "Updating nonexistant track should fail");
self::assertFalse($trackInvalid->update("newName", "newComment"), "Updating nonexistant track should fail");
}
public function testIsValid() {
public function testIsValid(): void {
$userId = $this->addTestUser();
$trackId = $this->addTestTrack($userId);
$trackValid = new uTrack($trackId);
$this->assertTrue($trackValid->isValid, "Track should be valid");
self::assertTrue($trackValid->isValid, "Track should be valid");
$trackInvalid = new uTrack($trackId + 1);
$this->assertFalse($trackInvalid->isValid, "Track should not be valid");
self::assertFalse($trackInvalid->isValid, "Track should not be valid");
}
}
?>

View File

@ -5,93 +5,93 @@ require_once(__DIR__ . "/../../helpers/user.php");
class UserTest extends UloggerDatabaseTestCase {
public function testAddUser() {
public function testAddUser(): void {
$userId = uUser::add($this->testUser, $this->testPass);
$this->assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count");
$this->assertEquals(1, $userId, "Wrong user id returned");
self::assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count");
self::assertEquals(1, $userId, "Wrong user id returned");
$expected = [ "id" => 1, "login" => $this->testUser ];
$actual = $this->getConnection()->createQueryTable("users", "SELECT id, login FROM users");
$this->assertTableContains($expected, $actual, "Wrong actual table data");
$this->assertTrue(password_verify($this->testPass, $this->pdoGetColumn("SELECT password FROM users")), "Wrong actual password hash");
$this->assertFalse(uUser::add($this->testUser, $this->testPass), "Adding user with same login should fail");
$this->assertFalse(uUser::add($this->testUser, ""), "Adding user with empty password should fail");
$this->assertFalse(uUser::add("", $this->testPass), "Adding user with empty login should fail");
self::assertTrue(password_verify($this->testPass, $this->pdoGetColumn("SELECT password FROM users")), "Wrong actual password hash");
self::assertFalse(uUser::add($this->testUser, $this->testPass), "Adding user with same login should fail");
self::assertFalse(uUser::add($this->testUser, ""), "Adding user with empty password should fail");
self::assertFalse(uUser::add("", $this->testPass), "Adding user with empty login should fail");
}
public function testDeleteUser() {
public function testDeleteUser(): void {
$userId = $this->addTestUser($this->testUser);
$trackId = $this->addTestTrack($userId);
$this->addTestPosition($userId, $trackId);
$this->assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count");
$this->assertEquals(1, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
$this->assertEquals(1, $this->getConnection()->getRowCount('positions'), "Wrong row count");
self::assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count");
self::assertEquals(1, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
self::assertEquals(1, $this->getConnection()->getRowCount('positions'), "Wrong row count");
$user = new uUser($this->testUser);
$user->delete();
$this->assertEquals(0, $this->getConnection()->getRowCount('users'), "Wrong row count");
$this->assertEquals(0, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
$this->assertEquals(0, $this->getConnection()->getRowCount('positions'), "Wrong row count");
$this->assertFalse($user->isValid, "Deleted user should not be valid");
self::assertEquals(0, $this->getConnection()->getRowCount('users'), "Wrong row count");
self::assertEquals(0, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
self::assertEquals(0, $this->getConnection()->getRowCount('positions'), "Wrong row count");
self::assertFalse($user->isValid, "Deleted user should not be valid");
}
public function testSetPass() {
public function testSetPass(): void {
$newPass = $this->testPass . "new";
$this->addTestUser($this->testUser);
$this->assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count");
self::assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count");
$user = new uUser($this->testUser);
$user->setPass($newPass);
$this->assertTrue(password_verify($newPass, $this->pdoGetColumn("SELECT password FROM users")), "Wrong actual password hash");
$this->assertFalse($user->setPass(""), "Password should not be empty");
self::assertTrue(password_verify($newPass, $this->pdoGetColumn("SELECT password FROM users")), "Wrong actual password hash");
self::assertFalse($user->setPass(""), "Password should not be empty");
$userInvalid = new uUser($this->testUser . "-noexistant");
$this->assertFalse($userInvalid->setPass($newPass), "Setting pass for nonexistant user should fail");
self::assertFalse($userInvalid->setPass($newPass), "Setting pass for nonexistant user should fail");
}
public function testSetAdmin() {
public function testSetAdmin(): void {
$this->addTestUser($this->testUser);
$this->assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count");
self::assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count");
$user = new uUser($this->testUser);
$this->assertFalse((bool) $this->pdoGetColumn("SELECT admin FROM users"), "User should not be admin");
$this->assertFalse($user->isAdmin, "User should not be admin");
self::assertFalse((bool) $this->pdoGetColumn("SELECT admin FROM users"), "User should not be admin");
self::assertFalse($user->isAdmin, "User should not be admin");
$user->setAdmin(true);
$this->assertTrue((bool) $this->pdoGetColumn("SELECT admin FROM users"), "User should be admin");
$this->assertTrue($user->isAdmin, "User should be admin");
self::assertTrue((bool) $this->pdoGetColumn("SELECT admin FROM users"), "User should be admin");
self::assertTrue($user->isAdmin, "User should be admin");
$user->setAdmin(false);
$this->assertFalse((bool) $this->pdoGetColumn("SELECT admin FROM users"), "User should not be admin");
$this->assertFalse($user->isAdmin, "User should not be admin");
self::assertFalse((bool) $this->pdoGetColumn("SELECT admin FROM users"), "User should not be admin");
self::assertFalse($user->isAdmin, "User should not be admin");
}
public function testGetAll() {
public function testGetAll(): void {
$this->addTestUser($this->testUser);
$this->addTestUser($this->testUser2);
$this->assertEquals(2, $this->getConnection()->getRowCount('users'), "Wrong row count");
self::assertEquals(2, $this->getConnection()->getRowCount('users'), "Wrong row count");
$userArr = uUser::getAll();
$this->assertCount(2, $userArr, "Wrong array size");
$this->assertInstanceOf(uUser::class, $userArr[0], "Wrong array member");
self::assertCount(2, $userArr, "Wrong array size");
self::assertInstanceOf(uUser::class, $userArr[0], "Wrong array member");
}
public function testIsAdmin() {
public function testIsAdmin(): void {
$this->addTestUser($this->testUser, NULL, true);
$user = new uUser($this->testUser);
$this->assertTrue($user->isAdmin, "User should be admin");
self::assertTrue($user->isAdmin, "User should be admin");
}
public function testIsNotAdmin() {
public function testIsNotAdmin(): void {
$this->addTestUser($this->testUser);
$user = new uUser($this->testUser);
$this->assertFalse($user->isAdmin, "User should not be admin");
self::assertFalse($user->isAdmin, "User should not be admin");
}
public function testIsValid() {
public function testIsValid(): void {
$this->addTestUser($this->testUser);
$userValid = new uUser($this->testUser);
$this->assertTrue($userValid->isValid, "User should be valid");
self::assertTrue($userValid->isValid, "User should be valid");
$userInvalid = new uUser($this->testUser . "-noexistant");
$this->assertFalse($userInvalid->isValid, "User should not be valid");
self::assertFalse($userInvalid->isValid, "User should not be valid");
}
}
?>

View File

@ -1,33 +1,38 @@
<?php
use PHPUnit\Framework\TestCase;
require_once(__DIR__ . "/../../helpers/utils.php");
class UtilsTest extends TestCase {
public function testGetUploadMaxSize() {
/**
* @throws ReflectionException
*/
public function testGetUploadMaxSize(): void {
$iniGetBytes = new ReflectionMethod('uUtils', 'iniGetBytes');
$iniGetBytes->setAccessible(true);
ini_set("memory_limit", "1G");
$result = $iniGetBytes->invoke(null, "memory_limit");
$this->assertEquals(1024 * 1024 * 1024, $result);
self::assertEquals(1024 * 1024 * 1024, $result);
ini_set("memory_limit", 100 . "M");
$result = $iniGetBytes->invoke(null, "memory_limit");
$this->assertEquals(100 * 1024 * 1024, $result);
self::assertEquals(100 * 1024 * 1024, $result);
ini_set("memory_limit", 100 * 1024 . "K");
$result = $iniGetBytes->invoke(null, "memory_limit");
$this->assertEquals(100 * 1024 * 1024, $result);
self::assertEquals(100 * 1024 * 1024, $result);
ini_set("memory_limit", 100 * 1024 * 1024);
$result = $iniGetBytes->invoke(null, "memory_limit");
$this->assertEquals(100 * 1024 * 1024, $result);
self::assertEquals(100 * 1024 * 1024, $result);
}
public function testGetBaseUrlMain() {
/** @noinspection HttpUrlsUsage */
public function testGetBaseUrlMain(): void {
if (!defined("ROOT_DIR")) {
define("ROOT_DIR", "/var/www/html/ulogger");
}
@ -38,10 +43,11 @@ class UtilsTest extends TestCase {
$_SERVER["PHP_SELF"] = "/index.php";
$result = uUtils::getBaseUrl();
$expected = "http://www.example.com/";
$this->assertEquals($expected, $result);
self::assertEquals($expected, $result);
}
public function testGetBaseUrlScript() {
/** @noinspection HttpUrlsUsage */
public function testGetBaseUrlScript(): void {
if (!defined("ROOT_DIR")) {
define("ROOT_DIR", "/var/www/html");
}
@ -52,10 +58,11 @@ class UtilsTest extends TestCase {
$_SERVER["PHP_SELF"] = "/utils/test.php";
$result = uUtils::getBaseUrl();
$expected = "http://www.example.com/";
$this->assertEquals($expected, $result);
self::assertEquals($expected, $result);
}
public function testGetBaseUrlSubfolder() {
/** @noinspection HttpUrlsUsage */
public function testGetBaseUrlSubfolder(): void {
if (!defined("ROOT_DIR")) {
define("ROOT_DIR", "/var/www/html");
}
@ -66,10 +73,10 @@ class UtilsTest extends TestCase {
$_SERVER["PHP_SELF"] = "/ulogger/index.php";
$result = uUtils::getBaseUrl();
$expected = "http://www.example.com/ulogger/";
$this->assertEquals($expected, $result);
self::assertEquals($expected, $result);
}
public function testGetBaseUrlHttps() {
public function testGetBaseUrlHttps(): void {
if (!defined("ROOT_DIR")) {
define("ROOT_DIR", "/var/www/html");
}
@ -80,10 +87,11 @@ class UtilsTest extends TestCase {
$_SERVER["PHP_SELF"] = "/index.php";
$result = uUtils::getBaseUrl();
$expected = "https://www.example.com/";
$this->assertEquals($expected, $result);
self::assertEquals($expected, $result);
}
public function testGetBaseUrlHttp() {
/** @noinspection HttpUrlsUsage */
public function testGetBaseUrlHttp(): void {
if (!defined("ROOT_DIR")) {
define("ROOT_DIR", "/var/www/html");
}
@ -94,26 +102,26 @@ class UtilsTest extends TestCase {
$_SERVER["PHP_SELF"] = "/index.php";
$result = uUtils::getBaseUrl();
$expected = "http://www.example.com/";
$this->assertEquals($expected, $result);
self::assertEquals($expected, $result);
unset($_SERVER["HTTPS"]);
$this->assertEquals($expected, $result);
self::assertEquals($expected, $result);
}
public function testIsAbsolutePath() {
$this->assertTrue(uUtils::isAbsolutePath("/foo"));
$this->assertTrue(uUtils::isAbsolutePath("/foo/bar"));
$this->assertTrue(uUtils::isAbsolutePath("/"));
$this->assertTrue(uUtils::isAbsolutePath("/."));
$this->assertTrue(uUtils::isAbsolutePath("\\"));
$this->assertTrue(uUtils::isAbsolutePath("C:\\\\foo"));
$this->assertTrue(uUtils::isAbsolutePath("Z:\\\\FOO/BAR"));
public function testIsAbsolutePath(): void {
self::assertTrue(uUtils::isAbsolutePath("/foo"));
self::assertTrue(uUtils::isAbsolutePath("/foo/bar"));
self::assertTrue(uUtils::isAbsolutePath("/"));
self::assertTrue(uUtils::isAbsolutePath("/."));
self::assertTrue(uUtils::isAbsolutePath("\\"));
self::assertTrue(uUtils::isAbsolutePath("C:\\\\foo"));
self::assertTrue(uUtils::isAbsolutePath("Z:\\\\FOO/BAR"));
$this->assertFalse(uUtils::isAbsolutePath("foo"));
$this->assertFalse(uUtils::isAbsolutePath("foo/bar"));
$this->assertFalse(uUtils::isAbsolutePath("./foo"));
$this->assertFalse(uUtils::isAbsolutePath("../"));
$this->assertFalse(uUtils::isAbsolutePath(".\\foo"));
self::assertFalse(uUtils::isAbsolutePath("foo"));
self::assertFalse(uUtils::isAbsolutePath("foo/bar"));
self::assertFalse(uUtils::isAbsolutePath("./foo"));
self::assertFalse(uUtils::isAbsolutePath("../"));
self::assertFalse(uUtils::isAbsolutePath(".\\foo"));
}
}
?>

View File

@ -3,7 +3,7 @@ os: linux
dist: xenial
php:
- 7.2
- 7.4
env:
jobs:
@ -63,7 +63,7 @@ after_failure:
- docker logs ulogger
script:
- ./vendor/bin/phpunit -c .tests/phpunit.xml
- XDEBUG_MODE=coverage ./vendor/bin/phpunit -c .tests/phpunit.xml
- npm test
- npm run lint:js
- npm run lint:css

View File

@ -66,9 +66,10 @@ Together with a dedicated [μlogger mobile client](https://github.com/bfabiszews
- For example: `docker run --name ulogger -e ULOGGER_LANG="pl" -p 8080:80 -d bfabiszewski/ulogger`
- You may also build the image yourself. Run `docker build .` from the root folder where `Dockerfile` reside. There are optional build-time arguments that allow you to set default database passwords for root and ulogger users
- For example: `docker build --build-arg DB_ROOT_PASS=secret1 --build-arg DB_USER_PASS=secret2 --build-arg DB_DRIVER=sqlite .`
- Docker was created to facilitate development and testing. It is not production ready. If you want to use it in production, you will have to adjust it to your needs.
## Tests
- Install tests dependecies.
- Install tests dependecies. PHP tests require PHP >= 7.3.
- `composer install`
- `npm install`
- Integration tests may be run against docker image. We need exposed http and optionally database ports (eg. mapped to localhost 8080 and 8081). Below example for MySQL setup
@ -80,7 +81,7 @@ Together with a dedicated [μlogger mobile client](https://github.com/bfabiszews
- `DB_PASS=secret2`
- `ULOGGER_URL="http://127.0.0.1:8080"`
- PHP tests
- `./vendor/bin/phpunit -c .tests/phpunit.xml`
- `XDEBUG_MODE=coverage ./vendor/bin/phpunit -c .tests/phpunit.xml`
- JS tests
- `npm test`
- Other tests

View File

@ -1,4 +1,6 @@
{
"name": "bfabiszewski/ulogger-server",
"description": "ulogger server",
"require": {
"ulrichsg/getopt-php": "^3.2",
"ext-json": "*",
@ -8,12 +10,13 @@
"ext-libxml": "*"
},
"scripts": {
"test": "./vendor/bin/phpunit"
"test": [ "@putenv XDEBUG_MODE=coverage", "./vendor/bin/phpunit" ]
},
"require-dev": {
"phpunit/phpunit": "^5.7",
"vlucas/phpdotenv": "^3.3",
"guzzlehttp/guzzle": "^6.3",
"phpunit/dbunit": "^2.0"
"roave/security-advisories": "dev-latest",
"phpunit/phpunit": "^9.5",
"vlucas/phpdotenv": "^5.3",
"guzzlehttp/guzzle": "^7.3",
"kornrunner/dbunit": "^6.0"
}
}

2602
composer.lock generated

File diff suppressed because it is too large Load Diff