authenticate(), "Authentication failed");
self::assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
self::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);
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
$json = json_decode($response->getBody());
self::assertNotNull($json, "JSON object is null");
self::assertCount(1, $json, "Wrong count of tracks");
$track = $json[0];
self::assertEquals(1, (int) $track->id, "Wrong track id");
self::assertEquals($this->testTrackName, $track->name, "Wrong track name");
self::assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
self::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");
}
/**
* @throws GuzzleException
*/
public function testImportGPX11(): void {
self::assertTrue($this->authenticate(), "Authentication failed");
self::assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
self::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);
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
$json = json_decode($response->getBody());
self::assertNotNull($json, "JSON object is null");
self::assertCount(1, $json, "Wrong count of tracks");
$track = $json[0];
self::assertEquals(1, (int) $track->id, "Wrong track id");
self::assertEquals($this->testTrackName, $track->name, "Wrong track name");
self::assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
self::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");
}
/**
* @throws GuzzleException
*/
public function testImportExtensions(): void {
self::assertTrue($this->authenticate(), "Authentication failed");
self::assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
self::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);
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
$json = json_decode($response->getBody());
self::assertNotNull($json, "JSON object is null");
self::assertCount(1, $json, "Wrong count of tracks");
$track = $json[0];
self::assertEquals(1, (int) $track->id, "Wrong track id");
self::assertEquals($this->testTrackName, $track->name, "Wrong track name");
self::assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
self::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");
}
/**
* @throws GuzzleException
*/
public function testImportNoTime(): void {
self::assertTrue($this->authenticate(), "Authentication failed");
self::assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
self::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);
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
$json = json_decode($response->getBody());
self::assertNotNull($json, "JSON object is null");
self::assertCount(1, $json, "Wrong count of tracks");
$track = $json[0];
self::assertEquals(1, (int) $track->id, "Wrong track id");
self::assertEquals($this->testTrackName, $track->name, "Wrong track name");
self::assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
self::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");
}
/**
* @throws GuzzleException
*/
public function testImportMultipleSegments(): void {
self::assertTrue($this->authenticate(), "Authentication failed");
self::assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
self::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);
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
$json = json_decode($response->getBody());
self::assertNotNull($json, "JSON object is null");
self::assertCount(1, $json, "Wrong count of tracks");
$track = $json[0];
self::assertEquals(1, (int) $track->id, "Wrong track id");
self::assertEquals($this->testTrackName, $track->name, "Wrong track name");
self::assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
self::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");
}
/**
* @throws GuzzleException
*/
public function testImportMultipleTracks(): void {
self::assertTrue($this->authenticate(), "Authentication failed");
self::assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
self::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);
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
$json = json_decode($response->getBody());
self::assertNotNull($json, "JSON object is null");
self::assertCount(2, $json, "Wrong count of tracks");
$track = $json[0];
self::assertEquals(2, (int) $track->id, "Wrong track id");
self::assertEquals($this->testTrackName, $track->name, "Wrong track name");
$track = $json[1];
self::assertEquals(1, (int) $track->id, "Wrong track id");
self::assertEquals($this->testTrackName, $track->name, "Wrong track name");
self::assertEquals(2, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
self::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");
}
/**
* @throws GuzzleException
*/
public function testImportNoLongitude(): void {
$lang = (new uLang($this->mockConfig))->getStrings();
self::assertTrue($this->authenticate(), "Authentication failed");
self::assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
self::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);
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
$json = json_decode($response->getBody());
self::assertNotNull($json, "JSON object is null");
self::assertEquals(1, (int) $json->error, "Wrong error status");
self::assertEquals($lang["iparsefailure"], (string) $json->message, "Wrong error status");
self::assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
self::assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
}
/**
* @throws GuzzleException
*/
public function testImportNoLatitude(): void {
$lang = (new uLang($this->mockConfig))->getStrings();
self::assertTrue($this->authenticate(), "Authentication failed");
self::assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
self::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);
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
$json = json_decode($response->getBody());
self::assertNotNull($json, "JSON object is null");
self::assertEquals(1, (int) $json->error, "Wrong error status");
self::assertEquals($lang["iparsefailure"], (string) $json->message, "Wrong error status");
self::assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
self::assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
}
/**
* @throws GuzzleException
*/
public function testImportNoGPX(): void {
$lang = (new uLang($this->mockConfig))->getStrings();
self::assertTrue($this->authenticate(), "Authentication failed");
self::assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
self::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);
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
$json = json_decode($response->getBody());
self::assertNotNull($json, "JSON object is null");
self::assertEquals(1, (int) $json->error, "Wrong error status");
self::assertEquals($lang["iparsefailure"], (string) $json->message, "Wrong error status");
self::assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
self::assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
}
/**
* @throws GuzzleException
*/
public function testImportCorrupt(): void {
$lang = (new uLang($this->mockConfig))->getStrings();
self::assertTrue($this->authenticate(), "Authentication failed");
self::assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
self::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);
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
$json = json_decode($response->getBody());
self::assertNotNull($json, "JSON object is null");
self::assertEquals(1, (int) $json->error, "Wrong error status");
self::assertEquals(0, strpos((string) $json->message, $lang["iparsefailure"]), "Wrong error status");
self::assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
self::assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
}
private function getStream($string) {
$stream = tmpfile();
fwrite($stream, $string);
fseek($stream, 0);
return $stream;
}
}
?>