assertTrue($this->authenticate(), "Authentication failed"); $this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); $this->assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count"); $gpx10 = ' ' . $this->testTrackName . ' ' . $this->testAltitude . ' ' . $this->testAltitude . ' '; $options = [ "http_errors" => false, "multipart" => [ [ "name" => "gpx", "contents" => $this->getStream($gpx10) ], [ "name" => "MAX_FILE_SIZE", "contents" => 300000 ] ], ]; $response = $this->http->post("/utils/import.php", $options); $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); $this->assertNotNull($json, "JSON object is null"); $this->assertEquals(count($json), 1, "Wrong count of tracks"); $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"); $expected = [ "id" => 1, "user_id" => 1, "name" => $this->testTrackName, "comment" => null ]; $actual = $this->getConnection()->createQueryTable( "tracks", "SELECT * FROM tracks" ); $this->assertTableContains($expected, $actual, "Wrong actual table data"); $expected = [ "id" => 1, "time" => $this->testTimestamp, "user_id" => 1, "track_id" => 1, "latitude" => $this->testLat, "longitude" => $this->testLon, "altitude" => $this->testAltitude, "speed" => null, "bearing" => null, "accuracy" => null, "provider" => "gps", "comment" => null, "image" => null ]; $actual = $this->getConnection()->createQueryTable( "positions", "SELECT id, " . $this->unix_timestamp('time') . " AS time, user_id, track_id, latitude, longitude, altitude, speed, bearing, accuracy, provider, comment, image FROM positions" ); $this->assertTableContains($expected, $actual, "Wrong actual table data"); $expected = [ "id" => 2, "time" => $this->testTimestamp + 1, "user_id" => 1, "track_id" => 1, "latitude" => $this->testLat, "longitude" => $this->testLon * -1, "altitude" => $this->testAltitude, "speed" => null, "bearing" => null, "accuracy" => null, "provider" => "gps", "comment" => null, "image" => null ]; $this->assertTableContains($expected, $actual, "Wrong actual table data"); } public function testImportGPX11() { $this->assertTrue($this->authenticate(), "Authentication failed"); $this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); $this->assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count"); $gpx11 = ' ' . $this->testTrackComment . ' Track for testing ulogger Bartek Fabiszewski fabiszewski.net Test, ulogger Crafted by Bartek Fabiszewski fabiszewski.net ' . $this->testAltitude . ' 3d 300300300 '; $options = [ "http_errors" => false, "multipart" => [ [ "name" => "gpx", "contents" => $this->getStream($gpx11), "filename" => $this->testTrackName ], [ "name" => "MAX_FILE_SIZE", "contents" => 300000 ] ], ]; $response = $this->http->post("/utils/import.php", $options); $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); $this->assertNotNull($json, "JSON object is null"); $this->assertEquals(count($json), 1, "Wrong count of tracks"); $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"); $expected = [ "id" => 1, "user_id" => 1, "name" => $this->testTrackName, "comment" => $this->testTrackComment ]; $actual = $this->getConnection()->createQueryTable( "tracks", "SELECT * FROM tracks" ); $this->assertTableContains($expected, $actual, "Wrong actual table data"); $expected = [ "id" => 1, "time" => $this->testTimestamp, "user_id" => 1, "track_id" => 1, "latitude" => $this->testLat, "longitude" => $this->testLon, "altitude" => $this->testAltitude, "speed" => null, "bearing" => null, "accuracy" => null, "provider" => "gps", "comment" => null, "image" => null ]; $actual = $this->getConnection()->createQueryTable( "positions", "SELECT id, " . $this->unix_timestamp('time') . " AS time, user_id, track_id, latitude, longitude, altitude, speed, bearing, accuracy, provider, comment, image FROM positions" ); $this->assertTableContains($expected, $actual, "Wrong actual table data"); } public function testImportExtensions() { $this->assertTrue($this->authenticate(), "Authentication failed"); $this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); $this->assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count"); $gpx = ' ' . $this->testTrackComment . ' ' . $this->testTrackName . ' ' . $this->testAltitude . ' 1 testComment . ']]> ' . $this->testSpeed . ' ' . $this->testBearing . ' ' . $this->testAccuracy . ' ' . $this->testProvider . ' '; $options = [ "http_errors" => false, "multipart" => [ [ "name" => "gpx", "contents" => $this->getStream($gpx), "filename" => $this->testTrackName ], [ "name" => "MAX_FILE_SIZE", "contents" => 300000 ] ], ]; $response = $this->http->post("/utils/import.php", $options); $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); $this->assertNotNull($json, "JSON object is null"); $this->assertEquals(count($json), 1, "Wrong count of tracks"); $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"); $expected = [ "id" => 1, "user_id" => 1, "name" => $this->testTrackName, "comment" => $this->testTrackComment ]; $actual = $this->getConnection()->createQueryTable( "tracks", "SELECT * FROM tracks" ); $this->assertTableContains($expected, $actual, "Wrong actual table data"); $expected = [ "id" => 1, "time" => $this->testTimestamp, "user_id" => 1, "track_id" => 1, "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, " . $this->unix_timestamp('time') . " AS time, user_id, track_id, latitude, longitude, altitude, speed, bearing, accuracy, provider, comment, image FROM positions" ); $this->assertTableContains($expected, $actual, "Wrong actual table data"); } public function testImportNoTime() { $this->assertTrue($this->authenticate(), "Authentication failed"); $this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); $this->assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count"); $gpx = ' '; $options = [ "http_errors" => false, "multipart" => [ [ "name" => "gpx", "contents" => $this->getStream($gpx), "filename" => $this->testTrackName ], [ "name" => "MAX_FILE_SIZE", "contents" => 300000 ] ], ]; $response = $this->http->post("/utils/import.php", $options); $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); $this->assertNotNull($json, "JSON object is null"); $this->assertEquals(count($json), 1, "Wrong count of tracks"); $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"); $expected = [ "id" => 1, "user_id" => 1, "name" => $this->testTrackName, "comment" => null ]; $actual = $this->getConnection()->createQueryTable( "tracks", "SELECT * FROM tracks" ); $this->assertTableContains($expected, $actual, "Wrong actual table data"); $expected = [ "id" => 1, "time" => 1, "user_id" => 1, "track_id" => 1, "latitude" => $this->testLat, "longitude" => $this->testLon, "altitude" => null, "speed" => null, "bearing" => null, "accuracy" => null, "provider" => "gps", "comment" => null, "image" => null ]; $actual = $this->getConnection()->createQueryTable( "positions", "SELECT id, " . $this->unix_timestamp('time') . " AS time, user_id, track_id, latitude, longitude, altitude, speed, bearing, accuracy, provider, comment, image FROM positions" ); $this->assertTableContains($expected, $actual, "Wrong actual table data"); } public function testImportMultipleSegments() { $this->assertTrue($this->authenticate(), "Authentication failed"); $this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); $this->assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count"); $gpx = ' '; $options = [ "http_errors" => false, "multipart" => [ [ "name" => "gpx", "contents" => $this->getStream($gpx), "filename" => $this->testTrackName ], [ "name" => "MAX_FILE_SIZE", "contents" => 300000 ] ], ]; $response = $this->http->post("/utils/import.php", $options); $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); $this->assertNotNull($json, "JSON object is null"); $this->assertEquals(count($json), 1, "Wrong count of tracks"); $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"); $expected = [ "id" => 1, "user_id" => 1, "name" => $this->testTrackName, "comment" => null ]; $actual = $this->getConnection()->createQueryTable( "tracks", "SELECT * FROM tracks" ); $this->assertTableContains($expected, $actual, "Wrong actual table data"); $expected = [ "id" => 1, "time" => $this->testTimestamp, "user_id" => 1, "track_id" => 1, "latitude" => $this->testLat, "longitude" => $this->testLon, "altitude" => null, "speed" => null, "bearing" => null, "accuracy" => null, "provider" => "gps", "comment" => null, "image" => null ]; $actual = $this->getConnection()->createQueryTable( "positions", "SELECT id, " . $this->unix_timestamp('time') . " AS time, user_id, track_id, latitude, longitude, altitude, speed, bearing, accuracy, provider, comment, image FROM positions" ); $this->assertTableContains($expected, $actual, "Wrong actual table data"); $expected = [ "id" => 2, "time" => $this->testTimestamp + 1, "user_id" => 1, "track_id" => 1, "latitude" => $this->testLat + 1, "longitude" => $this->testLon + 1, "altitude" => null, "speed" => null, "bearing" => null, "accuracy" => null, "provider" => "gps", "comment" => null, "image" => null ]; $this->assertTableContains($expected, $actual, "Wrong actual table data"); } public function testImportMultipleTracks() { $this->assertTrue($this->authenticate(), "Authentication failed"); $this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); $this->assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count"); $gpx = ' '; $options = [ "http_errors" => false, "multipart" => [ [ "name" => "gpx", "contents" => $this->getStream($gpx), "filename" => $this->testTrackName ], [ "name" => "MAX_FILE_SIZE", "contents" => 300000 ] ], ]; $response = $this->http->post("/utils/import.php", $options); $this->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"); $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"); $expected = [ "id" => 1, "user_id" => 1, "name" => $this->testTrackName, "comment" => null ]; $actual = $this->getConnection()->createQueryTable( "tracks", "SELECT * FROM tracks" ); $this->assertTableContains($expected, $actual, "Wrong actual table data"); $expected = [ "id" => 2, "user_id" => 1, "name" => $this->testTrackName, "comment" => null ]; $this->assertTableContains($expected, $actual, "Wrong actual table data"); $expected = [ "id" => 1, "time" => $this->testTimestamp, "user_id" => 1, "track_id" => 1, "latitude" => $this->testLat, "longitude" => $this->testLon, "altitude" => null, "speed" => null, "bearing" => null, "accuracy" => null, "provider" => "gps", "comment" => null, "image" => null ]; $actual = $this->getConnection()->createQueryTable( "positions", "SELECT id, " . $this->unix_timestamp('time') . " AS time, user_id, track_id, latitude, longitude, altitude, speed, bearing, accuracy, provider, comment, image FROM positions" ); $this->assertTableContains($expected, $actual, "Wrong actual table data"); $expected = [ "id" => 2, "time" => $this->testTimestamp + 1, "user_id" => 1, "track_id" => 2, "latitude" => $this->testLat + 1, "longitude" => $this->testLon + 1, "altitude" => null, "speed" => null, "bearing" => null, "accuracy" => null, "provider" => "gps", "comment" => null, "image" => null ]; $this->assertTableContains($expected, $actual, "Wrong actual table data"); } public function testImportNoLongitude() { $lang = (new uLang("en"))->getStrings(); $this->assertTrue($this->authenticate(), "Authentication failed"); $this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); $this->assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count"); $gpx = ' '; $options = [ "http_errors" => false, "multipart" => [ [ "name" => "gpx", "contents" => $this->getStream($gpx), "filename" => $this->testTrackName ], [ "name" => "MAX_FILE_SIZE", "contents" => 300000 ] ], ]; $response = $this->http->post("/utils/import.php", $options); $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); $this->assertNotNull($json, "JSON object is null"); $this->assertEquals(1, (int) $json->error, "Wrong error status"); $this->assertEquals($lang["iparsefailure"], (string) $json->message, "Wrong error status"); $this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); $this->assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count"); } public function testImportNoLatitude() { $lang = (new uLang("en"))->getStrings(); $this->assertTrue($this->authenticate(), "Authentication failed"); $this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); $this->assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count"); $gpx = ' '; $options = [ "http_errors" => false, "multipart" => [ [ "name" => "gpx", "contents" => $this->getStream($gpx), "filename" => $this->testTrackName ], [ "name" => "MAX_FILE_SIZE", "contents" => 300000 ] ], ]; $response = $this->http->post("/utils/import.php", $options); $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); $this->assertNotNull($json, "JSON object is null"); $this->assertEquals(1, (int) $json->error, "Wrong error status"); $this->assertEquals($lang["iparsefailure"], (string) $json->message, "Wrong error status"); $this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); $this->assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count"); } public function testImportNoGPX() { $lang = (new uLang("en"))->getStrings(); $this->assertTrue($this->authenticate(), "Authentication failed"); $this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); $this->assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count"); $gpx = ' '; $options = [ "http_errors" => false, "multipart" => [ [ "name" => "gpx", "contents" => $this->getStream($gpx), "filename" => $this->testTrackName ], [ "name" => "MAX_FILE_SIZE", "contents" => 300000 ] ], ]; $response = $this->http->post("/utils/import.php", $options); $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); $this->assertNotNull($json, "JSON object is null"); $this->assertEquals(1, (int) $json->error, "Wrong error status"); $this->assertEquals($lang["iparsefailure"], (string) $json->message, "Wrong error status"); $this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); $this->assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count"); } public function testImportCorrupt() { $lang = (new uLang("en"))->getStrings(); $this->assertTrue($this->authenticate(), "Authentication failed"); $this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); $this->assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count"); $gpx = ' '; $options = [ "http_errors" => false, "multipart" => [ [ "name" => "gpx", "contents" => $this->getStream($gpx), "filename" => $this->testTrackName ], [ "name" => "MAX_FILE_SIZE", "contents" => 300000 ] ], ]; $response = $this->http->post("/utils/import.php", $options); $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $json = json_decode($response->getBody()); $this->assertNotNull($json, "JSON object is null"); $this->assertEquals(1, (int) $json->error, "Wrong error status"); $this->assertEquals(0, strpos((string) $json->message, $lang["iparsefailure"]), "Wrong error status"); $this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); $this->assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count"); } private function getStream($string) { $stream = tmpfile(); fwrite($stream, $string); fseek($stream, 0); return $stream; } } ?>