2018-04-09 21:23:41 +02:00
< ? php
/**
* ApiTest class .
*/
namespace Friendica\Test ;
2019-07-26 15:54:14 +02:00
use Dice\Dice ;
2019-02-05 22:03:07 +01:00
use Friendica\App ;
2020-01-19 21:29:36 +01:00
use Friendica\Core\Config\IConfig ;
2020-01-19 22:23:44 +01:00
use Friendica\Core\PConfig\IPConfig ;
2018-07-10 04:39:59 +02:00
use Friendica\Core\Protocol ;
2019-12-10 22:56:56 +01:00
use Friendica\Core\Session ;
2019-12-10 22:29:49 +01:00
use Friendica\Core\Session\ISession ;
2018-07-10 04:39:59 +02:00
use Friendica\Core\System ;
2019-07-27 14:37:24 +02:00
use Friendica\Database\Database ;
2020-01-28 22:00:21 +01:00
use Friendica\Database\DBA ;
2019-12-15 22:34:11 +01:00
use Friendica\DI ;
2019-12-13 21:22:24 +01:00
use Friendica\Model\Contact ;
2018-04-09 21:23:41 +02:00
use Friendica\Network\HTTPException ;
2019-07-27 14:37:24 +02:00
use Friendica\Test\Util\Database\StaticDatabase ;
2020-01-31 21:40:45 +01:00
use Friendica\Util\Temporal ;
2018-12-30 21:42:56 +01:00
use Monolog\Handler\TestHandler ;
2018-04-09 21:23:41 +02:00
2018-11-01 13:45:21 +01:00
require_once __DIR__ . '/../../include/api.php' ;
2018-10-22 20:59:51 +02:00
2018-04-09 21:23:41 +02:00
/**
* Tests for the API functions .
*
* Functions that use header () need to be tested in a separate process .
* @ see https :// phpunit . de / manual / 5.7 / en / appendixes . annotations . html #appendixes.annotations.runTestsInSeparateProcesses
*/
class ApiTest extends DatabaseTest
{
2018-12-30 21:42:56 +01:00
/**
* @ var TestHandler Can handle log - outputs
*/
protected $logOutput ;
2019-03-23 15:02:32 +01:00
/** @var array */
protected $selfUser ;
/** @var array */
protected $friendUser ;
/** @var array */
protected $otherUser ;
protected $wrongUserId ;
2019-07-26 15:54:14 +02:00
/** @var App */
protected $app ;
2020-01-19 21:29:36 +01:00
/** @var IConfig */
2019-08-04 18:50:24 +02:00
protected $config ;
/** @var Dice */
protected $dice ;
2018-04-09 21:23:41 +02:00
/**
* Create variables used by tests .
*/
2019-07-28 17:40:42 +02:00
protected function setUp ()
2018-04-09 21:23:41 +02:00
{
2019-07-28 17:40:42 +02:00
parent :: setUp ();
2018-07-01 20:46:24 +02:00
2019-08-05 09:02:55 +02:00
$this -> dice = ( new Dice ())
-> addRules ( include __DIR__ . '/../../static/dependencies.config.php' )
2019-12-10 22:56:56 +01:00
-> addRule ( Database :: class , [ 'instanceOf' => StaticDatabase :: class , 'shared' => true ])
2019-12-10 23:35:16 +01:00
-> addRule ( ISession :: class , [ 'instanceOf' => Session\Memory :: class , 'shared' => true , 'call' => null ]);
2019-12-15 23:28:01 +01:00
DI :: init ( $this -> dice );
2019-07-26 15:54:14 +02:00
2019-07-28 17:40:42 +02:00
/** @var Database $dba */
2019-08-04 18:50:24 +02:00
$dba = $this -> dice -> create ( Database :: class );
2019-07-28 17:40:42 +02:00
2020-01-19 21:29:36 +01:00
/** @var IConfig $config */
$this -> config = $this -> dice -> create ( IConfig :: class );
2019-08-04 19:02:16 +02:00
$this -> config -> set ( 'system' , 'url' , 'http://localhost' );
$this -> config -> set ( 'system' , 'hostname' , 'localhost' );
$this -> config -> set ( 'system' , 'worker_dont_fork' , true );
// Default config
$this -> config -> set ( 'config' , 'hostname' , 'localhost' );
$this -> config -> set ( 'system' , 'throttle_limit_day' , 100 );
$this -> config -> set ( 'system' , 'throttle_limit_week' , 100 );
$this -> config -> set ( 'system' , 'throttle_limit_month' , 100 );
$this -> config -> set ( 'system' , 'theme' , 'system_theme' );
2019-07-28 17:40:42 +02:00
// Load the API dataset for the whole API
2019-07-28 20:46:29 +02:00
$this -> loadFixture ( __DIR__ . '/../datasets/api.fixture.php' , $dba );
2019-07-28 17:40:42 +02:00
2019-08-04 19:02:16 +02:00
/** @var App app */
2019-12-15 22:34:11 +01:00
$this -> app = DI :: app ();
2019-07-27 14:37:24 +02:00
2019-07-26 15:54:14 +02:00
$this -> app -> argc = 1 ;
$this -> app -> argv = [ 'home' ];
2018-04-09 21:23:41 +02:00
// User data that the test database is populated with
2019-07-28 17:40:42 +02:00
$this -> selfUser = [
'id' => 42 ,
2018-04-09 21:23:41 +02:00
'name' => 'Self contact' ,
'nick' => 'selfcontact' ,
2018-07-01 21:07:50 +02:00
'nurl' => 'http://localhost/profile/selfcontact'
2018-07-01 20:46:24 +02:00
];
$this -> friendUser = [
2019-07-28 17:40:42 +02:00
'id' => 44 ,
2018-07-01 20:46:24 +02:00
'name' => 'Friend contact' ,
'nick' => 'friendcontact' ,
2018-07-01 21:07:50 +02:00
'nurl' => 'http://localhost/profile/friendcontact'
2018-04-09 21:23:41 +02:00
];
2019-07-28 17:40:42 +02:00
$this -> otherUser = [
'id' => 43 ,
2018-04-09 21:23:41 +02:00
'name' => 'othercontact' ,
'nick' => 'othercontact' ,
2018-07-01 21:07:50 +02:00
'nurl' => 'http://localhost/profile/othercontact'
2018-04-09 21:23:41 +02:00
];
// User ID that we know is not in the database
$this -> wrongUserId = 666 ;
2019-12-16 01:35:26 +01:00
DI :: session () -> start ();
2019-12-10 22:29:49 +01:00
2018-04-09 21:23:41 +02:00
// Most API require login so we force the session
$_SESSION = [
2019-07-28 17:40:42 +02:00
'allow_api' => true ,
2018-04-09 21:23:41 +02:00
'authenticated' => true ,
2019-07-28 17:40:42 +02:00
'uid' => $this -> selfUser [ 'id' ]
2018-04-09 21:23:41 +02:00
];
2019-07-28 17:40:42 +02:00
$_POST = [];
$_GET = [];
$_SERVER = [];
2018-04-09 21:23:41 +02:00
}
/**
* Assert that an user array contains expected keys .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ param array $user User array
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
private function assertSelfUser ( array $user )
{
$this -> assertEquals ( $this -> selfUser [ 'id' ], $user [ 'uid' ]);
$this -> assertEquals ( $this -> selfUser [ 'id' ], $user [ 'cid' ]);
$this -> assertEquals ( 1 , $user [ 'self' ]);
2018-11-18 21:40:10 +01:00
$this -> assertEquals ( 'DFRN' , $user [ 'location' ]);
2018-04-09 21:23:41 +02:00
$this -> assertEquals ( $this -> selfUser [ 'name' ], $user [ 'name' ]);
$this -> assertEquals ( $this -> selfUser [ 'nick' ], $user [ 'screen_name' ]);
$this -> assertEquals ( 'dfrn' , $user [ 'network' ]);
$this -> assertTrue ( $user [ 'verified' ]);
}
/**
* Assert that an user array contains expected keys .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ param array $user User array
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
private function assertOtherUser ( array $user )
{
$this -> assertEquals ( $this -> otherUser [ 'id' ], $user [ 'id' ]);
$this -> assertEquals ( $this -> otherUser [ 'id' ], $user [ 'id_str' ]);
$this -> assertEquals ( 0 , $user [ 'self' ]);
$this -> assertEquals ( $this -> otherUser [ 'name' ], $user [ 'name' ]);
$this -> assertEquals ( $this -> otherUser [ 'nick' ], $user [ 'screen_name' ]);
$this -> assertFalse ( $user [ 'verified' ]);
}
/**
* Assert that a status array contains expected keys .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ param array $status Status array
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
private function assertStatus ( array $status )
{
$this -> assertInternalType ( 'string' , $status [ 'text' ]);
$this -> assertInternalType ( 'int' , $status [ 'id' ]);
// We could probably do more checks here.
}
/**
* Assert that a list array contains expected keys .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ param array $list List array
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
private function assertList ( array $list )
{
$this -> assertInternalType ( 'string' , $list [ 'name' ]);
$this -> assertInternalType ( 'int' , $list [ 'id' ]);
$this -> assertInternalType ( 'string' , $list [ 'id_str' ]);
$this -> assertContains ( $list [ 'mode' ], [ 'public' , 'private' ]);
// We could probably do more checks here.
}
/**
* Assert that the string is XML and contain the root element .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ param string $result XML string
* @ param string $root_element Root element name
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
private function assertXml ( $result , $root_element )
{
$this -> assertStringStartsWith ( '<?xml version="1.0"?>' , $result );
2019-07-28 17:40:42 +02:00
$this -> assertContains ( '<' . $root_element , $result );
2018-04-09 21:23:41 +02:00
// We could probably do more checks here.
}
/**
* Get the path to a temporary empty PNG image .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return string Path
*/
private function getTempImage ()
{
$tmpFile = tempnam ( sys_get_temp_dir (), 'tmp_file' );
file_put_contents (
$tmpFile ,
base64_decode (
2019-07-28 17:40:42 +02:00
// Empty 1x1 px PNG image
2018-04-09 21:23:41 +02:00
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
)
);
return $tmpFile ;
}
/**
* Test the api_user () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiUser ()
{
$this -> assertEquals ( $this -> selfUser [ 'id' ], api_user ());
}
/**
* Test the api_user () function with an unallowed user .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiUserWithUnallowedUser ()
{
$_SESSION = [ 'allow_api' => false ];
$this -> assertEquals ( false , api_user ());
}
/**
* Test the api_source () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiSource ()
{
$this -> assertEquals ( 'api' , api_source ());
}
/**
* Test the api_source () function with a Twidere user agent .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiSourceWithTwidere ()
{
$_SERVER [ 'HTTP_USER_AGENT' ] = 'Twidere' ;
$this -> assertEquals ( 'Twidere' , api_source ());
}
/**
* Test the api_source () function with a GET parameter .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiSourceWithGet ()
{
$_GET [ 'source' ] = 'source_name' ;
$this -> assertEquals ( 'source_name' , api_source ());
}
/**
* Test the api_date () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiDate ()
{
$this -> assertEquals ( 'Wed Oct 10 00:00:00 +0000 1990' , api_date ( '1990-10-10' ));
}
/**
* Test the api_register_func () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiRegisterFunc ()
{
global $API ;
$this -> assertNull (
api_register_func (
'api_path' ,
function () {
},
true ,
'method'
)
);
$this -> assertTrue ( $API [ 'api_path' ][ 'auth' ]);
$this -> assertEquals ( 'method' , $API [ 'api_path' ][ 'method' ]);
$this -> assertTrue ( is_callable ( $API [ 'api_path' ][ 'func' ]));
}
/**
* Test the api_login () function without any login .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ runInSeparateProcess
* @ expectedException Friendica\Network\HTTPException\UnauthorizedException
*/
public function testApiLoginWithoutLogin ()
{
api_login ( $this -> app );
}
/**
* Test the api_login () function with a bad login .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ runInSeparateProcess
* @ expectedException Friendica\Network\HTTPException\UnauthorizedException
*/
public function testApiLoginWithBadLogin ()
{
$_SERVER [ 'PHP_AUTH_USER' ] = 'user@server' ;
api_login ( $this -> app );
}
/**
* Test the api_login () function with oAuth .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiLoginWithOauth ()
{
$this -> markTestIncomplete ( 'Can we test this easily?' );
}
/**
* Test the api_login () function with authentication provided by an addon .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiLoginWithAddonAuth ()
{
$this -> markTestIncomplete ( 'Can we test this easily?' );
}
/**
* Test the api_login () function with a correct login .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ runInSeparateProcess
*/
public function testApiLoginWithCorrectLogin ()
{
$_SERVER [ 'PHP_AUTH_USER' ] = 'Test user' ;
2019-07-28 17:40:42 +02:00
$_SERVER [ 'PHP_AUTH_PW' ] = 'password' ;
2018-04-09 21:23:41 +02:00
api_login ( $this -> app );
}
/**
* Test the api_login () function with a remote user .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ runInSeparateProcess
* @ expectedException Friendica\Network\HTTPException\UnauthorizedException
*/
public function testApiLoginWithRemoteUser ()
{
$_SERVER [ 'REDIRECT_REMOTE_USER' ] = '123456dXNlcjpwYXNzd29yZA==' ;
api_login ( $this -> app );
}
/**
* Test the api_check_method () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiCheckMethod ()
{
$this -> assertFalse ( api_check_method ( 'method' ));
}
/**
* Test the api_check_method () function with a correct method .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiCheckMethodWithCorrectMethod ()
{
$_SERVER [ 'REQUEST_METHOD' ] = 'method' ;
$this -> assertTrue ( api_check_method ( 'method' ));
}
/**
* Test the api_check_method () function with a wildcard .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiCheckMethodWithWildcard ()
{
$this -> assertTrue ( api_check_method ( '*' ));
}
/**
* Test the api_call () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ runInSeparateProcess
*/
public function testApiCall ()
{
global $API ;
2019-07-28 17:40:42 +02:00
$API [ 'api_path' ] = [
2018-04-09 21:23:41 +02:00
'method' => 'method' ,
2019-07-28 17:40:42 +02:00
'func' => function () {
2018-04-09 21:23:41 +02:00
return [ 'data' => [ 'some_data' ]];
}
];
$_SERVER [ 'REQUEST_METHOD' ] = 'method' ;
2019-12-16 01:35:26 +01:00
$_SERVER [ 'QUERY_STRING' ] = 'q=api_path' ;
2019-07-28 17:40:42 +02:00
$_GET [ 'callback' ] = 'callback_name' ;
2018-04-09 21:23:41 +02:00
2019-12-16 01:35:26 +01:00
$args = DI :: args () -> determine ( $_SERVER , $_GET );
2018-04-09 21:23:41 +02:00
$this -> assertEquals (
'callback_name(["some_data"])' ,
2019-12-16 01:35:26 +01:00
api_call ( $this -> app , $args )
2018-04-09 21:23:41 +02:00
);
}
/**
* Test the api_call () function with the profiled enabled .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ runInSeparateProcess
*/
public function testApiCallWithProfiler ()
{
global $API ;
2019-07-28 17:40:42 +02:00
$API [ 'api_path' ] = [
2018-04-09 21:23:41 +02:00
'method' => 'method' ,
2019-07-28 17:40:42 +02:00
'func' => function () {
2018-04-09 21:23:41 +02:00
return [ 'data' => [ 'some_data' ]];
}
];
2019-12-16 01:35:26 +01:00
2018-04-09 21:23:41 +02:00
$_SERVER [ 'REQUEST_METHOD' ] = 'method' ;
2019-12-16 01:35:26 +01:00
$_SERVER [ 'QUERY_STRING' ] = 'q=api_path' ;
$args = DI :: args () -> determine ( $_SERVER , $_GET );
2019-08-04 19:02:16 +02:00
$this -> config -> set ( 'system' , 'profiler' , true );
$this -> config -> set ( 'rendertime' , 'callstack' , true );
2018-04-09 21:23:41 +02:00
$this -> app -> callstack = [
2019-07-28 17:40:42 +02:00
'database' => [ 'some_function' => 200 ],
2018-04-09 21:23:41 +02:00
'database_write' => [ 'some_function' => 200 ],
2019-07-28 17:40:42 +02:00
'cache' => [ 'some_function' => 200 ],
'cache_write' => [ 'some_function' => 200 ],
'network' => [ 'some_function' => 200 ]
2018-04-09 21:23:41 +02:00
];
$this -> assertEquals (
'["some_data"]' ,
2019-12-16 01:35:26 +01:00
api_call ( $this -> app , $args )
2018-04-09 21:23:41 +02:00
);
}
/**
* Test the api_call () function without any result .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ runInSeparateProcess
*/
public function testApiCallWithNoResult ()
{
global $API ;
2019-07-28 17:40:42 +02:00
$API [ 'api_path' ] = [
2018-04-09 21:23:41 +02:00
'method' => 'method' ,
2019-07-28 17:40:42 +02:00
'func' => function () {
2018-04-09 21:23:41 +02:00
return false ;
}
];
$_SERVER [ 'REQUEST_METHOD' ] = 'method' ;
2019-12-16 01:35:26 +01:00
$_SERVER [ 'QUERY_STRING' ] = 'q=api_path' ;
$args = DI :: args () -> determine ( $_SERVER , $_GET );
2018-04-09 21:23:41 +02:00
$this -> assertEquals (
'{"status":{"error":"Internal Server Error","code":"500 Internal Server Error","request":"api_path"}}' ,
2019-12-16 01:35:26 +01:00
api_call ( $this -> app , $args )
2018-04-09 21:23:41 +02:00
);
}
/**
* Test the api_call () function with an unimplemented API .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ runInSeparateProcess
*/
public function testApiCallWithUninplementedApi ()
{
$this -> assertEquals (
'{"status":{"error":"Not Implemented","code":"501 Not Implemented","request":""}}' ,
api_call ( $this -> app )
);
}
/**
* Test the api_call () function with a JSON result .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ runInSeparateProcess
*/
public function testApiCallWithJson ()
{
global $API ;
2019-07-28 17:40:42 +02:00
$API [ 'api_path' ] = [
2018-04-09 21:23:41 +02:00
'method' => 'method' ,
2019-07-28 17:40:42 +02:00
'func' => function () {
2018-04-09 21:23:41 +02:00
return [ 'data' => [ 'some_data' ]];
}
];
$_SERVER [ 'REQUEST_METHOD' ] = 'method' ;
2019-12-16 01:35:26 +01:00
$_SERVER [ 'QUERY_STRING' ] = 'q=api_path.json' ;
$args = DI :: args () -> determine ( $_SERVER , $_GET );
2018-04-09 21:23:41 +02:00
$this -> assertEquals (
'["some_data"]' ,
2019-12-16 01:35:26 +01:00
api_call ( $this -> app , $args )
2018-04-09 21:23:41 +02:00
);
}
/**
* Test the api_call () function with an XML result .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ runInSeparateProcess
*/
public function testApiCallWithXml ()
{
global $API ;
2019-07-28 17:40:42 +02:00
$API [ 'api_path' ] = [
2018-04-09 21:23:41 +02:00
'method' => 'method' ,
2019-07-28 17:40:42 +02:00
'func' => function () {
2018-04-09 21:23:41 +02:00
return 'some_data' ;
}
];
$_SERVER [ 'REQUEST_METHOD' ] = 'method' ;
2019-12-16 01:35:26 +01:00
$_SERVER [ 'QUERY_STRING' ] = 'q=api_path.xml' ;
$args = DI :: args () -> determine ( $_SERVER , $_GET );
2018-04-09 21:23:41 +02:00
$this -> assertEquals (
'some_data' ,
2019-12-16 01:35:26 +01:00
api_call ( $this -> app , $args )
2018-04-09 21:23:41 +02:00
);
}
/**
* Test the api_call () function with an RSS result .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ runInSeparateProcess
*/
public function testApiCallWithRss ()
{
global $API ;
2019-07-28 17:40:42 +02:00
$API [ 'api_path' ] = [
2018-04-09 21:23:41 +02:00
'method' => 'method' ,
2019-07-28 17:40:42 +02:00
'func' => function () {
2018-04-09 21:23:41 +02:00
return 'some_data' ;
}
];
$_SERVER [ 'REQUEST_METHOD' ] = 'method' ;
2019-12-16 01:35:26 +01:00
$_SERVER [ 'QUERY_STRING' ] = 'q=api_path.rss' ;
$args = DI :: args () -> determine ( $_SERVER , $_GET );
2018-04-09 21:23:41 +02:00
$this -> assertEquals (
2019-07-28 17:40:42 +02:00
'<?xml version="1.0" encoding="UTF-8"?>' . " \n " .
'some_data' ,
2019-12-16 01:35:26 +01:00
api_call ( $this -> app , $args )
2018-04-09 21:23:41 +02:00
);
}
/**
* Test the api_call () function with an Atom result .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ runInSeparateProcess
*/
public function testApiCallWithAtom ()
{
global $API ;
2019-07-28 17:40:42 +02:00
$API [ 'api_path' ] = [
2018-04-09 21:23:41 +02:00
'method' => 'method' ,
2019-07-28 17:40:42 +02:00
'func' => function () {
2018-04-09 21:23:41 +02:00
return 'some_data' ;
}
];
$_SERVER [ 'REQUEST_METHOD' ] = 'method' ;
2019-12-16 01:35:26 +01:00
$_SERVER [ 'QUERY_STRING' ] = 'q=api_path.atom' ;
$args = DI :: args () -> determine ( $_SERVER , $_GET );
2018-04-09 21:23:41 +02:00
$this -> assertEquals (
2019-07-28 17:40:42 +02:00
'<?xml version="1.0" encoding="UTF-8"?>' . " \n " .
'some_data' ,
2019-12-16 01:35:26 +01:00
api_call ( $this -> app , $args )
2018-04-09 21:23:41 +02:00
);
}
/**
* Test the api_call () function with an unallowed method .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ runInSeparateProcess
*/
public function testApiCallWithWrongMethod ()
{
global $API ;
$API [ 'api_path' ] = [ 'method' => 'method' ];
2019-12-16 01:35:26 +01:00
$_SERVER [ 'QUERY_STRING' ] = 'q=api_path' ;
$args = DI :: args () -> determine ( $_SERVER , $_GET );
2018-04-09 21:23:41 +02:00
$this -> assertEquals (
'{"status":{"error":"Method Not Allowed","code":"405 Method Not Allowed","request":"api_path"}}' ,
2019-12-16 01:35:26 +01:00
api_call ( $this -> app , $args )
2018-04-09 21:23:41 +02:00
);
}
/**
* Test the api_call () function with an unauthorized user .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ runInSeparateProcess
*/
public function testApiCallWithWrongAuth ()
{
global $API ;
2019-07-28 17:40:42 +02:00
$API [ 'api_path' ] = [
2018-04-09 21:23:41 +02:00
'method' => 'method' ,
2019-07-28 17:40:42 +02:00
'auth' => true
2018-04-09 21:23:41 +02:00
];
$_SESSION [ 'authenticated' ] = false ;
2019-12-16 01:35:26 +01:00
$_SERVER [ 'REQUEST_METHOD' ] = 'method' ;
$_SERVER [ 'QUERY_STRING' ] = 'q=api_path' ;
$args = DI :: args () -> determine ( $_SERVER , $_GET );
2018-04-09 21:23:41 +02:00
$this -> assertEquals (
'{"status":{"error":"This API requires login","code":"401 Unauthorized","request":"api_path"}}' ,
2019-12-16 01:35:26 +01:00
api_call ( $this -> app , $args )
2018-04-09 21:23:41 +02:00
);
}
/**
* Test the api_error () function with a JSON result .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ runInSeparateProcess
*/
public function testApiErrorWithJson ()
{
$this -> assertEquals (
2019-05-02 05:20:25 +02:00
'{"status":{"error":"error_message","code":"200 OK","request":""}}' ,
2019-12-16 01:35:26 +01:00
api_error ( 'json' , new HTTPException\OKException ( 'error_message' ), DI :: args ())
2018-04-09 21:23:41 +02:00
);
}
/**
* Test the api_error () function with an XML result .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ runInSeparateProcess
*/
public function testApiErrorWithXml ()
{
$this -> assertEquals (
2019-07-28 17:40:42 +02:00
'<?xml version="1.0"?>' . " \n " .
'<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
'xmlns:georss="http://www.georss.org/georss">' . " \n " .
' <error>error_message</error>' . " \n " .
' <code>200 OK</code>' . " \n " .
' <request/>' . " \n " .
'</status>' . " \n " ,
2019-12-16 01:35:26 +01:00
api_error ( 'xml' , new HTTPException\OKException ( 'error_message' ), DI :: args ())
2018-04-09 21:23:41 +02:00
);
}
/**
* Test the api_error () function with an RSS result .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ runInSeparateProcess
*/
public function testApiErrorWithRss ()
{
$this -> assertEquals (
2019-07-28 17:40:42 +02:00
'<?xml version="1.0"?>' . " \n " .
'<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
'xmlns:georss="http://www.georss.org/georss">' . " \n " .
' <error>error_message</error>' . " \n " .
' <code>200 OK</code>' . " \n " .
' <request/>' . " \n " .
'</status>' . " \n " ,
2019-12-16 01:35:26 +01:00
api_error ( 'rss' , new HTTPException\OKException ( 'error_message' ), DI :: args ())
2018-04-09 21:23:41 +02:00
);
}
/**
* Test the api_error () function with an Atom result .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ runInSeparateProcess
*/
public function testApiErrorWithAtom ()
{
$this -> assertEquals (
2019-07-28 17:40:42 +02:00
'<?xml version="1.0"?>' . " \n " .
'<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
'xmlns:georss="http://www.georss.org/georss">' . " \n " .
' <error>error_message</error>' . " \n " .
' <code>200 OK</code>' . " \n " .
' <request/>' . " \n " .
'</status>' . " \n " ,
2019-12-16 01:35:26 +01:00
api_error ( 'atom' , new HTTPException\OKException ( 'error_message' ), DI :: args ())
2018-04-09 21:23:41 +02:00
);
}
/**
* Test the api_rss_extra () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiRssExtra ()
{
2018-07-04 23:55:06 +02:00
$user_info = [ 'url' => 'user_url' , 'lang' => 'en' ];
2019-07-28 17:40:42 +02:00
$result = api_rss_extra ( $this -> app , [], $user_info );
2018-04-09 21:23:41 +02:00
$this -> assertEquals ( $user_info , $result [ '$user' ]);
$this -> assertEquals ( $user_info [ 'url' ], $result [ '$rss' ][ 'alternate' ]);
$this -> assertArrayHasKey ( 'self' , $result [ '$rss' ]);
$this -> assertArrayHasKey ( 'base' , $result [ '$rss' ]);
$this -> assertArrayHasKey ( 'updated' , $result [ '$rss' ]);
$this -> assertArrayHasKey ( 'atom_updated' , $result [ '$rss' ]);
$this -> assertArrayHasKey ( 'language' , $result [ '$rss' ]);
$this -> assertArrayHasKey ( 'logo' , $result [ '$rss' ]);
}
/**
* Test the api_rss_extra () function without any user info .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiRssExtraWithoutUserInfo ()
{
$result = api_rss_extra ( $this -> app , [], null );
$this -> assertInternalType ( 'array' , $result [ '$user' ]);
$this -> assertArrayHasKey ( 'alternate' , $result [ '$rss' ]);
$this -> assertArrayHasKey ( 'self' , $result [ '$rss' ]);
$this -> assertArrayHasKey ( 'base' , $result [ '$rss' ]);
$this -> assertArrayHasKey ( 'updated' , $result [ '$rss' ]);
$this -> assertArrayHasKey ( 'atom_updated' , $result [ '$rss' ]);
$this -> assertArrayHasKey ( 'language' , $result [ '$rss' ]);
$this -> assertArrayHasKey ( 'logo' , $result [ '$rss' ]);
}
/**
* Test the api_unique_id_to_nurl () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiUniqueIdToNurl ()
{
$this -> assertFalse ( api_unique_id_to_nurl ( $this -> wrongUserId ));
}
/**
* Test the api_unique_id_to_nurl () function with a correct ID .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiUniqueIdToNurlWithCorrectId ()
{
$this -> assertEquals ( $this -> otherUser [ 'nurl' ], api_unique_id_to_nurl ( $this -> otherUser [ 'id' ]));
}
/**
* Test the api_get_user () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiGetUser ()
{
$user = api_get_user ( $this -> app );
$this -> assertSelfUser ( $user );
$this -> assertEquals ( '708fa0' , $user [ 'profile_sidebar_fill_color' ]);
$this -> assertEquals ( '6fdbe8' , $user [ 'profile_link_color' ]);
$this -> assertEquals ( 'ededed' , $user [ 'profile_background_color' ]);
}
/**
* Test the api_get_user () function with a Frio schema .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiGetUserWithFrioSchema ()
{
2020-01-19 22:23:44 +01:00
$pConfig = $this -> dice -> create ( IPConfig :: class );
2019-08-04 18:50:24 +02:00
$pConfig -> set ( $this -> selfUser [ 'id' ], 'frio' , 'schema' , 'red' );
2018-04-09 21:23:41 +02:00
$user = api_get_user ( $this -> app );
$this -> assertSelfUser ( $user );
$this -> assertEquals ( '708fa0' , $user [ 'profile_sidebar_fill_color' ]);
$this -> assertEquals ( '6fdbe8' , $user [ 'profile_link_color' ]);
$this -> assertEquals ( 'ededed' , $user [ 'profile_background_color' ]);
}
/**
* Test the api_get_user () function with a custom Frio schema .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiGetUserWithCustomFrioSchema ()
{
2020-01-19 22:23:44 +01:00
$pConfig = $this -> dice -> create ( IPConfig :: class );
2019-08-04 18:50:24 +02:00
$pConfig -> set ( $this -> selfUser [ 'id' ], 'frio' , 'schema' , '---' );
$pConfig -> set ( $this -> selfUser [ 'id' ], 'frio' , 'nav_bg' , '#123456' );
$pConfig -> set ( $this -> selfUser [ 'id' ], 'frio' , 'link_color' , '#123456' );
$pConfig -> set ( $this -> selfUser [ 'id' ], 'frio' , 'background_color' , '#123456' );
2018-04-09 21:23:41 +02:00
$user = api_get_user ( $this -> app );
$this -> assertSelfUser ( $user );
$this -> assertEquals ( '123456' , $user [ 'profile_sidebar_fill_color' ]);
$this -> assertEquals ( '123456' , $user [ 'profile_link_color' ]);
$this -> assertEquals ( '123456' , $user [ 'profile_background_color' ]);
}
/**
* Test the api_get_user () function with an empty Frio schema .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiGetUserWithEmptyFrioSchema ()
{
2020-01-19 22:23:44 +01:00
$pConfig = $this -> dice -> create ( IPConfig :: class );
2019-08-04 18:50:24 +02:00
$pConfig -> set ( $this -> selfUser [ 'id' ], 'frio' , 'schema' , '---' );
2018-04-09 21:23:41 +02:00
$user = api_get_user ( $this -> app );
$this -> assertSelfUser ( $user );
$this -> assertEquals ( '708fa0' , $user [ 'profile_sidebar_fill_color' ]);
$this -> assertEquals ( '6fdbe8' , $user [ 'profile_link_color' ]);
$this -> assertEquals ( 'ededed' , $user [ 'profile_background_color' ]);
}
/**
* Test the api_get_user () function with an user that is not allowed to use the API .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ runInSeparateProcess
*/
public function testApiGetUserWithoutApiUser ()
{
$_SERVER [ 'PHP_AUTH_USER' ] = 'Test user' ;
2019-07-28 17:40:42 +02:00
$_SERVER [ 'PHP_AUTH_PW' ] = 'password' ;
$_SESSION [ 'allow_api' ] = false ;
2018-04-09 21:23:41 +02:00
$this -> assertFalse ( api_get_user ( $this -> app ));
}
/**
* Test the api_get_user () function with an user ID in a GET parameter .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiGetUserWithGetId ()
{
$_GET [ 'user_id' ] = $this -> otherUser [ 'id' ];
$this -> assertOtherUser ( api_get_user ( $this -> app ));
}
/**
* Test the api_get_user () function with a wrong user ID in a GET parameter .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\BadRequestException
*/
public function testApiGetUserWithWrongGetId ()
{
$_GET [ 'user_id' ] = $this -> wrongUserId ;
$this -> assertOtherUser ( api_get_user ( $this -> app ));
}
/**
* Test the api_get_user () function with an user name in a GET parameter .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiGetUserWithGetName ()
{
$_GET [ 'screen_name' ] = $this -> selfUser [ 'nick' ];
$this -> assertSelfUser ( api_get_user ( $this -> app ));
}
/**
* Test the api_get_user () function with a profile URL in a GET parameter .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiGetUserWithGetUrl ()
{
$_GET [ 'profileurl' ] = $this -> selfUser [ 'nurl' ];
$this -> assertSelfUser ( api_get_user ( $this -> app ));
}
/**
* Test the api_get_user () function with an user ID in the API path .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiGetUserWithNumericCalledApi ()
{
global $called_api ;
2019-07-28 17:40:42 +02:00
$called_api = [ 'api_path' ];
$this -> app -> argv [ 1 ] = $this -> otherUser [ 'id' ] . '.json' ;
2018-04-09 21:23:41 +02:00
$this -> assertOtherUser ( api_get_user ( $this -> app ));
}
/**
* Test the api_get_user () function with the $called_api global variable .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiGetUserWithCalledApi ()
{
global $called_api ;
2018-07-01 06:16:32 +02:00
$called_api = [ 'api' , 'api_path' ];
2018-04-09 21:23:41 +02:00
$this -> assertSelfUser ( api_get_user ( $this -> app ));
}
/**
* Test the api_get_user () function with a valid user .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiGetUserWithCorrectUser ()
{
$this -> assertOtherUser ( api_get_user ( $this -> app , $this -> otherUser [ 'id' ]));
}
/**
* Test the api_get_user () function with a wrong user ID .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\BadRequestException
*/
public function testApiGetUserWithWrongUser ()
{
$this -> assertOtherUser ( api_get_user ( $this -> app , $this -> wrongUserId ));
}
/**
* Test the api_get_user () function with a 0 user ID .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiGetUserWithZeroUser ()
{
$this -> assertSelfUser ( api_get_user ( $this -> app , 0 ));
}
/**
* Test the api_item_get_user () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiItemGetUser ()
{
$users = api_item_get_user ( $this -> app , []);
$this -> assertSelfUser ( $users [ 0 ]);
}
/**
* Test the api_item_get_user () function with a different item parent .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiItemGetUserWithDifferentParent ()
{
$users = api_item_get_user ( $this -> app , [ 'thr-parent' => 'item_parent' , 'uri' => 'item_uri' ]);
$this -> assertSelfUser ( $users [ 0 ]);
$this -> assertEquals ( $users [ 0 ], $users [ 1 ]);
}
/**
* Test the api_walk_recursive () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiWalkRecursive ()
{
$array = [ 'item1' ];
$this -> assertEquals (
$array ,
api_walk_recursive (
$array ,
function () {
// Should we test this with a callback that actually does something?
return true ;
}
)
);
}
/**
* Test the api_walk_recursive () function with an array .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiWalkRecursiveWithArray ()
{
$array = [[ 'item1' ], [ 'item2' ]];
$this -> assertEquals (
$array ,
api_walk_recursive (
$array ,
function () {
// Should we test this with a callback that actually does something?
return true ;
}
)
);
}
/**
* Test the api_reformat_xml () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiReformatXml ()
{
$item = true ;
2019-07-28 17:40:42 +02:00
$key = '' ;
2018-04-09 21:23:41 +02:00
$this -> assertTrue ( api_reformat_xml ( $item , $key ));
$this -> assertEquals ( 'true' , $item );
}
/**
* Test the api_reformat_xml () function with a statusnet_api key .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiReformatXmlWithStatusnetKey ()
{
$item = '' ;
2019-07-28 17:40:42 +02:00
$key = 'statusnet_api' ;
2018-04-09 21:23:41 +02:00
$this -> assertTrue ( api_reformat_xml ( $item , $key ));
$this -> assertEquals ( 'statusnet:api' , $key );
}
/**
* Test the api_reformat_xml () function with a friendica_api key .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiReformatXmlWithFriendicaKey ()
{
$item = '' ;
2019-07-28 17:40:42 +02:00
$key = 'friendica_api' ;
2018-04-09 21:23:41 +02:00
$this -> assertTrue ( api_reformat_xml ( $item , $key ));
$this -> assertEquals ( 'friendica:api' , $key );
}
/**
* Test the api_create_xml () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiCreateXml ()
{
$this -> assertEquals (
2019-07-28 17:40:42 +02:00
'<?xml version="1.0"?>' . " \n " .
'<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
'xmlns:georss="http://www.georss.org/georss">' . " \n " .
' <data>some_data</data>' . " \n " .
'</root_element>' . " \n " ,
2018-04-09 21:23:41 +02:00
api_create_xml ([ 'data' => [ 'some_data' ]], 'root_element' )
);
}
/**
* Test the api_create_xml () function without any XML namespace .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiCreateXmlWithoutNamespaces ()
{
$this -> assertEquals (
2019-07-28 17:40:42 +02:00
'<?xml version="1.0"?>' . " \n " .
'<ok>' . " \n " .
' <data>some_data</data>' . " \n " .
'</ok>' . " \n " ,
2018-04-09 21:23:41 +02:00
api_create_xml ([ 'data' => [ 'some_data' ]], 'ok' )
);
}
/**
* Test the api_format_data () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiFormatData ()
{
$data = [ 'some_data' ];
$this -> assertEquals ( $data , api_format_data ( 'root_element' , 'json' , $data ));
}
/**
* Test the api_format_data () function with an XML result .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiFormatDataWithXml ()
{
$this -> assertEquals (
2019-07-28 17:40:42 +02:00
'<?xml version="1.0"?>' . " \n " .
'<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" ' .
'xmlns:friendica="http://friendi.ca/schema/api/1/" ' .
'xmlns:georss="http://www.georss.org/georss">' . " \n " .
' <data>some_data</data>' . " \n " .
'</root_element>' . " \n " ,
2018-04-09 21:23:41 +02:00
api_format_data ( 'root_element' , 'xml' , [ 'data' => [ 'some_data' ]])
);
}
/**
* Test the api_account_verify_credentials () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiAccountVerifyCredentials ()
{
$this -> assertArrayHasKey ( 'user' , api_account_verify_credentials ( 'json' ));
}
/**
* Test the api_account_verify_credentials () function without an authenticated user .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\ForbiddenException
*/
public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser ()
{
$_SESSION [ 'authenticated' ] = false ;
api_account_verify_credentials ( 'json' );
}
/**
* Test the requestdata () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testRequestdata ()
{
$this -> assertNull ( requestdata ( 'variable_name' ));
}
/**
* Test the requestdata () function with a POST parameter .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testRequestdataWithPost ()
{
$_POST [ 'variable_name' ] = 'variable_value' ;
$this -> assertEquals ( 'variable_value' , requestdata ( 'variable_name' ));
}
/**
* Test the requestdata () function with a GET parameter .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testRequestdataWithGet ()
{
$_GET [ 'variable_name' ] = 'variable_value' ;
$this -> assertEquals ( 'variable_value' , requestdata ( 'variable_name' ));
}
/**
* Test the api_statuses_mediap () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiStatusesMediap ()
{
$this -> app -> argc = 2 ;
2019-07-28 17:40:42 +02:00
$_FILES = [
2018-04-09 21:23:41 +02:00
'media' => [
2019-07-28 17:40:42 +02:00
'id' => 666 ,
'size' => 666 ,
'width' => 666 ,
'height' => 666 ,
2018-04-09 21:23:41 +02:00
'tmp_name' => $this -> getTempImage (),
2019-07-28 17:40:42 +02:00
'name' => 'spacer.png' ,
'type' => 'image/png'
2018-04-09 21:23:41 +02:00
]
];
$_GET [ 'status' ] = '<b>Status content</b>' ;
$result = api_statuses_mediap ( 'json' );
$this -> assertStatus ( $result [ 'status' ]);
}
/**
* Test the api_statuses_mediap () function without an authenticated user .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\ForbiddenException
*/
public function testApiStatusesMediapWithoutAuthenticatedUser ()
{
$_SESSION [ 'authenticated' ] = false ;
api_statuses_mediap ( 'json' );
}
/**
* Test the api_statuses_update () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiStatusesUpdate ()
{
2019-07-28 17:40:42 +02:00
$_GET [ 'status' ] = 'Status content #friendica' ;
2018-04-09 21:23:41 +02:00
$_GET [ 'in_reply_to_status_id' ] = - 1 ;
2019-07-28 17:40:42 +02:00
$_GET [ 'lat' ] = 48 ;
$_GET [ 'long' ] = 7 ;
$_FILES = [
2018-04-09 21:23:41 +02:00
'media' => [
2019-07-28 17:40:42 +02:00
'id' => 666 ,
'size' => 666 ,
'width' => 666 ,
'height' => 666 ,
2018-04-09 21:23:41 +02:00
'tmp_name' => $this -> getTempImage (),
2019-07-28 17:40:42 +02:00
'name' => 'spacer.png' ,
'type' => 'image/png'
2018-04-09 21:23:41 +02:00
]
];
$result = api_statuses_update ( 'json' );
$this -> assertStatus ( $result [ 'status' ]);
}
/**
* Test the api_statuses_update () function with an HTML status .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiStatusesUpdateWithHtml ()
{
$_GET [ 'htmlstatus' ] = '<b>Status content</b>' ;
$result = api_statuses_update ( 'json' );
$this -> assertStatus ( $result [ 'status' ]);
}
/**
* Test the api_statuses_update () function without an authenticated user .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\ForbiddenException
*/
public function testApiStatusesUpdateWithoutAuthenticatedUser ()
{
$_SESSION [ 'authenticated' ] = false ;
api_statuses_update ( 'json' );
}
/**
* Test the api_statuses_update () function with a parent status .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiStatusesUpdateWithParent ()
{
$this -> markTestIncomplete ( 'This triggers an exit() somewhere and kills PHPUnit.' );
}
/**
* Test the api_statuses_update () function with a media_ids parameter .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiStatusesUpdateWithMediaIds ()
{
$this -> markTestIncomplete ();
}
/**
* Test the api_statuses_update () function with the throttle limit reached .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiStatusesUpdateWithDayThrottleReached ()
{
$this -> markTestIncomplete ();
}
/**
* Test the api_media_upload () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\BadRequestException
*/
public function testApiMediaUpload ()
{
api_media_upload ();
}
/**
* Test the api_media_upload () function without an authenticated user .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\ForbiddenException
*/
public function testApiMediaUploadWithoutAuthenticatedUser ()
{
$_SESSION [ 'authenticated' ] = false ;
api_media_upload ();
}
/**
* Test the api_media_upload () function with an invalid uploaded media .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\InternalServerErrorException
*/
public function testApiMediaUploadWithMedia ()
{
$_FILES = [
'media' => [
2019-07-28 17:40:42 +02:00
'id' => 666 ,
2018-07-18 21:36:51 +02:00
'tmp_name' => 'tmp_name'
2018-04-09 21:23:41 +02:00
]
];
api_media_upload ();
}
/**
* Test the api_media_upload () function with an valid uploaded media .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiMediaUploadWithValidMedia ()
{
2019-07-28 17:40:42 +02:00
$_FILES = [
2018-04-09 21:23:41 +02:00
'media' => [
2019-07-28 17:40:42 +02:00
'id' => 666 ,
'size' => 666 ,
'width' => 666 ,
'height' => 666 ,
2018-04-09 21:23:41 +02:00
'tmp_name' => $this -> getTempImage (),
2019-07-28 17:40:42 +02:00
'name' => 'spacer.png' ,
'type' => 'image/png'
2018-04-09 21:23:41 +02:00
]
];
2020-01-04 23:42:01 +01:00
$app = DI :: app ();
2018-04-09 21:23:41 +02:00
$app -> argc = 2 ;
$result = api_media_upload ();
$this -> assertEquals ( 'image/png' , $result [ 'media' ][ 'image' ][ 'image_type' ]);
$this -> assertEquals ( 1 , $result [ 'media' ][ 'image' ][ 'w' ]);
$this -> assertEquals ( 1 , $result [ 'media' ][ 'image' ][ 'h' ]);
2018-12-16 07:16:45 +01:00
$this -> assertNotEmpty ( $result [ 'media' ][ 'image' ][ 'friendica_preview_url' ]);
2018-04-09 21:23:41 +02:00
}
/**
* Test the api_status_show () function .
*/
2019-03-02 22:11:56 +01:00
public function testApiStatusShowWithJson ()
2018-04-09 21:23:41 +02:00
{
2019-03-23 15:02:32 +01:00
$result = api_status_show ( 'json' , 1 );
2018-04-09 21:23:41 +02:00
$this -> assertStatus ( $result [ 'status' ]);
}
/**
* Test the api_status_show () function with an XML result .
*/
public function testApiStatusShowWithXml ()
{
2019-03-23 15:02:32 +01:00
$result = api_status_show ( 'xml' , 1 );
2018-04-09 21:23:41 +02:00
$this -> assertXml ( $result , 'statuses' );
}
/**
2019-03-23 15:02:32 +01:00
* Test the api_get_last_status () function
2018-04-09 21:23:41 +02:00
*/
2019-03-02 22:11:56 +01:00
public function testApiGetLastStatus ()
2018-04-09 21:23:41 +02:00
{
2019-03-23 15:02:32 +01:00
$item = api_get_last_status ( $this -> selfUser [ 'id' ], $this -> selfUser [ 'id' ]);
2019-03-02 22:11:56 +01:00
2019-03-23 15:02:32 +01:00
$this -> assertNotNull ( $item );
2018-04-09 21:23:41 +02:00
}
/**
* Test the api_users_show () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiUsersShow ()
{
$result = api_users_show ( 'json' );
// We can't use assertSelfUser() here because the user object is missing some properties.
$this -> assertEquals ( $this -> selfUser [ 'id' ], $result [ 'user' ][ 'cid' ]);
2018-11-18 21:59:40 +01:00
$this -> assertEquals ( 'DFRN' , $result [ 'user' ][ 'location' ]);
2018-04-09 21:23:41 +02:00
$this -> assertEquals ( $this -> selfUser [ 'name' ], $result [ 'user' ][ 'name' ]);
$this -> assertEquals ( $this -> selfUser [ 'nick' ], $result [ 'user' ][ 'screen_name' ]);
$this -> assertEquals ( 'dfrn' , $result [ 'user' ][ 'network' ]);
$this -> assertTrue ( $result [ 'user' ][ 'verified' ]);
}
/**
* Test the api_users_show () function with an XML result .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiUsersShowWithXml ()
{
$result = api_users_show ( 'xml' );
$this -> assertXml ( $result , 'statuses' );
}
/**
* Test the api_users_search () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiUsersSearch ()
{
$_GET [ 'q' ] = 'othercontact' ;
2019-07-28 17:40:42 +02:00
$result = api_users_search ( 'json' );
2018-04-09 21:23:41 +02:00
$this -> assertOtherUser ( $result [ 'users' ][ 0 ]);
}
/**
* Test the api_users_search () function with an XML result .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiUsersSearchWithXml ()
{
$_GET [ 'q' ] = 'othercontact' ;
2019-07-28 17:40:42 +02:00
$result = api_users_search ( 'xml' );
2018-04-09 21:23:41 +02:00
$this -> assertXml ( $result , 'users' );
}
/**
* Test the api_users_search () function without a GET q parameter .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\BadRequestException
*/
public function testApiUsersSearchWithoutQuery ()
{
api_users_search ( 'json' );
}
/**
* Test the api_users_lookup () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\NotFoundException
*/
public function testApiUsersLookup ()
{
api_users_lookup ( 'json' );
}
/**
* Test the api_users_lookup () function with an user ID .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiUsersLookupWithUserId ()
{
$_REQUEST [ 'user_id' ] = $this -> otherUser [ 'id' ];
2019-07-28 17:40:42 +02:00
$result = api_users_lookup ( 'json' );
2018-04-09 21:23:41 +02:00
$this -> assertOtherUser ( $result [ 'users' ][ 0 ]);
}
/**
* Test the api_search () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiSearch ()
{
2019-07-28 17:40:42 +02:00
$_REQUEST [ 'q' ] = 'reply' ;
2018-04-09 21:23:41 +02:00
$_REQUEST [ 'max_id' ] = 10 ;
2019-07-28 17:40:42 +02:00
$result = api_search ( 'json' );
2018-04-09 21:23:41 +02:00
foreach ( $result [ 'status' ] as $status ) {
$this -> assertStatus ( $status );
$this -> assertContains ( 'reply' , $status [ 'text' ], null , true );
}
}
/**
* Test the api_search () function a count parameter .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiSearchWithCount ()
{
2019-07-28 17:40:42 +02:00
$_REQUEST [ 'q' ] = 'reply' ;
2018-04-09 21:23:41 +02:00
$_REQUEST [ 'count' ] = 20 ;
2019-07-28 17:40:42 +02:00
$result = api_search ( 'json' );
2018-04-09 21:23:41 +02:00
foreach ( $result [ 'status' ] as $status ) {
$this -> assertStatus ( $status );
$this -> assertContains ( 'reply' , $status [ 'text' ], null , true );
}
}
/**
* Test the api_search () function with an rpp parameter .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiSearchWithRpp ()
{
2019-07-28 17:40:42 +02:00
$_REQUEST [ 'q' ] = 'reply' ;
2018-04-09 21:23:41 +02:00
$_REQUEST [ 'rpp' ] = 20 ;
2019-07-28 17:40:42 +02:00
$result = api_search ( 'json' );
2018-04-09 21:23:41 +02:00
foreach ( $result [ 'status' ] as $status ) {
$this -> assertStatus ( $status );
$this -> assertContains ( 'reply' , $status [ 'text' ], null , true );
}
}
2018-12-17 15:36:56 +01:00
/**
* Test the api_search () function with an q parameter contains hashtag .
2019-07-28 17:40:42 +02:00
*
2018-12-17 15:36:56 +01:00
* @ return void
*/
public function testApiSearchWithHashtag ()
{
2018-12-17 15:52:04 +01:00
$_REQUEST [ 'q' ] = '%23friendica' ;
2019-07-28 17:40:42 +02:00
$result = api_search ( 'json' );
2018-12-17 15:36:56 +01:00
foreach ( $result [ 'status' ] as $status ) {
$this -> assertStatus ( $status );
$this -> assertContains ( '#friendica' , $status [ 'text' ], null , true );
}
}
2018-04-09 21:23:41 +02:00
2018-12-21 17:00:56 +01:00
/**
* Test the api_search () function with an exclude_replies parameter .
2019-07-28 17:40:42 +02:00
*
2018-12-21 17:00:56 +01:00
* @ return void
*/
public function testApiSearchWithExcludeReplies ()
{
2019-07-28 17:40:42 +02:00
$_REQUEST [ 'max_id' ] = 10 ;
2018-12-21 17:00:56 +01:00
$_REQUEST [ 'exclude_replies' ] = true ;
2019-07-28 17:40:42 +02:00
$_REQUEST [ 'q' ] = 'friendica' ;
$result = api_search ( 'json' );
2018-12-21 17:00:56 +01:00
foreach ( $result [ 'status' ] as $status ) {
$this -> assertStatus ( $status );
}
}
2018-04-09 21:23:41 +02:00
/**
* Test the api_search () function without an authenticated user .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\ForbiddenException
*/
public function testApiSearchWithUnallowedUser ()
{
$_SESSION [ 'allow_api' ] = false ;
2019-07-28 17:40:42 +02:00
$_GET [ 'screen_name' ] = $this -> selfUser [ 'nick' ];
2018-04-09 21:23:41 +02:00
api_search ( 'json' );
}
/**
* Test the api_search () function without any GET query parameter .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\BadRequestException
*/
public function testApiSearchWithoutQuery ()
{
api_search ( 'json' );
}
/**
* Test the api_statuses_home_timeline () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiStatusesHomeTimeline ()
{
2019-07-28 17:40:42 +02:00
$_REQUEST [ 'max_id' ] = 10 ;
2018-04-09 21:23:41 +02:00
$_REQUEST [ 'exclude_replies' ] = true ;
$_REQUEST [ 'conversation_id' ] = 1 ;
2019-07-28 17:40:42 +02:00
$result = api_statuses_home_timeline ( 'json' );
2018-04-09 21:23:41 +02:00
$this -> assertNotEmpty ( $result [ 'status' ]);
foreach ( $result [ 'status' ] as $status ) {
$this -> assertStatus ( $status );
}
}
/**
* Test the api_statuses_home_timeline () function with a negative page parameter .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiStatusesHomeTimelineWithNegativePage ()
{
$_REQUEST [ 'page' ] = - 2 ;
2019-07-28 17:40:42 +02:00
$result = api_statuses_home_timeline ( 'json' );
2018-04-09 21:23:41 +02:00
$this -> assertNotEmpty ( $result [ 'status' ]);
foreach ( $result [ 'status' ] as $status ) {
$this -> assertStatus ( $status );
}
}
/**
* Test the api_statuses_home_timeline () with an unallowed user .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\ForbiddenException
*/
public function testApiStatusesHomeTimelineWithUnallowedUser ()
{
$_SESSION [ 'allow_api' ] = false ;
2019-07-28 17:40:42 +02:00
$_GET [ 'screen_name' ] = $this -> selfUser [ 'nick' ];
2018-04-09 21:23:41 +02:00
api_statuses_home_timeline ( 'json' );
}
/**
* Test the api_statuses_home_timeline () function with an RSS result .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiStatusesHomeTimelineWithRss ()
{
$result = api_statuses_home_timeline ( 'rss' );
$this -> assertXml ( $result , 'statuses' );
}
/**
* Test the api_statuses_public_timeline () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiStatusesPublicTimeline ()
{
2019-07-28 17:40:42 +02:00
$_REQUEST [ 'max_id' ] = 10 ;
2018-04-09 21:23:41 +02:00
$_REQUEST [ 'conversation_id' ] = 1 ;
2019-07-28 17:40:42 +02:00
$result = api_statuses_public_timeline ( 'json' );
2018-04-09 21:23:41 +02:00
$this -> assertNotEmpty ( $result [ 'status' ]);
foreach ( $result [ 'status' ] as $status ) {
$this -> assertStatus ( $status );
}
}
/**
* Test the api_statuses_public_timeline () function with the exclude_replies parameter .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiStatusesPublicTimelineWithExcludeReplies ()
{
2019-07-28 17:40:42 +02:00
$_REQUEST [ 'max_id' ] = 10 ;
2018-04-09 21:23:41 +02:00
$_REQUEST [ 'exclude_replies' ] = true ;
2019-07-28 17:40:42 +02:00
$result = api_statuses_public_timeline ( 'json' );
2018-04-09 21:23:41 +02:00
$this -> assertNotEmpty ( $result [ 'status' ]);
foreach ( $result [ 'status' ] as $status ) {
$this -> assertStatus ( $status );
}
}
/**
* Test the api_statuses_public_timeline () function with a negative page parameter .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiStatusesPublicTimelineWithNegativePage ()
{
$_REQUEST [ 'page' ] = - 2 ;
2019-07-28 17:40:42 +02:00
$result = api_statuses_public_timeline ( 'json' );
2018-04-09 21:23:41 +02:00
$this -> assertNotEmpty ( $result [ 'status' ]);
foreach ( $result [ 'status' ] as $status ) {
$this -> assertStatus ( $status );
}
}
/**
* Test the api_statuses_public_timeline () function with an unallowed user .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\ForbiddenException
*/
public function testApiStatusesPublicTimelineWithUnallowedUser ()
{
$_SESSION [ 'allow_api' ] = false ;
2019-07-28 17:40:42 +02:00
$_GET [ 'screen_name' ] = $this -> selfUser [ 'nick' ];
2018-04-09 21:23:41 +02:00
api_statuses_public_timeline ( 'json' );
}
/**
* Test the api_statuses_public_timeline () function with an RSS result .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiStatusesPublicTimelineWithRss ()
{
$result = api_statuses_public_timeline ( 'rss' );
$this -> assertXml ( $result , 'statuses' );
}
/**
* Test the api_statuses_networkpublic_timeline () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiStatusesNetworkpublicTimeline ()
{
$_REQUEST [ 'max_id' ] = 10 ;
2019-07-28 17:40:42 +02:00
$result = api_statuses_networkpublic_timeline ( 'json' );
2018-04-09 21:23:41 +02:00
$this -> assertNotEmpty ( $result [ 'status' ]);
foreach ( $result [ 'status' ] as $status ) {
$this -> assertStatus ( $status );
}
}
/**
* Test the api_statuses_networkpublic_timeline () function with a negative page parameter .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiStatusesNetworkpublicTimelineWithNegativePage ()
{
$_REQUEST [ 'page' ] = - 2 ;
2019-07-28 17:40:42 +02:00
$result = api_statuses_networkpublic_timeline ( 'json' );
2018-04-09 21:23:41 +02:00
$this -> assertNotEmpty ( $result [ 'status' ]);
foreach ( $result [ 'status' ] as $status ) {
$this -> assertStatus ( $status );
}
}
/**
* Test the api_statuses_networkpublic_timeline () function with an unallowed user .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\ForbiddenException
*/
public function testApiStatusesNetworkpublicTimelineWithUnallowedUser ()
{
$_SESSION [ 'allow_api' ] = false ;
2019-07-28 17:40:42 +02:00
$_GET [ 'screen_name' ] = $this -> selfUser [ 'nick' ];
2018-04-09 21:23:41 +02:00
api_statuses_networkpublic_timeline ( 'json' );
}
/**
* Test the api_statuses_networkpublic_timeline () function with an RSS result .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiStatusesNetworkpublicTimelineWithRss ()
{
$result = api_statuses_networkpublic_timeline ( 'rss' );
$this -> assertXml ( $result , 'statuses' );
}
/**
* Test the api_statuses_show () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\BadRequestException
*/
public function testApiStatusesShow ()
{
api_statuses_show ( 'json' );
}
/**
* Test the api_statuses_show () function with an ID .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiStatusesShowWithId ()
{
$this -> app -> argv [ 3 ] = 1 ;
2019-07-28 17:40:42 +02:00
$result = api_statuses_show ( 'json' );
2018-04-09 21:23:41 +02:00
$this -> assertStatus ( $result [ 'status' ]);
}
/**
* Test the api_statuses_show () function with the conversation parameter .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiStatusesShowWithConversation ()
{
2019-07-28 17:40:42 +02:00
$this -> app -> argv [ 3 ] = 1 ;
2018-04-09 21:23:41 +02:00
$_REQUEST [ 'conversation' ] = 1 ;
2019-07-28 17:40:42 +02:00
$result = api_statuses_show ( 'json' );
2018-04-09 21:23:41 +02:00
$this -> assertNotEmpty ( $result [ 'status' ]);
foreach ( $result [ 'status' ] as $status ) {
$this -> assertStatus ( $status );
}
}
/**
* Test the api_statuses_show () function with an unallowed user .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\ForbiddenException
*/
public function testApiStatusesShowWithUnallowedUser ()
{
$_SESSION [ 'allow_api' ] = false ;
2019-07-28 17:40:42 +02:00
$_GET [ 'screen_name' ] = $this -> selfUser [ 'nick' ];
2018-04-09 21:23:41 +02:00
api_statuses_show ( 'json' );
}
/**
* Test the api_conversation_show () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\BadRequestException
*/
public function testApiConversationShow ()
{
api_conversation_show ( 'json' );
}
/**
* Test the api_conversation_show () function with an ID .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiConversationShowWithId ()
{
$this -> app -> argv [ 3 ] = 1 ;
$_REQUEST [ 'max_id' ] = 10 ;
2019-07-28 17:40:42 +02:00
$_REQUEST [ 'page' ] = - 2 ;
$result = api_conversation_show ( 'json' );
2018-04-09 21:23:41 +02:00
$this -> assertNotEmpty ( $result [ 'status' ]);
foreach ( $result [ 'status' ] as $status ) {
$this -> assertStatus ( $status );
}
}
/**
* Test the api_conversation_show () function with an unallowed user .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\ForbiddenException
*/
public function testApiConversationShowWithUnallowedUser ()
{
$_SESSION [ 'allow_api' ] = false ;
2019-07-28 17:40:42 +02:00
$_GET [ 'screen_name' ] = $this -> selfUser [ 'nick' ];
2018-04-09 21:23:41 +02:00
api_conversation_show ( 'json' );
}
/**
* Test the api_statuses_repeat () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\ForbiddenException
*/
public function testApiStatusesRepeat ()
{
api_statuses_repeat ( 'json' );
}
/**
* Test the api_statuses_repeat () function without an authenticated user .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\ForbiddenException
*/
public function testApiStatusesRepeatWithoutAuthenticatedUser ()
{
$_SESSION [ 'authenticated' ] = false ;
api_statuses_repeat ( 'json' );
}
/**
* Test the api_statuses_repeat () function with an ID .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiStatusesRepeatWithId ()
{
$this -> app -> argv [ 3 ] = 1 ;
2019-07-28 17:40:42 +02:00
$result = api_statuses_repeat ( 'json' );
2018-04-09 21:23:41 +02:00
$this -> assertStatus ( $result [ 'status' ]);
// Also test with a shared status
$this -> app -> argv [ 3 ] = 5 ;
2019-07-28 17:40:42 +02:00
$result = api_statuses_repeat ( 'json' );
2018-04-09 21:23:41 +02:00
$this -> assertStatus ( $result [ 'status' ]);
}
/**
* Test the api_statuses_destroy () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\BadRequestException
*/
public function testApiStatusesDestroy ()
{
api_statuses_destroy ( 'json' );
}
/**
* Test the api_statuses_destroy () function without an authenticated user .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\ForbiddenException
*/
public function testApiStatusesDestroyWithoutAuthenticatedUser ()
{
$_SESSION [ 'authenticated' ] = false ;
api_statuses_destroy ( 'json' );
}
/**
* Test the api_statuses_destroy () function with an ID .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiStatusesDestroyWithId ()
{
$this -> app -> argv [ 3 ] = 1 ;
2019-07-28 17:40:42 +02:00
$result = api_statuses_destroy ( 'json' );
2018-04-09 21:23:41 +02:00
$this -> assertStatus ( $result [ 'status' ]);
}
/**
* Test the api_statuses_mentions () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiStatusesMentions ()
{
2019-07-28 17:40:42 +02:00
$this -> app -> user = [ 'nickname' => $this -> selfUser [ 'nick' ]];
2018-04-09 21:23:41 +02:00
$_REQUEST [ 'max_id' ] = 10 ;
2019-07-28 17:40:42 +02:00
$result = api_statuses_mentions ( 'json' );
2018-04-09 21:23:41 +02:00
$this -> assertEmpty ( $result [ 'status' ]);
// We should test with mentions in the database.
}
/**
* Test the api_statuses_mentions () function with a negative page parameter .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiStatusesMentionsWithNegativePage ()
{
$_REQUEST [ 'page' ] = - 2 ;
2019-07-28 17:40:42 +02:00
$result = api_statuses_mentions ( 'json' );
2018-04-09 21:23:41 +02:00
$this -> assertEmpty ( $result [ 'status' ]);
}
/**
* Test the api_statuses_mentions () function with an unallowed user .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\ForbiddenException
*/
public function testApiStatusesMentionsWithUnallowedUser ()
{
$_SESSION [ 'allow_api' ] = false ;
2019-07-28 17:40:42 +02:00
$_GET [ 'screen_name' ] = $this -> selfUser [ 'nick' ];
2018-04-09 21:23:41 +02:00
api_statuses_mentions ( 'json' );
}
/**
* Test the api_statuses_mentions () function with an RSS result .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiStatusesMentionsWithRss ()
{
$result = api_statuses_mentions ( 'rss' );
$this -> assertXml ( $result , 'statuses' );
}
/**
* Test the api_statuses_user_timeline () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiStatusesUserTimeline ()
{
2019-07-28 17:40:42 +02:00
$_REQUEST [ 'max_id' ] = 10 ;
2018-04-09 21:23:41 +02:00
$_REQUEST [ 'exclude_replies' ] = true ;
$_REQUEST [ 'conversation_id' ] = 1 ;
2019-07-28 17:40:42 +02:00
$result = api_statuses_user_timeline ( 'json' );
2018-04-09 21:23:41 +02:00
$this -> assertNotEmpty ( $result [ 'status' ]);
foreach ( $result [ 'status' ] as $status ) {
$this -> assertStatus ( $status );
}
}
/**
* Test the api_statuses_user_timeline () function with a negative page parameter .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiStatusesUserTimelineWithNegativePage ()
{
$_REQUEST [ 'page' ] = - 2 ;
2019-07-28 17:40:42 +02:00
$result = api_statuses_user_timeline ( 'json' );
2018-04-09 21:23:41 +02:00
$this -> assertNotEmpty ( $result [ 'status' ]);
foreach ( $result [ 'status' ] as $status ) {
$this -> assertStatus ( $status );
}
}
/**
* Test the api_statuses_user_timeline () function with an RSS result .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiStatusesUserTimelineWithRss ()
{
$result = api_statuses_user_timeline ( 'rss' );
$this -> assertXml ( $result , 'statuses' );
}
/**
* Test the api_statuses_user_timeline () function with an unallowed user .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\ForbiddenException
*/
public function testApiStatusesUserTimelineWithUnallowedUser ()
{
$_SESSION [ 'allow_api' ] = false ;
2019-07-28 17:40:42 +02:00
$_GET [ 'screen_name' ] = $this -> selfUser [ 'nick' ];
2018-04-09 21:23:41 +02:00
api_statuses_user_timeline ( 'json' );
}
/**
* Test the api_favorites_create_destroy () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\BadRequestException
*/
public function testApiFavoritesCreateDestroy ()
{
2018-07-01 20:46:24 +02:00
$this -> app -> argv = [ 'api' , '1.1' , 'favorites' , 'create' ];
$this -> app -> argc = count ( $this -> app -> argv );
2018-04-09 21:23:41 +02:00
api_favorites_create_destroy ( 'json' );
}
/**
* Test the api_favorites_create_destroy () function with an invalid ID .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\BadRequestException
*/
public function testApiFavoritesCreateDestroyWithInvalidId ()
{
2018-07-01 20:46:24 +02:00
$this -> app -> argv = [ 'api' , '1.1' , 'favorites' , 'create' , '12.json' ];
$this -> app -> argc = count ( $this -> app -> argv );
2018-04-09 21:23:41 +02:00
api_favorites_create_destroy ( 'json' );
}
/**
* Test the api_favorites_create_destroy () function with an invalid action .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\BadRequestException
*/
public function testApiFavoritesCreateDestroyWithInvalidAction ()
{
2018-07-01 20:46:24 +02:00
$this -> app -> argv = [ 'api' , '1.1' , 'favorites' , 'change.json' ];
$this -> app -> argc = count ( $this -> app -> argv );
2019-07-28 17:40:42 +02:00
$_REQUEST [ 'id' ] = 1 ;
2018-04-09 21:23:41 +02:00
api_favorites_create_destroy ( 'json' );
}
/**
* Test the api_favorites_create_destroy () function with the create action .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiFavoritesCreateDestroyWithCreateAction ()
{
2018-07-01 20:46:24 +02:00
$this -> app -> argv = [ 'api' , '1.1' , 'favorites' , 'create.json' ];
$this -> app -> argc = count ( $this -> app -> argv );
2019-07-28 17:40:42 +02:00
$_REQUEST [ 'id' ] = 3 ;
$result = api_favorites_create_destroy ( 'json' );
2018-04-09 21:23:41 +02:00
$this -> assertStatus ( $result [ 'status' ]);
}
/**
* Test the api_favorites_create_destroy () function with the create action and an RSS result .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiFavoritesCreateDestroyWithCreateActionAndRss ()
{
2018-07-01 20:46:24 +02:00
$this -> app -> argv = [ 'api' , '1.1' , 'favorites' , 'create.rss' ];
$this -> app -> argc = count ( $this -> app -> argv );
2019-07-28 17:40:42 +02:00
$_REQUEST [ 'id' ] = 3 ;
$result = api_favorites_create_destroy ( 'rss' );
2018-04-09 21:23:41 +02:00
$this -> assertXml ( $result , 'status' );
}
/**
* Test the api_favorites_create_destroy () function with the destroy action .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiFavoritesCreateDestroyWithDestroyAction ()
{
2018-07-01 20:46:24 +02:00
$this -> app -> argv = [ 'api' , '1.1' , 'favorites' , 'destroy.json' ];
$this -> app -> argc = count ( $this -> app -> argv );
2019-07-28 17:40:42 +02:00
$_REQUEST [ 'id' ] = 3 ;
$result = api_favorites_create_destroy ( 'json' );
2018-04-09 21:23:41 +02:00
$this -> assertStatus ( $result [ 'status' ]);
}
/**
* Test the api_favorites_create_destroy () function without an authenticated user .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\ForbiddenException
*/
public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser ()
{
2019-07-28 17:40:42 +02:00
$this -> app -> argv = [ 'api' , '1.1' , 'favorites' , 'create.json' ];
$this -> app -> argc = count ( $this -> app -> argv );
2018-04-09 21:23:41 +02:00
$_SESSION [ 'authenticated' ] = false ;
api_favorites_create_destroy ( 'json' );
}
/**
* Test the api_favorites () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiFavorites ()
{
2019-07-28 17:40:42 +02:00
$_REQUEST [ 'page' ] = - 1 ;
2018-04-09 21:23:41 +02:00
$_REQUEST [ 'max_id' ] = 10 ;
2019-07-28 17:40:42 +02:00
$result = api_favorites ( 'json' );
2018-04-09 21:23:41 +02:00
foreach ( $result [ 'status' ] as $status ) {
$this -> assertStatus ( $status );
}
}
/**
* Test the api_favorites () function with an RSS result .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiFavoritesWithRss ()
{
$result = api_favorites ( 'rss' );
$this -> assertXml ( $result , 'statuses' );
}
/**
* Test the api_favorites () function with an unallowed user .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\ForbiddenException
*/
public function testApiFavoritesWithUnallowedUser ()
{
$_SESSION [ 'allow_api' ] = false ;
2019-07-28 17:40:42 +02:00
$_GET [ 'screen_name' ] = $this -> selfUser [ 'nick' ];
2018-04-09 21:23:41 +02:00
api_favorites ( 'json' );
}
/**
* Test the api_format_messages () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiFormatMessages ()
{
$result = api_format_messages (
[ 'id' => 1 , 'title' => 'item_title' , 'body' => '[b]item_body[/b]' ],
[ 'id' => 2 , 'screen_name' => 'recipient_name' ],
[ 'id' => 3 , 'screen_name' => 'sender_name' ]
);
2019-07-28 17:40:42 +02:00
$this -> assertEquals ( 'item_title' . " \n " . 'item_body' , $result [ 'text' ]);
2018-04-09 21:23:41 +02:00
$this -> assertEquals ( 1 , $result [ 'id' ]);
$this -> assertEquals ( 2 , $result [ 'recipient_id' ]);
$this -> assertEquals ( 3 , $result [ 'sender_id' ]);
$this -> assertEquals ( 'recipient_name' , $result [ 'recipient_screen_name' ]);
$this -> assertEquals ( 'sender_name' , $result [ 'sender_screen_name' ]);
}
/**
* Test the api_format_messages () function with HTML .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiFormatMessagesWithHtmlText ()
{
$_GET [ 'getText' ] = 'html' ;
2019-07-28 17:40:42 +02:00
$result = api_format_messages (
2018-04-09 21:23:41 +02:00
[ 'id' => 1 , 'title' => 'item_title' , 'body' => '[b]item_body[/b]' ],
[ 'id' => 2 , 'screen_name' => 'recipient_name' ],
[ 'id' => 3 , 'screen_name' => 'sender_name' ]
);
$this -> assertEquals ( 'item_title' , $result [ 'title' ]);
$this -> assertEquals ( '<strong>item_body</strong>' , $result [ 'text' ]);
}
/**
* Test the api_format_messages () function with plain text .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiFormatMessagesWithPlainText ()
{
$_GET [ 'getText' ] = 'plain' ;
2019-07-28 17:40:42 +02:00
$result = api_format_messages (
2018-04-09 21:23:41 +02:00
[ 'id' => 1 , 'title' => 'item_title' , 'body' => '[b]item_body[/b]' ],
[ 'id' => 2 , 'screen_name' => 'recipient_name' ],
[ 'id' => 3 , 'screen_name' => 'sender_name' ]
);
$this -> assertEquals ( 'item_title' , $result [ 'title' ]);
$this -> assertEquals ( 'item_body' , $result [ 'text' ]);
}
/**
* Test the api_format_messages () function with the getUserObjects GET parameter set to false .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiFormatMessagesWithoutUserObjects ()
{
$_GET [ 'getUserObjects' ] = 'false' ;
2019-07-28 17:40:42 +02:00
$result = api_format_messages (
2018-04-09 21:23:41 +02:00
[ 'id' => 1 , 'title' => 'item_title' , 'body' => '[b]item_body[/b]' ],
[ 'id' => 2 , 'screen_name' => 'recipient_name' ],
[ 'id' => 3 , 'screen_name' => 'sender_name' ]
);
2018-07-01 20:46:24 +02:00
$this -> assertTrue ( ! isset ( $result [ 'sender' ]));
$this -> assertTrue ( ! isset ( $result [ 'recipient' ]));
2018-04-09 21:23:41 +02:00
}
/**
* Test the api_convert_item () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiConvertItem ()
{
$result = api_convert_item (
[
'network' => 'feed' ,
2019-07-28 17:40:42 +02:00
'title' => 'item_title' ,
2018-04-09 21:23:41 +02:00
// We need a long string to test that it is correctly cut
2019-07-28 17:40:42 +02:00
'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui ' .
'reiciendis dolorum aut ducimus sunt consequatur inventore dolor ' .
'officiis pariatur doloremque nemo culpa aut quidem qui dolore ' .
'laudantium atque commodi alias voluptatem non possimus aperiam ' .
'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium ' .
'repellendus quibusdam et et inventore mollitia rerum sit autem ' .
'pariatur maiores ipsum accusantium perferendis vel sit possimus ' .
'veritatis nihil distinctio qui eum repellat officia illum quos ' .
'impedit quam iste esse unde qui suscipit aut facilis ut inventore ' .
'omnis exercitationem quo magnam consequatur maxime aut illum ' .
'soluta quaerat natus unde aspernatur et sed beatae nihil ullam ' .
'temporibus corporis ratione blanditiis perspiciatis impedit ' .
'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus ' .
'sunt consequatur inventore dolor officiis pariatur doloremque ' .
'nemo culpa aut quidem qui dolore laudantium atque commodi alias ' .
'voluptatem non possimus aperiam ipsum rerum consequuntur aut ' .
'amet fugit quia aliquid praesentium repellendus quibusdam et et ' .
'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium ' .
'perferendis vel sit possimus veritatis nihil distinctio qui eum ' .
'repellat officia illum quos impedit quam iste esse unde qui ' .
'suscipit aut facilis ut inventore omnis exercitationem quo magnam ' .
'consequatur maxime aut illum soluta quaerat natus unde aspernatur ' .
'et sed beatae nihil ullam temporibus corporis ratione blanditiis' ,
'plink' => 'item_plink'
2018-04-09 21:23:41 +02:00
]
);
$this -> assertStringStartsWith ( 'item_title' , $result [ 'text' ]);
$this -> assertStringStartsWith ( '<h4>item_title</h4><br>perspiciatis impedit voluptatem' , $result [ 'html' ]);
}
/**
* Test the api_convert_item () function with an empty item body .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiConvertItemWithoutBody ()
{
$result = api_convert_item (
[
'network' => 'feed' ,
2019-07-28 17:40:42 +02:00
'title' => 'item_title' ,
'body' => '' ,
'plink' => 'item_plink'
2018-04-09 21:23:41 +02:00
]
);
$this -> assertEquals ( 'item_title' , $result [ 'text' ]);
$this -> assertEquals ( '<h4>item_title</h4><br>item_plink' , $result [ 'html' ]);
}
/**
* Test the api_convert_item () function with the title in the body .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiConvertItemWithTitleInBody ()
{
$result = api_convert_item (
[
'title' => 'item_title' ,
2019-07-28 17:40:42 +02:00
'body' => 'item_title item_body'
2018-04-09 21:23:41 +02:00
]
);
$this -> assertEquals ( 'item_title item_body' , $result [ 'text' ]);
$this -> assertEquals ( '<h4>item_title</h4><br>item_title item_body' , $result [ 'html' ]);
}
/**
* Test the api_get_attachments () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiGetAttachments ()
{
$body = 'body' ;
$this -> assertEmpty ( api_get_attachments ( $body ));
}
/**
* Test the api_get_attachments () function with an img tag .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiGetAttachmentsWithImage ()
{
2018-07-01 20:46:24 +02:00
$body = '[img]http://via.placeholder.com/1x1.png[/img]' ;
2018-04-09 21:23:41 +02:00
$this -> assertInternalType ( 'array' , api_get_attachments ( $body ));
}
/**
* Test the api_get_attachments () function with an img tag and an AndStatus user agent .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiGetAttachmentsWithImageAndAndStatus ()
{
$_SERVER [ 'HTTP_USER_AGENT' ] = 'AndStatus' ;
2019-07-28 17:40:42 +02:00
$body = '[img]http://via.placeholder.com/1x1.png[/img]' ;
2018-04-09 21:23:41 +02:00
$this -> assertInternalType ( 'array' , api_get_attachments ( $body ));
}
/**
* Test the api_get_entitities () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiGetEntitities ()
{
$text = 'text' ;
$this -> assertInternalType ( 'array' , api_get_entitities ( $text , 'bbcode' ));
}
/**
* Test the api_get_entitities () function with the include_entities parameter .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiGetEntititiesWithIncludeEntities ()
{
$_REQUEST [ 'include_entities' ] = 'true' ;
2019-07-28 17:40:42 +02:00
$text = 'text' ;
$result = api_get_entitities ( $text , 'bbcode' );
2018-04-09 21:23:41 +02:00
$this -> assertInternalType ( 'array' , $result [ 'hashtags' ]);
$this -> assertInternalType ( 'array' , $result [ 'symbols' ]);
$this -> assertInternalType ( 'array' , $result [ 'urls' ]);
$this -> assertInternalType ( 'array' , $result [ 'user_mentions' ]);
}
/**
* Test the api_format_items_embeded_images () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiFormatItemsEmbededImages ()
{
$this -> assertEquals (
2019-12-30 23:00:08 +01:00
'text ' . DI :: baseUrl () . '/display/item_guid' ,
2018-04-09 21:23:41 +02:00
api_format_items_embeded_images ([ 'guid' => 'item_guid' ], 'text data:image/foo' )
);
}
/**
* Test the api_contactlink_to_array () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiContactlinkToArray ()
{
$this -> assertEquals (
[
'name' => 'text' ,
2019-07-28 17:40:42 +02:00
'url' => '' ,
2018-04-09 21:23:41 +02:00
],
api_contactlink_to_array ( 'text' )
);
}
/**
* Test the api_contactlink_to_array () function with an URL .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiContactlinkToArrayWithUrl ()
{
$this -> assertEquals (
[
'name' => [ 'link_text' ],
2019-07-28 17:40:42 +02:00
'url' => [ 'url' ],
2018-04-09 21:23:41 +02:00
],
api_contactlink_to_array ( 'text <a href="url">link_text</a>' )
);
}
/**
* Test the api_format_items_activities () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiFormatItemsActivities ()
{
2019-07-28 17:40:42 +02:00
$item = [ 'uid' => 0 , 'uri' => '' ];
2018-04-09 21:23:41 +02:00
$result = api_format_items_activities ( $item );
$this -> assertArrayHasKey ( 'like' , $result );
$this -> assertArrayHasKey ( 'dislike' , $result );
$this -> assertArrayHasKey ( 'attendyes' , $result );
$this -> assertArrayHasKey ( 'attendno' , $result );
$this -> assertArrayHasKey ( 'attendmaybe' , $result );
}
/**
* Test the api_format_items_activities () function with an XML result .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiFormatItemsActivitiesWithXml ()
{
2019-07-28 17:40:42 +02:00
$item = [ 'uid' => 0 , 'uri' => '' ];
2018-04-09 21:23:41 +02:00
$result = api_format_items_activities ( $item , 'xml' );
$this -> assertArrayHasKey ( 'friendica:like' , $result );
$this -> assertArrayHasKey ( 'friendica:dislike' , $result );
$this -> assertArrayHasKey ( 'friendica:attendyes' , $result );
$this -> assertArrayHasKey ( 'friendica:attendno' , $result );
$this -> assertArrayHasKey ( 'friendica:attendmaybe' , $result );
}
/**
* Test the api_format_items_profiles () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiFormatItemsProfiles ()
{
$profile_row = [
2019-07-28 17:40:42 +02:00
'id' => 'profile_id' ,
2018-04-09 21:23:41 +02:00
'profile-name' => 'profile_name' ,
2019-07-28 17:40:42 +02:00
'is-default' => true ,
2018-04-09 21:23:41 +02:00
'hide-friends' => true ,
2019-07-28 17:40:42 +02:00
'photo' => 'profile_photo' ,
'thumb' => 'profile_thumb' ,
'publish' => true ,
'net-publish' => true ,
'pdesc' => 'description' ,
'dob' => 'date_of_birth' ,
'address' => 'address' ,
'locality' => 'city' ,
'region' => 'region' ,
'postal-code' => 'postal_code' ,
2018-04-09 21:23:41 +02:00
'country-name' => 'country' ,
2019-07-28 17:40:42 +02:00
'hometown' => 'hometown' ,
'gender' => 'gender' ,
'marital' => 'marital' ,
'with' => 'marital_with' ,
'howlong' => 'marital_since' ,
'sexual' => 'sexual' ,
'politic' => 'politic' ,
'religion' => 'religion' ,
2018-04-09 21:23:41 +02:00
'pub_keywords' => 'public_keywords' ,
'prv_keywords' => 'private_keywords' ,
2019-07-28 17:40:42 +02:00
'likes' => 'likes' ,
'dislikes' => 'dislikes' ,
'about' => 'about' ,
'music' => 'music' ,
'book' => 'book' ,
'tv' => 'tv' ,
'film' => 'film' ,
'interest' => 'interest' ,
'romance' => 'romance' ,
'work' => 'work' ,
2018-04-09 21:23:41 +02:00
'education' => 'education' ,
2019-07-28 17:40:42 +02:00
'contact' => 'social_networks' ,
'homepage' => 'homepage'
2018-04-09 21:23:41 +02:00
];
2019-07-28 17:40:42 +02:00
$result = api_format_items_profiles ( $profile_row );
2018-04-09 21:23:41 +02:00
$this -> assertEquals (
[
2019-07-28 17:40:42 +02:00
'profile_id' => 'profile_id' ,
'profile_name' => 'profile_name' ,
'is_default' => true ,
'hide_friends' => true ,
'profile_photo' => 'profile_photo' ,
'profile_thumb' => 'profile_thumb' ,
'publish' => true ,
'net_publish' => true ,
'description' => 'description' ,
'date_of_birth' => 'date_of_birth' ,
'address' => 'address' ,
'city' => 'city' ,
'region' => 'region' ,
'postal_code' => 'postal_code' ,
'country' => 'country' ,
'hometown' => 'hometown' ,
'gender' => 'gender' ,
'marital' => 'marital' ,
'marital_with' => 'marital_with' ,
'marital_since' => 'marital_since' ,
'sexual' => 'sexual' ,
'politic' => 'politic' ,
'religion' => 'religion' ,
'public_keywords' => 'public_keywords' ,
2018-04-09 21:23:41 +02:00
'private_keywords' => 'private_keywords' ,
2019-07-28 17:40:42 +02:00
'likes' => 'likes' ,
'dislikes' => 'dislikes' ,
'about' => 'about' ,
'music' => 'music' ,
'book' => 'book' ,
'tv' => 'tv' ,
'film' => 'film' ,
'interest' => 'interest' ,
'romance' => 'romance' ,
'work' => 'work' ,
'education' => 'education' ,
2018-04-09 21:23:41 +02:00
'social_networks' => 'social_networks' ,
2019-07-28 17:40:42 +02:00
'homepage' => 'homepage' ,
'users' => null
2018-04-09 21:23:41 +02:00
],
$result
);
}
/**
* Test the api_format_items () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiFormatItems ()
{
2019-07-28 17:40:42 +02:00
$items = [
2018-04-09 21:23:41 +02:00
[
2019-07-28 17:40:42 +02:00
'item_network' => 'item_network' ,
'source' => 'web' ,
'coord' => '5 7' ,
'body' => '' ,
'verb' => '' ,
'author-id' => 43 ,
2018-07-10 04:39:59 +02:00
'author-network' => Protocol :: DFRN ,
2019-07-28 17:40:42 +02:00
'author-link' => 'http://localhost/profile/othercontact' ,
'plink' => '' ,
2018-04-09 21:23:41 +02:00
]
];
2018-07-01 20:46:24 +02:00
$result = api_format_items ( $items , [ 'id' => 0 ], true );
2018-04-09 21:23:41 +02:00
foreach ( $result as $status ) {
$this -> assertStatus ( $status );
}
}
/**
* Test the api_format_items () function with an XML result .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiFormatItemsWithXml ()
{
2019-07-28 17:40:42 +02:00
$items = [
2018-04-09 21:23:41 +02:00
[
2019-07-28 17:40:42 +02:00
'coord' => '5 7' ,
'body' => '' ,
'verb' => '' ,
'author-id' => 43 ,
2018-07-10 04:39:59 +02:00
'author-network' => Protocol :: DFRN ,
2019-07-28 17:40:42 +02:00
'author-link' => 'http://localhost/profile/othercontact' ,
'plink' => '' ,
2018-04-09 21:23:41 +02:00
]
];
2018-07-01 20:46:24 +02:00
$result = api_format_items ( $items , [ 'id' => 0 ], true , 'xml' );
2018-04-09 21:23:41 +02:00
foreach ( $result as $status ) {
$this -> assertStatus ( $status );
}
}
/**
* Test the api_format_items () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiAccountRateLimitStatus ()
{
$result = api_account_rate_limit_status ( 'json' );
$this -> assertEquals ( 150 , $result [ 'hash' ][ 'remaining_hits' ]);
$this -> assertEquals ( 150 , $result [ 'hash' ][ 'hourly_limit' ]);
$this -> assertInternalType ( 'int' , $result [ 'hash' ][ 'reset_time_in_seconds' ]);
}
/**
* Test the api_format_items () function with an XML result .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiAccountRateLimitStatusWithXml ()
{
$result = api_account_rate_limit_status ( 'xml' );
$this -> assertXml ( $result , 'hash' );
}
/**
* Test the api_help_test () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiHelpTest ()
{
$result = api_help_test ( 'json' );
$this -> assertEquals ([ 'ok' => 'ok' ], $result );
}
/**
* Test the api_help_test () function with an XML result .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiHelpTestWithXml ()
{
$result = api_help_test ( 'xml' );
$this -> assertXml ( $result , 'ok' );
}
/**
* Test the api_lists_list () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiListsList ()
{
$result = api_lists_list ( 'json' );
$this -> assertEquals ([ 'lists_list' => []], $result );
}
/**
* Test the api_lists_ownerships () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiListsOwnerships ()
{
$result = api_lists_ownerships ( 'json' );
foreach ( $result [ 'lists' ][ 'lists' ] as $list ) {
$this -> assertList ( $list );
}
}
/**
* Test the api_lists_ownerships () function without an authenticated user .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\ForbiddenException
*/
public function testApiListsOwnershipsWithoutAuthenticatedUser ()
{
$_SESSION [ 'authenticated' ] = false ;
api_lists_ownerships ( 'json' );
}
/**
* Test the api_lists_statuses () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ expectedException Friendica\Network\HTTPException\BadRequestException
* @ return void
*/
public function testApiListsStatuses ()
{
api_lists_statuses ( 'json' );
}
/**
* Test the api_lists_statuses () function with a list ID .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiListsStatusesWithListId ()
{
$_REQUEST [ 'list_id' ] = 1 ;
2019-07-28 17:40:42 +02:00
$_REQUEST [ 'page' ] = - 1 ;
$_REQUEST [ 'max_id' ] = 10 ;
$result = api_lists_statuses ( 'json' );
2018-04-09 21:23:41 +02:00
foreach ( $result [ 'status' ] as $status ) {
$this -> assertStatus ( $status );
}
}
/**
* Test the api_lists_statuses () function with a list ID and a RSS result .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiListsStatusesWithListIdAndRss ()
{
$_REQUEST [ 'list_id' ] = 1 ;
2019-07-28 17:40:42 +02:00
$result = api_lists_statuses ( 'rss' );
2018-04-09 21:23:41 +02:00
$this -> assertXml ( $result , 'statuses' );
}
/**
* Test the api_lists_statuses () function with an unallowed user .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\ForbiddenException
*/
public function testApiListsStatusesWithUnallowedUser ()
{
$_SESSION [ 'allow_api' ] = false ;
2019-07-28 17:40:42 +02:00
$_GET [ 'screen_name' ] = $this -> selfUser [ 'nick' ];
2018-04-09 21:23:41 +02:00
api_lists_statuses ( 'json' );
}
/**
* Test the api_statuses_f () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiStatusesFWithFriends ()
{
$_GET [ 'page' ] = - 1 ;
2019-07-28 17:40:42 +02:00
$result = api_statuses_f ( 'friends' );
2018-04-09 21:23:41 +02:00
$this -> assertArrayHasKey ( 'user' , $result );
}
/**
* Test the api_statuses_f () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiStatusesFWithFollowers ()
{
$result = api_statuses_f ( 'followers' );
$this -> assertArrayHasKey ( 'user' , $result );
}
/**
* Test the api_statuses_f () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiStatusesFWithBlocks ()
{
$result = api_statuses_f ( 'blocks' );
$this -> assertArrayHasKey ( 'user' , $result );
}
/**
* Test the api_statuses_f () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiStatusesFWithIncoming ()
{
$result = api_statuses_f ( 'incoming' );
$this -> assertArrayHasKey ( 'user' , $result );
}
/**
* Test the api_statuses_f () function an undefined cursor GET variable .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiStatusesFWithUndefinedCursor ()
{
$_GET [ 'cursor' ] = 'undefined' ;
$this -> assertFalse ( api_statuses_f ( 'friends' ));
}
/**
* Test the api_statuses_friends () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiStatusesFriends ()
{
$result = api_statuses_friends ( 'json' );
$this -> assertArrayHasKey ( 'user' , $result );
}
/**
* Test the api_statuses_friends () function an undefined cursor GET variable .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiStatusesFriendsWithUndefinedCursor ()
{
$_GET [ 'cursor' ] = 'undefined' ;
$this -> assertFalse ( api_statuses_friends ( 'json' ));
}
/**
* Test the api_statuses_followers () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiStatusesFollowers ()
{
$result = api_statuses_followers ( 'json' );
$this -> assertArrayHasKey ( 'user' , $result );
}
/**
* Test the api_statuses_followers () function an undefined cursor GET variable .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiStatusesFollowersWithUndefinedCursor ()
{
$_GET [ 'cursor' ] = 'undefined' ;
$this -> assertFalse ( api_statuses_followers ( 'json' ));
}
/**
* Test the api_blocks_list () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiBlocksList ()
{
$result = api_blocks_list ( 'json' );
$this -> assertArrayHasKey ( 'user' , $result );
}
/**
* Test the api_blocks_list () function an undefined cursor GET variable .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiBlocksListWithUndefinedCursor ()
{
$_GET [ 'cursor' ] = 'undefined' ;
$this -> assertFalse ( api_blocks_list ( 'json' ));
}
/**
* Test the api_friendships_incoming () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiFriendshipsIncoming ()
{
$result = api_friendships_incoming ( 'json' );
$this -> assertArrayHasKey ( 'id' , $result );
}
/**
* Test the api_friendships_incoming () function an undefined cursor GET variable .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiFriendshipsIncomingWithUndefinedCursor ()
{
$_GET [ 'cursor' ] = 'undefined' ;
$this -> assertFalse ( api_friendships_incoming ( 'json' ));
}
/**
* Test the api_statusnet_config () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiStatusnetConfig ()
{
$result = api_statusnet_config ( 'json' );
$this -> assertEquals ( 'localhost' , $result [ 'config' ][ 'site' ][ 'server' ]);
$this -> assertEquals ( 'default' , $result [ 'config' ][ 'site' ][ 'theme' ]);
2019-12-30 23:00:08 +01:00
$this -> assertEquals ( DI :: baseUrl () . '/images/friendica-64.png' , $result [ 'config' ][ 'site' ][ 'logo' ]);
2018-04-09 21:23:41 +02:00
$this -> assertTrue ( $result [ 'config' ][ 'site' ][ 'fancy' ]);
$this -> assertEquals ( 'en' , $result [ 'config' ][ 'site' ][ 'language' ]);
$this -> assertEquals ( 'UTC' , $result [ 'config' ][ 'site' ][ 'timezone' ]);
$this -> assertEquals ( 200000 , $result [ 'config' ][ 'site' ][ 'textlimit' ]);
$this -> assertEquals ( 'false' , $result [ 'config' ][ 'site' ][ 'private' ]);
$this -> assertEquals ( 'false' , $result [ 'config' ][ 'site' ][ 'ssl' ]);
$this -> assertEquals ( 30 , $result [ 'config' ][ 'site' ][ 'shorturllength' ]);
}
/**
* Test the api_statusnet_version () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiStatusnetVersion ()
{
$result = api_statusnet_version ( 'json' );
$this -> assertEquals ( '0.9.7' , $result [ 'version' ]);
}
/**
* Test the api_ff_ids () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiFfIds ()
{
2019-12-13 21:22:24 +01:00
$result = api_ff_ids ( 'json' , Contact :: FOLLOWER );
$this -> assertEquals ([ 'id' => []], $result );
2018-04-09 21:23:41 +02:00
}
/**
* Test the api_ff_ids () function with a result .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiFfIdsWithResult ()
{
$this -> markTestIncomplete ();
}
/**
* Test the api_ff_ids () function without an authenticated user .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\ForbiddenException
*/
public function testApiFfIdsWithoutAuthenticatedUser ()
{
$_SESSION [ 'authenticated' ] = false ;
2019-12-13 21:22:24 +01:00
api_ff_ids ( 'json' , Contact :: FOLLOWER );
2018-04-09 21:23:41 +02:00
}
/**
* Test the api_friends_ids () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiFriendsIds ()
{
$result = api_friends_ids ( 'json' );
2019-12-13 21:22:24 +01:00
$this -> assertEquals ([ 'id' => []], $result );
2018-04-09 21:23:41 +02:00
}
/**
* Test the api_followers_ids () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiFollowersIds ()
{
$result = api_followers_ids ( 'json' );
2019-12-13 21:22:24 +01:00
$this -> assertEquals ([ 'id' => []], $result );
2018-04-09 21:23:41 +02:00
}
/**
* Test the api_direct_messages_new () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiDirectMessagesNew ()
{
$result = api_direct_messages_new ( 'json' );
$this -> assertNull ( $result );
}
/**
* Test the api_direct_messages_new () function without an authenticated user .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\ForbiddenException
*/
public function testApiDirectMessagesNewWithoutAuthenticatedUser ()
{
$_SESSION [ 'authenticated' ] = false ;
api_direct_messages_new ( 'json' );
}
/**
* Test the api_direct_messages_new () function with an user ID .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiDirectMessagesNewWithUserId ()
{
2019-07-28 17:40:42 +02:00
$_POST [ 'text' ] = 'message_text' ;
2018-07-04 06:09:17 +02:00
$_POST [ 'user_id' ] = $this -> otherUser [ 'id' ];
2019-07-28 17:40:42 +02:00
$result = api_direct_messages_new ( 'json' );
2018-04-09 21:23:41 +02:00
$this -> assertEquals ([ 'direct_message' => [ 'error' => - 1 ]], $result );
}
/**
* Test the api_direct_messages_new () function with a screen name .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiDirectMessagesNewWithScreenName ()
{
2019-07-28 17:40:42 +02:00
$_POST [ 'text' ] = 'message_text' ;
2018-07-01 20:46:24 +02:00
$_POST [ 'screen_name' ] = $this -> friendUser [ 'nick' ];
2019-07-28 17:40:42 +02:00
$result = api_direct_messages_new ( 'json' );
2018-04-09 21:23:41 +02:00
$this -> assertContains ( 'message_text' , $result [ 'direct_message' ][ 'text' ]);
$this -> assertEquals ( 'selfcontact' , $result [ 'direct_message' ][ 'sender_screen_name' ]);
$this -> assertEquals ( 1 , $result [ 'direct_message' ][ 'friendica_seen' ]);
}
/**
* Test the api_direct_messages_new () function with a title .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiDirectMessagesNewWithTitle ()
{
2019-07-28 17:40:42 +02:00
$_POST [ 'text' ] = 'message_text' ;
2018-07-01 20:46:24 +02:00
$_POST [ 'screen_name' ] = $this -> friendUser [ 'nick' ];
2019-07-28 17:40:42 +02:00
$_REQUEST [ 'title' ] = 'message_title' ;
$result = api_direct_messages_new ( 'json' );
2018-04-09 21:23:41 +02:00
$this -> assertContains ( 'message_text' , $result [ 'direct_message' ][ 'text' ]);
$this -> assertContains ( 'message_title' , $result [ 'direct_message' ][ 'text' ]);
$this -> assertEquals ( 'selfcontact' , $result [ 'direct_message' ][ 'sender_screen_name' ]);
$this -> assertEquals ( 1 , $result [ 'direct_message' ][ 'friendica_seen' ]);
}
/**
* Test the api_direct_messages_new () function with an RSS result .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiDirectMessagesNewWithRss ()
{
2019-07-28 17:40:42 +02:00
$_POST [ 'text' ] = 'message_text' ;
2018-07-01 20:46:24 +02:00
$_POST [ 'screen_name' ] = $this -> friendUser [ 'nick' ];
2019-07-28 17:40:42 +02:00
$result = api_direct_messages_new ( 'rss' );
2018-04-09 21:23:41 +02:00
$this -> assertXml ( $result , 'direct-messages' );
}
/**
* Test the api_direct_messages_destroy () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\BadRequestException
*/
public function testApiDirectMessagesDestroy ()
{
api_direct_messages_destroy ( 'json' );
}
/**
* Test the api_direct_messages_destroy () function with the friendica_verbose GET param .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiDirectMessagesDestroyWithVerbose ()
{
$_GET [ 'friendica_verbose' ] = 'true' ;
2019-07-28 17:40:42 +02:00
$result = api_direct_messages_destroy ( 'json' );
2018-04-09 21:23:41 +02:00
$this -> assertEquals (
[
'$result' => [
2019-07-28 17:40:42 +02:00
'result' => 'error' ,
2018-04-09 21:23:41 +02:00
'message' => 'message id or parenturi not specified'
]
],
$result
);
}
/**
* Test the api_direct_messages_destroy () function without an authenticated user .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\ForbiddenException
*/
public function testApiDirectMessagesDestroyWithoutAuthenticatedUser ()
{
$_SESSION [ 'authenticated' ] = false ;
api_direct_messages_destroy ( 'json' );
}
/**
* Test the api_direct_messages_destroy () function with a non - zero ID .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\BadRequestException
*/
public function testApiDirectMessagesDestroyWithId ()
{
$_REQUEST [ 'id' ] = 1 ;
api_direct_messages_destroy ( 'json' );
}
/**
* Test the api_direct_messages_destroy () with a non - zero ID and the friendica_verbose GET param .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiDirectMessagesDestroyWithIdAndVerbose ()
{
2019-07-28 17:40:42 +02:00
$_REQUEST [ 'id' ] = 1 ;
2018-04-09 21:23:41 +02:00
$_REQUEST [ 'friendica_parenturi' ] = 'parent_uri' ;
2019-07-28 17:40:42 +02:00
$_GET [ 'friendica_verbose' ] = 'true' ;
$result = api_direct_messages_destroy ( 'json' );
2018-04-09 21:23:41 +02:00
$this -> assertEquals (
[
'$result' => [
2019-07-28 17:40:42 +02:00
'result' => 'error' ,
2018-04-09 21:23:41 +02:00
'message' => 'message id not in database'
]
],
$result
);
}
/**
* Test the api_direct_messages_destroy () function with a non - zero ID .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiDirectMessagesDestroyWithCorrectId ()
{
$this -> markTestIncomplete ( 'We need to add a dataset for this.' );
}
/**
* Test the api_direct_messages_box () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiDirectMessagesBoxWithSentbox ()
{
2019-07-28 17:40:42 +02:00
$_REQUEST [ 'page' ] = - 1 ;
2018-04-09 21:23:41 +02:00
$_REQUEST [ 'max_id' ] = 10 ;
2019-07-28 17:40:42 +02:00
$result = api_direct_messages_box ( 'json' , 'sentbox' , 'false' );
2018-04-09 21:23:41 +02:00
$this -> assertArrayHasKey ( 'direct_message' , $result );
}
/**
* Test the api_direct_messages_box () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiDirectMessagesBoxWithConversation ()
{
$result = api_direct_messages_box ( 'json' , 'conversation' , 'false' );
$this -> assertArrayHasKey ( 'direct_message' , $result );
}
/**
* Test the api_direct_messages_box () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiDirectMessagesBoxWithAll ()
{
$result = api_direct_messages_box ( 'json' , 'all' , 'false' );
$this -> assertArrayHasKey ( 'direct_message' , $result );
}
/**
* Test the api_direct_messages_box () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiDirectMessagesBoxWithInbox ()
{
$result = api_direct_messages_box ( 'json' , 'inbox' , 'false' );
$this -> assertArrayHasKey ( 'direct_message' , $result );
}
/**
* Test the api_direct_messages_box () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiDirectMessagesBoxWithVerbose ()
{
$result = api_direct_messages_box ( 'json' , 'sentbox' , 'true' );
$this -> assertEquals (
[
'$result' => [
2019-07-28 17:40:42 +02:00
'result' => 'error' ,
2018-04-09 21:23:41 +02:00
'message' => 'no mails available'
]
],
$result
);
}
/**
* Test the api_direct_messages_box () function with a RSS result .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiDirectMessagesBoxWithRss ()
{
$result = api_direct_messages_box ( 'rss' , 'sentbox' , 'false' );
$this -> assertXml ( $result , 'direct-messages' );
}
/**
* Test the api_direct_messages_box () function without an authenticated user .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\ForbiddenException
*/
public function testApiDirectMessagesBoxWithUnallowedUser ()
{
$_SESSION [ 'allow_api' ] = false ;
2019-07-28 17:40:42 +02:00
$_GET [ 'screen_name' ] = $this -> selfUser [ 'nick' ];
2018-04-09 21:23:41 +02:00
api_direct_messages_box ( 'json' , 'sentbox' , 'false' );
}
/**
* Test the api_direct_messages_sentbox () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiDirectMessagesSentbox ()
{
$result = api_direct_messages_sentbox ( 'json' );
$this -> assertArrayHasKey ( 'direct_message' , $result );
}
/**
* Test the api_direct_messages_inbox () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiDirectMessagesInbox ()
{
$result = api_direct_messages_inbox ( 'json' );
$this -> assertArrayHasKey ( 'direct_message' , $result );
}
/**
* Test the api_direct_messages_all () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiDirectMessagesAll ()
{
$result = api_direct_messages_all ( 'json' );
$this -> assertArrayHasKey ( 'direct_message' , $result );
}
/**
* Test the api_direct_messages_conversation () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiDirectMessagesConversation ()
{
$result = api_direct_messages_conversation ( 'json' );
$this -> assertArrayHasKey ( 'direct_message' , $result );
}
/**
* Test the api_oauth_request_token () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiOauthRequestToken ()
{
2020-01-04 23:43:13 +01:00
$this -> markTestIncomplete ( 'exit() kills phpunit as well' );
2018-04-09 21:23:41 +02:00
}
/**
* Test the api_oauth_access_token () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiOauthAccessToken ()
{
2020-01-04 23:43:13 +01:00
$this -> markTestIncomplete ( 'exit() kills phpunit as well' );
2018-04-09 21:23:41 +02:00
}
/**
* Test the api_fr_photoalbum_delete () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\BadRequestException
*/
public function testApiFrPhotoalbumDelete ()
{
api_fr_photoalbum_delete ( 'json' );
}
/**
* Test the api_fr_photoalbum_delete () function with an album name .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\BadRequestException
*/
public function testApiFrPhotoalbumDeleteWithAlbum ()
{
$_REQUEST [ 'album' ] = 'album_name' ;
api_fr_photoalbum_delete ( 'json' );
}
/**
* Test the api_fr_photoalbum_delete () function with an album name .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiFrPhotoalbumDeleteWithValidAlbum ()
{
$this -> markTestIncomplete ( 'We need to add a dataset for this.' );
}
/**
* Test the api_fr_photoalbum_delete () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\BadRequestException
*/
public function testApiFrPhotoalbumUpdate ()
{
api_fr_photoalbum_update ( 'json' );
}
/**
* Test the api_fr_photoalbum_delete () function with an album name .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\BadRequestException
*/
public function testApiFrPhotoalbumUpdateWithAlbum ()
{
$_REQUEST [ 'album' ] = 'album_name' ;
api_fr_photoalbum_update ( 'json' );
}
/**
* Test the api_fr_photoalbum_delete () function with an album name .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\BadRequestException
*/
public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum ()
{
2019-07-28 17:40:42 +02:00
$_REQUEST [ 'album' ] = 'album_name' ;
2018-04-09 21:23:41 +02:00
$_REQUEST [ 'album_new' ] = 'album_name' ;
api_fr_photoalbum_update ( 'json' );
}
/**
* Test the api_fr_photoalbum_update () function without an authenticated user .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\ForbiddenException
*/
public function testApiFrPhotoalbumUpdateWithoutAuthenticatedUser ()
{
$_SESSION [ 'authenticated' ] = false ;
api_fr_photoalbum_update ( 'json' );
}
/**
* Test the api_fr_photoalbum_delete () function with an album name .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiFrPhotoalbumUpdateWithValidAlbum ()
{
$this -> markTestIncomplete ( 'We need to add a dataset for this.' );
}
/**
* Test the api_fr_photos_list () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiFrPhotosList ()
{
$result = api_fr_photos_list ( 'json' );
$this -> assertArrayHasKey ( 'photo' , $result );
}
/**
* Test the api_fr_photos_list () function without an authenticated user .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\ForbiddenException
*/
public function testApiFrPhotosListWithoutAuthenticatedUser ()
{
$_SESSION [ 'authenticated' ] = false ;
api_fr_photos_list ( 'json' );
}
/**
* Test the api_fr_photo_create_update () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\BadRequestException
*/
public function testApiFrPhotoCreateUpdate ()
{
api_fr_photo_create_update ( 'json' );
}
/**
* Test the api_fr_photo_create_update () function without an authenticated user .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\ForbiddenException
*/
public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser ()
{
$_SESSION [ 'authenticated' ] = false ;
api_fr_photo_create_update ( 'json' );
}
/**
* Test the api_fr_photo_create_update () function with an album name .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\BadRequestException
*/
public function testApiFrPhotoCreateUpdateWithAlbum ()
{
$_REQUEST [ 'album' ] = 'album_name' ;
api_fr_photo_create_update ( 'json' );
}
/**
* Test the api_fr_photo_create_update () function with the update mode .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiFrPhotoCreateUpdateWithUpdate ()
{
$this -> markTestIncomplete ( 'We need to create a dataset for this' );
}
/**
* Test the api_fr_photo_create_update () function with an uploaded file .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiFrPhotoCreateUpdateWithFile ()
{
$this -> markTestIncomplete ();
}
/**
* Test the api_fr_photo_delete () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\BadRequestException
*/
public function testApiFrPhotoDelete ()
{
api_fr_photo_delete ( 'json' );
}
/**
* Test the api_fr_photo_delete () function without an authenticated user .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\ForbiddenException
*/
public function testApiFrPhotoDeleteWithoutAuthenticatedUser ()
{
$_SESSION [ 'authenticated' ] = false ;
api_fr_photo_delete ( 'json' );
}
/**
* Test the api_fr_photo_delete () function with a photo ID .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\BadRequestException
*/
public function testApiFrPhotoDeleteWithPhotoId ()
{
$_REQUEST [ 'photo_id' ] = 1 ;
api_fr_photo_delete ( 'json' );
}
/**
* Test the api_fr_photo_delete () function with a correct photo ID .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiFrPhotoDeleteWithCorrectPhotoId ()
{
$this -> markTestIncomplete ( 'We need to create a dataset for this.' );
}
/**
* Test the api_fr_photo_detail () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\BadRequestException
*/
public function testApiFrPhotoDetail ()
{
api_fr_photo_detail ( 'json' );
}
/**
* Test the api_fr_photo_detail () function without an authenticated user .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\ForbiddenException
*/
public function testApiFrPhotoDetailWithoutAuthenticatedUser ()
{
$_SESSION [ 'authenticated' ] = false ;
api_fr_photo_detail ( 'json' );
}
/**
* Test the api_fr_photo_detail () function with a photo ID .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\NotFoundException
*/
public function testApiFrPhotoDetailWithPhotoId ()
{
$_REQUEST [ 'photo_id' ] = 1 ;
api_fr_photo_detail ( 'json' );
}
/**
* Test the api_fr_photo_detail () function with a correct photo ID .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiFrPhotoDetailCorrectPhotoId ()
{
$this -> markTestIncomplete ( 'We need to create a dataset for this.' );
}
/**
* Test the api_account_update_profile_image () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\BadRequestException
*/
public function testApiAccountUpdateProfileImage ()
{
api_account_update_profile_image ( 'json' );
}
/**
* Test the api_account_update_profile_image () function without an authenticated user .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\ForbiddenException
*/
public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser ()
{
$_SESSION [ 'authenticated' ] = false ;
api_account_update_profile_image ( 'json' );
}
/**
* Test the api_account_update_profile_image () function with an uploaded file .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\BadRequestException
*/
public function testApiAccountUpdateProfileImageWithUpload ()
{
$this -> markTestIncomplete ();
}
/**
* Test the api_account_update_profile () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiAccountUpdateProfile ()
{
2019-07-28 17:40:42 +02:00
$_POST [ 'name' ] = 'new_name' ;
2018-04-09 21:23:41 +02:00
$_POST [ 'description' ] = 'new_description' ;
2019-07-28 17:40:42 +02:00
$result = api_account_update_profile ( 'json' );
2018-04-09 21:23:41 +02:00
// We can't use assertSelfUser() here because the user object is missing some properties.
$this -> assertEquals ( $this -> selfUser [ 'id' ], $result [ 'user' ][ 'cid' ]);
2018-11-18 21:59:40 +01:00
$this -> assertEquals ( 'DFRN' , $result [ 'user' ][ 'location' ]);
2018-04-09 21:23:41 +02:00
$this -> assertEquals ( $this -> selfUser [ 'nick' ], $result [ 'user' ][ 'screen_name' ]);
$this -> assertEquals ( 'dfrn' , $result [ 'user' ][ 'network' ]);
$this -> assertEquals ( 'new_name' , $result [ 'user' ][ 'name' ]);
$this -> assertEquals ( 'new_description' , $result [ 'user' ][ 'description' ]);
}
/**
* Test the check_acl_input () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testCheckAclInput ()
{
$result = check_acl_input ( '<aclstring>' );
// Where does this result come from?
$this -> assertEquals ( 1 , $result );
}
/**
* Test the check_acl_input () function with an empty ACL string .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testCheckAclInputWithEmptyAclString ()
{
$result = check_acl_input ( ' ' );
$this -> assertFalse ( $result );
}
/**
* Test the save_media_to_database () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testSaveMediaToDatabase ()
{
$this -> markTestIncomplete ();
}
/**
* Test the post_photo_item () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testPostPhotoItem ()
{
$this -> markTestIncomplete ();
}
/**
* Test the prepare_photo_data () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testPreparePhotoData ()
{
$this -> markTestIncomplete ();
}
/**
* Test the api_friendica_remoteauth () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\BadRequestException
*/
public function testApiFriendicaRemoteauth ()
{
api_friendica_remoteauth ();
}
/**
* Test the api_friendica_remoteauth () function with an URL .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\BadRequestException
*/
public function testApiFriendicaRemoteauthWithUrl ()
{
2019-07-28 17:40:42 +02:00
$_GET [ 'url' ] = 'url' ;
2018-04-09 21:23:41 +02:00
$_GET [ 'c_url' ] = 'url' ;
api_friendica_remoteauth ();
}
/**
* Test the api_friendica_remoteauth () function with a correct URL .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiFriendicaRemoteauthWithCorrectUrl ()
{
2018-10-13 20:02:04 +02:00
$this -> markTestIncomplete ( " We can't use an assertion here because of App->redirect(). " );
2019-07-28 17:40:42 +02:00
$_GET [ 'url' ] = 'url' ;
2018-04-09 21:23:41 +02:00
$_GET [ 'c_url' ] = $this -> selfUser [ 'nurl' ];
api_friendica_remoteauth ();
}
/**
* Test the api_share_as_retweet () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiShareAsRetweet ()
{
2019-07-28 17:40:42 +02:00
$item = [ 'body' => '' , 'author-id' => 1 , 'owner-id' => 1 ];
2018-04-09 21:23:41 +02:00
$result = api_share_as_retweet ( $item );
$this -> assertFalse ( $result );
}
/**
* Test the api_share_as_retweet () function with a valid item .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiShareAsRetweetWithValidItem ()
{
$this -> markTestIncomplete ();
}
/**
* Test the api_in_reply_to () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiInReplyTo ()
{
2018-07-01 21:08:14 +02:00
$result = api_in_reply_to ([ 'id' => 0 , 'parent' => 0 , 'uri' => '' , 'thr-parent' => '' ]);
2018-04-09 21:23:41 +02:00
$this -> assertArrayHasKey ( 'status_id' , $result );
$this -> assertArrayHasKey ( 'user_id' , $result );
$this -> assertArrayHasKey ( 'status_id_str' , $result );
$this -> assertArrayHasKey ( 'user_id_str' , $result );
$this -> assertArrayHasKey ( 'screen_name' , $result );
}
/**
* Test the api_in_reply_to () function with a valid item .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiInReplyToWithValidItem ()
{
$this -> markTestIncomplete ();
}
/**
* Test the api_clean_plain_items () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiCleanPlainItems ()
{
$_REQUEST [ 'include_entities' ] = 'true' ;
2019-07-28 17:40:42 +02:00
$result = api_clean_plain_items ( 'some_text [url="some_url"]some_text[/url]' );
2018-04-09 21:23:41 +02:00
$this -> assertEquals ( 'some_text [url="some_url"]"some_url"[/url]' , $result );
}
/**
* Test the api_best_nickname () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiBestNickname ()
{
$contacts = [];
2019-07-28 17:40:42 +02:00
$result = api_best_nickname ( $contacts );
2018-04-09 21:23:41 +02:00
$this -> assertNull ( $result );
}
/**
* Test the api_best_nickname () function with contacts .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiBestNicknameWithContacts ()
{
$this -> markTestIncomplete ();
}
/**
* Test the api_friendica_group_show () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiFriendicaGroupShow ()
{
$this -> markTestIncomplete ();
}
/**
* Test the api_friendica_group_delete () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiFriendicaGroupDelete ()
{
$this -> markTestIncomplete ();
}
/**
* Test the api_lists_destroy () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiListsDestroy ()
{
$this -> markTestIncomplete ();
}
/**
* Test the group_create () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testGroupCreate ()
{
$this -> markTestIncomplete ();
}
/**
* Test the api_friendica_group_create () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiFriendicaGroupCreate ()
{
$this -> markTestIncomplete ();
}
/**
* Test the api_lists_create () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiListsCreate ()
{
$this -> markTestIncomplete ();
}
/**
* Test the api_friendica_group_update () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiFriendicaGroupUpdate ()
{
$this -> markTestIncomplete ();
}
/**
* Test the api_lists_update () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiListsUpdate ()
{
$this -> markTestIncomplete ();
}
/**
* Test the api_friendica_activity () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiFriendicaActivity ()
{
$this -> markTestIncomplete ();
}
/**
* Test the api_friendica_notification () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\BadRequestException
*/
public function testApiFriendicaNotification ()
{
api_friendica_notification ( 'json' );
}
/**
* Test the api_friendica_notification () function without an authenticated user .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\ForbiddenException
*/
public function testApiFriendicaNotificationWithoutAuthenticatedUser ()
{
$_SESSION [ 'authenticated' ] = false ;
api_friendica_notification ( 'json' );
}
/**
2020-01-28 22:00:21 +01:00
* Test the api_friendica_notification () function with empty result
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
2020-01-28 22:00:21 +01:00
public function testApiFriendicaNotificationWithEmptyResult ()
2018-04-09 21:23:41 +02:00
{
2018-07-01 20:46:24 +02:00
$this -> app -> argv = [ 'api' , 'friendica' , 'notification' ];
$this -> app -> argc = count ( $this -> app -> argv );
2020-01-28 22:00:21 +01:00
$_SESSION [ 'uid' ] = 41 ;
2019-07-28 17:40:42 +02:00
$result = api_friendica_notification ( 'json' );
2018-04-09 21:23:41 +02:00
$this -> assertEquals ([ 'note' => false ], $result );
}
/**
* Test the api_friendica_notification () function with an XML result .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiFriendicaNotificationWithXmlResult ()
{
2018-07-01 20:46:24 +02:00
$this -> app -> argv = [ 'api' , 'friendica' , 'notification' ];
$this -> app -> argc = count ( $this -> app -> argv );
2019-07-28 17:40:42 +02:00
$result = api_friendica_notification ( 'xml' );
2020-01-31 21:40:45 +01:00
$dateRel = Temporal :: getRelativeDate ( '2020-01-01 12:12:02' );
2020-01-28 22:00:21 +01:00
$assertXml =<<< XML
< ? xml version = " 1.0 " ?>
< notes >
2020-01-31 21:40:45 +01:00
< note id = " 1 " hash = " " type = " 8 " name = " Reply to " url = " http://localhost/display/1 " photo = " http://localhost/ " date = " 2020-01-01 12:12:02 " msg = " A test reply from an item " uid = " 42 " link = " http://localhost/notification/1 " iid = " 4 " parent = " 0 " seen = " 0 " verb = " " otype = " item " name_cache = " " msg_cache = " A test reply from an item " timestamp = " 1577880722 " date_rel = " { $dateRel } " msg_html = " A test reply from an item " msg_plain = " A test reply from an item " />
2020-01-28 22:00:21 +01:00
</ notes >
XML ;
$this -> assertXmlStringEqualsXmlString ( $assertXml , $result );
}
/**
* Test the api_friendica_notification () function with an JSON result .
*
* @ return void
*/
public function testApiFriendicaNotificationWithJsonResult ()
{
$this -> app -> argv = [ 'api' , 'friendica' , 'notification' ];
$this -> app -> argc = count ( $this -> app -> argv );
$result = json_encode ( api_friendica_notification ( 'json' ));
$this -> assertJson ( $result );
2018-04-09 21:23:41 +02:00
}
/**
* Test the api_friendica_notification_seen () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiFriendicaNotificationSeen ()
{
$this -> markTestIncomplete ();
}
/**
* Test the api_friendica_direct_messages_setseen () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiFriendicaDirectMessagesSetseen ()
{
$this -> markTestIncomplete ();
}
/**
* Test the api_friendica_direct_messages_search () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiFriendicaDirectMessagesSearch ()
{
$this -> markTestIncomplete ();
}
/**
* Test the api_friendica_profile_show () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiFriendicaProfileShow ()
{
$result = api_friendica_profile_show ( 'json' );
// We can't use assertSelfUser() here because the user object is missing some properties.
$this -> assertEquals ( $this -> selfUser [ 'id' ], $result [ '$result' ][ 'friendica_owner' ][ 'cid' ]);
2018-11-18 21:59:40 +01:00
$this -> assertEquals ( 'DFRN' , $result [ '$result' ][ 'friendica_owner' ][ 'location' ]);
2018-04-09 21:23:41 +02:00
$this -> assertEquals ( $this -> selfUser [ 'name' ], $result [ '$result' ][ 'friendica_owner' ][ 'name' ]);
$this -> assertEquals ( $this -> selfUser [ 'nick' ], $result [ '$result' ][ 'friendica_owner' ][ 'screen_name' ]);
$this -> assertEquals ( 'dfrn' , $result [ '$result' ][ 'friendica_owner' ][ 'network' ]);
$this -> assertTrue ( $result [ '$result' ][ 'friendica_owner' ][ 'verified' ]);
$this -> assertFalse ( $result [ '$result' ][ 'multi_profiles' ]);
}
/**
* Test the api_friendica_profile_show () function with a profile ID .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiFriendicaProfileShowWithProfileId ()
{
$this -> markTestIncomplete ( 'We need to add a dataset for this.' );
}
/**
* Test the api_friendica_profile_show () function with a wrong profile ID .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\BadRequestException
*/
public function testApiFriendicaProfileShowWithWrongProfileId ()
{
$_REQUEST [ 'profile_id' ] = 666 ;
api_friendica_profile_show ( 'json' );
}
/**
* Test the api_friendica_profile_show () function without an authenticated user .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
* @ expectedException Friendica\Network\HTTPException\ForbiddenException
*/
public function testApiFriendicaProfileShowWithoutAuthenticatedUser ()
{
$_SESSION [ 'authenticated' ] = false ;
api_friendica_profile_show ( 'json' );
}
/**
* Test the api_saved_searches_list () function .
2019-07-28 17:40:42 +02:00
*
2018-04-09 21:23:41 +02:00
* @ return void
*/
public function testApiSavedSearchesList ()
{
$result = api_saved_searches_list ( 'json' );
$this -> assertEquals ( 1 , $result [ 'terms' ][ 0 ][ 'id' ]);
$this -> assertEquals ( 1 , $result [ 'terms' ][ 0 ][ 'id_str' ]);
$this -> assertEquals ( 'Saved search' , $result [ 'terms' ][ 0 ][ 'name' ]);
$this -> assertEquals ( 'Saved search' , $result [ 'terms' ][ 0 ][ 'query' ]);
}
}