diff --git a/.tests/lib/BaseDatabaseTestCase.php b/.tests/lib/BaseDatabaseTestCase.php
index c59fad9..2e71e53 100644
--- a/.tests/lib/BaseDatabaseTestCase.php
+++ b/.tests/lib/BaseDatabaseTestCase.php
@@ -180,7 +180,11 @@ abstract class BaseDatabaseTestCase extends PHPUnit_Extensions_Database_TestCase
protected function addTestUser($user = NULL, $pass = NULL) {
if (is_null($user)) { $user = $this->testUser; }
if (is_null($pass)) { $pass = $this->testPass; }
- return $this->pdoInsert('users', [ 'login' => $user, 'password' => $pass ]);
+ $id = $this->pdoInsert('users', [ 'login' => $user, 'password' => $pass ]);
+ if ($id !== false) {
+ return (int) $id;
+ }
+ return false;
}
/**
@@ -196,7 +200,11 @@ abstract class BaseDatabaseTestCase extends PHPUnit_Extensions_Database_TestCase
if (is_null($userId)) { $userId = $this->testUserId; }
if (is_null($trackName)) { $trackName = $this->testTrackName; }
if (is_null($comment)) { $comment = $this->testTrackComment; }
- return $this->pdoInsert('tracks', [ 'user_id' => $userId, 'name' => $trackName, 'comment' => $comment ]);
+ $id = $this->pdoInsert('tracks', [ 'user_id' => $userId, 'name' => $trackName, 'comment' => $comment ]);
+ if ($id !== false) {
+ return (int) $id;
+ }
+ return false;
}
/**
diff --git a/.tests/tests/ClientAPITest.php b/.tests/tests/ClientAPITest.php
index 7cd135d..396eb57 100644
--- a/.tests/tests/ClientAPITest.php
+++ b/.tests/tests/ClientAPITest.php
@@ -224,8 +224,7 @@ class ClientAPITest extends UloggerAPITestCase {
'bearing' => $this->testBearing,
'accuracy' => $this->testAccuracy,
'provider' => $this->testProvider,
- 'comment' => $this->testComment,
- 'imageid' => $this->testImage
+ 'comment' => $this->testComment
],
];
$response = $this->http->post('/client/index.php', $options);
@@ -246,7 +245,7 @@ class ClientAPITest extends UloggerAPITestCase {
"accuracy" => $this->testAccuracy,
"provider" => $this->testProvider,
"comment" => $this->testComment,
- "image" => $this->testImage
+ "image" => null
];
$actual = $this->getConnection()->createQueryTable(
"positions",
@@ -255,6 +254,107 @@ class ClientAPITest extends UloggerAPITestCase {
$this->assertTableContains($expected, $actual, "Wrong actual table data");
}
+ public function testAddPositionWithImage() {
+ $this->assertTrue($this->authenticate(), "Authentication failed");
+
+ $trackId = $this->addTestTrack($this->testUserId);
+ $this->assertEquals(1, $this->getConnection()->getRowCount('tracks'), "Wrong row count");
+ $this->assertEquals(0, $this->getConnection()->getRowCount('positions'), "Wrong row count");
+
+ $options = [
+ 'http_errors' => false,
+ 'multipart' => [
+ [
+ 'name' => 'action',
+ 'contents' => 'addpos',
+ ],
+ [
+ 'name' => 'trackid',
+ 'contents' => $trackId,
+ ],
+ [
+ 'name' => 'time',
+ 'contents' => $this->testTimestamp,
+ ],
+ [
+ 'name' => 'lat',
+ 'contents' => $this->testLat,
+ ],
+ [
+ 'name' => 'lon',
+ 'contents' => $this->testLon,
+ ],
+ [
+ 'name' => 'altitude',
+ 'contents' => $this->testAltitude,
+ ],
+ [
+ 'name' => 'speed',
+ 'contents' => $this->testSpeed,
+ ],
+ [
+ 'name' => 'bearing',
+ 'contents' => $this->testBearing,
+ ],
+ [
+ 'name' => 'accuracy',
+ 'contents' => $this->testAccuracy,
+ ],
+ [
+ 'name' => 'provider',
+ 'contents' => $this->testProvider,
+ ],
+ [
+ 'name' => 'comment',
+ 'contents' => $this->testComment,
+ ],
+ [
+ 'name' => 'image',
+ 'contents' => 'DEADBEEF',
+ 'filename' => 'upload',
+ 'headers' => [ 'Content-Type' => 'image/jpeg', 'Content-Transfer-Encoding' => 'binary' ]
+ ]
+ ]
+ ];
+ $response = $this->http->post('/client/index.php', $options);
+ $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
+ $json = json_decode((string) $response->getBody());
+ $this->assertFalse($json->{'error'}, "Unexpected error");
+ $this->assertEquals(1, $this->getConnection()->getRowCount('positions'), "Wrong row count");
+ $expected = [
+ "id" => 1,
+ "user_id" => $this->testUserId,
+ "track_id" => $trackId,
+ "time" => $this->testTimestamp,
+ "latitude" => $this->testLat,
+ "longitude" => $this->testLon,
+ "altitude" => $this->testAltitude,
+ "speed" => $this->testSpeed,
+ "bearing" => $this->testBearing,
+ "accuracy" => $this->testAccuracy,
+ "provider" => $this->testProvider,
+ "comment" => $this->testComment,
+ "image" => null
+ ];
+ $actual = $this->getConnection()->createQueryTable(
+ "positions",
+ "SELECT id, user_id, track_id, " . $this->unix_timestamp('time') . " AS time, latitude, longitude, altitude, speed, bearing, accuracy, provider, comment, image FROM positions"
+ );
+ $this->assertEquals($expected['id'], $actual->getValue(0, 'id'));
+ $this->assertEquals($expected['user_id'], $actual->getValue(0, 'user_id'));
+ $this->assertEquals($expected['track_id'], $actual->getValue(0, 'track_id'));
+ $this->assertEquals($expected['time'], $actual->getValue(0, 'time'));
+ $this->assertEquals($expected['latitude'], $actual->getValue(0, 'latitude'));
+ $this->assertEquals($expected['longitude'], $actual->getValue(0, 'longitude'));
+ $this->assertEquals($expected['altitude'], $actual->getValue(0, 'altitude'));
+ $this->assertEquals($expected['speed'], $actual->getValue(0, 'speed'));
+ $this->assertEquals($expected['bearing'], $actual->getValue(0, 'bearing'));
+ $this->assertEquals($expected['accuracy'], $actual->getValue(0, 'accuracy'));
+ $this->assertEquals($expected['provider'], $actual->getValue(0, 'provider'));
+ $this->assertEquals($expected['comment'], $actual->getValue(0, 'comment'));
+ $this->assertContains('.jpg', $actual->getValue(0, 'image'));
+ }
+
public function testAddPositionNoexistantTrack() {
$this->assertTrue($this->authenticate(), "Authentication failed");
diff --git a/.tests/tests/ImportTest.php b/.tests/tests/ImportTest.php
index f01bb9f..1b3dba8 100644
--- a/.tests/tests/ImportTest.php
+++ b/.tests/tests/ImportTest.php
@@ -1,4 +1,4 @@
-http->post("/utils/import.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
+ $json = json_decode($response->getBody());
+ $this->assertNotNull($json, "JSON object is null");
+ $this->assertEquals(count($json), 1, "Wrong count of tracks");
- $this->assertTrue($xml !== false, "XML object is false");
- $this->assertEquals(0, (int) $xml->error, "Wrong error status");
- $this->assertEquals(1, (int) $xml->trackid, "Wrong error message");
- $this->assertEquals(1, (int) $xml->trackcnt, "Wrong error message");
+ $track = $json[0];
+ $this->assertEquals(1, (int) $track->id, "Wrong track id");
+ $this->assertEquals($this->testTrackName, $track->name, "Wrong track name");
$this->assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
$this->assertEquals(2, $this->getConnection()->getRowCount("positions"), "Wrong row count");
@@ -170,12 +171,14 @@ class ImportTest extends UloggerAPITestCase {
$response = $this->http->post("/utils/import.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
+ $json = json_decode($response->getBody());
- $this->assertTrue($xml !== false, "XML object is false");
- $this->assertEquals(0, (int) $xml->error, "Wrong error status");
- $this->assertEquals(1, (int) $xml->trackid, "Wrong error message");
- $this->assertEquals(1, (int) $xml->trackcnt, "Wrong error message");
+ $this->assertNotNull($json, "JSON object is null");
+ $this->assertEquals(count($json), 1, "Wrong count of tracks");
+
+ $track = $json[0];
+ $this->assertEquals(1, (int) $track->id, "Wrong track id");
+ $this->assertEquals($this->testTrackName, $track->name, "Wrong track name");
$this->assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
$this->assertEquals(1, $this->getConnection()->getRowCount("positions"), "Wrong row count");
@@ -241,7 +244,7 @@ class ImportTest extends UloggerAPITestCase {
' . $this->testAltitude . '
1
-
+ testComment . ']]>
' . $this->testSpeed . '
' . $this->testBearing . '
@@ -270,12 +273,14 @@ class ImportTest extends UloggerAPITestCase {
$response = $this->http->post("/utils/import.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
+ $json = json_decode($response->getBody());
- $this->assertTrue($xml !== false, "XML object is false");
- $this->assertEquals(0, (int) $xml->error, "Wrong error status");
- $this->assertEquals(1, (int) $xml->trackid, "Wrong error message");
- $this->assertEquals(1, (int) $xml->trackcnt, "Wrong error message");
+ $this->assertNotNull($json, "JSON object is null");
+ $this->assertEquals(count($json), 1, "Wrong count of tracks");
+
+ $track = $json[0];
+ $this->assertEquals(1, (int) $track->id, "Wrong track id");
+ $this->assertEquals($this->testTrackName, $track->name, "Wrong track name");
$this->assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
$this->assertEquals(1, $this->getConnection()->getRowCount("positions"), "Wrong row count");
@@ -303,7 +308,7 @@ class ImportTest extends UloggerAPITestCase {
"bearing" => $this->testBearing,
"accuracy" => $this->testAccuracy,
"provider" => $this->testProvider,
- "comment" => null,
+ "comment" => $this->testComment,
"image" => null
];
$actual = $this->getConnection()->createQueryTable(
@@ -351,12 +356,14 @@ class ImportTest extends UloggerAPITestCase {
$response = $this->http->post("/utils/import.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
+ $json = json_decode($response->getBody());
- $this->assertTrue($xml !== false, "XML object is false");
- $this->assertEquals(0, (int) $xml->error, "Wrong error status");
- $this->assertEquals(1, (int) $xml->trackid, "Wrong error message");
- $this->assertEquals(1, (int) $xml->trackcnt, "Wrong error message");
+ $this->assertNotNull($json, "JSON object is null");
+ $this->assertEquals(count($json), 1, "Wrong count of tracks");
+
+ $track = $json[0];
+ $this->assertEquals(1, (int) $track->id, "Wrong track id");
+ $this->assertEquals($this->testTrackName, $track->name, "Wrong track name");
$this->assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
$this->assertEquals(1, $this->getConnection()->getRowCount("positions"), "Wrong row count");
@@ -438,12 +445,14 @@ class ImportTest extends UloggerAPITestCase {
$response = $this->http->post("/utils/import.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
+ $json = json_decode($response->getBody());
- $this->assertTrue($xml !== false, "XML object is false");
- $this->assertEquals(0, (int) $xml->error, "Wrong error status: $xml->message");
- $this->assertEquals(1, (int) $xml->trackid, "Wrong error message");
- $this->assertEquals(1, (int) $xml->trackcnt, "Wrong error message");
+ $this->assertNotNull($json, "JSON object is null");
+ $this->assertEquals(count($json), 1, "Wrong count of tracks");
+
+ $track = $json[0];
+ $this->assertEquals(1, (int) $track->id, "Wrong track id");
+ $this->assertEquals($this->testTrackName, $track->name, "Wrong track name");
$this->assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
$this->assertEquals(2, $this->getConnection()->getRowCount("positions"), "Wrong row count");
@@ -543,12 +552,18 @@ class ImportTest extends UloggerAPITestCase {
$response = $this->http->post("/utils/import.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
+ $json = json_decode($response->getBody());
- $this->assertTrue($xml !== false, "XML object is false");
- $this->assertEquals(0, (int) $xml->error, "Wrong error status: $xml->message");
- $this->assertEquals(2, (int) $xml->trackid, "Wrong error message");
- $this->assertEquals(2, (int) $xml->trackcnt, "Wrong error message");
+ $this->assertNotNull($json, "JSON object is null");
+ $this->assertEquals(count($json), 2, "Wrong count of tracks");
+
+ $track = $json[0];
+ $this->assertEquals(2, (int) $track->id, "Wrong track id");
+ $this->assertEquals($this->testTrackName, $track->name, "Wrong track name");
+
+ $track = $json[1];
+ $this->assertEquals(1, (int) $track->id, "Wrong track id");
+ $this->assertEquals($this->testTrackName, $track->name, "Wrong track name");
$this->assertEquals(2, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
$this->assertEquals(2, $this->getConnection()->getRowCount("positions"), "Wrong row count");
@@ -647,11 +662,11 @@ class ImportTest extends UloggerAPITestCase {
$response = $this->http->post("/utils/import.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
+ $json = json_decode($response->getBody());
- $this->assertTrue($xml !== false, "XML object is false");
- $this->assertEquals(1, (int) $xml->error, "Wrong error status");
- $this->assertEquals($lang["iparsefailure"], (string) $xml->message, "Wrong error status");
+ $this->assertNotNull($json, "JSON object is null");
+ $this->assertEquals(1, (int) $json->error, "Wrong error status");
+ $this->assertEquals($lang["iparsefailure"], (string) $json->message, "Wrong error status");
$this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
$this->assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
@@ -694,11 +709,11 @@ class ImportTest extends UloggerAPITestCase {
$response = $this->http->post("/utils/import.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
+ $json = json_decode($response->getBody());
- $this->assertTrue($xml !== false, "XML object is false");
- $this->assertEquals(1, (int) $xml->error, "Wrong error status");
- $this->assertEquals($lang["iparsefailure"], (string) $xml->message, "Wrong error status");
+ $this->assertNotNull($json, "JSON object is null");
+ $this->assertEquals(1, (int) $json->error, "Wrong error status");
+ $this->assertEquals($lang["iparsefailure"], (string) $json->message, "Wrong error status");
$this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
$this->assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
@@ -735,11 +750,11 @@ class ImportTest extends UloggerAPITestCase {
$response = $this->http->post("/utils/import.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
+ $json = json_decode($response->getBody());
- $this->assertTrue($xml !== false, "XML object is false");
- $this->assertEquals(1, (int) $xml->error, "Wrong error status");
- $this->assertEquals($lang["iparsefailure"], (string) $xml->message, "Wrong error status");
+ $this->assertNotNull($json, "JSON object is null");
+ $this->assertEquals(1, (int) $json->error, "Wrong error status");
+ $this->assertEquals($lang["iparsefailure"], (string) $json->message, "Wrong error status");
$this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
$this->assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
@@ -780,29 +795,16 @@ class ImportTest extends UloggerAPITestCase {
$response = $this->http->post("/utils/import.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
+ $json = json_decode($response->getBody());
- $this->assertTrue($xml !== false, "XML object is false");
- $this->assertEquals(1, (int) $xml->error, "Wrong error status");
- $this->assertEquals(0, strpos((string) $xml->message, $lang["iparsefailure"]), "Wrong error status");
+ $this->assertNotNull($json, "JSON object is null");
+ $this->assertEquals(1, (int) $json->error, "Wrong error status");
+ $this->assertEquals(0, strpos((string) $json->message, $lang["iparsefailure"]), "Wrong error status");
$this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
$this->assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
}
- /**
- * @param ResponseInterface $response
- * @return bool|SimpleXMLElement
- */
- private function getXMLfromResponse($response) {
- $xml = false;
- libxml_use_internal_errors(true);
- try {
- $xml = new SimpleXMLElement((string) $response->getBody());
- } catch (Exception $e) { /* ignore */ }
- return $xml;
- }
-
private function getStream($string) {
$stream = tmpfile();
fwrite($stream, $string);
diff --git a/.tests/tests/InternalAPITest.php b/.tests/tests/InternalAPITest.php
index d4472d3..8a68d80 100644
--- a/.tests/tests/InternalAPITest.php
+++ b/.tests/tests/InternalAPITest.php
@@ -28,20 +28,20 @@ class InternalAPITest extends UloggerAPITestCase {
$response = $this->http->get("/utils/getpositions.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
- $this->assertTrue($xml !== false, "XML object is false");
- $this->assertEquals($xml->position->count(), 2, "Wrong count of positions");
+ $json = json_decode($response->getBody());
+ $this->assertNotNull($json, "JSON object is null");
+ $this->assertEquals(count($json), 2, "Wrong count of positions");
- $position = $xml->position[0];
- $this->assertEquals((int) $position["id"], 1, "Wrong position id");
+ $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");
- $position = $xml->position[1];
- $this->assertEquals((int) $position["id"], 2, "Wrong position id");
+ $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");
@@ -67,20 +67,20 @@ class InternalAPITest extends UloggerAPITestCase {
$response = $this->http->get("/utils/getpositions.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
- $this->assertTrue($xml !== false, "XML object is false");
- $this->assertEquals($xml->position->count(), 2, "Wrong count of positions");
+ $json = json_decode($response->getBody());
+ $this->assertNotNull($json, "JSON object is null");
+ $this->assertEquals(count($json), 2, "Wrong count of positions");
- $position = $xml->position[0];
- $this->assertEquals((int) $position["id"], 1, "Wrong position id");
+ $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");
- $position = $xml->position[1];
- $this->assertEquals((int) $position["id"], 2, "Wrong position id");
+ $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");
@@ -107,9 +107,9 @@ class InternalAPITest extends UloggerAPITestCase {
$response = $this->http->get("/utils/getpositions.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
- $this->assertTrue($xml !== false, "XML object is false");
- $this->assertEquals($xml->position->count(), 0, "Wrong count of positions");
+ $json = json_decode($response->getBody());
+ $this->assertNotNull($json, "JSON object is null");
+ $this->assertEquals(count($json), 0, "Wrong count of positions");
}
public function testGetPositionsOtherUserByAdmin() {
@@ -131,20 +131,20 @@ class InternalAPITest extends UloggerAPITestCase {
$response = $this->http->get("/utils/getpositions.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
- $this->assertTrue($xml !== false, "XML object is false");
- $this->assertEquals($xml->position->count(), 2, "Wrong count of positions");
+ $json = json_decode($response->getBody());
+ $this->assertNotNull($json, "JSON object is null");
+ $this->assertEquals(count($json), 2, "Wrong count of positions");
- $position = $xml->position[0];
- $this->assertEquals((int) $position["id"], 1, "Wrong position id");
+ $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");
- $position = $xml->position[1];
- $this->assertEquals((int) $position["id"], 2, "Wrong position id");
+ $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");
@@ -175,12 +175,12 @@ class InternalAPITest extends UloggerAPITestCase {
$response = $this->http->get("/utils/getpositions.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
- $this->assertTrue($xml !== false, "XML object is false");
- $this->assertEquals($xml->position->count(), 1, "Wrong count of positions");
+ $json = json_decode($response->getBody());
+ $this->assertNotNull($json, "JSON object is null");
+ $this->assertEquals(count($json), 1, "Wrong count of positions");
- $position = $xml->position[0];
- $this->assertEquals((int) $position["id"], 2, "Wrong position id");
+ $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");
@@ -212,20 +212,20 @@ class InternalAPITest extends UloggerAPITestCase {
$response = $this->http->get("/utils/getpositions.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
- $this->assertTrue($xml !== false, "XML object is false");
- $this->assertEquals($xml->position->count(), 2, "Wrong count of positions");
+ $json = json_decode($response->getBody());
+ $this->assertNotNull($json, "JSON object is null");
+ $this->assertEquals(count($json), 2, "Wrong count of positions");
- $position = $xml->position[0];
- $this->assertEquals((int) $position["id"], 2, "Wrong position id");
+ $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");
- $position = $xml->position[1];
- $this->assertEquals((int) $position["id"], 3, "Wrong position id");
+ $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");
@@ -250,9 +250,9 @@ class InternalAPITest extends UloggerAPITestCase {
$response = $this->http->get("/utils/getpositions.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
- $this->assertTrue($xml !== false, "XML object is false");
- $this->assertEquals(0, $xml->position->count(), "Wrong count of positions");
+ $json = json_decode($response->getBody());
+ $this->assertNotNull($json, "JSON object is null");
+ $this->assertCount(0, $json, "Wrong count of positions");
}
public function testGetPositionsNoUserId() {
@@ -272,10 +272,9 @@ class InternalAPITest extends UloggerAPITestCase {
$response = $this->http->get("/utils/getpositions.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
-
- $this->assertTrue($xml !== false, "XML object is false");
- $this->assertEquals(0, $xml->position->count(), "Wrong count of positions");
+ $json = json_decode($response->getBody());
+ $this->assertNotNull($json, "JSON object is null");
+ $this->assertCount(0, $json, "Wrong count of positions");
}
public function testGetPositionsNoAuth() {
@@ -291,10 +290,10 @@ class InternalAPITest extends UloggerAPITestCase {
$response = $this->http->get("/utils/getpositions.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
+ $json = json_decode($response->getBody());
- $this->assertTrue($xml !== false, "XML object is not false");
- $this->assertEquals($xml->position->count(), 0, "Wrong count of positions");
+ $this->assertNotNull($json, "JSON object is null");
+ $this->assertEquals(count($json), 0, "Wrong count of positions");
}
@@ -317,17 +316,17 @@ class InternalAPITest extends UloggerAPITestCase {
$response = $this->http->get("/utils/gettracks.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
- $this->assertTrue($xml !== false, "XML object is false");
- $this->assertEquals($xml->track->count(), 2, "Wrong count of tracks");
+ $json = json_decode($response->getBody());
+ $this->assertNotNull($json, "JSON object is null");
+ $this->assertEquals(count($json), 2, "Wrong count of tracks");
- $track = $xml->track[0];
- $this->assertEquals((int) $track->trackid, $this->testTrackId2, "Wrong track id");
- $this->assertEquals((string) $track->trackname, $this->testTrackName . "2", "Wrong track name");
+ $track = $json[0];
+ $this->assertEquals((int) $track->id, $this->testTrackId2, "Wrong track id");
+ $this->assertEquals((string) $track->name, $this->testTrackName . "2", "Wrong track name");
- $track = $xml->track[1];
- $this->assertEquals((int) $track->trackid, $this->testTrackId, "Wrong track id");
- $this->assertEquals((string) $track->trackname, $this->testTrackName, "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");
}
public function testGetTracksUser() {
@@ -347,18 +346,18 @@ class InternalAPITest extends UloggerAPITestCase {
$response = $this->http->get("/utils/gettracks.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
- $this->assertTrue($xml !== false, "XML object is false");
- $this->assertEquals($xml->track->count(), 2, "Wrong count of tracks");
+ $json = json_decode($response->getBody());
+ $this->assertNotNull($json, "JSON object is null");
+ $this->assertEquals(count($json), 2, "Wrong count of tracks");
- $track = $xml->track[0];
- $this->assertEquals((int) $track->trackid, $this->testTrackId2, "Wrong track id");
- $this->assertEquals((string) $track->trackname, $this->testTrackName . "2", "Wrong track name");
+ $track = $json[0];
+ $this->assertEquals((int) $track->id, $this->testTrackId2, "Wrong track id");
+ $this->assertEquals((string) $track->name, $this->testTrackName . "2", "Wrong track name");
- $track = $xml->track[1];
- $this->assertEquals((int) $track->trackid, $this->testTrackId, "Wrong track id");
- $this->assertEquals((string) $track->trackname, $this->testTrackName, "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");
+ }
public function testGetTracksOtherUser() {
$this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
@@ -377,9 +376,9 @@ class InternalAPITest extends UloggerAPITestCase {
$response = $this->http->get("/utils/gettracks.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
- $this->assertTrue($xml !== false, "XML object is false");
- $this->assertEquals($xml->track->count(), 0, "Wrong count of tracks");
+ $json = json_decode($response->getBody());
+ $this->assertNotNull($json, "JSON object is null");
+ $this->assertEquals(count($json), 0, "Wrong count of tracks");
}
public function testGetTracksNoUserId() {
@@ -397,9 +396,9 @@ class InternalAPITest extends UloggerAPITestCase {
];
$response = $this->http->get("/utils/gettracks.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
- $this->assertTrue($xml !== false, "XML object is not false");
- $this->assertEquals($xml->track->count(), 0, "Wrong count of tracks");
+ $json = json_decode($response->getBody());
+ $this->assertNotNull($json, "JSON object is null");
+ $this->assertEquals(count($json), 0, "Wrong count of tracks");
}
public function testGetTracksNoAuth() {
@@ -416,9 +415,9 @@ class InternalAPITest extends UloggerAPITestCase {
$response = $this->http->get("/utils/gettracks.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
- $this->assertTrue($xml !== false, "XML object is not false");
- $this->assertEquals($xml->track->count(), 0, "Wrong count of tracks");
+ $json = json_decode($response->getBody());
+ $this->assertNotNull($json, "JSON object is null");
+ $this->assertEquals(count($json), 0, "Wrong count of tracks");
}
@@ -437,10 +436,10 @@ class InternalAPITest extends UloggerAPITestCase {
$response = $this->http->post("/utils/changepass.php", $options);
$this->assertEquals(401, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
- $this->assertTrue($xml !== false, "XML object is not false");
- $this->assertEquals((int) $xml->error, 1, "Wrong error status");
- $this->assertEquals((string) $xml->message, "Unauthorized", "Wrong error message");
+ $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");
}
public function testChangePassEmpty() {
@@ -453,10 +452,10 @@ class InternalAPITest extends UloggerAPITestCase {
$response = $this->http->post("/utils/changepass.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
- $this->assertTrue($xml !== false, "XML object is not false");
- $this->assertEquals((int) $xml->error, 1, "Wrong error status");
- $this->assertEquals((string) $xml->message, "Empty password", "Wrong error message");
+ $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");
}
public function testChangePassUserUnknown() {
@@ -472,10 +471,10 @@ class InternalAPITest extends UloggerAPITestCase {
$response = $this->http->post("/utils/changepass.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
- $this->assertTrue($xml !== false, "XML object is not false");
- $this->assertEquals((int) $xml->error, 1, "Wrong error status");
- $this->assertEquals((string) $xml->message, "User unknown", "Wrong error message");
+ $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");
}
public function testChangePassEmptyLogin() {
@@ -490,10 +489,10 @@ class InternalAPITest extends UloggerAPITestCase {
$response = $this->http->post("/utils/changepass.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
- $this->assertTrue($xml !== false, "XML object is not false");
- $this->assertEquals((int) $xml->error, 1, "Wrong error status");
- $this->assertEquals((string) $xml->message, "Empty login", "Wrong error message");
+ $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");
}
public function testChangePassWrongOldpass() {
@@ -510,10 +509,10 @@ class InternalAPITest extends UloggerAPITestCase {
$response = $this->http->post("/utils/changepass.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
- $this->assertTrue($xml !== false, "XML object is not false");
- $this->assertEquals((int) $xml->error, 1, "Wrong error status");
- $this->assertEquals((string) $xml->message, "Wrong old password", "Wrong error message");
+ $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");
}
public function testChangePassNoOldpass() {
@@ -529,10 +528,10 @@ class InternalAPITest extends UloggerAPITestCase {
$response = $this->http->post("/utils/changepass.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
- $this->assertTrue($xml !== false, "XML object is not false");
- $this->assertEquals((int) $xml->error, 1, "Wrong error status");
- $this->assertEquals((string) $xml->message, "Wrong old password", "Wrong error message");
+ $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");
}
public function testChangePassSelfAdmin() {
@@ -551,9 +550,8 @@ class InternalAPITest extends UloggerAPITestCase {
$response = $this->http->post("/utils/changepass.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
- $this->assertTrue($xml !== false, "XML object is not false");
- $this->assertEquals((int) $xml->error, 0, "Wrong error status");
+ $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");
}
@@ -574,9 +572,8 @@ class InternalAPITest extends UloggerAPITestCase {
$response = $this->http->post("/utils/changepass.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
- $this->assertTrue($xml !== false, "XML object is not false");
- $this->assertEquals((int) $xml->error, 0, "Wrong error status");
+ $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");
}
@@ -596,9 +593,8 @@ class InternalAPITest extends UloggerAPITestCase {
$response = $this->http->post("/utils/changepass.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
- $this->assertTrue($xml !== false, "XML object is not false");
- $this->assertEquals((int) $xml->error, 0, "Wrong error status");
+ $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");
}
@@ -619,10 +615,10 @@ class InternalAPITest extends UloggerAPITestCase {
$response = $this->http->post("/utils/changepass.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
- $this->assertTrue($xml !== false, "XML object is not false");
- $this->assertEquals((int) $xml->error, 1, "Wrong error status");
- $this->assertEquals((string) $xml->message, "Unauthorized", "Wrong error message");
+ $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");
}
/* handletrack.php */
@@ -643,9 +639,8 @@ class InternalAPITest extends UloggerAPITestCase {
];
$response = $this->http->post("/utils/handletrack.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
- $this->assertTrue($xml !== false, "XML object is false");
- $this->assertEquals((int) $xml->error, 0, "Wrong error status");
+ $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");
}
@@ -666,9 +661,8 @@ class InternalAPITest extends UloggerAPITestCase {
];
$response = $this->http->post("/utils/handletrack.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
- $this->assertTrue($xml !== false, "XML object is false");
- $this->assertEquals((int) $xml->error, 0, "Wrong error status");
+ $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");
}
@@ -689,10 +683,10 @@ class InternalAPITest extends UloggerAPITestCase {
];
$response = $this->http->post("/utils/handletrack.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
- $this->assertTrue($xml !== false, "XML object is false");
- $this->assertEquals((int) $xml->error, 1, "Wrong error status");
- $this->assertEquals((string) $xml->message, $lang["servererror"], "Wrong error message");
+ $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");
}
public function testHandleTrackUpdate() {
@@ -712,9 +706,8 @@ class InternalAPITest extends UloggerAPITestCase {
];
$response = $this->http->post("/utils/handletrack.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
- $this->assertTrue($xml !== false, "XML object is false");
- $this->assertEquals((int) $xml->error, 0, "Wrong error status");
+ $json = json_decode($response->getBody());
+ $this->assertNotNull($json, "JSON object is null");
$this->assertEquals(2, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
$row1 = [
"id" => $trackId2,
@@ -753,10 +746,10 @@ class InternalAPITest extends UloggerAPITestCase {
];
$response = $this->http->post("/utils/handletrack.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
- $this->assertTrue($xml !== false, "XML object is false");
- $this->assertEquals((int) $xml->error, 1, "Wrong error status");
- $this->assertEquals((string) $xml->message, $lang["servererror"], "Wrong error message");
+ $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");
}
@@ -778,10 +771,10 @@ class InternalAPITest extends UloggerAPITestCase {
];
$response = $this->http->post("/utils/handletrack.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
- $this->assertTrue($xml !== false, "XML object is false");
- $this->assertEquals((int) $xml->error, 1, "Wrong error status");
- $this->assertEquals((string) $xml->message, $lang["servererror"], "Wrong error message");
+ $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");
}
public function testHandleTrackMissingAction() {
@@ -793,10 +786,10 @@ class InternalAPITest extends UloggerAPITestCase {
];
$response = $this->http->post("/utils/handletrack.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
- $this->assertTrue($xml !== false, "XML object is false");
- $this->assertEquals((int) $xml->error, 1, "Wrong error status");
- $this->assertEquals((string) $xml->message, $lang["servererror"], "Wrong error message");
+ $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");
}
@@ -811,10 +804,10 @@ class InternalAPITest extends UloggerAPITestCase {
];
$response = $this->http->post("/utils/handleuser.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
- $this->assertTrue($xml !== false, "XML object is false");
- $this->assertEquals((int) $xml->error, 1, "Wrong error status");
- $this->assertEquals((string) $xml->message, $lang["servererror"], "Wrong error message");
+ $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");
}
public function testHandleUserNonAdmin() {
@@ -829,10 +822,10 @@ class InternalAPITest extends UloggerAPITestCase {
];
$response = $this->http->post("/utils/handleuser.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
- $this->assertTrue($xml !== false, "XML object is false");
- $this->assertEquals((int) $xml->error, 1, "Wrong error status");
- $this->assertEquals((string) $xml->message, $lang["servererror"], "Wrong error message");
+ $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");
}
@@ -848,10 +841,10 @@ class InternalAPITest extends UloggerAPITestCase {
];
$response = $this->http->post("/utils/handleuser.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
- $this->assertTrue($xml !== false, "XML object is false");
- $this->assertEquals((int) $xml->error, 1, "Wrong error status");
- $this->assertEquals((string) $xml->message, $lang["servererror"], "Wrong error message");
+ $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");
}
@@ -866,10 +859,10 @@ class InternalAPITest extends UloggerAPITestCase {
];
$response = $this->http->post("/utils/handleuser.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
- $this->assertTrue($xml !== false, "XML object is false");
- $this->assertEquals((int) $xml->error, 1, "Wrong error status");
- $this->assertEquals((string) $xml->message, $lang["servererror"], "Wrong error message");
+ $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");
}
@@ -885,10 +878,10 @@ class InternalAPITest extends UloggerAPITestCase {
];
$response = $this->http->post("/utils/handleuser.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
- $this->assertTrue($xml !== false, "XML object is false");
- $this->assertEquals((int) $xml->error, 1, "Wrong error status");
- $this->assertEquals((string) $xml->message, $lang["servererror"], "Wrong error message");
+ $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");
}
@@ -902,9 +895,8 @@ class InternalAPITest extends UloggerAPITestCase {
];
$response = $this->http->post("/utils/handleuser.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
- $this->assertTrue($xml !== false, "XML object is false");
- $this->assertEquals(0, (int) $xml->error, "Wrong error status");
+ $json = json_decode($response->getBody());
+ $this->assertNotNull($json, "JSON object is null");
$this->assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count");
$expected = [
"login" => $this->testUser,
@@ -929,10 +921,10 @@ class InternalAPITest extends UloggerAPITestCase {
];
$response = $this->http->post("/utils/handleuser.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
- $this->assertTrue($xml !== false, "XML object is false");
- $this->assertEquals(1, (int) $xml->error, "Wrong error status");
- $this->assertEquals((string) $xml->message, $lang["userexists"], "Wrong error message");
+ $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");
}
@@ -948,9 +940,8 @@ class InternalAPITest extends UloggerAPITestCase {
];
$response = $this->http->post("/utils/handleuser.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
- $this->assertTrue($xml !== false, "XML object is false");
- $this->assertEquals(0, (int) $xml->error, "Wrong error status");
+ $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");
}
@@ -967,10 +958,10 @@ class InternalAPITest extends UloggerAPITestCase {
];
$response = $this->http->post("/utils/handleuser.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
- $this->assertTrue($xml !== false, "XML object is false");
- $this->assertEquals(1, (int) $xml->error, "Wrong error status");
- $this->assertEquals((string) $xml->message, $lang["servererror"], "Wrong error message");
+ $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["servererror"], "Wrong error message");
$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");
}
@@ -986,25 +977,11 @@ class InternalAPITest extends UloggerAPITestCase {
];
$response = $this->http->post("/utils/handleuser.php", $options);
$this->assertEquals(200, $response->getStatusCode(), "Unexpected status code");
- $xml = $this->getXMLfromResponse($response);
- $this->assertTrue($xml !== false, "XML object is false");
- $this->assertEquals(0, (int) $xml->error, "Wrong error status");
+ $json = json_decode($response->getBody());
+ $this->assertNotNull($json, "JSON object is null");
$this->assertEquals(1, $this->getConnection()->getRowCount("users"), "Wrong row count");
}
- /**
- * @param ResponseInterface $response
- * @return bool|SimpleXMLElement
- */
- private function getXMLfromResponse($response) {
- $xml = false;
- libxml_use_internal_errors(true);
- try {
- $xml = new SimpleXMLElement((string) $response->getBody());
- } catch (Exception $e) { /* ignore */ }
- return $xml;
- }
-
}
?>
\ No newline at end of file