2017-09-19 22:04:40 +02:00
< ? php
2021-04-22 19:47:52 +02:00
use GuzzleHttp\Exception\GuzzleException ;
2017-09-19 22:04:40 +02:00
require_once ( __DIR__ . " /../lib/UloggerAPITestCase.php " );
if ( ! defined ( " ROOT_DIR " )) { define ( " ROOT_DIR " , __DIR__ . " /../.. " ); }
require_once ( ROOT_DIR . " /helpers/config.php " );
2019-02-25 10:04:09 +01:00
require_once ( ROOT_DIR . " /helpers/lang.php " );
2017-09-19 22:04:40 +02:00
class InternalAPITest extends UloggerAPITestCase {
/* getpositions */
2021-04-22 19:47:52 +02:00
/**
* @ throws GuzzleException
*/
public function testGetPositionsAdmin () : void {
2017-09-19 22:04:40 +02:00
2020-11-11 18:29:40 +01:00
self :: assertTrue ( $this -> authenticate (), " Authentication failed " );
2017-09-19 22:04:40 +02:00
$trackId = $this -> addTestTrack ( $this -> testUserId );
$this -> addTestPosition ( $this -> testUserId , $trackId , $this -> testTimestamp );
$this -> addTestPosition ( $this -> testUserId , $trackId , $this -> testTimestamp + 1 );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 1 , $this -> getConnection () -> getRowCount ( " tracks " ), " Wrong row count " );
self :: assertEquals ( 2 , $this -> getConnection () -> getRowCount ( " positions " ), " Wrong row count " );
2017-09-19 22:04:40 +02:00
$options = [
" http_errors " => false ,
2019-01-24 19:07:41 +01:00
" query " => [ " userid " => $this -> testUserId , " trackid " => $trackId ],
2017-09-19 22:04:40 +02:00
];
2019-01-24 19:07:41 +01:00
$response = $this -> http -> get ( " /utils/getpositions.php " , $options );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 200 , $response -> getStatusCode (), " Unexpected status code " );
2017-09-19 22:04:40 +02:00
2020-01-07 17:21:40 +01:00
$json = json_decode ( $response -> getBody ());
2020-11-11 18:29:40 +01:00
self :: assertNotNull ( $json , " JSON object is null " );
self :: assertCount ( 2 , $json , " Wrong count of positions " );
2017-09-19 22:04:40 +02:00
2020-01-07 17:21:40 +01:00
$position = $json [ 0 ];
2020-11-11 18:29:40 +01:00
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 " );
2017-09-19 22:04:40 +02:00
2020-01-07 17:21:40 +01:00
$position = $json [ 1 ];
2020-11-11 18:29:40 +01:00
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 " );
2017-09-19 22:04:40 +02:00
}
2021-04-22 19:47:52 +02:00
/**
* @ throws GuzzleException
*/
public function testGetPositionsUser () : void {
2017-09-19 22:04:40 +02:00
$userId = $this -> addTestUser ( $this -> testUser , password_hash ( $this -> testPass , PASSWORD_DEFAULT ));
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 2 , $this -> getConnection () -> getRowCount ( " users " ), " Wrong row count " );
self :: assertTrue ( $this -> authenticate ( $this -> testUser , $this -> testPass ), " Authentication failed " );
2017-09-19 22:04:40 +02:00
$trackId = $this -> addTestTrack ( $userId );
$this -> addTestPosition ( $userId , $trackId , $this -> testTimestamp );
$this -> addTestPosition ( $userId , $trackId , $this -> testTimestamp + 1 );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 1 , $this -> getConnection () -> getRowCount ( " tracks " ), " Wrong row count " );
self :: assertEquals ( 2 , $this -> getConnection () -> getRowCount ( " positions " ), " Wrong row count " );
2017-09-19 22:04:40 +02:00
$options = [
" http_errors " => false ,
2019-01-24 19:07:41 +01:00
" query " => [ " userid " => $userId , " trackid " => $trackId ],
2017-09-19 22:04:40 +02:00
];
2019-01-24 19:07:41 +01:00
$response = $this -> http -> get ( " /utils/getpositions.php " , $options );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 200 , $response -> getStatusCode (), " Unexpected status code " );
2017-09-19 22:04:40 +02:00
2020-01-07 17:21:40 +01:00
$json = json_decode ( $response -> getBody ());
2020-11-11 18:29:40 +01:00
self :: assertNotNull ( $json , " JSON object is null " );
self :: assertCount ( 2 , $json , " Wrong count of positions " );
2017-09-19 22:04:40 +02:00
2020-01-07 17:21:40 +01:00
$position = $json [ 0 ];
2020-11-11 18:29:40 +01:00
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 " );
2017-09-19 22:04:40 +02:00
2020-01-07 17:21:40 +01:00
$position = $json [ 1 ];
2020-11-11 18:29:40 +01:00
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 " );
2017-09-19 22:04:40 +02:00
}
2021-04-22 19:47:52 +02:00
/**
* @ throws GuzzleException
*/
public function testGetPositionsOtherUser () : void {
2017-09-19 22:04:40 +02:00
$userId = $this -> addTestUser ( $this -> testUser , password_hash ( $this -> testPass , PASSWORD_DEFAULT ));
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 2 , $userId );
self :: assertEquals ( 2 , $this -> getConnection () -> getRowCount ( " users " ), " Wrong row count " );
self :: assertTrue ( $this -> authenticate ( $this -> testUser , $this -> testPass ), " Authentication failed " );
2017-09-19 22:04:40 +02:00
$trackId = $this -> addTestTrack ( $userId );
$this -> addTestPosition ( $userId , $trackId , $this -> testTimestamp );
$this -> addTestPosition ( $userId , $trackId , $this -> testTimestamp + 1 );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 1 , $this -> getConnection () -> getRowCount ( " tracks " ), " Wrong row count " );
self :: assertEquals ( 2 , $this -> getConnection () -> getRowCount ( " positions " ), " Wrong row count " );
2017-09-19 22:04:40 +02:00
$options = [
" http_errors " => false ,
2019-01-24 19:07:41 +01:00
" query " => [ " userid " => $this -> testUserId , " trackid " => $trackId ],
2017-09-19 22:04:40 +02:00
];
2019-01-24 19:07:41 +01:00
$response = $this -> http -> get ( " /utils/getpositions.php " , $options );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 200 , $response -> getStatusCode (), " Unexpected status code " );
2017-09-19 22:04:40 +02:00
2020-01-07 17:21:40 +01:00
$json = json_decode ( $response -> getBody ());
2020-11-11 18:29:40 +01:00
self :: assertNotNull ( $json , " JSON object is null " );
self :: assertCount ( 0 , $json , " Wrong count of positions " );
2017-09-19 22:04:40 +02:00
}
2021-04-22 19:47:52 +02:00
/**
* @ throws GuzzleException
*/
public function testGetPositionsOtherUserByAdmin () : void {
2017-09-19 22:04:40 +02:00
$userId = $this -> addTestUser ( $this -> testUser , password_hash ( $this -> testPass , PASSWORD_DEFAULT ));
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 2 , $userId );
self :: assertEquals ( 2 , $this -> getConnection () -> getRowCount ( " users " ), " Wrong row count " );
self :: assertTrue ( $this -> authenticate (), " Authentication failed " );
2017-09-19 22:04:40 +02:00
$trackId = $this -> addTestTrack ( $userId );
$this -> addTestPosition ( $userId , $trackId , $this -> testTimestamp );
$this -> addTestPosition ( $userId , $trackId , $this -> testTimestamp + 1 );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 1 , $this -> getConnection () -> getRowCount ( " tracks " ), " Wrong row count " );
self :: assertEquals ( 2 , $this -> getConnection () -> getRowCount ( " positions " ), " Wrong row count " );
2017-09-19 22:04:40 +02:00
$options = [
" http_errors " => false ,
2019-01-24 19:07:41 +01:00
" query " => [ " userid " => $userId , " trackid " => $trackId ],
2017-09-19 22:04:40 +02:00
];
2019-01-24 19:07:41 +01:00
$response = $this -> http -> get ( " /utils/getpositions.php " , $options );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 200 , $response -> getStatusCode (), " Unexpected status code " );
2017-09-19 22:04:40 +02:00
2020-01-07 17:21:40 +01:00
$json = json_decode ( $response -> getBody ());
2020-11-11 18:29:40 +01:00
self :: assertNotNull ( $json , " JSON object is null " );
self :: assertCount ( 2 , $json , " Wrong count of positions " );
2017-09-19 22:04:40 +02:00
2020-01-07 17:21:40 +01:00
$position = $json [ 0 ];
2020-11-11 18:29:40 +01:00
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 " );
2017-09-19 22:04:40 +02:00
2020-01-07 17:21:40 +01:00
$position = $json [ 1 ];
2020-11-11 18:29:40 +01:00
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 " );
2017-09-19 22:04:40 +02:00
}
2021-04-22 19:47:52 +02:00
/**
* @ throws GuzzleException
*/
public function testGetPositionsUserLatest () : void {
2020-11-11 18:29:40 +01:00
self :: assertTrue ( $this -> authenticate (), " Authentication failed " );
2017-09-19 22:04:40 +02:00
$trackId = $this -> addTestTrack ( $this -> testUserId );
$this -> addTestPosition ( $this -> testUserId , $trackId , $this -> testTimestamp );
2019-03-02 23:53:45 +01:00
$this -> addTestPosition ( $this -> testUserId , $trackId , $this -> testTimestamp + 3 );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 1 , $this -> getConnection () -> getRowCount ( " tracks " ), " Wrong row count " );
self :: assertEquals ( 2 , $this -> getConnection () -> getRowCount ( " positions " ), " Wrong row count " );
2017-09-19 22:04:40 +02:00
2019-03-02 23:53:45 +01:00
$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 );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 2 , $this -> getConnection () -> getRowCount ( " tracks " ), " Wrong row count " );
self :: assertEquals ( 4 , $this -> getConnection () -> getRowCount ( " positions " ), " Wrong row count " );
2019-03-02 23:53:45 +01:00
2017-09-19 22:04:40 +02:00
$options = [
" http_errors " => false ,
2019-03-02 23:53:45 +01:00
" query " => [ " userid " => $this -> testUserId , " last " => 1 ],
2017-09-19 22:04:40 +02:00
];
2019-01-24 19:07:41 +01:00
$response = $this -> http -> get ( " /utils/getpositions.php " , $options );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 200 , $response -> getStatusCode (), " Unexpected status code " );
2017-09-19 22:04:40 +02:00
2020-01-07 17:21:40 +01:00
$json = json_decode ( $response -> getBody ());
2020-11-11 18:29:40 +01:00
self :: assertNotNull ( $json , " JSON object is null " );
self :: assertCount ( 1 , $json , " Wrong count of positions " );
2017-09-19 22:04:40 +02:00
2020-01-07 17:21:40 +01:00
$position = $json [ 0 ];
2020-11-11 18:29:40 +01:00
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 " );
2017-09-19 22:04:40 +02:00
}
2021-04-22 19:47:52 +02:00
/**
* @ throws GuzzleException
*/
public function testGetPositionsAllUsersLatest () : void {
2020-11-11 18:29:40 +01:00
self :: assertTrue ( $this -> authenticate (), " Authentication failed " );
2019-03-02 23:53:45 +01:00
$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 );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 1 , $this -> getConnection () -> getRowCount ( " tracks " ), " Wrong row count " );
self :: assertEquals ( 2 , $this -> getConnection () -> getRowCount ( " positions " ), " Wrong row count " );
2019-03-02 23:53:45 +01:00
$trackName = " Track 2 " ;
$trackId2 = $this -> addTestTrack ( $userId , $trackName );
$this -> addTestPosition ( $userId , $trackId2 , $this -> testTimestamp + 2 );
$this -> addTestPosition ( $userId , $trackId2 , $this -> testTimestamp + 1 );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 2 , $this -> getConnection () -> getRowCount ( " tracks " ), " Wrong row count " );
self :: assertEquals ( 4 , $this -> getConnection () -> getRowCount ( " positions " ), " Wrong row count " );
2019-03-02 23:53:45 +01:00
$options = [
" http_errors " => false ,
" query " => [ " last " => 1 ],
];
$response = $this -> http -> get ( " /utils/getpositions.php " , $options );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 200 , $response -> getStatusCode (), " Unexpected status code " );
2019-03-02 23:53:45 +01:00
2020-01-07 17:21:40 +01:00
$json = json_decode ( $response -> getBody ());
2020-11-11 18:29:40 +01:00
self :: assertNotNull ( $json , " JSON object is null " );
self :: assertCount ( 2 , $json , " Wrong count of positions " );
2019-03-02 23:53:45 +01:00
2020-01-07 17:21:40 +01:00
$position = $json [ 0 ];
2020-11-11 18:29:40 +01:00
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 " );
2019-03-02 23:53:45 +01:00
2020-01-07 17:21:40 +01:00
$position = $json [ 1 ];
2020-11-11 18:29:40 +01:00
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 " );
2019-03-02 23:53:45 +01:00
}
2021-04-22 19:47:52 +02:00
/**
* @ throws GuzzleException
*/
public function testGetPositionsNoTrackId () : void {
2019-03-02 23:53:45 +01:00
2020-11-11 18:29:40 +01:00
self :: assertTrue ( $this -> authenticate (), " Authentication failed " );
2019-03-02 23:53:45 +01:00
$trackId = $this -> addTestTrack ( $this -> testUserId );
$this -> addTestPosition ( $this -> testUserId , $trackId , $this -> testTimestamp );
$this -> addTestPosition ( $this -> testUserId , $trackId , $this -> testTimestamp + 1 );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 1 , $this -> getConnection () -> getRowCount ( " tracks " ), " Wrong row count " );
self :: assertEquals ( 2 , $this -> getConnection () -> getRowCount ( " positions " ), " Wrong row count " );
2019-03-02 23:53:45 +01:00
$options = [
" http_errors " => false ,
" query " => [ " userid " => $this -> testUserId ],
];
$response = $this -> http -> get ( " /utils/getpositions.php " , $options );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 200 , $response -> getStatusCode (), " Unexpected status code " );
2019-03-02 23:53:45 +01:00
2020-01-07 17:21:40 +01:00
$json = json_decode ( $response -> getBody ());
2020-11-11 18:29:40 +01:00
self :: assertNotNull ( $json , " JSON object is null " );
self :: assertCount ( 0 , $json , " Wrong count of positions " );
2019-03-02 23:53:45 +01:00
}
2021-04-22 19:47:52 +02:00
/**
* @ throws GuzzleException
*/
public function testGetPositionsNoUserId () : void {
2017-09-19 22:04:40 +02:00
2020-11-11 18:29:40 +01:00
self :: assertTrue ( $this -> authenticate (), " Authentication failed " );
2017-09-19 22:04:40 +02:00
$trackId = $this -> addTestTrack ( $this -> testUserId );
$this -> addTestPosition ( $this -> testUserId , $trackId , $this -> testTimestamp );
$this -> addTestPosition ( $this -> testUserId , $trackId , $this -> testTimestamp + 1 );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 1 , $this -> getConnection () -> getRowCount ( " tracks " ), " Wrong row count " );
self :: assertEquals ( 2 , $this -> getConnection () -> getRowCount ( " positions " ), " Wrong row count " );
2017-09-19 22:04:40 +02:00
$options = [
" http_errors " => false ,
2019-01-24 19:07:41 +01:00
" query " => [ " trackid " => $trackId ],
2017-09-19 22:04:40 +02:00
];
2019-01-24 19:07:41 +01:00
$response = $this -> http -> get ( " /utils/getpositions.php " , $options );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 200 , $response -> getStatusCode (), " Unexpected status code " );
2017-09-19 22:04:40 +02:00
2020-01-07 17:21:40 +01:00
$json = json_decode ( $response -> getBody ());
2020-11-11 18:29:40 +01:00
self :: assertNotNull ( $json , " JSON object is null " );
self :: assertCount ( 0 , $json , " Wrong count of positions " );
2017-09-19 22:04:40 +02:00
}
2021-04-22 19:47:52 +02:00
/**
* @ throws GuzzleException
*/
public function testGetPositionsNoAuth () : void {
2017-09-19 22:04:40 +02:00
$trackId = $this -> addTestTrack ( $this -> testUserId );
$this -> addTestPosition ( $this -> testUserId , $trackId , $this -> testTimestamp );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 1 , $this -> getConnection () -> getRowCount ( " tracks " ), " Wrong row count " );
2017-09-19 22:04:40 +02:00
$options = [
" http_errors " => false ,
2019-01-24 19:07:41 +01:00
" query " => [ " userid " => $this -> testUserId , " trackid " => $trackId ],
2017-09-19 22:04:40 +02:00
];
2019-01-24 19:07:41 +01:00
$response = $this -> http -> get ( " /utils/getpositions.php " , $options );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 200 , $response -> getStatusCode (), " Unexpected status code " );
2017-09-19 22:04:40 +02:00
2020-01-07 17:21:40 +01:00
$json = json_decode ( $response -> getBody ());
2017-09-19 22:04:40 +02:00
2020-11-11 18:29:40 +01:00
self :: assertNotNull ( $json , " JSON object is null " );
self :: assertCount ( 0 , $json , " Wrong count of positions " );
2017-09-19 22:04:40 +02:00
}
2021-04-22 19:47:52 +02:00
/**
* @ throws GuzzleException
*/
public function testGetPositionsAfterId () : void {
2020-04-13 23:50:31 +02:00
2020-11-11 18:29:40 +01:00
self :: assertTrue ( $this -> authenticate (), " Authentication failed " );
2020-04-13 23:50:31 +02:00
$trackId = $this -> addTestTrack ( $this -> testUserId );
$afterId = $this -> addTestPosition ( $this -> testUserId , $trackId , $this -> testTimestamp );
$this -> addTestPosition ( $this -> testUserId , $trackId , $this -> testTimestamp + 1 , $this -> testLat + 1 );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 1 , $this -> getConnection () -> getRowCount ( " tracks " ), " Wrong row count " );
self :: assertEquals ( 2 , $this -> getConnection () -> getRowCount ( " positions " ), " Wrong row count " );
2020-04-13 23:50:31 +02:00
$options = [
" http_errors " => false ,
" query " => [ " userid " => $this -> testUserId , " trackid " => $trackId , " afterid " => $afterId ],
];
$response = $this -> http -> get ( " /utils/getpositions.php " , $options );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 200 , $response -> getStatusCode (), " Unexpected status code " );
2020-04-13 23:50:31 +02:00
$json = json_decode ( $response -> getBody ());
2020-11-11 18:29:40 +01:00
self :: assertNotNull ( $json , " JSON object is null " );
self :: assertCount ( 1 , $json , " Wrong count of positions " );
2020-04-13 23:50:31 +02:00
$position = $json [ 0 ];
2020-11-11 18:29:40 +01:00
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 " );
2020-04-13 23:50:31 +02:00
}
2017-09-19 22:04:40 +02:00
/* gettracks.php */
2021-04-22 19:47:52 +02:00
/**
* @ throws GuzzleException
*/
public function testGetTracksAdmin () : void {
2017-09-19 22:04:40 +02:00
2020-11-11 18:29:40 +01:00
self :: assertTrue ( $this -> authenticate (), " Authentication failed " );
2017-09-19 22:04:40 +02:00
$this -> addTestTrack ( $this -> testUserId );
$this -> addTestTrack ( $this -> testUserId , $this -> testTrackName . " 2 " );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 2 , $this -> getConnection () -> getRowCount ( " tracks " ), " Wrong row count " );
2017-09-19 22:04:40 +02:00
$options = [
" http_errors " => false ,
2019-01-24 19:07:41 +01:00
" query " => [ " userid " => $this -> testUserId ],
2017-09-19 22:04:40 +02:00
];
2019-01-24 19:07:41 +01:00
$response = $this -> http -> get ( " /utils/gettracks.php " , $options );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 200 , $response -> getStatusCode (), " Unexpected status code " );
2017-09-19 22:04:40 +02:00
2020-01-07 17:21:40 +01:00
$json = json_decode ( $response -> getBody ());
2020-11-11 18:29:40 +01:00
self :: assertNotNull ( $json , " JSON object is null " );
self :: assertCount ( 2 , $json , " Wrong count of tracks " );
2017-09-19 22:04:40 +02:00
2020-01-07 17:21:40 +01:00
$track = $json [ 0 ];
2020-11-11 18:29:40 +01:00
self :: assertEquals ( $this -> testTrackId2 , ( int ) $track -> id , " Wrong track id " );
self :: assertEquals ( $this -> testTrackName . " 2 " , ( string ) $track -> name , " Wrong track name " );
2017-09-19 22:04:40 +02:00
2020-01-07 17:21:40 +01:00
$track = $json [ 1 ];
2020-11-11 18:29:40 +01:00
self :: assertEquals ( $this -> testTrackId , ( int ) $track -> id , " Wrong track id " );
self :: assertEquals ( $this -> testTrackName , ( string ) $track -> name , " Wrong track name " );
2017-09-19 22:04:40 +02:00
}
2021-04-22 19:47:52 +02:00
/**
* @ throws GuzzleException
*/
public function testGetTracksUser () : void {
2017-09-19 22:04:40 +02:00
$userId = $this -> addTestUser ( $this -> testUser , password_hash ( $this -> testPass , PASSWORD_DEFAULT ));
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 2 , $this -> getConnection () -> getRowCount ( " users " ), " Wrong row count " );
self :: assertTrue ( $this -> authenticate ( $this -> testUser , $this -> testPass ), " Authentication failed " );
2017-09-19 22:04:40 +02:00
$this -> addTestTrack ( $userId );
$this -> addTestTrack ( $userId , $this -> testTrackName . " 2 " );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 2 , $this -> getConnection () -> getRowCount ( " tracks " ), " Wrong row count " );
2017-09-19 22:04:40 +02:00
$options = [
" http_errors " => false ,
2019-01-24 19:07:41 +01:00
" query " => [ " userid " => $userId ],
2017-09-19 22:04:40 +02:00
];
2019-01-24 19:07:41 +01:00
$response = $this -> http -> get ( " /utils/gettracks.php " , $options );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 200 , $response -> getStatusCode (), " Unexpected status code " );
2017-09-19 22:04:40 +02:00
2020-01-07 17:21:40 +01:00
$json = json_decode ( $response -> getBody ());
2020-11-11 18:29:40 +01:00
self :: assertNotNull ( $json , " JSON object is null " );
self :: assertCount ( 2 , $json , " Wrong count of tracks " );
2017-09-19 22:04:40 +02:00
2020-01-07 17:21:40 +01:00
$track = $json [ 0 ];
2020-11-11 18:29:40 +01:00
self :: assertEquals ( $this -> testTrackId2 , ( int ) $track -> id , " Wrong track id " );
self :: assertEquals ( $this -> testTrackName . " 2 " , ( string ) $track -> name , " Wrong track name " );
2017-09-19 22:04:40 +02:00
2020-01-07 17:21:40 +01:00
$track = $json [ 1 ];
2020-11-11 18:29:40 +01:00
self :: assertEquals ( $this -> testTrackId , ( int ) $track -> id , " Wrong track id " );
self :: assertEquals ( $this -> testTrackName , ( string ) $track -> name , " Wrong track name " );
2020-01-07 17:21:40 +01:00
}
2017-09-19 22:04:40 +02:00
2021-04-22 19:47:52 +02:00
/**
* @ throws GuzzleException
*/
public function testGetTracksOtherUser () : void {
2017-09-19 22:04:40 +02:00
$this -> addTestUser ( $this -> testUser , password_hash ( $this -> testPass , PASSWORD_DEFAULT ));
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 2 , $this -> getConnection () -> getRowCount ( " users " ), " Wrong row count " );
self :: assertTrue ( $this -> authenticate ( $this -> testUser , $this -> testPass ), " Authentication failed " );
2017-09-19 22:04:40 +02:00
$this -> addTestTrack ( $this -> testUserId );
$this -> addTestTrack ( $this -> testUserId , $this -> testTrackName . " 2 " );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 2 , $this -> getConnection () -> getRowCount ( " tracks " ), " Wrong row count " );
2017-09-19 22:04:40 +02:00
$options = [
" http_errors " => false ,
2019-01-24 19:07:41 +01:00
" query " => [ " userid " => $this -> testUserId ],
2017-09-19 22:04:40 +02:00
];
2019-01-24 19:07:41 +01:00
$response = $this -> http -> get ( " /utils/gettracks.php " , $options );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 200 , $response -> getStatusCode (), " Unexpected status code " );
2017-09-19 22:04:40 +02:00
2020-01-07 17:21:40 +01:00
$json = json_decode ( $response -> getBody ());
2020-11-11 18:29:40 +01:00
self :: assertNotNull ( $json , " JSON object is null " );
self :: assertCount ( 0 , $json , " Wrong count of tracks " );
2017-09-19 22:04:40 +02:00
}
2021-04-22 19:47:52 +02:00
/**
* @ throws GuzzleException
*/
public function testGetTracksNoUserId () : void {
2017-09-19 22:04:40 +02:00
$this -> addTestUser ( $this -> testUser , password_hash ( $this -> testPass , PASSWORD_DEFAULT ));
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 2 , $this -> getConnection () -> getRowCount ( " users " ), " Wrong row count " );
self :: assertTrue ( $this -> authenticate ( $this -> testUser , $this -> testPass ), " Authentication failed " );
2017-09-19 22:04:40 +02:00
$this -> addTestTrack ( $this -> testUserId );
$this -> addTestTrack ( $this -> testUserId , $this -> testTrackName . " 2 " );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 2 , $this -> getConnection () -> getRowCount ( " tracks " ), " Wrong row count " );
2017-09-19 22:04:40 +02:00
$options = [
" http_errors " => false ,
];
2019-01-24 19:07:41 +01:00
$response = $this -> http -> get ( " /utils/gettracks.php " , $options );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 200 , $response -> getStatusCode (), " Unexpected status code " );
2020-01-07 17:21:40 +01:00
$json = json_decode ( $response -> getBody ());
2020-11-11 18:29:40 +01:00
self :: assertNotNull ( $json , " JSON object is null " );
self :: assertCount ( 0 , $json , " Wrong count of tracks " );
2017-09-19 22:04:40 +02:00
}
2021-04-22 19:47:52 +02:00
/**
* @ throws GuzzleException
*/
public function testGetTracksNoAuth () : void {
2017-09-19 22:04:40 +02:00
$this -> addTestTrack ( $this -> testUserId );
$this -> addTestTrack ( $this -> testUserId , $this -> testTrackName . " 2 " );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 2 , $this -> getConnection () -> getRowCount ( " tracks " ), " Wrong row count " );
2017-09-19 22:04:40 +02:00
$options = [
" http_errors " => false ,
2019-01-24 19:07:41 +01:00
" query " => [ " userid " => $this -> testUserId ],
2017-09-19 22:04:40 +02:00
];
2019-01-24 19:07:41 +01:00
$response = $this -> http -> get ( " /utils/gettracks.php " , $options );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 200 , $response -> getStatusCode (), " Unexpected status code " );
2017-09-19 22:04:40 +02:00
2020-01-07 17:21:40 +01:00
$json = json_decode ( $response -> getBody ());
2020-11-11 18:29:40 +01:00
self :: assertNotNull ( $json , " JSON object is null " );
self :: assertCount ( 0 , $json , " Wrong count of tracks " );
2017-09-19 22:04:40 +02:00
}
/* changepass.php */
2021-04-22 19:47:52 +02:00
/**
* @ throws GuzzleException
*/
public function testChangePassNoAuth () : void {
2017-09-19 22:04:40 +02:00
$options = [
" http_errors " => false ,
2019-05-15 11:32:36 +02:00
" form_params " => [
" login " => $this -> testUser ,
" pass " => $this -> testPass ,
" oldpass " => $this -> testPass
],
2017-09-19 22:04:40 +02:00
];
$response = $this -> http -> post ( " /utils/changepass.php " , $options );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 401 , $response -> getStatusCode (), " Unexpected status code " );
2017-09-19 22:04:40 +02:00
2020-01-07 17:21:40 +01:00
$json = json_decode ( $response -> getBody ());
2020-11-11 18:29:40 +01:00
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 " );
2017-09-19 22:04:40 +02:00
}
2021-04-22 19:47:52 +02:00
/**
* @ throws GuzzleException
*/
public function testChangePassEmpty () : void {
2020-11-11 18:29:40 +01:00
self :: assertTrue ( $this -> authenticate (), " Authentication failed " );
2017-09-19 22:04:40 +02:00
$options = [
" http_errors " => false ,
" form_params " => [ " login " => $this -> testAdminUser ],
];
$response = $this -> http -> post ( " /utils/changepass.php " , $options );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 200 , $response -> getStatusCode (), " Unexpected status code " );
2017-09-19 22:04:40 +02:00
2020-01-07 17:21:40 +01:00
$json = json_decode ( $response -> getBody ());
2020-11-11 18:29:40 +01:00
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 " );
2017-09-19 22:04:40 +02:00
}
2021-04-22 19:47:52 +02:00
/**
* @ throws GuzzleException
*/
public function testChangePassUserUnknown () : void {
2020-11-11 18:29:40 +01:00
self :: assertTrue ( $this -> authenticate (), " Authentication failed " );
2017-09-19 22:04:40 +02:00
$options = [
" http_errors " => false ,
" form_params " => [
" login " => $this -> testUser ,
" pass " => $this -> testPass ,
],
];
$response = $this -> http -> post ( " /utils/changepass.php " , $options );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 200 , $response -> getStatusCode (), " Unexpected status code " );
2017-09-19 22:04:40 +02:00
2020-01-07 17:21:40 +01:00
$json = json_decode ( $response -> getBody ());
2020-11-11 18:29:40 +01:00
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 " );
2017-09-19 22:04:40 +02:00
}
2021-04-22 19:47:52 +02:00
/**
* @ throws GuzzleException
*/
public function testChangePassEmptyLogin () : void {
2020-11-11 18:29:40 +01:00
self :: assertTrue ( $this -> authenticate (), " Authentication failed " );
2019-05-15 11:32:36 +02:00
$options = [
" http_errors " => false ,
" form_params " => [
" pass " => $this -> testPass ,
],
];
$response = $this -> http -> post ( " /utils/changepass.php " , $options );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 200 , $response -> getStatusCode (), " Unexpected status code " );
2019-05-15 11:32:36 +02:00
2020-01-07 17:21:40 +01:00
$json = json_decode ( $response -> getBody ());
2020-11-11 18:29:40 +01:00
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 " );
2019-05-15 11:32:36 +02:00
}
2021-04-22 19:47:52 +02:00
/**
* @ throws GuzzleException
*/
public function testChangePassWrongOldpass () : void {
2020-11-11 18:29:40 +01:00
self :: assertTrue ( $this -> authenticate (), " Authentication failed " );
2017-09-19 22:04:40 +02:00
$options = [
" http_errors " => false ,
" form_params " => [
2019-05-15 11:32:36 +02:00
" login " => $this -> testAdminUser ,
2017-09-19 22:04:40 +02:00
" oldpass " => " badpass " ,
2020-02-19 18:42:44 +01:00
" pass " => " Newpass1234567890 " ,
2017-09-19 22:04:40 +02:00
],
];
$response = $this -> http -> post ( " /utils/changepass.php " , $options );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 200 , $response -> getStatusCode (), " Unexpected status code " );
2017-09-19 22:04:40 +02:00
2020-01-07 17:21:40 +01:00
$json = json_decode ( $response -> getBody ());
2020-11-11 18:29:40 +01:00
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 " );
2017-09-19 22:04:40 +02:00
}
2021-04-22 19:47:52 +02:00
/**
* @ throws GuzzleException
*/
public function testChangePassNoOldpass () : void {
2020-11-11 18:29:40 +01:00
self :: assertTrue ( $this -> authenticate (), " Authentication failed " );
2017-09-19 22:04:40 +02:00
$options = [
" http_errors " => false ,
" form_params " => [
2019-05-15 11:32:36 +02:00
" login " => $this -> testAdminUser ,
2020-02-19 18:42:44 +01:00
" pass " => " Newpass1234567890 " ,
2017-09-19 22:04:40 +02:00
],
];
$response = $this -> http -> post ( " /utils/changepass.php " , $options );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 200 , $response -> getStatusCode (), " Unexpected status code " );
2017-09-19 22:04:40 +02:00
2020-01-07 17:21:40 +01:00
$json = json_decode ( $response -> getBody ());
2020-11-11 18:29:40 +01:00
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 " );
2017-09-19 22:04:40 +02:00
}
2021-04-22 19:47:52 +02:00
/**
* @ throws GuzzleException
*/
public function testChangePassSelfAdmin () : void {
2020-11-11 18:29:40 +01:00
self :: assertTrue ( $this -> authenticate (), " Authentication failed " );
2017-09-19 22:04:40 +02:00
2020-02-19 18:42:44 +01:00
$newPass = " Newpass1234567890 " ;
2017-09-19 22:04:40 +02:00
$options = [
" http_errors " => false ,
" form_params " => [
2019-05-15 11:32:36 +02:00
" login " => $this -> testAdminUser ,
2017-09-19 22:04:40 +02:00
" oldpass " => $this -> testAdminPass ,
" pass " => $newPass ,
],
];
$response = $this -> http -> post ( " /utils/changepass.php " , $options );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 200 , $response -> getStatusCode (), " Unexpected status code " );
2017-09-19 22:04:40 +02:00
2020-01-07 17:21:40 +01:00
$json = json_decode ( $response -> getBody ());
2020-11-11 18:29:40 +01:00
self :: assertNotNull ( $json , " JSON object is null " );
self :: assertTrue ( password_verify ( $newPass , $this -> pdoGetColumn ( " SELECT password FROM users " )), " Wrong actual password hash " );
2017-09-19 22:04:40 +02:00
}
2021-04-22 19:47:52 +02:00
/**
* @ throws GuzzleException
*/
public function testChangePassSelfUser () : void {
2017-09-19 22:04:40 +02:00
$userId = $this -> addTestUser ( $this -> testUser , password_hash ( $this -> testPass , PASSWORD_DEFAULT ));
2020-11-11 18:29:40 +01:00
self :: assertTrue ( $this -> authenticate ( $this -> testUser , $this -> testPass ), " Authentication failed " );
2017-09-19 22:04:40 +02:00
2020-02-19 18:42:44 +01:00
$newPass = " Newpass1234567890 " ;
2017-09-19 22:04:40 +02:00
$options = [
" http_errors " => false ,
" form_params " => [
2019-05-15 11:32:36 +02:00
" login " => $this -> testUser ,
2017-09-19 22:04:40 +02:00
" oldpass " => $this -> testPass ,
" pass " => $newPass ,
],
];
$response = $this -> http -> post ( " /utils/changepass.php " , $options );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 200 , $response -> getStatusCode (), " Unexpected status code " );
2017-09-19 22:04:40 +02:00
2020-01-07 17:21:40 +01:00
$json = json_decode ( $response -> getBody ());
2020-11-11 18:29:40 +01:00
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 " );
2017-09-19 22:04:40 +02:00
}
2021-04-22 19:47:52 +02:00
/**
* @ throws GuzzleException
*/
public function testChangePassOtherAdmin () : void {
2020-11-11 18:29:40 +01:00
self :: assertTrue ( $this -> authenticate (), " Authentication failed " );
2017-09-19 22:04:40 +02:00
$userId = $this -> addTestUser ( $this -> testUser , password_hash ( $this -> testPass , PASSWORD_DEFAULT ));
2020-02-19 18:42:44 +01:00
$newPass = " Newpass1234567890 " ;
2017-09-19 22:04:40 +02:00
$options = [
" http_errors " => false ,
" form_params " => [
" login " => $this -> testUser ,
" pass " => $newPass ,
],
];
$response = $this -> http -> post ( " /utils/changepass.php " , $options );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 200 , $response -> getStatusCode (), " Unexpected status code " );
2017-09-19 22:04:40 +02:00
2020-01-07 17:21:40 +01:00
$json = json_decode ( $response -> getBody ());
2020-11-11 18:29:40 +01:00
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 " );
2017-09-19 22:04:40 +02:00
}
2021-04-22 19:47:52 +02:00
/**
* @ throws GuzzleException
*/
public function testChangePassOtherUser () : void {
2020-02-19 18:42:44 +01:00
$this -> addTestUser ( $this -> testUser , password_hash ( $this -> testPass , PASSWORD_DEFAULT ));
$this -> addTestUser ( $this -> testUser2 , password_hash ( $this -> testPass , PASSWORD_DEFAULT ));
2020-11-11 18:29:40 +01:00
self :: assertTrue ( $this -> authenticate ( $this -> testUser , $this -> testPass ), " Authentication failed " );
2017-09-19 22:04:40 +02:00
2020-02-19 18:42:44 +01:00
$newPass = " Newpass1234567890 " ;
2017-09-19 22:04:40 +02:00
$options = [
" http_errors " => false ,
" form_params " => [
" login " => $this -> testUser2 ,
" pass " => $newPass ,
],
];
$response = $this -> http -> post ( " /utils/changepass.php " , $options );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 200 , $response -> getStatusCode (), " Unexpected status code " );
2017-09-19 22:04:40 +02:00
2020-01-07 17:21:40 +01:00
$json = json_decode ( $response -> getBody ());
2020-11-11 18:29:40 +01:00
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 " );
2017-09-19 22:04:40 +02:00
}
/* handletrack.php */
2021-04-22 19:47:52 +02:00
/**
* @ throws GuzzleException
*/
public function testHandleTrackDeleteAdmin () : void {
2020-11-11 18:29:40 +01:00
self :: assertTrue ( $this -> authenticate (), " Authentication failed " );
2017-09-19 22:04:40 +02:00
$userId = $this -> addTestUser ( $this -> testUser , password_hash ( $this -> testPass , PASSWORD_DEFAULT ));
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 2 , $this -> getConnection () -> getRowCount ( " users " ), " Wrong row count " );
2017-09-19 22:04:40 +02:00
$trackId = $this -> addTestTrack ( $userId );
$trackId2 = $this -> addTestTrack ( $userId );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 2 , $this -> getConnection () -> getRowCount ( " tracks " ), " Wrong row count " );
2017-09-19 22:04:40 +02:00
$options = [
" http_errors " => false ,
" form_params " => [ " trackid " => $trackId , " action " => " delete " ],
];
$response = $this -> http -> post ( " /utils/handletrack.php " , $options );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 200 , $response -> getStatusCode (), " Unexpected status code " );
2020-01-07 17:21:40 +01:00
$json = json_decode ( $response -> getBody ());
2020-11-11 18:29:40 +01:00
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 " );
2017-09-19 22:04:40 +02:00
}
2021-04-22 19:47:52 +02:00
/**
* @ throws GuzzleException
*/
public function testHandleTrackDeleteSelf () : void {
2017-09-19 22:04:40 +02:00
$userId = $this -> addTestUser ( $this -> testUser , password_hash ( $this -> testPass , PASSWORD_DEFAULT ));
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 2 , $this -> getConnection () -> getRowCount ( " users " ), " Wrong row count " );
self :: assertTrue ( $this -> authenticate ( $this -> testUser , $this -> testPass ), " Authentication failed " );
2017-09-19 22:04:40 +02:00
$trackId = $this -> addTestTrack ( $userId );
$trackId2 = $this -> addTestTrack ( $userId );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 2 , $this -> getConnection () -> getRowCount ( " tracks " ), " Wrong row count " );
2017-09-19 22:04:40 +02:00
$options = [
" http_errors " => false ,
" form_params " => [ " trackid " => $trackId , " action " => " delete " ],
];
$response = $this -> http -> post ( " /utils/handletrack.php " , $options );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 200 , $response -> getStatusCode (), " Unexpected status code " );
2020-01-07 17:21:40 +01:00
$json = json_decode ( $response -> getBody ());
2020-11-11 18:29:40 +01:00
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 " );
2017-09-19 22:04:40 +02:00
}
2021-04-22 19:47:52 +02:00
/**
* @ throws GuzzleException
*/
public function testHandleTrackDeleteOtherUser () : void {
2020-02-20 17:08:47 +01:00
$lang = ( new uLang ( $this -> mockConfig )) -> getStrings ();
2017-09-19 22:04:40 +02:00
$this -> addTestUser ( $this -> testUser , password_hash ( $this -> testPass , PASSWORD_DEFAULT ));
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 2 , $this -> getConnection () -> getRowCount ( " users " ), " Wrong row count " );
self :: assertTrue ( $this -> authenticate ( $this -> testUser , $this -> testPass ), " Authentication failed " );
2017-09-19 22:04:40 +02:00
$trackId = $this -> addTestTrack ( $this -> testUserId );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 1 , $this -> getConnection () -> getRowCount ( " tracks " ), " Wrong row count " );
2017-09-19 22:04:40 +02:00
$options = [
" http_errors " => false ,
" form_params " => [ " trackid " => $trackId , " action " => " delete " ],
];
$response = $this -> http -> post ( " /utils/handletrack.php " , $options );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 200 , $response -> getStatusCode (), " Unexpected status code " );
2020-01-07 17:21:40 +01:00
$json = json_decode ( $response -> getBody ());
2020-11-11 18:29:40 +01:00
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 " );
2017-09-19 22:04:40 +02:00
}
2021-04-22 19:47:52 +02:00
/**
* @ throws GuzzleException
*/
public function testHandleTrackUpdate () : void {
2017-09-19 22:04:40 +02:00
$newName = " New name " ;
2020-11-11 18:29:40 +01:00
self :: assertTrue ( $this -> authenticate (), " Authentication failed " );
2017-09-19 22:04:40 +02:00
$userId = $this -> addTestUser ( $this -> testUser , password_hash ( $this -> testPass , PASSWORD_DEFAULT ));
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 2 , $this -> getConnection () -> getRowCount ( " users " ), " Wrong row count " );
2017-09-19 22:04:40 +02:00
$trackId = $this -> addTestTrack ( $userId );
$trackId2 = $this -> addTestTrack ( $userId );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 2 , $this -> getConnection () -> getRowCount ( " tracks " ), " Wrong row count " );
2017-09-19 22:04:40 +02:00
$options = [
" http_errors " => false ,
" form_params " => [ " trackid " => $trackId , " action " => " update " , " trackname " => $newName ],
];
$response = $this -> http -> post ( " /utils/handletrack.php " , $options );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 200 , $response -> getStatusCode (), " Unexpected status code " );
2020-01-07 17:21:40 +01:00
$json = json_decode ( $response -> getBody ());
2020-11-11 18:29:40 +01:00
self :: assertNotNull ( $json , " JSON object is null " );
self :: assertEquals ( 2 , $this -> getConnection () -> getRowCount ( " tracks " ), " Wrong row count " );
2017-09-19 22:04:40 +02:00
$row1 = [
" id " => $trackId2 ,
" user_id " => $userId ,
" name " => $this -> testTrackName ,
" comment " => $this -> testTrackComment
];
$row2 = [
" id " => $trackId ,
" user_id " => $userId ,
" name " => $newName ,
" comment " => $this -> testTrackComment
];
$actual = $this -> getConnection () -> createQueryTable (
" tracks " ,
" SELECT * FROM tracks "
);
$this -> assertTableContains ( $row1 , $actual , " Wrong actual table data " );
$this -> assertTableContains ( $row2 , $actual , " Wrong actual table data " );
}
2021-04-22 19:47:52 +02:00
/**
* @ throws GuzzleException
*/
public function testHandleTrackUpdateEmptyName () : void {
2020-02-20 17:08:47 +01:00
$lang = ( new uLang ( $this -> mockConfig )) -> getStrings ();
2020-11-11 18:29:40 +01:00
self :: assertTrue ( $this -> authenticate (), " Authentication failed " );
2017-09-19 22:04:40 +02:00
$userId = $this -> addTestUser ( $this -> testUser , password_hash ( $this -> testPass , PASSWORD_DEFAULT ));
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 2 , $this -> getConnection () -> getRowCount ( " users " ), " Wrong row count " );
2017-09-19 22:04:40 +02:00
$trackId = $this -> addTestTrack ( $userId );
2020-02-19 18:42:44 +01:00
$this -> addTestTrack ( $userId );
2017-09-19 22:04:40 +02:00
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 2 , $this -> getConnection () -> getRowCount ( " tracks " ), " Wrong row count " );
2017-09-19 22:04:40 +02:00
$options = [
" http_errors " => false ,
" form_params " => [ " trackid " => $trackId , " action " => " update " , " trackname " => " " ],
];
$response = $this -> http -> post ( " /utils/handletrack.php " , $options );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 200 , $response -> getStatusCode (), " Unexpected status code " );
2020-01-07 17:21:40 +01:00
$json = json_decode ( $response -> getBody ());
2020-11-11 18:29:40 +01:00
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 " );
2017-09-19 22:04:40 +02:00
}
2021-04-22 19:47:52 +02:00
/**
* @ throws GuzzleException
*/
public function testHandleTrackUpdateNonexistantTrack () : void {
2020-02-20 17:08:47 +01:00
$lang = ( new uLang ( $this -> mockConfig )) -> getStrings ();
2017-09-19 22:04:40 +02:00
$newName = " New name " ;
2020-11-11 18:29:40 +01:00
self :: assertTrue ( $this -> authenticate (), " Authentication failed " );
2017-09-19 22:04:40 +02:00
$userId = $this -> addTestUser ( $this -> testUser , password_hash ( $this -> testPass , PASSWORD_DEFAULT ));
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 2 , $this -> getConnection () -> getRowCount ( " users " ), " Wrong row count " );
2017-09-19 22:04:40 +02:00
$trackId = $this -> addTestTrack ( $userId );
$nonexistantTrackId = $trackId + 1 ;
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 1 , $this -> getConnection () -> getRowCount ( " tracks " ), " Wrong row count " );
self :: assertFalse ( $this -> pdoGetColumn ( " SELECT id FROM tracks WHERE id = $nonexistantTrackId " ), " Nonexistant track exists " );
2017-09-19 22:04:40 +02:00
$options = [
" http_errors " => false ,
" form_params " => [ " trackid " => $nonexistantTrackId , " action " => " update " , " trackname " => $newName ],
];
$response = $this -> http -> post ( " /utils/handletrack.php " , $options );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 200 , $response -> getStatusCode (), " Unexpected status code " );
2020-01-07 17:21:40 +01:00
$json = json_decode ( $response -> getBody ());
2020-11-11 18:29:40 +01:00
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 " );
2017-09-19 22:04:40 +02:00
}
2021-04-22 19:47:52 +02:00
/**
* @ throws GuzzleException
*/
public function testHandleTrackMissingAction () : void {
2020-02-20 17:08:47 +01:00
$lang = ( new uLang ( $this -> mockConfig )) -> getStrings ();
2020-11-11 18:29:40 +01:00
self :: assertTrue ( $this -> authenticate (), " Authentication failed " );
2017-09-19 22:04:40 +02:00
$options = [
" http_errors " => false ,
];
$response = $this -> http -> post ( " /utils/handletrack.php " , $options );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 200 , $response -> getStatusCode (), " Unexpected status code " );
2020-01-07 17:21:40 +01:00
$json = json_decode ( $response -> getBody ());
2020-11-11 18:29:40 +01:00
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 " );
2017-09-19 22:04:40 +02:00
}
/* handleuser.php */
2021-04-22 19:47:52 +02:00
/**
* @ throws GuzzleException
*/
public function testHandleUserMissingAction () : void {
2020-02-20 17:08:47 +01:00
$lang = ( new uLang ( $this -> mockConfig )) -> getStrings ();
2020-11-11 18:29:40 +01:00
self :: assertTrue ( $this -> authenticate (), " Authentication failed " );
2017-09-19 22:04:40 +02:00
$options = [
" http_errors " => false ,
];
$response = $this -> http -> post ( " /utils/handleuser.php " , $options );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 200 , $response -> getStatusCode (), " Unexpected status code " );
2020-01-07 17:21:40 +01:00
$json = json_decode ( $response -> getBody ());
2020-11-11 18:29:40 +01:00
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 " );
2017-09-19 22:04:40 +02:00
}
2021-04-22 19:47:52 +02:00
/**
* @ throws GuzzleException
*/
public function testHandleUserNonAdmin () : void {
2020-02-20 17:08:47 +01:00
$lang = ( new uLang ( $this -> mockConfig )) -> getStrings ();
2017-09-19 22:04:40 +02:00
$this -> addTestUser ( $this -> testUser , password_hash ( $this -> testPass , PASSWORD_DEFAULT ));
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 2 , $this -> getConnection () -> getRowCount ( " users " ), " Wrong row count " );
self :: assertTrue ( $this -> authenticate ( $this -> testUser , $this -> testPass ), " Authentication failed " );
2017-09-19 22:04:40 +02:00
$options = [
" http_errors " => false ,
" form_params " => [ " action " => " delete " , " login " => " test " ],
];
$response = $this -> http -> post ( " /utils/handleuser.php " , $options );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 200 , $response -> getStatusCode (), " Unexpected status code " );
2020-01-07 17:21:40 +01:00
$json = json_decode ( $response -> getBody ());
2020-11-11 18:29:40 +01:00
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 " );
2017-09-19 22:04:40 +02:00
}
2021-04-22 19:47:52 +02:00
/**
* @ throws GuzzleException
*/
public function testHandleUserSelf () : void {
2020-02-20 17:08:47 +01:00
$lang = ( new uLang ( $this -> mockConfig )) -> getStrings ();
2020-11-11 18:29:40 +01:00
self :: assertTrue ( $this -> authenticate (), " Authentication failed " );
self :: assertEquals ( 1 , $this -> getConnection () -> getRowCount ( " users " ), " Wrong row count " );
2017-09-19 22:04:40 +02:00
$options = [
" http_errors " => false ,
" form_params " => [ " action " => " delete " , " login " => $this -> testAdminUser ],
];
$response = $this -> http -> post ( " /utils/handleuser.php " , $options );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 200 , $response -> getStatusCode (), " Unexpected status code " );
2020-01-07 17:21:40 +01:00
$json = json_decode ( $response -> getBody ());
2020-11-11 18:29:40 +01:00
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 " );
2017-09-19 22:04:40 +02:00
}
2021-04-22 19:47:52 +02:00
/**
* @ throws GuzzleException
*/
public function testHandleUserEmptyLogin () : void {
2020-02-20 17:08:47 +01:00
$lang = ( new uLang ( $this -> mockConfig )) -> getStrings ();
2020-11-11 18:29:40 +01:00
self :: assertTrue ( $this -> authenticate (), " Authentication failed " );
self :: assertEquals ( 1 , $this -> getConnection () -> getRowCount ( " users " ), " Wrong row count " );
2017-09-19 22:04:40 +02:00
$options = [
" http_errors " => false ,
" form_params " => [ " action " => " delete " , " login " => " " ],
];
$response = $this -> http -> post ( " /utils/handleuser.php " , $options );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 200 , $response -> getStatusCode (), " Unexpected status code " );
2020-01-07 17:21:40 +01:00
$json = json_decode ( $response -> getBody ());
2020-11-11 18:29:40 +01:00
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 " );
2017-09-19 22:04:40 +02:00
}
2021-04-22 19:47:52 +02:00
/**
* @ throws GuzzleException
*/
public function testHandleUserNoAuth () : void {
2020-02-20 17:08:47 +01:00
$lang = ( new uLang ( $this -> mockConfig )) -> getStrings ();
2017-09-19 22:04:40 +02:00
$this -> addTestUser ( $this -> testUser , password_hash ( $this -> testPass , PASSWORD_DEFAULT ));
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 2 , $this -> getConnection () -> getRowCount ( " users " ), " Wrong row count " );
2017-09-19 22:04:40 +02:00
$options = [
" http_errors " => false ,
" form_params " => [ " action " => " delete " , " login " => $this -> testUser ],
];
$response = $this -> http -> post ( " /utils/handleuser.php " , $options );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 200 , $response -> getStatusCode (), " Unexpected status code " );
2020-01-07 17:21:40 +01:00
$json = json_decode ( $response -> getBody ());
2020-11-11 18:29:40 +01:00
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 " );
2017-09-19 22:04:40 +02:00
}
2021-04-22 19:47:52 +02:00
/**
* @ throws GuzzleException
*/
public function testHandleUserAdd () : void {
2020-11-11 18:29:40 +01:00
self :: assertTrue ( $this -> authenticate (), " Authentication failed " );
self :: assertEquals ( 1 , $this -> getConnection () -> getRowCount ( " users " ), " Wrong row count " );
2017-09-19 22:04:40 +02:00
$options = [
" http_errors " => false ,
" form_params " => [ " action " => " add " , " login " => $this -> testUser , " pass " => $this -> testPass ],
];
$response = $this -> http -> post ( " /utils/handleuser.php " , $options );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 200 , $response -> getStatusCode (), " Unexpected status code " );
2020-01-07 17:21:40 +01:00
$json = json_decode ( $response -> getBody ());
2020-11-11 18:29:40 +01:00
self :: assertNotNull ( $json , " JSON object is null " );
self :: assertEquals ( 2 , $this -> getConnection () -> getRowCount ( " users " ), " Wrong row count " );
2017-09-19 22:04:40 +02:00
$expected = [
" login " => $this -> testUser ,
];
$actual = $this -> getConnection () -> createQueryTable (
" users " ,
" SELECT login FROM users "
);
$this -> assertTableContains ( $expected , $actual , " Wrong actual table data " );
2020-11-11 18:29:40 +01:00
self :: assertTrue ( password_verify ( $this -> testPass , $this -> pdoGetColumn ( " SELECT password FROM users WHERE login = ' $this->testUser ' " )), " Wrong actual password hash " );
2017-09-19 22:04:40 +02:00
}
2021-04-22 19:47:52 +02:00
/**
* @ throws GuzzleException
*/
public function testHandleUserAddSameLogin () : void {
2020-02-20 17:08:47 +01:00
$lang = ( new uLang ( $this -> mockConfig )) -> getStrings ();
2020-11-11 18:29:40 +01:00
self :: assertTrue ( $this -> authenticate (), " Authentication failed " );
2017-09-19 22:04:40 +02:00
$this -> addTestUser ( $this -> testUser , password_hash ( $this -> testPass , PASSWORD_DEFAULT ));
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 2 , $this -> getConnection () -> getRowCount ( " users " ), " Wrong row count " );
2017-09-19 22:04:40 +02:00
$options = [
" http_errors " => false ,
" form_params " => [ " action " => " add " , " login " => $this -> testUser , " pass " => $this -> testPass ],
];
$response = $this -> http -> post ( " /utils/handleuser.php " , $options );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 200 , $response -> getStatusCode (), " Unexpected status code " );
2020-01-07 17:21:40 +01:00
$json = json_decode ( $response -> getBody ());
2020-11-11 18:29:40 +01:00
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 " );
2017-09-19 22:04:40 +02:00
}
2021-04-22 19:47:52 +02:00
/**
* @ throws GuzzleException
*/
public function testHandleUserUpdate () : void {
2017-09-19 22:04:40 +02:00
$newPass = $this -> testPass . " new " ;
2020-11-11 18:29:40 +01:00
self :: assertTrue ( $this -> authenticate (), " Authentication failed " );
2017-09-19 22:04:40 +02:00
$this -> addTestUser ( $this -> testUser , password_hash ( $this -> testPass , PASSWORD_DEFAULT ));
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 2 , $this -> getConnection () -> getRowCount ( " users " ), " Wrong row count " );
2017-09-19 22:04:40 +02:00
$options = [
" http_errors " => false ,
" form_params " => [ " action " => " update " , " login " => $this -> testUser , " pass " => $newPass ],
];
$response = $this -> http -> post ( " /utils/handleuser.php " , $options );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 200 , $response -> getStatusCode (), " Unexpected status code " );
2020-01-07 17:21:40 +01:00
$json = json_decode ( $response -> getBody ());
2020-11-11 18:29:40 +01:00
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 " );
2017-09-19 22:04:40 +02:00
}
2021-04-22 19:47:52 +02:00
/**
* @ throws GuzzleException
*/
public function testHandleUserUpdateEmptyPass () : void {
2020-11-11 18:29:40 +01:00
self :: assertTrue ( $this -> authenticate (), " Authentication failed " );
2017-09-19 22:04:40 +02:00
$this -> addTestUser ( $this -> testUser , password_hash ( $this -> testPass , PASSWORD_DEFAULT ));
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 2 , $this -> getConnection () -> getRowCount ( " users " ), " Wrong row count " );
2017-09-19 22:04:40 +02:00
$options = [
" http_errors " => false ,
" form_params " => [ " action " => " update " , " login " => $this -> testUser , " pass " => " " ],
];
$response = $this -> http -> post ( " /utils/handleuser.php " , $options );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 200 , $response -> getStatusCode (), " Unexpected status code " );
2020-02-19 18:42:44 +01:00
2020-11-11 18:29:40 +01:00
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 " );
2017-09-19 22:04:40 +02:00
}
2021-04-22 19:47:52 +02:00
/**
* @ throws GuzzleException
*/
public function testHandleUserDelete () : void {
2020-11-11 18:29:40 +01:00
self :: assertTrue ( $this -> authenticate (), " Authentication failed " );
2017-09-19 22:04:40 +02:00
$this -> addTestUser ( $this -> testUser , password_hash ( $this -> testPass , PASSWORD_DEFAULT ));
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 2 , $this -> getConnection () -> getRowCount ( " users " ), " Wrong row count " );
2017-09-19 22:04:40 +02:00
$options = [
" http_errors " => false ,
" form_params " => [ " action " => " delete " , " login " => $this -> testUser ],
];
$response = $this -> http -> post ( " /utils/handleuser.php " , $options );
2020-11-11 18:29:40 +01:00
self :: assertEquals ( 200 , $response -> getStatusCode (), " Unexpected status code " );
2020-01-07 17:21:40 +01:00
$json = json_decode ( $response -> getBody ());
2020-11-11 18:29:40 +01:00
self :: assertNotNull ( $json , " JSON object is null " );
self :: assertEquals ( 1 , $this -> getConnection () -> getRowCount ( " users " ), " Wrong row count " );
2017-09-19 22:04:40 +02:00
}
}
?>