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

View File

@ -1,5 +1,7 @@
<?php <?php
use PHPUnit\Framework\TestCase;
use GuzzleHttp\Exception\GuzzleException;
use PHPUnit\DbUnit\DataSet\IDataSet;
require_once("BaseDatabaseTestCase.php"); require_once("BaseDatabaseTestCase.php");
@ -8,27 +10,27 @@ class UloggerAPITestCase extends BaseDatabaseTestCase {
/** /**
* @var null|GuzzleHttp\Client $http * @var null|GuzzleHttp\Client $http
*/ */
protected $http = null; protected $http;
public function setUp() { public function setUp(): void {
parent::setUp(); parent::setUp();
if (file_exists(__DIR__ . '/../.env')) { if (file_exists(__DIR__ . '/../.env')) {
$dotenv = Dotenv\Dotenv::create(__DIR__ . '/..'); $dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . '/..');
$dotenv->load(); $dotenv->load();
$dotenv->required(['ULOGGER_URL']); $dotenv->required(['ULOGGER_URL']);
} }
$url = getenv('ULOGGER_URL'); $url = $_ENV['ULOGGER_URL'];
$this->http = new GuzzleHttp\Client([ 'base_uri' => $url, 'cookies' => true ]); $this->http = new GuzzleHttp\Client([ 'base_uri' => $url, 'cookies' => true ]);
} }
public function tearDown() { public function tearDown(): void {
parent::tearDown(); parent::tearDown();
$this->http = null; $this->http = null;
} }
protected function getDataSet() { protected function getDataSet(): IDataSet {
$this->resetAutoincrement(2); $this->resetAutoincrement(2);
return $this->createFlatXMLDataSet(__DIR__ . '/../fixtures/fixture_admin.xml'); 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 $user Login (defaults to test user)
* @param string|null $pass Optional password (defaults to test password) * @param string|null $pass Optional password (defaults to test password)
* @return bool true on success, false otherwise * @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($user)) { $user = $this->testAdminUser; }
if (is_null($pass)) { $pass = $this->testAdminPass; } if (is_null($pass)) { $pass = $this->testAdminPass; }
@ -50,7 +53,7 @@ class UloggerAPITestCase extends BaseDatabaseTestCase {
]; ];
$response = $this->http->post('/client/index.php', $options); $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 * @throws ReflectionException
*/ */
public static function setUpBeforeClass() { public static function setUpBeforeClass(): void {
parent::setUpBeforeClass(); parent::setUpBeforeClass();
if (file_exists(__DIR__ . '/../.env')) { if (file_exists(__DIR__ . '/../.env')) {
$dotenv = Dotenv\Dotenv::create(__DIR__ . '/..'); $dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . '/..');
$dotenv->load(); $dotenv->load();
$dotenv->required(['DB_DSN', 'DB_USER', 'DB_PASS']); $dotenv->required(['DB_DSN', 'DB_USER', 'DB_PASS']);
} }
$db_dsn = getenv('DB_DSN'); $db_dsn = $_ENV['DB_DSN'];
$db_user = getenv('DB_USER'); $db_user = $_ENV['DB_USER'];
$db_pass = getenv('DB_PASS'); $db_pass = $_ENV['DB_PASS'];
// uDb connection // uDb connection
if (self::$udb == null) { if (self::$udb == null) {
self::$udb = new ReflectionClass("uDb"); self::$udb = new ReflectionClass('uDb');
$dbInstance = self::$udb->getProperty('instance'); $dbInstance = self::$udb->getProperty('instance');
$dbInstance->setAccessible(true); $dbInstance->setAccessible(true);
$dbInstance->setValue(new uDb($db_dsn, $db_user, $db_pass)); $dbInstance->setValue(new uDb($db_dsn, $db_user, $db_pass));
} }
} }
public static function tearDownAfterClass() { public static function tearDownAfterClass(): void {
parent::tearDownAfterClass(); parent::tearDownAfterClass();
self::$udb = null; self::$udb = null;
} }

View File

@ -1,23 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="../vendor/autoload.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">
<testsuites> <coverage>
<testsuite name="µlogger test suite"> <include>
<directory suffix=".php">tests</directory> <directory suffix=".php">..</directory>
</testsuite> </include>
</testsuites> <exclude>
<filter> <directory suffix=".php">../.tests</directory>
<whitelist> <directory suffix=".php">../vendor</directory>
<directory suffix=".php">..</directory> </exclude>
<exclude> <report>
<directory suffix=".php">../.tests</directory> <text outputFile="php://stdout" showUncoveredFiles="false"/>
<directory suffix=".php">../vendor</directory> </report>
</exclude> </coverage>
</whitelist> <testsuites>
</filter> <testsuite name="µlogger test suite">
<logging> <directory suffix=".php">tests</directory>
<log type="coverage-text" target="php://stdout" showUncoveredFiles="false"/> </testsuite>
</logging> </testsuites>
<php> <logging/>
<server name='HTTP_HOST' value='http://127.0.0.1' /> <php>
</php> <server name="HTTP_HOST" value="http://127.0.0.1"/>
</php>
</phpunit> </phpunit>

View File

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

View File

@ -1,215 +1,253 @@
<?php <?php
use GuzzleHttp\Exception\GuzzleException;
require_once(__DIR__ . "/../lib/UloggerAPITestCase.php"); require_once(__DIR__ . "/../lib/UloggerAPITestCase.php");
class ClientAPITest extends UloggerAPITestCase { 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 = [ $options = [
'http_errors' => false 'http_errors' => false
]; ];
$response = $this->http->post('/client/index.php', $options); $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()); $json = json_decode((string) $response->getBody());
$this->assertTrue($json->{'error'}, "Unexpected success"); self::assertTrue($json->{'error'}, "Unexpected success");
} }
/* auth */ /* auth */
public function testAuthOk() { /**
* @throws GuzzleException
*/
public function testAuthOk(): void {
$options = [ $options = [
'http_errors' => false, 'http_errors' => false,
'form_params' => [ 'action' => 'auth', 'user' => $this->testAdminUser, 'pass' => $this->testAdminPass ], 'form_params' => [ 'action' => 'auth', 'user' => $this->testAdminUser, 'pass' => $this->testAdminPass ],
]; ];
$response = $this->http->post('/client/index.php', $options); $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()); $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 = [ $options = [
'http_errors' => false, 'http_errors' => false,
'form_params' => [ 'action' => 'adduser', 'user' => 'noexist', 'pass' => 'noexist' ], 'form_params' => [ 'action' => 'adduser', 'user' => 'noexist', 'pass' => 'noexist' ],
]; ];
$response = $this->http->post('/client/index.php', $options); $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 */ /* adduser */
/**
public function testAddUser() { * @throws GuzzleException
$this->assertTrue($this->authenticate(), "Authentication failed"); */
$this->assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count"); public function testAddUser(): void {
self::assertTrue($this->authenticate(), "Authentication failed");
self::assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count");
$options = [ $options = [
'http_errors' => false, 'http_errors' => false,
'form_params' => [ 'action' => 'adduser', 'login' => $this->testUser, 'password' => $this->testPass ], 'form_params' => [ 'action' => 'adduser', 'login' => $this->testUser, 'password' => $this->testPass ],
]; ];
$response = $this->http->post('/client/index.php', $options); $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()); $json = json_decode((string) $response->getBody());
$this->assertFalse($json->{'error'}, "Unexpected error"); self::assertFalse($json->{'error'}, "Unexpected error");
$this->assertEquals(2, $json->{'userid'}, "Wrong user id"); self::assertEquals(2, $json->{'userid'}, "Wrong user id");
$this->assertEquals(2, $this->getConnection()->getRowCount('users'), "Wrong row count"); self::assertEquals(2, $this->getConnection()->getRowCount('users'), "Wrong row count");
$expected = [ "id" => 2, "login" => $this->testUser ]; $expected = [ "id" => 2, "login" => $this->testUser ];
$actual = $this->getConnection()->createQueryTable("users", "SELECT id, login FROM users"); $actual = $this->getConnection()->createQueryTable("users", "SELECT id, login FROM users");
$this->assertTableContains($expected, $actual, "Wrong actual table data"); $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 = [ $options = [
'http_errors' => false, 'http_errors' => false,
'form_params' => [ 'action' => 'adduser', 'login' => $this->testAdminUser, 'password' => $this->testPass ], 'form_params' => [ 'action' => 'adduser', 'login' => $this->testAdminUser, 'password' => $this->testPass ],
]; ];
$response = $this->http->post('/client/index.php', $options); $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()); $json = json_decode((string) $response->getBody());
$this->assertTrue($json->{'error'}, "Unexpected success"); self::assertTrue($json->{'error'}, "Unexpected success");
$this->assertFalse(isset($json->{'userid'}), "Unexpected user id"); self::assertFalse(isset($json->{'userid'}), "Unexpected user id");
$this->assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count"); 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 = [ $options = [
'http_errors' => false, 'http_errors' => false,
'form_params' => [ 'action' => 'adduser', 'login' => '', 'password' => $this->testPass ], 'form_params' => [ 'action' => 'adduser', 'login' => '', 'password' => $this->testPass ],
]; ];
$response = $this->http->post('/client/index.php', $options); $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()); $json = json_decode((string) $response->getBody());
$this->assertTrue($json->{'error'}, "Unexpected success"); self::assertTrue($json->{'error'}, "Unexpected success");
$this->assertFalse(isset($json->{'userid'}), "Unexpected user id"); self::assertFalse(isset($json->{'userid'}), "Unexpected user id");
$this->assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count"); 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 = [ $options = [
'http_errors' => false, 'http_errors' => false,
'form_params' => [ 'action' => 'adduser', 'login' => $this->testUser, 'password' => '' ], 'form_params' => [ 'action' => 'adduser', 'login' => $this->testUser, 'password' => '' ],
]; ];
$response = $this->http->post('/client/index.php', $options); $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()); $json = json_decode((string) $response->getBody());
$this->assertTrue($json->{'error'}, "Unexpected success"); self::assertTrue($json->{'error'}, "Unexpected success");
$this->assertFalse(isset($json->{'userid'}), "Unexpected user id"); self::assertFalse(isset($json->{'userid'}), "Unexpected user id");
$this->assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count"); 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 = [ $options = [
'http_errors' => false, 'http_errors' => false,
'form_params' => [ 'action' => 'adduser' ], 'form_params' => [ 'action' => 'adduser' ],
]; ];
$response = $this->http->post('/client/index.php', $options); $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()); $json = json_decode((string) $response->getBody());
$this->assertTrue($json->{'error'}, "Unexpected success"); self::assertTrue($json->{'error'}, "Unexpected success");
$this->assertFalse(isset($json->{'userid'}), "Unexpected user id"); self::assertFalse(isset($json->{'userid'}), "Unexpected user id");
$this->assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count"); 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->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 = [ $options = [
'http_errors' => false, 'http_errors' => false,
'form_params' => [ 'action' => 'adduser', 'login' => $this->testUser2, 'password' => $this->testPass ], 'form_params' => [ 'action' => 'adduser', 'login' => $this->testUser2, 'password' => $this->testPass ],
]; ];
$response = $this->http->post('/client/index.php', $options); $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()); $json = json_decode((string) $response->getBody());
$this->assertTrue($json->{'error'}, "Unexpected success"); self::assertTrue($json->{'error'}, "Unexpected success");
$this->assertFalse(isset($json->{'userid'}), "Unexpected user id"); self::assertFalse(isset($json->{'userid'}), "Unexpected user id");
$this->assertEquals(2, $this->getConnection()->getRowCount('users'), "Wrong row count"); self::assertEquals(2, $this->getConnection()->getRowCount('users'), "Wrong row count");
} }
/* addtrack */ /* addtrack */
/**
* @throws GuzzleException
*/
public function testAddTrack(): void {
self::assertTrue($this->authenticate(), "Authentication failed");
public function testAddTrack() { self::assertEquals(0, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
$this->assertTrue($this->authenticate(), "Authentication failed");
$this->assertEquals(0, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
$options = [ $options = [
'http_errors' => false, 'http_errors' => false,
'form_params' => [ 'action' => 'addtrack', 'track' => $this->testTrackName ], 'form_params' => [ 'action' => 'addtrack', 'track' => $this->testTrackName ],
]; ];
$response = $this->http->post('/client/index.php', $options); $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()); $json = json_decode((string) $response->getBody());
$this->assertFalse($json->{'error'}, "Unexpected error"); self::assertFalse($json->{'error'}, "Unexpected error");
$this->assertEquals(1, $json->{'trackid'}, "Wrong track id"); self::assertEquals(1, $json->{'trackid'}, "Wrong track id");
$this->assertEquals(1, $this->getConnection()->getRowCount('tracks'), "Wrong row count"); self::assertEquals(1, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
$expected = [ "id" => 1, "user_id" => 1, "name" => $this->testTrackName ]; $expected = [ "id" => 1, "user_id" => 1, "name" => $this->testTrackName ];
$actual = $this->getConnection()->createQueryTable("users", "SELECT id, user_id, name FROM tracks"); $actual = $this->getConnection()->createQueryTable("users", "SELECT id, user_id, name FROM tracks");
$this->assertTableContains($expected, $actual, "Wrong actual table data"); $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 = [ $options = [
'http_errors' => false, 'http_errors' => false,
'form_params' => [ 'action' => 'addtrack', 'track' => '' ], 'form_params' => [ 'action' => 'addtrack', 'track' => '' ],
]; ];
$response = $this->http->post('/client/index.php', $options); $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()); $json = json_decode((string) $response->getBody());
$this->assertTrue($json->{'error'}, "Unexpected success"); self::assertTrue($json->{'error'}, "Unexpected success");
$this->assertFalse(isset($json->{'trackid'}), "Unexpected track id"); self::assertFalse(isset($json->{'trackid'}), "Unexpected track id");
$this->assertEquals(0, $this->getConnection()->getRowCount('tracks'), "Wrong row count"); 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 = [ $options = [
'http_errors' => false, 'http_errors' => false,
'form_params' => [ 'action' => 'addtrack' ], 'form_params' => [ 'action' => 'addtrack' ],
]; ];
$response = $this->http->post('/client/index.php', $options); $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()); $json = json_decode((string) $response->getBody());
$this->assertTrue($json->{'error'}, "Unexpected success"); self::assertTrue($json->{'error'}, "Unexpected success");
$this->assertFalse(isset($json->{'trackid'}), "Unexpected track id"); self::assertFalse(isset($json->{'trackid'}), "Unexpected track id");
$this->assertEquals(0, $this->getConnection()->getRowCount('tracks'), "Wrong row count"); self::assertEquals(0, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
} }
/* addpos */ /* addpos */
/**
public function testAddPosition() { * @throws GuzzleException
$this->assertTrue($this->authenticate(), "Authentication failed"); */
public function testAddPosition(): void {
self::assertTrue($this->authenticate(), "Authentication failed");
$trackId = $this->addTestTrack($this->testUserId); $trackId = $this->addTestTrack($this->testUserId);
$this->assertEquals(1, $this->getConnection()->getRowCount('tracks'), "Wrong row count"); self::assertEquals(1, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
$this->assertEquals(0, $this->getConnection()->getRowCount('positions'), "Wrong row count"); self::assertEquals(0, $this->getConnection()->getRowCount('positions'), "Wrong row count");
$options = [ $options = [
'http_errors' => false, 'http_errors' => false,
@ -228,10 +266,10 @@ class ClientAPITest extends UloggerAPITestCase {
], ],
]; ];
$response = $this->http->post('/client/index.php', $options); $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()); $json = json_decode((string) $response->getBody());
$this->assertFalse($json->{'error'}, "Unexpected error"); self::assertFalse($json->{'error'}, "Unexpected error");
$this->assertEquals(1, $this->getConnection()->getRowCount('positions'), "Wrong row count"); self::assertEquals(1, $this->getConnection()->getRowCount('positions'), "Wrong row count");
$expected = [ $expected = [
"id" => 1, "id" => 1,
"user_id" => $this->testUserId, "user_id" => $this->testUserId,
@ -254,12 +292,15 @@ class ClientAPITest extends UloggerAPITestCase {
$this->assertTableContains($expected, $actual, "Wrong actual table data"); $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); $trackId = $this->addTestTrack($this->testUserId);
$this->assertEquals(1, $this->getConnection()->getRowCount('tracks'), "Wrong row count"); self::assertEquals(1, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
$this->assertEquals(0, $this->getConnection()->getRowCount('positions'), "Wrong row count"); self::assertEquals(0, $this->getConnection()->getRowCount('positions'), "Wrong row count");
$options = [ $options = [
'http_errors' => false, 'http_errors' => false,
@ -317,10 +358,10 @@ class ClientAPITest extends UloggerAPITestCase {
] ]
]; ];
$response = $this->http->post('/client/index.php', $options); $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()); $json = json_decode((string) $response->getBody());
$this->assertFalse($json->{'error'}, "Unexpected error"); self::assertFalse($json->{'error'}, "Unexpected error");
$this->assertEquals(1, $this->getConnection()->getRowCount('positions'), "Wrong row count"); self::assertEquals(1, $this->getConnection()->getRowCount('positions'), "Wrong row count");
$expected = [ $expected = [
"id" => 1, "id" => 1,
"user_id" => $this->testUserId, "user_id" => $this->testUserId,
@ -339,26 +380,29 @@ class ClientAPITest extends UloggerAPITestCase {
"positions", "positions",
"SELECT id, user_id, track_id, " . $this->unix_timestamp('time') . " AS time, latitude, longitude, altitude, speed, bearing, accuracy, provider, comment, image FROM 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')); self::assertEquals($expected['id'], $actual->getValue(0, 'id'));
$this->assertEquals($expected['user_id'], $actual->getValue(0, 'user_id')); self::assertEquals($expected['user_id'], $actual->getValue(0, 'user_id'));
$this->assertEquals($expected['track_id'], $actual->getValue(0, 'track_id')); self::assertEquals($expected['track_id'], $actual->getValue(0, 'track_id'));
$this->assertEquals($expected['time'], $actual->getValue(0, 'time')); self::assertEquals($expected['time'], $actual->getValue(0, 'time'));
$this->assertEquals($expected['latitude'], $actual->getValue(0, 'latitude')); self::assertEquals($expected['latitude'], $actual->getValue(0, 'latitude'));
$this->assertEquals($expected['longitude'], $actual->getValue(0, 'longitude')); self::assertEquals($expected['longitude'], $actual->getValue(0, 'longitude'));
$this->assertEquals($expected['altitude'], $actual->getValue(0, 'altitude')); self::assertEquals($expected['altitude'], $actual->getValue(0, 'altitude'));
$this->assertEquals($expected['speed'], $actual->getValue(0, 'speed')); self::assertEquals($expected['speed'], $actual->getValue(0, 'speed'));
$this->assertEquals($expected['bearing'], $actual->getValue(0, 'bearing')); self::assertEquals($expected['bearing'], $actual->getValue(0, 'bearing'));
$this->assertEquals($expected['accuracy'], $actual->getValue(0, 'accuracy')); self::assertEquals($expected['accuracy'], $actual->getValue(0, 'accuracy'));
$this->assertEquals($expected['provider'], $actual->getValue(0, 'provider')); self::assertEquals($expected['provider'], $actual->getValue(0, 'provider'));
$this->assertEquals($expected['comment'], $actual->getValue(0, 'comment')); self::assertEquals($expected['comment'], $actual->getValue(0, 'comment'));
$this->assertContains('.jpg', $actual->getValue(0, 'image')); 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"); self::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('positions'), "Wrong row count");
$options = [ $options = [
'http_errors' => false, 'http_errors' => false,
@ -378,18 +422,21 @@ class ClientAPITest extends UloggerAPITestCase {
], ],
]; ];
$response = $this->http->post('/client/index.php', $options); $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()); $json = json_decode((string) $response->getBody());
$this->assertTrue($json->{'error'}, "Unexpected success"); self::assertTrue($json->{'error'}, "Unexpected success");
$this->assertEquals(0, $this->getConnection()->getRowCount('positions'), "Wrong row count"); 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); $trackId = $this->addTestTrack($this->testUserId);
$this->assertEquals(1, $this->getConnection()->getRowCount('tracks'), "Wrong row count"); self::assertEquals(1, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
$this->assertEquals(0, $this->getConnection()->getRowCount('positions'), "Wrong row count"); self::assertEquals(0, $this->getConnection()->getRowCount('positions'), "Wrong row count");
$options = [ $options = [
'http_errors' => false, 'http_errors' => false,
@ -414,19 +461,22 @@ class ClientAPITest extends UloggerAPITestCase {
$optCopy = $options; $optCopy = $options;
$optCopy['form_params'][$parameter] = ''; $optCopy['form_params'][$parameter] = '';
$response = $this->http->post('/client/index.php', $optCopy); $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()); $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); $trackId = $this->addTestTrack($this->testUserId);
$this->assertEquals(1, $this->getConnection()->getRowCount('tracks'), "Wrong row count"); self::assertEquals(1, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
$this->assertEquals(0, $this->getConnection()->getRowCount('positions'), "Wrong row count"); self::assertEquals(0, $this->getConnection()->getRowCount('positions'), "Wrong row count");
$options = [ $options = [
'http_errors' => false, 'http_errors' => false,
@ -451,11 +501,11 @@ class ClientAPITest extends UloggerAPITestCase {
$optCopy = $options; $optCopy = $options;
unset($optCopy['form_params'][$parameter]); unset($optCopy['form_params'][$parameter]);
$response = $this->http->post('/client/index.php', $optCopy); $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()); $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
$optional = [ 'altitude', 'speed', 'bearing', 'accuracy', 'provider', 'comment', 'imageid' ]; $optional = [ 'altitude', 'speed', 'bearing', 'accuracy', 'provider', 'comment', 'imageid' ];
@ -463,11 +513,11 @@ class ClientAPITest extends UloggerAPITestCase {
$optCopy = $options; $optCopy = $options;
unset($optCopy['form_params'][$parameter]); unset($optCopy['form_params'][$parameter]);
$response = $this->http->post('/client/index.php', $optCopy); $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()); $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 <?php
use PHPUnit\DbUnit\DataSet\IDataSet;
if (!defined("ROOT_DIR")) { define("ROOT_DIR", __DIR__ . "/../.."); } if (!defined("ROOT_DIR")) { define("ROOT_DIR", __DIR__ . "/../.."); }
require_once(__DIR__ . "/../../helpers/config.php"); require_once(__DIR__ . "/../../helpers/config.php");
require_once(__DIR__ . "/../lib/UloggerDatabaseTestCase.php"); require_once(__DIR__ . "/../lib/UloggerDatabaseTestCase.php");
@ -26,16 +28,13 @@ class ConfigTest extends UloggerDatabaseTestCase {
private $testUrl; private $testUrl;
private $testPriority; private $testPriority;
public function setUp() { public function setUp(): void {
parent::setUp(); parent::setUp();
$this->config = uConfig::getInstance(); $this->config = uConfig::getInstance();
$this->initConfigValues(); $this->initConfigValues();
} }
/** protected function tearDown(): void {
* @throws ReflectionException
*/
protected function tearDown() {
parent::tearDown(); parent::tearDown();
$configClass = new ReflectionClass("uConfig"); $configClass = new ReflectionClass("uConfig");
$configInstance = $configClass->getProperty('instance'); $configInstance = $configClass->getProperty('instance');
@ -43,7 +42,7 @@ class ConfigTest extends UloggerDatabaseTestCase {
$configInstance->setValue(null); $configInstance->setValue(null);
} }
protected function getDataSet() { protected function getDataSet(): IDataSet {
$this->initConfigValues(); $this->initConfigValues();
$this->resetAutoincrement(); $this->resetAutoincrement();
$dataset = [ $dataset = [
@ -71,28 +70,28 @@ class ConfigTest extends UloggerDatabaseTestCase {
return $this->createArrayDataSet($dataset); return $this->createArrayDataSet($dataset);
} }
public function testSetFromDatabase() { public function testSetFromDatabase(): void {
$this->assertEquals($this->mapApi, $this->config->mapApi); self::assertEquals($this->mapApi, $this->config->mapApi);
$this->assertEquals($this->latitude, $this->config->initLatitude); self::assertEquals($this->latitude, $this->config->initLatitude);
$this->assertEquals($this->longitude, $this->config->initLongitude); self::assertEquals($this->longitude, $this->config->initLongitude);
$this->assertEquals($this->googleKey, $this->config->googleKey); self::assertEquals($this->googleKey, $this->config->googleKey);
$this->assertEquals($this->requireAuth, $this->config->requireAuthentication); self::assertEquals($this->requireAuth, $this->config->requireAuthentication);
$this->assertEquals($this->publicTracks, $this->config->publicTracks); self::assertEquals($this->publicTracks, $this->config->publicTracks);
$this->assertEquals($this->passLenMin, $this->config->passLenMin); self::assertEquals($this->passLenMin, $this->config->passLenMin);
$this->assertEquals($this->passStrength, $this->config->passStrength); self::assertEquals($this->passStrength, $this->config->passStrength);
$this->assertEquals($this->interval, $this->config->interval); self::assertEquals($this->interval, $this->config->interval);
$this->assertEquals($this->lang, $this->config->lang); self::assertEquals($this->lang, $this->config->lang);
$this->assertEquals($this->units, $this->config->units); self::assertEquals($this->units, $this->config->units);
$this->assertEquals($this->strokeWeight, $this->config->strokeWeight); self::assertEquals($this->strokeWeight, $this->config->strokeWeight);
$this->assertEquals($this->strokeColor, $this->config->strokeColor); self::assertEquals($this->strokeColor, $this->config->strokeColor);
$this->assertEquals($this->strokeOpacity, $this->config->strokeOpacity); self::assertEquals($this->strokeOpacity, $this->config->strokeOpacity);
$this->assertEquals($this->testLayer, $this->config->olLayers[0]->name); self::assertEquals($this->testLayer, $this->config->olLayers[0]->name);
$this->assertEquals($this->testUrl, $this->config->olLayers[0]->url); self::assertEquals($this->testUrl, $this->config->olLayers[0]->url);
$this->assertEquals($this->testPriority, $this->config->olLayers[0]->priority); self::assertEquals($this->testPriority, $this->config->olLayers[0]->priority);
} }
public function testSave() { public function testSave(): void {
$this->config->mapApi = 'newApi'; $this->config->mapApi = 'newApi';
$this->config->initLatitude = 33.11; $this->config->initLatitude = 33.11;
$this->config->initLongitude = 22.11; $this->config->initLongitude = 22.11;
@ -129,16 +128,16 @@ class ConfigTest extends UloggerDatabaseTestCase {
"stroke_opacity" => $this->config->strokeOpacity "stroke_opacity" => $this->config->strokeOpacity
]; ];
$cnt = count($expected); $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"); $actual = $this->getConnection()->createQueryTable("config", "SELECT * FROM config");
for ($i = 0; $i < $cnt; $i++) { for ($i = 0; $i < $cnt; $i++) {
$row = $actual->getRow($i); $row = $actual->getRow($i);
$actualValue = $row['value']; $actualValue = $row['value'];
if (isset($expected[$row['name']])) { 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 = [ $expected = [
"id" => $this->config->olLayers[0]->id, "id" => $this->config->olLayers[0]->id,
"name" => $this->config->olLayers[0]->name, "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))); $this->assertTableContains($expected, $actual, "Wrong actual table data: " . implode(', ', $actual->getRow(0)));
} }
private function initConfigValues() { private function initConfigValues(): void {
$this->mapApi = 'testApi'; $this->mapApi = 'testApi';
$this->latitude = 33.33; $this->latitude = 33.33;
$this->longitude = 22.22; $this->longitude = 22.22;
@ -169,7 +168,7 @@ class ConfigTest extends UloggerDatabaseTestCase {
$this->testPriority = 5; $this->testPriority = 5;
} }
public function testPassRegex() { public function testPassRegex(): void {
$this->config->passLenMin = 0; $this->config->passLenMin = 0;
$this->config->passStrength = 0; $this->config->passStrength = 0;
$password0 = "password"; $password0 = "password";
@ -178,49 +177,49 @@ class ConfigTest extends UloggerDatabaseTestCase {
$password3 = "PASSword1234-;"; $password3 = "PASSword1234-;";
$regex = $this->config->passRegex(); $regex = $this->config->passRegex();
$this->assertRegExp($regex, $password0, "Regex: \"$regex\", password: \"$password0\""); self::assertMatchesRegularExpression($regex, $password0, "Regex: \"$regex\", password: \"$password0\"");
$this->assertRegExp($regex, $password1, "Regex: \"$regex\", password: \"$password1\""); self::assertMatchesRegularExpression($regex, $password1, "Regex: \"$regex\", password: \"$password1\"");
$this->assertRegExp($regex, $password2, "Regex: \"$regex\", password: \"$password2\""); self::assertMatchesRegularExpression($regex, $password2, "Regex: \"$regex\", password: \"$password2\"");
$this->assertRegExp($regex, $password3, "Regex: \"$regex\", password: \"$password3\""); self::assertMatchesRegularExpression($regex, $password3, "Regex: \"$regex\", password: \"$password3\"");
$this->config->passStrength = 1; $this->config->passStrength = 1;
$regex = $this->config->passRegex(); $regex = $this->config->passRegex();
$this->assertNotRegExp($regex, $password0, "Regex: \"$regex\", password: \"$password0\""); self::assertDoesNotMatchRegularExpression($regex, $password0, "Regex: \"$regex\", password: \"$password0\"");
$this->assertRegExp($regex, $password1, "Regex: \"$regex\", password: \"$password1\""); self::assertMatchesRegularExpression($regex, $password1, "Regex: \"$regex\", password: \"$password1\"");
$this->assertRegExp($regex, $password2, "Regex: \"$regex\", password: \"$password2\""); self::assertMatchesRegularExpression($regex, $password2, "Regex: \"$regex\", password: \"$password2\"");
$this->assertRegExp($regex, $password3, "Regex: \"$regex\", password: \"$password3\""); self::assertMatchesRegularExpression($regex, $password3, "Regex: \"$regex\", password: \"$password3\"");
$this->config->passStrength = 2; $this->config->passStrength = 2;
$regex = $this->config->passRegex(); $regex = $this->config->passRegex();
$this->assertNotRegExp($regex, $password0, "Regex: \"$regex\", password: \"$password0\""); self::assertDoesNotMatchRegularExpression($regex, $password0, "Regex: \"$regex\", password: \"$password0\"");
$this->assertNotRegExp($regex, $password1, "Regex: \"$regex\", password: \"$password1\""); self::assertDoesNotMatchRegularExpression($regex, $password1, "Regex: \"$regex\", password: \"$password1\"");
$this->assertRegExp($regex, $password2, "Regex: \"$regex\", password: \"$password2\""); self::assertMatchesRegularExpression($regex, $password2, "Regex: \"$regex\", password: \"$password2\"");
$this->assertRegExp($regex, $password3, "Regex: \"$regex\", password: \"$password3\""); self::assertMatchesRegularExpression($regex, $password3, "Regex: \"$regex\", password: \"$password3\"");
$this->config->passStrength = 3; $this->config->passStrength = 3;
$regex = $this->config->passRegex(); $regex = $this->config->passRegex();
$this->assertNotRegExp($regex, $password0, "Regex: \"$regex\", password: \"$password0\""); self::assertDoesNotMatchRegularExpression($regex, $password0, "Regex: \"$regex\", password: \"$password0\"");
$this->assertNotRegExp($regex, $password1, "Regex: \"$regex\", password: \"$password1\""); self::assertDoesNotMatchRegularExpression($regex, $password1, "Regex: \"$regex\", password: \"$password1\"");
$this->assertNotRegExp($regex, $password2, "Regex: \"$regex\", password: \"$password2\""); self::assertDoesNotMatchRegularExpression($regex, $password2, "Regex: \"$regex\", password: \"$password2\"");
$this->assertRegExp($regex, $password3, "Regex: \"$regex\", password: \"$password3\""); self::assertMatchesRegularExpression($regex, $password3, "Regex: \"$regex\", password: \"$password3\"");
$password_len5 = "12345"; $password_len5 = "12345";
$password_len10 = "1234567890"; $password_len10 = "1234567890";
$this->config->passLenMin = 5; $this->config->passLenMin = 5;
$this->config->passStrength = 0; $this->config->passStrength = 0;
$regex = $this->config->passRegex(); $regex = $this->config->passRegex();
$this->assertRegExp($regex, $password_len5, "Regex: \"$regex\", password: \"$password_len5\""); self::assertMatchesRegularExpression($regex, $password_len5, "Regex: \"$regex\", password: \"$password_len5\"");
$this->assertRegExp($regex, $password_len10, "Regex: \"$regex\", password: \"$password_len10\""); self::assertMatchesRegularExpression($regex, $password_len10, "Regex: \"$regex\", password: \"$password_len10\"");
$this->config->passLenMin = 7; $this->config->passLenMin = 7;
$regex = $this->config->passRegex(); $regex = $this->config->passRegex();
$this->assertNotRegExp($regex, $password_len5, "Regex: \"$regex\", password: \"$password_len5\""); self::assertDoesNotMatchRegularExpression($regex, $password_len5, "Regex: \"$regex\", password: \"$password_len5\"");
$this->assertRegExp($regex, $password_len10, "Regex: \"$regex\", password: \"$password_len10\""); self::assertMatchesRegularExpression($regex, $password_len10, "Regex: \"$regex\", password: \"$password_len10\"");
$this->config->passLenMin = 12; $this->config->passLenMin = 12;
$regex = $this->config->passRegex(); $regex = $this->config->passRegex();
$this->assertNotRegExp($regex, $password_len5, "Regex: \"$regex\", password: \"$password_len5\""); self::assertDoesNotMatchRegularExpression($regex, $password_len5, "Regex: \"$regex\", password: \"$password_len5\"");
$this->assertNotRegExp($regex, $password_len10, "Regex: \"$regex\", password: \"$password_len10\""); 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 { class DbTest extends TestCase {
public function testGetDbNameValidNames() { public function testGetDbNameValidNames(): void {
$testDbName = "testDbName"; $testDbName = "testDbName";
$defaultDSNs = [ $defaultDSNs = [
"mysql:host=db.example.com;port=3306;dbname=$testDbName", "mysql:host=db.example.com;port=3306;dbname=$testDbName",
@ -22,11 +22,11 @@ class DbTest extends TestCase {
]; ];
foreach ($defaultDSNs as $dsn) { foreach ($defaultDSNs as $dsn) {
$this->assertEquals($testDbName, uDb::getDbName($dsn)); self::assertEquals($testDbName, uDb::getDbName($dsn));
} }
} }
public function testGetDbNameEmptyNames() { public function testGetDbNameEmptyNames(): void {
$testDbName = ""; $testDbName = "";
$defaultDSNs = [ $defaultDSNs = [
"mysql:host=db.example.com;port=3306;dbname=", "mysql:host=db.example.com;port=3306;dbname=",
@ -42,12 +42,12 @@ class DbTest extends TestCase {
]; ];
foreach ($defaultDSNs as $dsn) { foreach ($defaultDSNs as $dsn) {
$this->assertEquals($testDbName, uDb::getDbName($dsn)); self::assertEquals($testDbName, uDb::getDbName($dsn));
} }
} }
public function testGetDbFilename() { public function testGetDbFilename(): void {
$testFileNames = [ $testFileNames = [
"C:\\Program Files\\Database.db", "C:\\Program Files\\Database.db",
":memory:", ":memory:",
@ -55,11 +55,11 @@ class DbTest extends TestCase {
]; ];
foreach ($testFileNames as $fileName) { 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"; $testDbName = "testDbName";
$nonSqlite = [ $nonSqlite = [
"mysql:host=db.example.com;port=3306;dbname=$testDbName", "mysql:host=db.example.com;port=3306;dbname=$testDbName",
@ -72,12 +72,12 @@ class DbTest extends TestCase {
]; ];
foreach ($nonSqlite as $dsn) { 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")); self::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")); self::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::assertNotEquals("sqlite:" . realpath(ROOT_DIR . "/index.php"), uDb::normalizeDsn("sqlite:../index.php"));
} }
} }

View File

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

View File

@ -1,5 +1,7 @@
<?php <?php
use GuzzleHttp\Exception\GuzzleException;
require_once(__DIR__ . "/../lib/UloggerAPITestCase.php"); require_once(__DIR__ . "/../lib/UloggerAPITestCase.php");
if (!defined("ROOT_DIR")) { define("ROOT_DIR", __DIR__ . "/../.."); } if (!defined("ROOT_DIR")) { define("ROOT_DIR", __DIR__ . "/../.."); }
require_once(ROOT_DIR . "/helpers/config.php"); require_once(ROOT_DIR . "/helpers/config.php");
@ -9,7 +11,10 @@ class InternalAPITest extends UloggerAPITestCase {
/* getpositions */ /* getpositions */
public function testGetPositionsAdmin() { /**
* @throws GuzzleException
*/
public function testGetPositionsAdmin(): void {
self::assertTrue($this->authenticate(), "Authentication failed"); self::assertTrue($this->authenticate(), "Authentication failed");
@ -47,7 +52,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertEquals($this->testTrackName, (string) $position->trackname,"Wrong trackname"); 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)); $userId = $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count");
self::assertTrue($this->authenticate($this->testUser, $this->testPass), "Authentication failed"); 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"); 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)); $userId = $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
self::assertEquals(2, $userId); self::assertEquals(2, $userId);
self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); 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"); 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)); $userId = $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
self::assertEquals(2, $userId); self::assertEquals(2, $userId);
self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); 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"); self::assertEquals($this->testTrackName, (string) $position->trackname,"Wrong trackname");
} }
public function testGetPositionsUserLatest() { /**
* @throws GuzzleException
*/
public function testGetPositionsUserLatest(): void {
self::assertTrue($this->authenticate(), "Authentication failed"); self::assertTrue($this->authenticate(), "Authentication failed");
$trackId = $this->addTestTrack($this->testUserId); $trackId = $this->addTestTrack($this->testUserId);
@ -186,7 +203,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertEquals($this->testTrackName, (string) $position->trackname,"Wrong trackname"); self::assertEquals($this->testTrackName, (string) $position->trackname,"Wrong trackname");
} }
public function testGetPositionsAllUsersLatest() { /**
* @throws GuzzleException
*/
public function testGetPositionsAllUsersLatest(): void {
self::assertTrue($this->authenticate(), "Authentication failed"); self::assertTrue($this->authenticate(), "Authentication failed");
$userId = $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT)); $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"); self::assertEquals($trackName, (string) $position->trackname,"Wrong trackname");
} }
public function testGetPositionsNoTrackId() { /**
* @throws GuzzleException
*/
public function testGetPositionsNoTrackId(): void {
self::assertTrue($this->authenticate(), "Authentication failed"); self::assertTrue($this->authenticate(), "Authentication failed");
@ -253,7 +276,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertCount(0, $json, "Wrong count of positions"); self::assertCount(0, $json, "Wrong count of positions");
} }
public function testGetPositionsNoUserId() { /**
* @throws GuzzleException
*/
public function testGetPositionsNoUserId(): void {
self::assertTrue($this->authenticate(), "Authentication failed"); self::assertTrue($this->authenticate(), "Authentication failed");
@ -275,7 +301,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertCount(0, $json, "Wrong count of positions"); self::assertCount(0, $json, "Wrong count of positions");
} }
public function testGetPositionsNoAuth() { /**
* @throws GuzzleException
*/
public function testGetPositionsNoAuth(): void {
$trackId = $this->addTestTrack($this->testUserId); $trackId = $this->addTestTrack($this->testUserId);
$this->addTestPosition($this->testUserId, $trackId, $this->testTimestamp); $this->addTestPosition($this->testUserId, $trackId, $this->testTimestamp);
@ -294,7 +323,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertCount(0, $json, "Wrong count of positions"); self::assertCount(0, $json, "Wrong count of positions");
} }
public function testGetPositionsAfterId() { /**
* @throws GuzzleException
*/
public function testGetPositionsAfterId(): void {
self::assertTrue($this->authenticate(), "Authentication failed"); self::assertTrue($this->authenticate(), "Authentication failed");
@ -331,7 +363,10 @@ class InternalAPITest extends UloggerAPITestCase {
/* gettracks.php */ /* gettracks.php */
public function testGetTracksAdmin() { /**
* @throws GuzzleException
*/
public function testGetTracksAdmin(): void {
self::assertTrue($this->authenticate(), "Authentication failed"); self::assertTrue($this->authenticate(), "Authentication failed");
@ -360,7 +395,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertEquals($this->testTrackName, (string) $track->name,"Wrong track name"); 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)); $userId = $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count");
self::assertTrue($this->authenticate($this->testUser, $this->testPass), "Authentication failed"); 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"); 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)); $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count");
self::assertTrue($this->authenticate($this->testUser, $this->testPass), "Authentication failed"); 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"); 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)); $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count");
self::assertTrue($this->authenticate($this->testUser, $this->testPass), "Authentication failed"); 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"); 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->addTestTrack($this->testUserId, $this->testTrackName . "2"); $this->addTestTrack($this->testUserId, $this->testTrackName . "2");
@ -454,7 +501,10 @@ class InternalAPITest extends UloggerAPITestCase {
/* changepass.php */ /* changepass.php */
public function testChangePassNoAuth() { /**
* @throws GuzzleException
*/
public function testChangePassNoAuth(): void {
$options = [ $options = [
"http_errors" => false, "http_errors" => false,
@ -473,7 +523,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertEquals("User not authorized", (string) $json->message, "Wrong error message"); 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"); self::assertTrue($this->authenticate(), "Authentication failed");
$options = [ $options = [
@ -489,7 +542,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertEquals("Empty password", (string) $json->message, "Wrong error message"); 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"); self::assertTrue($this->authenticate(), "Authentication failed");
$options = [ $options = [
@ -508,7 +564,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertEquals("User unknown", (string) $json->message, "Wrong error message"); 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"); self::assertTrue($this->authenticate(), "Authentication failed");
$options = [ $options = [
@ -526,7 +585,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertEquals("Empty login", (string) $json->message, "Wrong error message"); 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"); self::assertTrue($this->authenticate(), "Authentication failed");
$options = [ $options = [
@ -546,7 +608,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertEquals("Wrong old password", (string) $json->message, "Wrong error message"); 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"); self::assertTrue($this->authenticate(), "Authentication failed");
$options = [ $options = [
@ -565,7 +630,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertEquals("Wrong old password", (string) $json->message,"Wrong error message"); 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"); self::assertTrue($this->authenticate(), "Authentication failed");
$newPass = "Newpass1234567890"; $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"); 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)); $userId = $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
self::assertTrue($this->authenticate($this->testUser, $this->testPass), "Authentication failed"); 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"); 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"); self::assertTrue($this->authenticate(), "Authentication failed");
$userId = $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT)); $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"); 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->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
$this->addTestUser($this->testUser2, 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"); self::assertTrue($this->authenticate($this->testUser, $this->testPass), "Authentication failed");
@ -654,7 +731,10 @@ class InternalAPITest extends UloggerAPITestCase {
/* handletrack.php */ /* handletrack.php */
public function testHandleTrackDeleteAdmin() { /**
* @throws GuzzleException
*/
public function testHandleTrackDeleteAdmin(): void {
self::assertTrue($this->authenticate(), "Authentication failed"); self::assertTrue($this->authenticate(), "Authentication failed");
$userId = $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT)); $userId = $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); 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"); 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)); $userId = $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count");
self::assertTrue($this->authenticate($this->testUser, $this->testPass), "Authentication failed"); 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"); 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(); $lang = (new uLang($this->mockConfig))->getStrings();
$this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT)); $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); 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"); self::assertEquals($lang["notauthorized"], (string) $json->message, "Wrong error message");
} }
public function testHandleTrackUpdate() { /**
* @throws GuzzleException
*/
public function testHandleTrackUpdate(): void {
$newName = "New name"; $newName = "New name";
self::assertTrue($this->authenticate(), "Authentication failed"); self::assertTrue($this->authenticate(), "Authentication failed");
$userId = $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT)); $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"); $this->assertTableContains($row2, $actual, "Wrong actual table data");
} }
public function testHandleTrackUpdateEmptyName() { /**
* @throws GuzzleException
*/
public function testHandleTrackUpdateEmptyName(): void {
$lang = (new uLang($this->mockConfig))->getStrings(); $lang = (new uLang($this->mockConfig))->getStrings();
self::assertTrue($this->authenticate(), "Authentication failed"); self::assertTrue($this->authenticate(), "Authentication failed");
$userId = $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT)); $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"); 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(); $lang = (new uLang($this->mockConfig))->getStrings();
$newName = "New name"; $newName = "New name";
self::assertTrue($this->authenticate(), "Authentication failed"); self::assertTrue($this->authenticate(), "Authentication failed");
@ -808,7 +903,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertEquals($lang["servererror"], (string) $json->message,"Wrong error message"); 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(); $lang = (new uLang($this->mockConfig))->getStrings();
self::assertTrue($this->authenticate(), "Authentication failed"); self::assertTrue($this->authenticate(), "Authentication failed");
@ -826,7 +924,10 @@ class InternalAPITest extends UloggerAPITestCase {
/* handleuser.php */ /* handleuser.php */
public function testHandleUserMissingAction() { /**
* @throws GuzzleException
*/
public function testHandleUserMissingAction(): void {
$lang = (new uLang($this->mockConfig))->getStrings(); $lang = (new uLang($this->mockConfig))->getStrings();
self::assertTrue($this->authenticate(), "Authentication failed"); self::assertTrue($this->authenticate(), "Authentication failed");
@ -841,7 +942,10 @@ class InternalAPITest extends UloggerAPITestCase {
self::assertEquals($lang["servererror"], (string) $json->message,"Wrong error message"); 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(); $lang = (new uLang($this->mockConfig))->getStrings();
$this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT)); $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); 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(); $lang = (new uLang($this->mockConfig))->getStrings();
self::assertTrue($this->authenticate(), "Authentication failed"); self::assertTrue($this->authenticate(), "Authentication failed");
self::assertEquals(1, $this->getConnection()->getRowCount("users"), "Wrong row count"); 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"); 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(); $lang = (new uLang($this->mockConfig))->getStrings();
self::assertTrue($this->authenticate(), "Authentication failed"); self::assertTrue($this->authenticate(), "Authentication failed");
self::assertEquals(1, $this->getConnection()->getRowCount("users"), "Wrong row count"); 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"); 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(); $lang = (new uLang($this->mockConfig))->getStrings();
$this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT)); $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); 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"); 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::assertTrue($this->authenticate(), "Authentication failed");
self::assertEquals(1, $this->getConnection()->getRowCount("users"), "Wrong row count"); 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"); 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(); $lang = (new uLang($this->mockConfig))->getStrings();
self::assertTrue($this->authenticate(), "Authentication failed"); self::assertTrue($this->authenticate(), "Authentication failed");
$this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT)); $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"); self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count");
} }
public function testHandleUserUpdate() { /**
* @throws GuzzleException
*/
public function testHandleUserUpdate(): void {
$newPass = $this->testPass . "new"; $newPass = $this->testPass . "new";
self::assertTrue($this->authenticate(), "Authentication failed"); self::assertTrue($this->authenticate(), "Authentication failed");
$this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT)); $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"); 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"); self::assertTrue($this->authenticate(), "Authentication failed");
$this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT)); $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); 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"); 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"); self::assertTrue($this->authenticate(), "Authentication failed");
$this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT)); $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count");

View File

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

View File

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

View File

@ -1,29 +1,40 @@
<?php <?php
use GuzzleHttp\Exception\GuzzleException;
require_once(__DIR__ . "/../lib/UloggerAPITestCase.php"); require_once(__DIR__ . "/../lib/UloggerAPITestCase.php");
class SetupTest extends UloggerAPITestCase { class SetupTest extends UloggerAPITestCase {
private $script = "/scripts/setup.php"; private $script = "/scripts/setup.php";
public function testPrePhase() { /**
* @throws GuzzleException
*/
public function testPrePhase(): void {
$response = $this->http->get($this->script); $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(); $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 = [ $options = [
"http_errors" => false, "http_errors" => false,
"form_params" => [ "command" => "setup" ] "form_params" => [ "command" => "setup" ]
]; ];
$response = $this->http->post($this->script, $options); $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(); $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 = [ $options = [
"http_errors" => false, "http_errors" => false,
"form_params" => [ "form_params" => [
@ -34,14 +45,14 @@ class SetupTest extends UloggerAPITestCase {
] ]
]; ];
$response = $this->http->post($this->script, $options); $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(); $body = (string) $response->getBody();
$this->assertContains("<span class=\"ok\">", $body); self::assertStringContainsString("<span class=\"ok\">", $body);
$this->assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count");
$expected = [ "id" => 2, "login" => $this->testUser, "admin" => 1 ]; $expected = [ "id" => 2, "login" => $this->testUser, "admin" => 1 ];
$actual = $this->getConnection()->createQueryTable("users", "SELECT id, login, admin FROM users WHERE id = 2"); $actual = $this->getConnection()->createQueryTable("users", "SELECT id, login, admin FROM users WHERE id = 2");
$this->assertTableContains($expected, $actual, "Wrong actual table data"); $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 <?php
use PHPUnit\Framework\TestCase;
require_once(__DIR__ . "/../lib/UloggerDatabaseTestCase.php"); require_once(__DIR__ . "/../lib/UloggerDatabaseTestCase.php");
require_once(__DIR__ . "/../../helpers/track.php"); require_once(__DIR__ . "/../../helpers/track.php");
class TrackTest extends UloggerDatabaseTestCase { class TrackTest extends UloggerDatabaseTestCase {
public function testAddTrack() { public function testAddTrack(): void {
$this->addTestUser(); $this->addTestUser();
$trackId = uTrack::add($this->testUserId, $this->testTrackName, $this->testTrackComment); $trackId = uTrack::add($this->testUserId, $this->testTrackName, $this->testTrackComment);
$this->assertNotFalse($trackId, "Track id should not be false"); self::assertNotFalse($trackId, "Track id should not be false");
$this->assertEquals(1, $this->getConnection()->getRowCount('tracks'), "Wrong row count"); self::assertEquals(1, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
$this->assertEquals(1, $trackId, "Wrong track id returned"); self::assertEquals(1, $trackId, "Wrong track id returned");
$expected = [ "id" => $trackId, "user_id" => $this->testUserId, "name" => $this->testTrackName, "comment" => $this->testTrackComment ]; $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"); $actual = $this->getConnection()->createQueryTable("tracks", "SELECT id, user_id, name, comment FROM tracks");
$this->assertTableContains($expected, $actual, "Wrong actual table data"); $this->assertTableContains($expected, $actual, "Wrong actual table data");
$this->assertFalse(uTrack::add("", $this->testTrackName), "Adding track with empty user id should fail"); self::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->testUserId, ""), "Adding track with empty name should fail");
} }
public function testDeleteTrack() { public function testDeleteTrack(): void {
$userId = $this->addTestUser(); $userId = $this->addTestUser();
$trackId = $this->addTestTrack($userId); $trackId = $this->addTestTrack($userId);
$this->addTestPosition($userId, $trackId); $this->addTestPosition($userId, $trackId);
$this->assertEquals(1, $this->getConnection()->getRowCount('tracks'), "Wrong row count"); self::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('positions'), "Wrong row count");
$track = new uTrack($trackId); $track = new uTrack($trackId);
$track->delete(); $track->delete();
$this->assertEquals(0, $this->getConnection()->getRowCount('tracks'), "Wrong row count"); self::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('positions'), "Wrong row count");
$this->assertFalse($track->isValid, "Deleted track should not be valid"); self::assertFalse($track->isValid, "Deleted track should not be valid");
} }
public function testAddPosition() { public function testAddPosition(): void {
$userId = $this->addTestUser(); $userId = $this->addTestUser();
$userId2 = $this->addTestUser($this->testUser2); $userId2 = $this->addTestUser($this->testUser2);
$trackId = $this->addTestTrack($userId); $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); $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); $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"); self::assertEquals(0, $this->getConnection()->getRowCount('positions'), "Wrong row count");
$this->assertFalse($posId, "Adding position with nonexistant track should fail"); self::assertFalse($posId, "Adding position with nonexistant track should fail");
$track = new uTrack($trackId); $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); $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"); self::assertEquals(0, $this->getConnection()->getRowCount('positions'), "Wrong row count");
$this->assertFalse($posId, "Adding position with wrong user should fail"); 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); $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 = [ $expected = [
"id" => $posId, "id" => $posId,
"user_id" => $this->testUserId, "user_id" => $this->testUserId,
@ -74,31 +73,31 @@ class TrackTest extends UloggerDatabaseTestCase {
$this->assertTableContains($expected, $actual, "Wrong actual table data"); $this->assertTableContains($expected, $actual, "Wrong actual table data");
$posId = $track->addPosition($userId, NULL, $this->testLat, $this->testLon); $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); $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); $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); $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); $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, ""); $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->addTestTrack($this->addTestUser($this->testUser2)); $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(); $trackArr = uTrack::getAll();
$this->assertEquals(2, count($trackArr), "Wrong array size"); self::assertCount(2, $trackArr, "Wrong array size");
$this->assertTrue($trackArr[0] instanceof uTrack, "Wrong array member"); self::assertInstanceOf(uTrack::class, $trackArr[0], "Wrong array member");
} }
public function testDeleteAll() { public function testDeleteAll(): void {
$userId = $this->addTestUser(); $userId = $this->addTestUser();
$trackId = $this->addTestTrack($userId); $trackId = $this->addTestTrack($userId);
$this->addTestTrack($userId); $this->addTestTrack($userId);
@ -108,16 +107,16 @@ class TrackTest extends UloggerDatabaseTestCase {
$trackId2 = $this->addTestTrack($userId2); $trackId2 = $this->addTestTrack($userId2);
$this->addTestPosition($userId2, $trackId2); $this->addTestPosition($userId2, $trackId2);
$this->assertEquals(3, $this->getConnection()->getRowCount('tracks'), "Wrong row count"); self::assertEquals(3, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
$this->assertEquals(2, $this->getConnection()->getRowCount('positions'), "Wrong row count"); self::assertEquals(2, $this->getConnection()->getRowCount('positions'), "Wrong row count");
uTrack::deleteAll($userId); uTrack::deleteAll($userId);
$this->assertEquals(1, $this->getConnection()->getRowCount('tracks'), "Wrong row count"); self::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('positions'), "Wrong row count");
$this->assertFalse(uTrack::deleteAll(NULL), "User id should not be empty"); self::assertFalse(uTrack::deleteAll(NULL), "User id should not be empty");
} }
public function testUpdate() { public function testUpdate(): void {
$userId = $this->addTestUser(); $userId = $this->addTestUser();
$trackId = $this->addTestTrack($userId); $trackId = $this->addTestTrack($userId);
$track = new uTrack($trackId); $track = new uTrack($trackId);
@ -127,16 +126,16 @@ class TrackTest extends UloggerDatabaseTestCase {
$this->assertTableContains($expected, $actual, "Wrong actual table data"); $this->assertTableContains($expected, $actual, "Wrong actual table data");
$trackInvalid = new uTrack($trackId + 1); $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(); $userId = $this->addTestUser();
$trackId = $this->addTestTrack($userId); $trackId = $this->addTestTrack($userId);
$trackValid = new uTrack($trackId); $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); $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 { class UserTest extends UloggerDatabaseTestCase {
public function testAddUser() { public function testAddUser(): void {
$userId = uUser::add($this->testUser, $this->testPass); $userId = uUser::add($this->testUser, $this->testPass);
$this->assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count"); self::assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count");
$this->assertEquals(1, $userId, "Wrong user id returned"); self::assertEquals(1, $userId, "Wrong user id returned");
$expected = [ "id" => 1, "login" => $this->testUser ]; $expected = [ "id" => 1, "login" => $this->testUser ];
$actual = $this->getConnection()->createQueryTable("users", "SELECT id, login FROM users"); $actual = $this->getConnection()->createQueryTable("users", "SELECT id, login FROM users");
$this->assertTableContains($expected, $actual, "Wrong actual table data"); $this->assertTableContains($expected, $actual, "Wrong actual table data");
$this->assertTrue(password_verify($this->testPass, $this->pdoGetColumn("SELECT password FROM users")), "Wrong actual password hash"); self::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"); self::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"); self::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::assertFalse(uUser::add("", $this->testPass), "Adding user with empty login should fail");
} }
public function testDeleteUser() { public function testDeleteUser(): void {
$userId = $this->addTestUser($this->testUser); $userId = $this->addTestUser($this->testUser);
$trackId = $this->addTestTrack($userId); $trackId = $this->addTestTrack($userId);
$this->addTestPosition($userId, $trackId); $this->addTestPosition($userId, $trackId);
$this->assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count"); self::assertEquals(1, $this->getConnection()->getRowCount('users'), "Wrong row count");
$this->assertEquals(1, $this->getConnection()->getRowCount('tracks'), "Wrong row count"); self::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('positions'), "Wrong row count");
$user = new uUser($this->testUser); $user = new uUser($this->testUser);
$user->delete(); $user->delete();
$this->assertEquals(0, $this->getConnection()->getRowCount('users'), "Wrong row count"); self::assertEquals(0, $this->getConnection()->getRowCount('users'), "Wrong row count");
$this->assertEquals(0, $this->getConnection()->getRowCount('tracks'), "Wrong row count"); self::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('positions'), "Wrong row count");
$this->assertFalse($user->isValid, "Deleted user should not be valid"); self::assertFalse($user->isValid, "Deleted user should not be valid");
} }
public function testSetPass() { public function testSetPass(): void {
$newPass = $this->testPass . "new"; $newPass = $this->testPass . "new";
$this->addTestUser($this->testUser); $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 = new uUser($this->testUser);
$user->setPass($newPass); $user->setPass($newPass);
$this->assertTrue(password_verify($newPass, $this->pdoGetColumn("SELECT password FROM users")), "Wrong actual password hash"); self::assertTrue(password_verify($newPass, $this->pdoGetColumn("SELECT password FROM users")), "Wrong actual password hash");
$this->assertFalse($user->setPass(""), "Password should not be empty"); self::assertFalse($user->setPass(""), "Password should not be empty");
$userInvalid = new uUser($this->testUser . "-noexistant"); $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->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 = new uUser($this->testUser);
$this->assertFalse((bool) $this->pdoGetColumn("SELECT admin FROM users"), "User should not be admin"); self::assertFalse((bool) $this->pdoGetColumn("SELECT admin FROM users"), "User should not be admin");
$this->assertFalse($user->isAdmin, "User should not be admin"); self::assertFalse($user->isAdmin, "User should not be admin");
$user->setAdmin(true); $user->setAdmin(true);
$this->assertTrue((bool) $this->pdoGetColumn("SELECT admin FROM users"), "User should be admin"); self::assertTrue((bool) $this->pdoGetColumn("SELECT admin FROM users"), "User should be admin");
$this->assertTrue($user->isAdmin, "User should be admin"); self::assertTrue($user->isAdmin, "User should be admin");
$user->setAdmin(false); $user->setAdmin(false);
$this->assertFalse((bool) $this->pdoGetColumn("SELECT admin FROM users"), "User should not be admin"); self::assertFalse((bool) $this->pdoGetColumn("SELECT admin FROM users"), "User should not be admin");
$this->assertFalse($user->isAdmin, "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->testUser);
$this->addTestUser($this->testUser2); $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(); $userArr = uUser::getAll();
$this->assertCount(2, $userArr, "Wrong array size"); self::assertCount(2, $userArr, "Wrong array size");
$this->assertInstanceOf(uUser::class, $userArr[0], "Wrong array member"); self::assertInstanceOf(uUser::class, $userArr[0], "Wrong array member");
} }
public function testIsAdmin() { public function testIsAdmin(): void {
$this->addTestUser($this->testUser, NULL, true); $this->addTestUser($this->testUser, NULL, true);
$user = new uUser($this->testUser); $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); $this->addTestUser($this->testUser);
$user = new uUser($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); $this->addTestUser($this->testUser);
$userValid = new uUser($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"); $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 <?php
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
require_once(__DIR__ . "/../../helpers/utils.php"); require_once(__DIR__ . "/../../helpers/utils.php");
class UtilsTest extends TestCase { class UtilsTest extends TestCase {
public function testGetUploadMaxSize() { /**
* @throws ReflectionException
*/
public function testGetUploadMaxSize(): void {
$iniGetBytes = new ReflectionMethod('uUtils', 'iniGetBytes'); $iniGetBytes = new ReflectionMethod('uUtils', 'iniGetBytes');
$iniGetBytes->setAccessible(true); $iniGetBytes->setAccessible(true);
ini_set("memory_limit", "1G"); ini_set("memory_limit", "1G");
$result = $iniGetBytes->invoke(null, "memory_limit"); $result = $iniGetBytes->invoke(null, "memory_limit");
$this->assertEquals(1024 * 1024 * 1024, $result); self::assertEquals(1024 * 1024 * 1024, $result);
ini_set("memory_limit", 100 . "M"); ini_set("memory_limit", 100 . "M");
$result = $iniGetBytes->invoke(null, "memory_limit"); $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"); ini_set("memory_limit", 100 * 1024 . "K");
$result = $iniGetBytes->invoke(null, "memory_limit"); $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); ini_set("memory_limit", 100 * 1024 * 1024);
$result = $iniGetBytes->invoke(null, "memory_limit"); $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")) { if (!defined("ROOT_DIR")) {
define("ROOT_DIR", "/var/www/html/ulogger"); define("ROOT_DIR", "/var/www/html/ulogger");
} }
@ -38,10 +43,11 @@ class UtilsTest extends TestCase {
$_SERVER["PHP_SELF"] = "/index.php"; $_SERVER["PHP_SELF"] = "/index.php";
$result = uUtils::getBaseUrl(); $result = uUtils::getBaseUrl();
$expected = "http://www.example.com/"; $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")) { if (!defined("ROOT_DIR")) {
define("ROOT_DIR", "/var/www/html"); define("ROOT_DIR", "/var/www/html");
} }
@ -52,10 +58,11 @@ class UtilsTest extends TestCase {
$_SERVER["PHP_SELF"] = "/utils/test.php"; $_SERVER["PHP_SELF"] = "/utils/test.php";
$result = uUtils::getBaseUrl(); $result = uUtils::getBaseUrl();
$expected = "http://www.example.com/"; $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")) { if (!defined("ROOT_DIR")) {
define("ROOT_DIR", "/var/www/html"); define("ROOT_DIR", "/var/www/html");
} }
@ -66,10 +73,10 @@ class UtilsTest extends TestCase {
$_SERVER["PHP_SELF"] = "/ulogger/index.php"; $_SERVER["PHP_SELF"] = "/ulogger/index.php";
$result = uUtils::getBaseUrl(); $result = uUtils::getBaseUrl();
$expected = "http://www.example.com/ulogger/"; $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")) { if (!defined("ROOT_DIR")) {
define("ROOT_DIR", "/var/www/html"); define("ROOT_DIR", "/var/www/html");
} }
@ -80,10 +87,11 @@ class UtilsTest extends TestCase {
$_SERVER["PHP_SELF"] = "/index.php"; $_SERVER["PHP_SELF"] = "/index.php";
$result = uUtils::getBaseUrl(); $result = uUtils::getBaseUrl();
$expected = "https://www.example.com/"; $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")) { if (!defined("ROOT_DIR")) {
define("ROOT_DIR", "/var/www/html"); define("ROOT_DIR", "/var/www/html");
} }
@ -94,26 +102,26 @@ class UtilsTest extends TestCase {
$_SERVER["PHP_SELF"] = "/index.php"; $_SERVER["PHP_SELF"] = "/index.php";
$result = uUtils::getBaseUrl(); $result = uUtils::getBaseUrl();
$expected = "http://www.example.com/"; $expected = "http://www.example.com/";
$this->assertEquals($expected, $result); self::assertEquals($expected, $result);
unset($_SERVER["HTTPS"]); unset($_SERVER["HTTPS"]);
$this->assertEquals($expected, $result); self::assertEquals($expected, $result);
} }
public function testIsAbsolutePath() { public function testIsAbsolutePath(): void {
$this->assertTrue(uUtils::isAbsolutePath("/foo")); self::assertTrue(uUtils::isAbsolutePath("/foo"));
$this->assertTrue(uUtils::isAbsolutePath("/foo/bar")); self::assertTrue(uUtils::isAbsolutePath("/foo/bar"));
$this->assertTrue(uUtils::isAbsolutePath("/")); self::assertTrue(uUtils::isAbsolutePath("/"));
$this->assertTrue(uUtils::isAbsolutePath("/.")); self::assertTrue(uUtils::isAbsolutePath("/."));
$this->assertTrue(uUtils::isAbsolutePath("\\")); self::assertTrue(uUtils::isAbsolutePath("\\"));
$this->assertTrue(uUtils::isAbsolutePath("C:\\\\foo")); self::assertTrue(uUtils::isAbsolutePath("C:\\\\foo"));
$this->assertTrue(uUtils::isAbsolutePath("Z:\\\\FOO/BAR")); self::assertTrue(uUtils::isAbsolutePath("Z:\\\\FOO/BAR"));
$this->assertFalse(uUtils::isAbsolutePath("foo")); self::assertFalse(uUtils::isAbsolutePath("foo"));
$this->assertFalse(uUtils::isAbsolutePath("foo/bar")); self::assertFalse(uUtils::isAbsolutePath("foo/bar"));
$this->assertFalse(uUtils::isAbsolutePath("./foo")); self::assertFalse(uUtils::isAbsolutePath("./foo"));
$this->assertFalse(uUtils::isAbsolutePath("../")); self::assertFalse(uUtils::isAbsolutePath("../"));
$this->assertFalse(uUtils::isAbsolutePath(".\\foo")); self::assertFalse(uUtils::isAbsolutePath(".\\foo"));
} }
} }
?> ?>

View File

@ -3,7 +3,7 @@ os: linux
dist: xenial dist: xenial
php: php:
- 7.2 - 7.4
env: env:
jobs: jobs:
@ -63,7 +63,7 @@ after_failure:
- docker logs ulogger - docker logs ulogger
script: script:
- ./vendor/bin/phpunit -c .tests/phpunit.xml - XDEBUG_MODE=coverage ./vendor/bin/phpunit -c .tests/phpunit.xml
- npm test - npm test
- npm run lint:js - npm run lint:js
- npm run lint:css - 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` - 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 - 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 .` - 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 ## Tests
- Install tests dependecies. - Install tests dependecies. PHP tests require PHP >= 7.3.
- `composer install` - `composer install`
- `npm 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 - 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` - `DB_PASS=secret2`
- `ULOGGER_URL="http://127.0.0.1:8080"` - `ULOGGER_URL="http://127.0.0.1:8080"`
- PHP tests - PHP tests
- `./vendor/bin/phpunit -c .tests/phpunit.xml` - `XDEBUG_MODE=coverage ./vendor/bin/phpunit -c .tests/phpunit.xml`
- JS tests - JS tests
- `npm test` - `npm test`
- Other tests - Other tests

View File

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

2602
composer.lock generated

File diff suppressed because it is too large Load Diff