From 689dff0768774238e68f6112f0524735ac115564 Mon Sep 17 00:00:00 2001 From: Bartek Fabiszewski Date: Wed, 11 Nov 2020 18:29:40 +0100 Subject: [PATCH] Fix, cleanup test --- .tests/tests/InternalAPITest.php | 638 +++++++++++++++---------------- 1 file changed, 319 insertions(+), 319 deletions(-) diff --git a/.tests/tests/InternalAPITest.php b/.tests/tests/InternalAPITest.php index 322884e..e864cec 100644 --- a/.tests/tests/InternalAPITest.php +++ b/.tests/tests/InternalAPITest.php @@ -11,320 +11,320 @@ class InternalAPITest extends UloggerAPITestCase { public function testGetPositionsAdmin() { - $this->assertTrue($this->authenticate(), "Authentication failed"); + self::assertTrue($this->authenticate(), "Authentication failed"); $trackId = $this->addTestTrack($this->testUserId); $this->addTestPosition($this->testUserId, $trackId, $this->testTimestamp); $this->addTestPosition($this->testUserId, $trackId, $this->testTimestamp + 1); - $this->assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); - $this->assertEquals(2, $this->getConnection()->getRowCount("positions"), "Wrong row count"); + self::assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); + self::assertEquals(2, $this->getConnection()->getRowCount("positions"), "Wrong row count"); $options = [ "http_errors" => false, "query" => [ "userid" => $this->testUserId, "trackid" => $trackId ], ]; $response = $this->http->get("/utils/getpositions.php", $options); - $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); + self::assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); - $this->assertNotNull($json, "JSON object is null"); - $this->assertEquals(count($json), 2, "Wrong count of positions"); + self::assertNotNull($json, "JSON object is null"); + self::assertCount(2, $json, "Wrong count of positions"); $position = $json[0]; - $this->assertEquals((int) $position->id, 1, "Wrong position id"); - $this->assertEquals((float) $position->latitude, $this->testLat, "Wrong latitude"); - $this->assertEquals((float) $position->longitude, $this->testLon, "Wrong longitude"); - $this->assertEquals((int) $position->timestamp, $this->testTimestamp, "Wrong timestamp"); - $this->assertEquals((string) $position->username, $this->testAdminUser, "Wrong username"); - $this->assertEquals((string) $position->trackname, $this->testTrackName, "Wrong trackname"); + self::assertEquals(1, (int) $position->id, "Wrong position id"); + self::assertEquals($this->testLat, (float) $position->latitude,"Wrong latitude"); + self::assertEquals($this->testLon, (float) $position->longitude,"Wrong longitude"); + self::assertEquals($this->testTimestamp, (int) $position->timestamp,"Wrong timestamp"); + self::assertEquals($this->testAdminUser, (string) $position->username,"Wrong username"); + self::assertEquals($this->testTrackName, (string) $position->trackname,"Wrong trackname"); $position = $json[1]; - $this->assertEquals((int) $position->id, 2, "Wrong position id"); - $this->assertEquals((float) $position->latitude, $this->testLat, "Wrong latitude"); - $this->assertEquals((float) $position->longitude, $this->testLon, "Wrong longitude"); - $this->assertEquals((int) $position->timestamp, $this->testTimestamp + 1, "Wrong timestamp"); - $this->assertEquals((string) $position->username, $this->testAdminUser, "Wrong username"); - $this->assertEquals((string) $position->trackname, $this->testTrackName, "Wrong trackname"); + self::assertEquals(2, (int) $position->id,"Wrong position id"); + self::assertEquals($this->testLat, (float) $position->latitude,"Wrong latitude"); + self::assertEquals($this->testLon, (float) $position->longitude,"Wrong longitude"); + self::assertEquals($this->testTimestamp + 1, (int) $position->timestamp,"Wrong timestamp"); + self::assertEquals($this->testAdminUser, (string) $position->username,"Wrong username"); + self::assertEquals($this->testTrackName, (string) $position->trackname,"Wrong trackname"); } public function testGetPositionsUser() { $userId = $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT)); - $this->assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); - $this->assertTrue($this->authenticate($this->testUser, $this->testPass), "Authentication failed"); + self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); + self::assertTrue($this->authenticate($this->testUser, $this->testPass), "Authentication failed"); $trackId = $this->addTestTrack($userId); $this->addTestPosition($userId, $trackId, $this->testTimestamp); $this->addTestPosition($userId, $trackId, $this->testTimestamp + 1); - $this->assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); - $this->assertEquals(2, $this->getConnection()->getRowCount("positions"), "Wrong row count"); + self::assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); + self::assertEquals(2, $this->getConnection()->getRowCount("positions"), "Wrong row count"); $options = [ "http_errors" => false, "query" => [ "userid" => $userId, "trackid" => $trackId ], ]; $response = $this->http->get("/utils/getpositions.php", $options); - $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); + self::assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); - $this->assertNotNull($json, "JSON object is null"); - $this->assertEquals(count($json), 2, "Wrong count of positions"); + self::assertNotNull($json, "JSON object is null"); + self::assertCount(2, $json, "Wrong count of positions"); $position = $json[0]; - $this->assertEquals((int) $position->id, 1, "Wrong position id"); - $this->assertEquals((float) $position->latitude, $this->testLat, "Wrong latitude"); - $this->assertEquals((float) $position->longitude, $this->testLon, "Wrong longitude"); - $this->assertEquals((int) $position->timestamp, $this->testTimestamp, "Wrong timestamp"); - $this->assertEquals((string) $position->username, $this->testUser, "Wrong username"); - $this->assertEquals((string) $position->trackname, $this->testTrackName, "Wrong trackname"); + self::assertEquals(1, (int) $position->id,"Wrong position id"); + self::assertEquals($this->testLat, (float) $position->latitude,"Wrong latitude"); + self::assertEquals($this->testLon, (float) $position->longitude,"Wrong longitude"); + self::assertEquals($this->testTimestamp, (int) $position->timestamp,"Wrong timestamp"); + self::assertEquals($this->testUser, (string) $position->username,"Wrong username"); + self::assertEquals($this->testTrackName, (string) $position->trackname,"Wrong trackname"); $position = $json[1]; - $this->assertEquals((int) $position->id, 2, "Wrong position id"); - $this->assertEquals((float) $position->latitude, $this->testLat, "Wrong latitude"); - $this->assertEquals((float) $position->longitude, $this->testLon, "Wrong longitude"); - $this->assertEquals((int) $position->timestamp, $this->testTimestamp + 1, "Wrong timestamp"); - $this->assertEquals((string) $position->username, $this->testUser, "Wrong username"); - $this->assertEquals((string) $position->trackname, $this->testTrackName, "Wrong trackname"); + self::assertEquals(2, (int) $position->id,"Wrong position id"); + self::assertEquals($this->testLat, (float) $position->latitude,"Wrong latitude"); + self::assertEquals($this->testLon, (float) $position->longitude,"Wrong longitude"); + self::assertEquals($this->testTimestamp + 1, (int) $position->timestamp,"Wrong timestamp"); + self::assertEquals($this->testUser, (string) $position->username,"Wrong username"); + self::assertEquals($this->testTrackName, (string) $position->trackname,"Wrong trackname"); } public function testGetPositionsOtherUser() { $userId = $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT)); - $this->assertEquals(2, $userId); - $this->assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); - $this->assertTrue($this->authenticate($this->testUser, $this->testPass), "Authentication failed"); + self::assertEquals(2, $userId); + self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); + self::assertTrue($this->authenticate($this->testUser, $this->testPass), "Authentication failed"); $trackId = $this->addTestTrack($userId); $this->addTestPosition($userId, $trackId, $this->testTimestamp); $this->addTestPosition($userId, $trackId, $this->testTimestamp + 1); - $this->assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); - $this->assertEquals(2, $this->getConnection()->getRowCount("positions"), "Wrong row count"); + self::assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); + self::assertEquals(2, $this->getConnection()->getRowCount("positions"), "Wrong row count"); $options = [ "http_errors" => false, "query" => [ "userid" => $this->testUserId, "trackid" => $trackId ], ]; $response = $this->http->get("/utils/getpositions.php", $options); - $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); + self::assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); - $this->assertNotNull($json, "JSON object is null"); - $this->assertEquals(count($json), 0, "Wrong count of positions"); + self::assertNotNull($json, "JSON object is null"); + self::assertCount(0, $json, "Wrong count of positions"); } public function testGetPositionsOtherUserByAdmin() { $userId = $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT)); - $this->assertEquals(2, $userId); - $this->assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); - $this->assertTrue($this->authenticate(), "Authentication failed"); + self::assertEquals(2, $userId); + self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); + self::assertTrue($this->authenticate(), "Authentication failed"); $trackId = $this->addTestTrack($userId); $this->addTestPosition($userId, $trackId, $this->testTimestamp); $this->addTestPosition($userId, $trackId, $this->testTimestamp + 1); - $this->assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); - $this->assertEquals(2, $this->getConnection()->getRowCount("positions"), "Wrong row count"); + self::assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); + self::assertEquals(2, $this->getConnection()->getRowCount("positions"), "Wrong row count"); $options = [ "http_errors" => false, "query" => [ "userid" => $userId, "trackid" => $trackId ], ]; $response = $this->http->get("/utils/getpositions.php", $options); - $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); + self::assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); - $this->assertNotNull($json, "JSON object is null"); - $this->assertEquals(count($json), 2, "Wrong count of positions"); + self::assertNotNull($json, "JSON object is null"); + self::assertCount(2, $json, "Wrong count of positions"); $position = $json[0]; - $this->assertEquals((int) $position->id, 1, "Wrong position id"); - $this->assertEquals((float) $position->latitude, $this->testLat, "Wrong latitude"); - $this->assertEquals((float) $position->longitude, $this->testLon, "Wrong longitude"); - $this->assertEquals((int) $position->timestamp, $this->testTimestamp, "Wrong timestamp"); - $this->assertEquals((string) $position->username, $this->testUser, "Wrong username"); - $this->assertEquals((string) $position->trackname, $this->testTrackName, "Wrong trackname"); + self::assertEquals(1, (int) $position->id,"Wrong position id"); + self::assertEquals($this->testLat, (float) $position->latitude,"Wrong latitude"); + self::assertEquals($this->testLon, (float) $position->longitude,"Wrong longitude"); + self::assertEquals($this->testTimestamp, (int) $position->timestamp,"Wrong timestamp"); + self::assertEquals($this->testUser, (string) $position->username,"Wrong username"); + self::assertEquals($this->testTrackName, (string) $position->trackname,"Wrong trackname"); $position = $json[1]; - $this->assertEquals((int) $position->id, 2, "Wrong position id"); - $this->assertEquals((float) $position->latitude, $this->testLat, "Wrong latitude"); - $this->assertEquals((float) $position->longitude, $this->testLon, "Wrong longitude"); - $this->assertEquals((int) $position->timestamp, $this->testTimestamp + 1, "Wrong timestamp"); - $this->assertEquals((string) $position->username, $this->testUser, "Wrong username"); - $this->assertEquals((string) $position->trackname, $this->testTrackName, "Wrong trackname"); + self::assertEquals(2, (int) $position->id,"Wrong position id"); + self::assertEquals($this->testLat, (float) $position->latitude,"Wrong latitude"); + self::assertEquals($this->testLon, (float) $position->longitude,"Wrong longitude"); + self::assertEquals($this->testTimestamp + 1, (int) $position->timestamp,"Wrong timestamp"); + self::assertEquals($this->testUser, (string) $position->username,"Wrong username"); + self::assertEquals($this->testTrackName, (string) $position->trackname,"Wrong trackname"); } public function testGetPositionsUserLatest() { - $this->assertTrue($this->authenticate(), "Authentication failed"); + self::assertTrue($this->authenticate(), "Authentication failed"); $trackId = $this->addTestTrack($this->testUserId); $this->addTestPosition($this->testUserId, $trackId, $this->testTimestamp); $this->addTestPosition($this->testUserId, $trackId, $this->testTimestamp + 3); - $this->assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); - $this->assertEquals(2, $this->getConnection()->getRowCount("positions"), "Wrong row count"); + self::assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); + self::assertEquals(2, $this->getConnection()->getRowCount("positions"), "Wrong row count"); $userId = $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT)); $trackId2 = $this->addTestTrack($userId); $this->addTestPosition($userId, $trackId2, $this->testTimestamp + 2); $this->addTestPosition($userId, $trackId2, $this->testTimestamp + 1); - $this->assertEquals(2, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); - $this->assertEquals(4, $this->getConnection()->getRowCount("positions"), "Wrong row count"); + self::assertEquals(2, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); + self::assertEquals(4, $this->getConnection()->getRowCount("positions"), "Wrong row count"); $options = [ "http_errors" => false, "query" => [ "userid" => $this->testUserId, "last" => 1 ], ]; $response = $this->http->get("/utils/getpositions.php", $options); - $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); + self::assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); - $this->assertNotNull($json, "JSON object is null"); - $this->assertEquals(count($json), 1, "Wrong count of positions"); + self::assertNotNull($json, "JSON object is null"); + self::assertCount(1, $json, "Wrong count of positions"); $position = $json[0]; - $this->assertEquals((int) $position->id, 2, "Wrong position id"); - $this->assertEquals((float) $position->latitude, $this->testLat, "Wrong latitude"); - $this->assertEquals((float) $position->longitude, $this->testLon, "Wrong longitude"); - $this->assertEquals((int) $position->timestamp, $this->testTimestamp + 3, "Wrong timestamp"); - $this->assertEquals((string) $position->username, $this->testAdminUser, "Wrong username"); - $this->assertEquals((string) $position->trackname, $this->testTrackName, "Wrong trackname"); + self::assertEquals(2, (int) $position->id,"Wrong position id"); + self::assertEquals($this->testLat, (float) $position->latitude,"Wrong latitude"); + self::assertEquals($this->testLon, (float) $position->longitude,"Wrong longitude"); + self::assertEquals($this->testTimestamp + 3, (int) $position->timestamp,"Wrong timestamp"); + self::assertEquals($this->testAdminUser, (string) $position->username,"Wrong username"); + self::assertEquals($this->testTrackName, (string) $position->trackname,"Wrong trackname"); } public function testGetPositionsAllUsersLatest() { - $this->assertTrue($this->authenticate(), "Authentication failed"); + self::assertTrue($this->authenticate(), "Authentication failed"); $userId = $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT)); $trackId = $this->addTestTrack($this->testUserId); $this->addTestPosition($this->testUserId, $trackId, $this->testTimestamp); $this->addTestPosition($this->testUserId, $trackId, $this->testTimestamp + 3); - $this->assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); - $this->assertEquals(2, $this->getConnection()->getRowCount("positions"), "Wrong row count"); + self::assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); + self::assertEquals(2, $this->getConnection()->getRowCount("positions"), "Wrong row count"); $trackName = "Track 2"; $trackId2 = $this->addTestTrack($userId, $trackName); $this->addTestPosition($userId, $trackId2, $this->testTimestamp + 2); $this->addTestPosition($userId, $trackId2, $this->testTimestamp + 1); - $this->assertEquals(2, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); - $this->assertEquals(4, $this->getConnection()->getRowCount("positions"), "Wrong row count"); + self::assertEquals(2, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); + self::assertEquals(4, $this->getConnection()->getRowCount("positions"), "Wrong row count"); $options = [ "http_errors" => false, "query" => [ "last" => 1 ], ]; $response = $this->http->get("/utils/getpositions.php", $options); - $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); + self::assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); - $this->assertNotNull($json, "JSON object is null"); - $this->assertEquals(count($json), 2, "Wrong count of positions"); + self::assertNotNull($json, "JSON object is null"); + self::assertCount(2, $json, "Wrong count of positions"); $position = $json[0]; - $this->assertEquals((int) $position->id, 2, "Wrong position id"); - $this->assertEquals((float) $position->latitude, $this->testLat, "Wrong latitude"); - $this->assertEquals((float) $position->longitude, $this->testLon, "Wrong longitude"); - $this->assertEquals((int) $position->timestamp, $this->testTimestamp + 3, "Wrong timestamp"); - $this->assertEquals((string) $position->username, $this->testAdminUser, "Wrong username"); - $this->assertEquals((string) $position->trackname, $this->testTrackName, "Wrong trackname"); + self::assertEquals(2, (int) $position->id,"Wrong position id"); + self::assertEquals($this->testLat, (float) $position->latitude,"Wrong latitude"); + self::assertEquals($this->testLon, (float) $position->longitude,"Wrong longitude"); + self::assertEquals($this->testTimestamp + 3, (int) $position->timestamp,"Wrong timestamp"); + self::assertEquals($this->testAdminUser, (string) $position->username,"Wrong username"); + self::assertEquals($this->testTrackName, (string) $position->trackname,"Wrong trackname"); $position = $json[1]; - $this->assertEquals((int) $position->id, 3, "Wrong position id"); - $this->assertEquals((float) $position->latitude, $this->testLat, "Wrong latitude"); - $this->assertEquals((float) $position->longitude, $this->testLon, "Wrong longitude"); - $this->assertEquals((int) $position->timestamp, $this->testTimestamp + 2, "Wrong timestamp"); - $this->assertEquals((string) $position->username, $this->testUser, "Wrong username"); - $this->assertEquals((string) $position->trackname, $trackName, "Wrong trackname"); + self::assertEquals(3, (int) $position->id,"Wrong position id"); + self::assertEquals($this->testLat, (float) $position->latitude,"Wrong latitude"); + self::assertEquals($this->testLon, (float) $position->longitude,"Wrong longitude"); + self::assertEquals($this->testTimestamp + 2, (int) $position->timestamp,"Wrong timestamp"); + self::assertEquals($this->testUser, (string) $position->username,"Wrong username"); + self::assertEquals($trackName, (string) $position->trackname,"Wrong trackname"); } public function testGetPositionsNoTrackId() { - $this->assertTrue($this->authenticate(), "Authentication failed"); + self::assertTrue($this->authenticate(), "Authentication failed"); $trackId = $this->addTestTrack($this->testUserId); $this->addTestPosition($this->testUserId, $trackId, $this->testTimestamp); $this->addTestPosition($this->testUserId, $trackId, $this->testTimestamp + 1); - $this->assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); - $this->assertEquals(2, $this->getConnection()->getRowCount("positions"), "Wrong row count"); + self::assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); + self::assertEquals(2, $this->getConnection()->getRowCount("positions"), "Wrong row count"); $options = [ "http_errors" => false, "query" => [ "userid" => $this->testUserId ], ]; $response = $this->http->get("/utils/getpositions.php", $options); - $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); + self::assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); - $this->assertNotNull($json, "JSON object is null"); - $this->assertCount(0, $json, "Wrong count of positions"); + self::assertNotNull($json, "JSON object is null"); + self::assertCount(0, $json, "Wrong count of positions"); } public function testGetPositionsNoUserId() { - $this->assertTrue($this->authenticate(), "Authentication failed"); + self::assertTrue($this->authenticate(), "Authentication failed"); $trackId = $this->addTestTrack($this->testUserId); $this->addTestPosition($this->testUserId, $trackId, $this->testTimestamp); $this->addTestPosition($this->testUserId, $trackId, $this->testTimestamp + 1); - $this->assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); - $this->assertEquals(2, $this->getConnection()->getRowCount("positions"), "Wrong row count"); + self::assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); + self::assertEquals(2, $this->getConnection()->getRowCount("positions"), "Wrong row count"); $options = [ "http_errors" => false, "query" => [ "trackid" => $trackId ], ]; $response = $this->http->get("/utils/getpositions.php", $options); - $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); + self::assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); - $this->assertNotNull($json, "JSON object is null"); - $this->assertCount(0, $json, "Wrong count of positions"); + self::assertNotNull($json, "JSON object is null"); + self::assertCount(0, $json, "Wrong count of positions"); } public function testGetPositionsNoAuth() { $trackId = $this->addTestTrack($this->testUserId); $this->addTestPosition($this->testUserId, $trackId, $this->testTimestamp); - $this->assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); + self::assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); $options = [ "http_errors" => false, "query" => [ "userid" => $this->testUserId, "trackid" => $trackId ], ]; $response = $this->http->get("/utils/getpositions.php", $options); - $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); + self::assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); - $this->assertNotNull($json, "JSON object is null"); - $this->assertEquals(count($json), 0, "Wrong count of positions"); + self::assertNotNull($json, "JSON object is null"); + self::assertCount(0, $json, "Wrong count of positions"); } public function testGetPositionsAfterId() { - $this->assertTrue($this->authenticate(), "Authentication failed"); + self::assertTrue($this->authenticate(), "Authentication failed"); $trackId = $this->addTestTrack($this->testUserId); $afterId = $this->addTestPosition($this->testUserId, $trackId, $this->testTimestamp); $this->addTestPosition($this->testUserId, $trackId, $this->testTimestamp + 1, $this->testLat + 1); - $this->assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); - $this->assertEquals(2, $this->getConnection()->getRowCount("positions"), "Wrong row count"); + self::assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); + self::assertEquals(2, $this->getConnection()->getRowCount("positions"), "Wrong row count"); $options = [ "http_errors" => false, "query" => [ "userid" => $this->testUserId, "trackid" => $trackId, "afterid" => $afterId ], ]; $response = $this->http->get("/utils/getpositions.php", $options); - $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); + self::assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); - $this->assertNotNull($json, "JSON object is null"); - $this->assertEquals(count($json), 1, "Wrong count of positions"); + self::assertNotNull($json, "JSON object is null"); + self::assertCount(1, $json, "Wrong count of positions"); $position = $json[0]; - $this->assertEquals((int) $position->id, $afterId + 1, "Wrong position id"); - $this->assertEquals((float) $position->latitude, $this->testLat + 1, "Wrong latitude"); - $this->assertEquals((float) $position->longitude, $this->testLon, "Wrong longitude"); - $this->assertEquals((int) $position->timestamp, $this->testTimestamp + 1, "Wrong timestamp"); - $this->assertEquals((string) $position->username, $this->testAdminUser, "Wrong username"); - $this->assertEquals((string) $position->trackname, $this->testTrackName, "Wrong trackname"); - $this->assertEquals((int) $position->meters, 111195, "Wrong distance delta"); - $this->assertEquals((int) $position->seconds, 1, "Wrong timestamp delta"); + self::assertEquals($afterId + 1, (int) $position->id,"Wrong position id"); + self::assertEquals($this->testLat + 1, (float) $position->latitude,"Wrong latitude"); + self::assertEquals($this->testLon, (float) $position->longitude,"Wrong longitude"); + self::assertEquals($this->testTimestamp + 1, (int) $position->timestamp,"Wrong timestamp"); + self::assertEquals($this->testAdminUser, (string) $position->username,"Wrong username"); + self::assertEquals($this->testTrackName, (string) $position->trackname,"Wrong trackname"); + self::assertEquals(111195, (int) $position->meters,"Wrong distance delta"); + self::assertEquals(1, (int) $position->seconds,"Wrong timestamp delta"); } @@ -333,103 +333,103 @@ class InternalAPITest extends UloggerAPITestCase { public function testGetTracksAdmin() { - $this->assertTrue($this->authenticate(), "Authentication failed"); + self::assertTrue($this->authenticate(), "Authentication failed"); $this->addTestTrack($this->testUserId); $this->addTestTrack($this->testUserId, $this->testTrackName . "2"); - $this->assertEquals(2, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); + self::assertEquals(2, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); $options = [ "http_errors" => false, "query" => [ "userid" => $this->testUserId ], ]; $response = $this->http->get("/utils/gettracks.php", $options); - $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); + self::assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); - $this->assertNotNull($json, "JSON object is null"); - $this->assertEquals(count($json), 2, "Wrong count of tracks"); + self::assertNotNull($json, "JSON object is null"); + self::assertCount(2, $json, "Wrong count of tracks"); $track = $json[0]; - $this->assertEquals((int) $track->id, $this->testTrackId2, "Wrong track id"); - $this->assertEquals((string) $track->name, $this->testTrackName . "2", "Wrong track name"); + self::assertEquals($this->testTrackId2, (int) $track->id,"Wrong track id"); + self::assertEquals($this->testTrackName . "2", (string) $track->name,"Wrong track name"); $track = $json[1]; - $this->assertEquals((int) $track->id, $this->testTrackId, "Wrong track id"); - $this->assertEquals((string) $track->name, $this->testTrackName, "Wrong track name"); + self::assertEquals($this->testTrackId, (int) $track->id,"Wrong track id"); + self::assertEquals($this->testTrackName, (string) $track->name,"Wrong track name"); } public function testGetTracksUser() { $userId = $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT)); - $this->assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); - $this->assertTrue($this->authenticate($this->testUser, $this->testPass), "Authentication failed"); + self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); + self::assertTrue($this->authenticate($this->testUser, $this->testPass), "Authentication failed"); $this->addTestTrack($userId); $this->addTestTrack($userId, $this->testTrackName . "2"); - $this->assertEquals(2, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); + self::assertEquals(2, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); $options = [ "http_errors" => false, "query" => [ "userid" => $userId ], ]; $response = $this->http->get("/utils/gettracks.php", $options); - $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); + self::assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); - $this->assertNotNull($json, "JSON object is null"); - $this->assertEquals(count($json), 2, "Wrong count of tracks"); + self::assertNotNull($json, "JSON object is null"); + self::assertCount(2, $json, "Wrong count of tracks"); $track = $json[0]; - $this->assertEquals((int) $track->id, $this->testTrackId2, "Wrong track id"); - $this->assertEquals((string) $track->name, $this->testTrackName . "2", "Wrong track name"); + self::assertEquals($this->testTrackId2, (int) $track->id,"Wrong track id"); + self::assertEquals($this->testTrackName . "2", (string) $track->name,"Wrong track name"); $track = $json[1]; - $this->assertEquals((int) $track->id, $this->testTrackId, "Wrong track id"); - $this->assertEquals((string) $track->name, $this->testTrackName, "Wrong track name"); + self::assertEquals($this->testTrackId, (int) $track->id,"Wrong track id"); + self::assertEquals($this->testTrackName, (string) $track->name,"Wrong track name"); } public function testGetTracksOtherUser() { $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT)); - $this->assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); - $this->assertTrue($this->authenticate($this->testUser, $this->testPass), "Authentication failed"); + self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); + self::assertTrue($this->authenticate($this->testUser, $this->testPass), "Authentication failed"); $this->addTestTrack($this->testUserId); $this->addTestTrack($this->testUserId, $this->testTrackName . "2"); - $this->assertEquals(2, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); + self::assertEquals(2, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); $options = [ "http_errors" => false, "query" => [ "userid" => $this->testUserId ], ]; $response = $this->http->get("/utils/gettracks.php", $options); - $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); + self::assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); - $this->assertNotNull($json, "JSON object is null"); - $this->assertEquals(count($json), 0, "Wrong count of tracks"); + self::assertNotNull($json, "JSON object is null"); + self::assertCount(0, $json, "Wrong count of tracks"); } public function testGetTracksNoUserId() { $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT)); - $this->assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); - $this->assertTrue($this->authenticate($this->testUser, $this->testPass), "Authentication failed"); + self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); + self::assertTrue($this->authenticate($this->testUser, $this->testPass), "Authentication failed"); $this->addTestTrack($this->testUserId); $this->addTestTrack($this->testUserId, $this->testTrackName . "2"); - $this->assertEquals(2, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); + self::assertEquals(2, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); $options = [ "http_errors" => false, ]; $response = $this->http->get("/utils/gettracks.php", $options); - $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); + self::assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); - $this->assertNotNull($json, "JSON object is null"); - $this->assertEquals(count($json), 0, "Wrong count of tracks"); + self::assertNotNull($json, "JSON object is null"); + self::assertCount(0, $json, "Wrong count of tracks"); } public function testGetTracksNoAuth() { @@ -437,18 +437,18 @@ class InternalAPITest extends UloggerAPITestCase { $this->addTestTrack($this->testUserId); $this->addTestTrack($this->testUserId, $this->testTrackName . "2"); - $this->assertEquals(2, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); + self::assertEquals(2, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); $options = [ "http_errors" => false, "query" => [ "userid" => $this->testUserId ], ]; $response = $this->http->get("/utils/gettracks.php", $options); - $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); + self::assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); - $this->assertNotNull($json, "JSON object is null"); - $this->assertEquals(count($json), 0, "Wrong count of tracks"); + self::assertNotNull($json, "JSON object is null"); + self::assertCount(0, $json, "Wrong count of tracks"); } @@ -465,32 +465,32 @@ class InternalAPITest extends UloggerAPITestCase { ], ]; $response = $this->http->post("/utils/changepass.php", $options); - $this->assertEquals(401, $response->getStatusCode(), "Unexpected status code"); + self::assertEquals(401, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); - $this->assertNotNull($json, "JSON object is null"); - $this->assertEquals((int) $json->error, 1, "Wrong error status"); - $this->assertEquals((string) $json->message, "Unauthorized", "Wrong error message"); + self::assertNotNull($json, "JSON object is null"); + self::assertEquals(1, (int) $json->error, "Wrong error status"); + self::assertEquals("User not authorized", (string) $json->message, "Wrong error message"); } public function testChangePassEmpty() { - $this->assertTrue($this->authenticate(), "Authentication failed"); + self::assertTrue($this->authenticate(), "Authentication failed"); $options = [ "http_errors" => false, "form_params" => [ "login" => $this->testAdminUser ], ]; $response = $this->http->post("/utils/changepass.php", $options); - $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); + self::assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); - $this->assertNotNull($json, "JSON object is null"); - $this->assertEquals((int) $json->error, 1, "Wrong error status"); - $this->assertEquals((string) $json->message, "Empty password", "Wrong error message"); + self::assertNotNull($json, "JSON object is null"); + self::assertEquals(1, (int) $json->error, "Wrong error status"); + self::assertEquals("Empty password", (string) $json->message, "Wrong error message"); } public function testChangePassUserUnknown() { - $this->assertTrue($this->authenticate(), "Authentication failed"); + self::assertTrue($this->authenticate(), "Authentication failed"); $options = [ "http_errors" => false, @@ -500,16 +500,16 @@ class InternalAPITest extends UloggerAPITestCase { ], ]; $response = $this->http->post("/utils/changepass.php", $options); - $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); + self::assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); - $this->assertNotNull($json, "JSON object is null"); - $this->assertEquals((int) $json->error, 1, "Wrong error status"); - $this->assertEquals((string) $json->message, "User unknown", "Wrong error message"); + self::assertNotNull($json, "JSON object is null"); + self::assertEquals(1, (int) $json->error, "Wrong error status"); + self::assertEquals("User unknown", (string) $json->message, "Wrong error message"); } public function testChangePassEmptyLogin() { - $this->assertTrue($this->authenticate(), "Authentication failed"); + self::assertTrue($this->authenticate(), "Authentication failed"); $options = [ "http_errors" => false, @@ -518,16 +518,16 @@ class InternalAPITest extends UloggerAPITestCase { ], ]; $response = $this->http->post("/utils/changepass.php", $options); - $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); + self::assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); - $this->assertNotNull($json, "JSON object is null"); - $this->assertEquals((int) $json->error, 1, "Wrong error status"); - $this->assertEquals((string) $json->message, "Empty login", "Wrong error message"); + self::assertNotNull($json, "JSON object is null"); + self::assertEquals(1, (int) $json->error, "Wrong error status"); + self::assertEquals("Empty login", (string) $json->message, "Wrong error message"); } public function testChangePassWrongOldpass() { - $this->assertTrue($this->authenticate(), "Authentication failed"); + self::assertTrue($this->authenticate(), "Authentication failed"); $options = [ "http_errors" => false, @@ -538,16 +538,16 @@ class InternalAPITest extends UloggerAPITestCase { ], ]; $response = $this->http->post("/utils/changepass.php", $options); - $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); + self::assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); - $this->assertNotNull($json, "JSON object is null"); - $this->assertEquals((int) $json->error, 1, "Wrong error status"); - $this->assertEquals((string) $json->message, "Wrong old password", "Wrong error message"); + self::assertNotNull($json, "JSON object is null"); + self::assertEquals(1, (int) $json->error, "Wrong error status"); + self::assertEquals("Wrong old password", (string) $json->message, "Wrong error message"); } public function testChangePassNoOldpass() { - $this->assertTrue($this->authenticate(), "Authentication failed"); + self::assertTrue($this->authenticate(), "Authentication failed"); $options = [ "http_errors" => false, @@ -557,16 +557,16 @@ class InternalAPITest extends UloggerAPITestCase { ], ]; $response = $this->http->post("/utils/changepass.php", $options); - $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); + self::assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); - $this->assertNotNull($json, "JSON object is null"); - $this->assertEquals((int) $json->error, 1, "Wrong error status"); - $this->assertEquals((string) $json->message, "Wrong old password", "Wrong error message"); + self::assertNotNull($json, "JSON object is null"); + self::assertEquals(1, (int) $json->error,"Wrong error status"); + self::assertEquals("Wrong old password", (string) $json->message,"Wrong error message"); } public function testChangePassSelfAdmin() { - $this->assertTrue($this->authenticate(), "Authentication failed"); + self::assertTrue($this->authenticate(), "Authentication failed"); $newPass = "Newpass1234567890"; @@ -579,16 +579,16 @@ class InternalAPITest extends UloggerAPITestCase { ], ]; $response = $this->http->post("/utils/changepass.php", $options); - $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); + self::assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); - $this->assertNotNull($json, "JSON object is null"); - $this->assertTrue(password_verify($newPass, $this->pdoGetColumn("SELECT password FROM users")), "Wrong actual password hash"); + self::assertNotNull($json, "JSON object is null"); + self::assertTrue(password_verify($newPass, $this->pdoGetColumn("SELECT password FROM users")), "Wrong actual password hash"); } public function testChangePassSelfUser() { $userId = $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"); $newPass = "Newpass1234567890"; @@ -601,15 +601,15 @@ class InternalAPITest extends UloggerAPITestCase { ], ]; $response = $this->http->post("/utils/changepass.php", $options); - $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); + self::assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); - $this->assertNotNull($json, "JSON object is null"); - $this->assertTrue(password_verify($newPass, $this->pdoGetColumn("SELECT password FROM users WHERE id = $userId")), "Wrong actual password hash"); + self::assertNotNull($json, "JSON object is null"); + self::assertTrue(password_verify($newPass, $this->pdoGetColumn("SELECT password FROM users WHERE id = $userId")), "Wrong actual password hash"); } public function testChangePassOtherAdmin() { - $this->assertTrue($this->authenticate(), "Authentication failed"); + self::assertTrue($this->authenticate(), "Authentication failed"); $userId = $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT)); $newPass = "Newpass1234567890"; @@ -622,17 +622,17 @@ class InternalAPITest extends UloggerAPITestCase { ], ]; $response = $this->http->post("/utils/changepass.php", $options); - $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); + self::assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); - $this->assertNotNull($json, "JSON object is null"); - $this->assertTrue(password_verify($newPass, $this->pdoGetColumn("SELECT password FROM users WHERE id = $userId")), "Wrong actual password hash"); + self::assertNotNull($json, "JSON object is null"); + self::assertTrue(password_verify($newPass, $this->pdoGetColumn("SELECT password FROM users WHERE id = $userId")), "Wrong actual password hash"); } public function testChangePassOtherUser() { $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT)); $this->addTestUser($this->testUser2, 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"); $newPass = "Newpass1234567890"; @@ -644,102 +644,102 @@ class InternalAPITest extends UloggerAPITestCase { ], ]; $response = $this->http->post("/utils/changepass.php", $options); - $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); + self::assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); - $this->assertNotNull($json, "JSON object is null"); - $this->assertEquals((int) $json->error, 1, "Wrong error status"); - $this->assertEquals((string) $json->message, "Unauthorized", "Wrong error message"); + self::assertNotNull($json, "JSON object is null"); + self::assertEquals(1, (int) $json->error, "Wrong error status"); + self::assertEquals("User not authorized", (string) $json->message, "Wrong error message"); } /* handletrack.php */ public function testHandleTrackDeleteAdmin() { - $this->assertTrue($this->authenticate(), "Authentication failed"); + self::assertTrue($this->authenticate(), "Authentication failed"); $userId = $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT)); - $this->assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); + self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); $trackId = $this->addTestTrack($userId); $trackId2 = $this->addTestTrack($userId); - $this->assertEquals(2, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); + self::assertEquals(2, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); $options = [ "http_errors" => false, "form_params" => [ "trackid" => $trackId, "action" => "delete" ], ]; $response = $this->http->post("/utils/handletrack.php", $options); - $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); + self::assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); - $this->assertNotNull($json, "JSON object is null"); - $this->assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); - $this->assertEquals($trackId2, $this->pdoGetColumn("SELECT id FROM tracks WHERE id = $trackId2"), "Wrong actual track id"); + self::assertNotNull($json, "JSON object is null"); + self::assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); + self::assertEquals($trackId2, $this->pdoGetColumn("SELECT id FROM tracks WHERE id = $trackId2"), "Wrong actual track id"); } public function testHandleTrackDeleteSelf() { $userId = $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT)); - $this->assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); - $this->assertTrue($this->authenticate($this->testUser, $this->testPass), "Authentication failed"); + self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); + self::assertTrue($this->authenticate($this->testUser, $this->testPass), "Authentication failed"); $trackId = $this->addTestTrack($userId); $trackId2 = $this->addTestTrack($userId); - $this->assertEquals(2, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); + self::assertEquals(2, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); $options = [ "http_errors" => false, "form_params" => [ "trackid" => $trackId, "action" => "delete" ], ]; $response = $this->http->post("/utils/handletrack.php", $options); - $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); + self::assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); - $this->assertNotNull($json, "JSON object is null"); - $this->assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); - $this->assertEquals($trackId2, $this->pdoGetColumn("SELECT id FROM tracks WHERE id = $trackId2"), "Wrong actual track id"); + self::assertNotNull($json, "JSON object is null"); + self::assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); + self::assertEquals($trackId2, $this->pdoGetColumn("SELECT id FROM tracks WHERE id = $trackId2"), "Wrong actual track id"); } public function testHandleTrackDeleteOtherUser() { $lang = (new uLang($this->mockConfig))->getStrings(); $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT)); - $this->assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); - $this->assertTrue($this->authenticate($this->testUser, $this->testPass), "Authentication failed"); + self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); + self::assertTrue($this->authenticate($this->testUser, $this->testPass), "Authentication failed"); $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"); $options = [ "http_errors" => false, "form_params" => [ "trackid" => $trackId, "action" => "delete" ], ]; $response = $this->http->post("/utils/handletrack.php", $options); - $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); + self::assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); - $this->assertNotNull($json, "JSON object is null"); - $this->assertEquals(1, (int) $json->error, "Wrong error status"); - $this->assertEquals($lang["notauthorized"], (string) $json->message, "Wrong error message"); + self::assertNotNull($json, "JSON object is null"); + self::assertEquals(1, (int) $json->error, "Wrong error status"); + self::assertEquals($lang["notauthorized"], (string) $json->message, "Wrong error message"); } public function testHandleTrackUpdate() { $newName = "New name"; - $this->assertTrue($this->authenticate(), "Authentication failed"); + self::assertTrue($this->authenticate(), "Authentication failed"); $userId = $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT)); - $this->assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); + self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); $trackId = $this->addTestTrack($userId); $trackId2 = $this->addTestTrack($userId); - $this->assertEquals(2, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); + self::assertEquals(2, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); $options = [ "http_errors" => false, "form_params" => [ "trackid" => $trackId, "action" => "update", "trackname" => $newName ], ]; $response = $this->http->post("/utils/handletrack.php", $options); - $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); + self::assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); - $this->assertNotNull($json, "JSON object is null"); - $this->assertEquals(2, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); + self::assertNotNull($json, "JSON object is null"); + self::assertEquals(2, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); $row1 = [ "id" => $trackId2, "user_id" => $userId, @@ -762,65 +762,65 @@ class InternalAPITest extends UloggerAPITestCase { public function testHandleTrackUpdateEmptyName() { $lang = (new uLang($this->mockConfig))->getStrings(); - $this->assertTrue($this->authenticate(), "Authentication failed"); + self::assertTrue($this->authenticate(), "Authentication failed"); $userId = $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT)); - $this->assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); + self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); $trackId = $this->addTestTrack($userId); $this->addTestTrack($userId); - $this->assertEquals(2, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); + self::assertEquals(2, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); $options = [ "http_errors" => false, "form_params" => [ "trackid" => $trackId, "action" => "update", "trackname" => "" ], ]; $response = $this->http->post("/utils/handletrack.php", $options); - $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); + self::assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); - $this->assertNotNull($json, "JSON object is null"); - $this->assertEquals((int) $json->error, 1, "Wrong error status"); - $this->assertEquals((string) $json->message, $lang["servererror"], "Wrong error message"); - $this->assertEquals(2, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); + self::assertNotNull($json, "JSON object is null"); + self::assertEquals(1, (int) $json->error,"Wrong error status"); + self::assertEquals($lang["servererror"], (string) $json->message,"Wrong error message"); + self::assertEquals(2, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); } public function testHandleTrackUpdateNonexistantTrack() { $lang = (new uLang($this->mockConfig))->getStrings(); $newName = "New name"; - $this->assertTrue($this->authenticate(), "Authentication failed"); + self::assertTrue($this->authenticate(), "Authentication failed"); $userId = $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT)); - $this->assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); + self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); $trackId = $this->addTestTrack($userId); $nonexistantTrackId = $trackId + 1; - $this->assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); - $this->assertFalse($this->pdoGetColumn("SELECT id FROM tracks WHERE id = $nonexistantTrackId"), "Nonexistant track exists"); + self::assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); + self::assertFalse($this->pdoGetColumn("SELECT id FROM tracks WHERE id = $nonexistantTrackId"), "Nonexistant track exists"); $options = [ "http_errors" => false, "form_params" => [ "trackid" => $nonexistantTrackId, "action" => "update", "trackname" => $newName ], ]; $response = $this->http->post("/utils/handletrack.php", $options); - $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); + self::assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); - $this->assertNotNull($json, "JSON object is null"); - $this->assertEquals((int) $json->error, 1, "Wrong error status"); - $this->assertEquals((string) $json->message, $lang["servererror"], "Wrong error message"); + self::assertNotNull($json, "JSON object is null"); + self::assertEquals(1, (int) $json->error,"Wrong error status"); + self::assertEquals($lang["servererror"], (string) $json->message,"Wrong error message"); } public function testHandleTrackMissingAction() { $lang = (new uLang($this->mockConfig))->getStrings(); - $this->assertTrue($this->authenticate(), "Authentication failed"); + self::assertTrue($this->authenticate(), "Authentication failed"); $options = [ "http_errors" => false, ]; $response = $this->http->post("/utils/handletrack.php", $options); - $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); + self::assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); - $this->assertNotNull($json, "JSON object is null"); - $this->assertEquals((int) $json->error, 1, "Wrong error status"); - $this->assertEquals((string) $json->message, $lang["servererror"], "Wrong error message"); + self::assertNotNull($json, "JSON object is null"); + self::assertEquals(1, (int) $json->error, "Wrong error status"); + self::assertEquals($lang["servererror"], (string) $json->message,"Wrong error message"); } @@ -828,79 +828,79 @@ class InternalAPITest extends UloggerAPITestCase { public function testHandleUserMissingAction() { $lang = (new uLang($this->mockConfig))->getStrings(); - $this->assertTrue($this->authenticate(), "Authentication failed"); + self::assertTrue($this->authenticate(), "Authentication failed"); $options = [ "http_errors" => false, ]; $response = $this->http->post("/utils/handleuser.php", $options); - $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); + self::assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); - $this->assertNotNull($json, "JSON object is null"); - $this->assertEquals((int) $json->error, 1, "Wrong error status"); - $this->assertEquals((string) $json->message, $lang["servererror"], "Wrong error message"); + self::assertNotNull($json, "JSON object is null"); + self::assertEquals(1, (int) $json->error,"Wrong error status"); + self::assertEquals($lang["servererror"], (string) $json->message,"Wrong error message"); } public function testHandleUserNonAdmin() { $lang = (new uLang($this->mockConfig))->getStrings(); $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT)); - $this->assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); - $this->assertTrue($this->authenticate($this->testUser, $this->testPass), "Authentication failed"); + self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); + self::assertTrue($this->authenticate($this->testUser, $this->testPass), "Authentication failed"); $options = [ "http_errors" => false, "form_params" => [ "action" => "delete", "login" => "test" ], ]; $response = $this->http->post("/utils/handleuser.php", $options); - $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); + self::assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); - $this->assertNotNull($json, "JSON object is null"); - $this->assertEquals((int) $json->error, 1, "Wrong error status"); - $this->assertEquals((string) $json->message, $lang["servererror"], "Wrong error message"); - $this->assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); + self::assertNotNull($json, "JSON object is null"); + self::assertEquals(1, (int) $json->error,"Wrong error status"); + self::assertEquals($lang["servererror"], (string) $json->message,"Wrong error message"); + self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); } public function testHandleUserSelf() { $lang = (new uLang($this->mockConfig))->getStrings(); - $this->assertTrue($this->authenticate(), "Authentication failed"); - $this->assertEquals(1, $this->getConnection()->getRowCount("users"), "Wrong row count"); + self::assertTrue($this->authenticate(), "Authentication failed"); + self::assertEquals(1, $this->getConnection()->getRowCount("users"), "Wrong row count"); $options = [ "http_errors" => false, "form_params" => [ "action" => "delete", "login" => $this->testAdminUser ], ]; $response = $this->http->post("/utils/handleuser.php", $options); - $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); + self::assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); - $this->assertNotNull($json, "JSON object is null"); - $this->assertEquals((int) $json->error, 1, "Wrong error status"); - $this->assertEquals((string) $json->message, $lang["servererror"], "Wrong error message"); - $this->assertEquals(1, $this->getConnection()->getRowCount("users"), "Wrong row count"); + self::assertNotNull($json, "JSON object is null"); + self::assertEquals(1, (int) $json->error,"Wrong error status"); + self::assertEquals($lang["servererror"], (string) $json->message,"Wrong error message"); + self::assertEquals(1, $this->getConnection()->getRowCount("users"), "Wrong row count"); } public function testHandleUserEmptyLogin() { $lang = (new uLang($this->mockConfig))->getStrings(); - $this->assertTrue($this->authenticate(), "Authentication failed"); - $this->assertEquals(1, $this->getConnection()->getRowCount("users"), "Wrong row count"); + self::assertTrue($this->authenticate(), "Authentication failed"); + self::assertEquals(1, $this->getConnection()->getRowCount("users"), "Wrong row count"); $options = [ "http_errors" => false, "form_params" => [ "action" => "delete", "login" => "" ], ]; $response = $this->http->post("/utils/handleuser.php", $options); - $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); + self::assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); - $this->assertNotNull($json, "JSON object is null"); - $this->assertEquals((int) $json->error, 1, "Wrong error status"); - $this->assertEquals((string) $json->message, $lang["servererror"], "Wrong error message"); - $this->assertEquals(1, $this->getConnection()->getRowCount("users"), "Wrong row count"); + self::assertNotNull($json, "JSON object is null"); + self::assertEquals(1, (int) $json->error,"Wrong error status"); + self::assertEquals($lang["servererror"], (string) $json->message,"Wrong error message"); + self::assertEquals(1, $this->getConnection()->getRowCount("users"), "Wrong row count"); } public function testHandleUserNoAuth() { $lang = (new uLang($this->mockConfig))->getStrings(); $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT)); - $this->assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); + self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); $options = [ "http_errors" => false, @@ -908,27 +908,27 @@ class InternalAPITest extends UloggerAPITestCase { ]; $response = $this->http->post("/utils/handleuser.php", $options); - $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); + self::assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); - $this->assertNotNull($json, "JSON object is null"); - $this->assertEquals((int) $json->error, 1, "Wrong error status"); - $this->assertEquals((string) $json->message, $lang["servererror"], "Wrong error message"); - $this->assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); + self::assertNotNull($json, "JSON object is null"); + self::assertEquals(1, (int) $json->error,"Wrong error status"); + self::assertEquals($lang["servererror"], (string) $json->message,"Wrong error message"); + self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); } public function testHandleUserAdd() { - $this->assertTrue($this->authenticate(), "Authentication failed"); - $this->assertEquals(1, $this->getConnection()->getRowCount("users"), "Wrong row count"); + self::assertTrue($this->authenticate(), "Authentication failed"); + self::assertEquals(1, $this->getConnection()->getRowCount("users"), "Wrong row count"); $options = [ "http_errors" => false, "form_params" => [ "action" => "add", "login" => $this->testUser, "pass" => $this->testPass ], ]; $response = $this->http->post("/utils/handleuser.php", $options); - $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); + self::assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); - $this->assertNotNull($json, "JSON object is null"); - $this->assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); + self::assertNotNull($json, "JSON object is null"); + self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); $expected = [ "login" => $this->testUser, ]; @@ -937,76 +937,76 @@ class InternalAPITest extends UloggerAPITestCase { "SELECT login FROM users" ); $this->assertTableContains($expected, $actual, "Wrong actual table data"); - $this->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() { $lang = (new uLang($this->mockConfig))->getStrings(); - $this->assertTrue($this->authenticate(), "Authentication failed"); + self::assertTrue($this->authenticate(), "Authentication failed"); $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT)); - $this->assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); + self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); $options = [ "http_errors" => false, "form_params" => [ "action" => "add", "login" => $this->testUser, "pass" => $this->testPass ], ]; $response = $this->http->post("/utils/handleuser.php", $options); - $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); + self::assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); - $this->assertNotNull($json, "JSON object is null"); - $this->assertEquals(1, (int) $json->error, "Wrong error status"); - $this->assertEquals((string) $json->message, $lang["userexists"], "Wrong error message"); - $this->assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); + self::assertNotNull($json, "JSON object is null"); + self::assertEquals(1, (int) $json->error, "Wrong error status"); + self::assertEquals($lang["userexists"], (string) $json->message,"Wrong error message"); + self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); } public function testHandleUserUpdate() { $newPass = $this->testPass . "new"; - $this->assertTrue($this->authenticate(), "Authentication failed"); + self::assertTrue($this->authenticate(), "Authentication failed"); $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT)); - $this->assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); + self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); $options = [ "http_errors" => false, "form_params" => [ "action" => "update", "login" => $this->testUser, "pass" => $newPass ], ]; $response = $this->http->post("/utils/handleuser.php", $options); - $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); + self::assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); - $this->assertNotNull($json, "JSON object is null"); - $this->assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); - $this->assertTrue(password_verify($newPass, $this->pdoGetColumn("SELECT password FROM users WHERE login = '$this->testUser'")), "Wrong actual password hash"); + self::assertNotNull($json, "JSON object is null"); + self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); + self::assertTrue(password_verify($newPass, $this->pdoGetColumn("SELECT password FROM users WHERE login = '$this->testUser'")), "Wrong actual password hash"); } public function testHandleUserUpdateEmptyPass() { - $this->assertTrue($this->authenticate(), "Authentication failed"); + self::assertTrue($this->authenticate(), "Authentication failed"); $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT)); - $this->assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); + self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); $options = [ "http_errors" => false, "form_params" => [ "action" => "update", "login" => $this->testUser, "pass" => "" ], ]; $response = $this->http->post("/utils/handleuser.php", $options); - $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); + self::assertEquals(200, $response->getStatusCode(), "Unexpected status code"); - $this->assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); - $this->assertTrue(password_verify($this->testPass, $this->pdoGetColumn("SELECT password FROM users WHERE login = '$this->testUser'")), "Wrong actual password hash"); + self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); + self::assertTrue(password_verify($this->testPass, $this->pdoGetColumn("SELECT password FROM users WHERE login = '$this->testUser'")), "Wrong actual password hash"); } public function testHandleUserDelete() { - $this->assertTrue($this->authenticate(), "Authentication failed"); + self::assertTrue($this->authenticate(), "Authentication failed"); $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT)); - $this->assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); + self::assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count"); $options = [ "http_errors" => false, "form_params" => [ "action" => "delete", "login" => $this->testUser ], ]; $response = $this->http->post("/utils/handleuser.php", $options); - $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); + self::assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); - $this->assertNotNull($json, "JSON object is null"); - $this->assertEquals(1, $this->getConnection()->getRowCount("users"), "Wrong row count"); + self::assertNotNull($json, "JSON object is null"); + self::assertEquals(1, $this->getConnection()->getRowCount("users"), "Wrong row count"); } }