Fix API test cases
- Add meaningful app->argv/c - Add support for subfolder install - Add meaningful image URL from placeholder.com - Fix incomplete test testApiHelpTestWithXml() - Use $this->frienduser for direct messages tests - Fix dataset to have an actual contact relationship
This commit is contained in:
parent
43688c04b1
commit
18eb13a598
2 changed files with 56 additions and 41 deletions
|
@ -29,18 +29,28 @@ class ApiTest extends DatabaseTest
|
||||||
global $a;
|
global $a;
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
|
// Reusable App object
|
||||||
|
$this->app = new App(__DIR__.'/../');
|
||||||
|
$a = $this->app;
|
||||||
|
|
||||||
// User data that the test database is populated with
|
// User data that the test database is populated with
|
||||||
$this->selfUser = [
|
$this->selfUser = [
|
||||||
'id' => 42,
|
'id' => 42,
|
||||||
'name' => 'Self contact',
|
'name' => 'Self contact',
|
||||||
'nick' => 'selfcontact',
|
'nick' => 'selfcontact',
|
||||||
'nurl' => 'http://localhost/profile/selfcontact'
|
'nurl' => \Friendica\Core\System::baseUrl() . '/profile/selfcontact'
|
||||||
|
];
|
||||||
|
$this->friendUser = [
|
||||||
|
'id' => 44,
|
||||||
|
'name' => 'Friend contact',
|
||||||
|
'nick' => 'friendcontact',
|
||||||
|
'nurl' => \Friendica\Core\System::baseUrl() . '/profile/friendcontact'
|
||||||
];
|
];
|
||||||
$this->otherUser = [
|
$this->otherUser = [
|
||||||
'id' => 43,
|
'id' => 43,
|
||||||
'name' => 'othercontact',
|
'name' => 'othercontact',
|
||||||
'nick' => 'othercontact',
|
'nick' => 'othercontact',
|
||||||
'nurl' => 'http://localhost/profile/othercontact'
|
'nurl' => \Friendica\Core\System::baseUrl() . '/profile/othercontact'
|
||||||
];
|
];
|
||||||
|
|
||||||
// User ID that we know is not in the database
|
// User ID that we know is not in the database
|
||||||
|
@ -53,10 +63,6 @@ class ApiTest extends DatabaseTest
|
||||||
'uid' => $this->selfUser['id']
|
'uid' => $this->selfUser['id']
|
||||||
];
|
];
|
||||||
|
|
||||||
// Reusable App object
|
|
||||||
$this->app = new App(__DIR__.'/../');
|
|
||||||
$a = $this->app;
|
|
||||||
|
|
||||||
// Default config
|
// Default config
|
||||||
Config::set('config', 'hostname', 'localhost');
|
Config::set('config', 'hostname', 'localhost');
|
||||||
Config::set('system', 'throttle_limit_day', 100);
|
Config::set('system', 'throttle_limit_day', 100);
|
||||||
|
@ -1835,6 +1841,8 @@ class ApiTest extends DatabaseTest
|
||||||
*/
|
*/
|
||||||
public function testApiFavoritesCreateDestroy()
|
public function testApiFavoritesCreateDestroy()
|
||||||
{
|
{
|
||||||
|
$this->app->argv = ['api', '1.1', 'favorites', 'create'];
|
||||||
|
$this->app->argc = count($this->app->argv);
|
||||||
api_favorites_create_destroy('json');
|
api_favorites_create_destroy('json');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1845,9 +1853,8 @@ class ApiTest extends DatabaseTest
|
||||||
*/
|
*/
|
||||||
public function testApiFavoritesCreateDestroyWithInvalidId()
|
public function testApiFavoritesCreateDestroyWithInvalidId()
|
||||||
{
|
{
|
||||||
// This triggers a very specific condition ($action_argv_id + 2)
|
$this->app->argv = ['api', '1.1', 'favorites', 'create', '12.json'];
|
||||||
$this->app->argv[1] = '1.1';
|
$this->app->argc = count($this->app->argv);
|
||||||
$this->app->argc = 5;
|
|
||||||
api_favorites_create_destroy('json');
|
api_favorites_create_destroy('json');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1858,8 +1865,8 @@ class ApiTest extends DatabaseTest
|
||||||
*/
|
*/
|
||||||
public function testApiFavoritesCreateDestroyWithInvalidAction()
|
public function testApiFavoritesCreateDestroyWithInvalidAction()
|
||||||
{
|
{
|
||||||
$this->app->argv[1] = '1.1';
|
$this->app->argv = ['api', '1.1', 'favorites', 'change.json'];
|
||||||
$this->app->argc = 10;
|
$this->app->argc = count($this->app->argv);
|
||||||
$_REQUEST['id'] = 1;
|
$_REQUEST['id'] = 1;
|
||||||
api_favorites_create_destroy('json');
|
api_favorites_create_destroy('json');
|
||||||
}
|
}
|
||||||
|
@ -1870,9 +1877,8 @@ class ApiTest extends DatabaseTest
|
||||||
*/
|
*/
|
||||||
public function testApiFavoritesCreateDestroyWithCreateAction()
|
public function testApiFavoritesCreateDestroyWithCreateAction()
|
||||||
{
|
{
|
||||||
$this->app->argv[1] = '1.1';
|
$this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
|
||||||
$this->app->argv[3] = 'create';
|
$this->app->argc = count($this->app->argv);
|
||||||
$this->app->argc = 10;
|
|
||||||
$_REQUEST['id'] = 3;
|
$_REQUEST['id'] = 3;
|
||||||
$result = api_favorites_create_destroy('json');
|
$result = api_favorites_create_destroy('json');
|
||||||
$this->assertStatus($result['status']);
|
$this->assertStatus($result['status']);
|
||||||
|
@ -1884,9 +1890,8 @@ class ApiTest extends DatabaseTest
|
||||||
*/
|
*/
|
||||||
public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
|
public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
|
||||||
{
|
{
|
||||||
$this->app->argv[1] = '1.1';
|
$this->app->argv = ['api', '1.1', 'favorites', 'create.rss'];
|
||||||
$this->app->argv[3] = 'create';
|
$this->app->argc = count($this->app->argv);
|
||||||
$this->app->argc = 10;
|
|
||||||
$_REQUEST['id'] = 3;
|
$_REQUEST['id'] = 3;
|
||||||
$result = api_favorites_create_destroy('rss');
|
$result = api_favorites_create_destroy('rss');
|
||||||
$this->assertXml($result, 'status');
|
$this->assertXml($result, 'status');
|
||||||
|
@ -1898,9 +1903,8 @@ class ApiTest extends DatabaseTest
|
||||||
*/
|
*/
|
||||||
public function testApiFavoritesCreateDestroyWithDestroyAction()
|
public function testApiFavoritesCreateDestroyWithDestroyAction()
|
||||||
{
|
{
|
||||||
$this->app->argv[1] = '1.1';
|
$this->app->argv = ['api', '1.1', 'favorites', 'destroy.json'];
|
||||||
$this->app->argv[3] = 'destroy';
|
$this->app->argc = count($this->app->argv);
|
||||||
$this->app->argc = 10;
|
|
||||||
$_REQUEST['id'] = 3;
|
$_REQUEST['id'] = 3;
|
||||||
$result = api_favorites_create_destroy('json');
|
$result = api_favorites_create_destroy('json');
|
||||||
$this->assertStatus($result['status']);
|
$this->assertStatus($result['status']);
|
||||||
|
@ -1913,6 +1917,8 @@ class ApiTest extends DatabaseTest
|
||||||
*/
|
*/
|
||||||
public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
|
public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
|
||||||
{
|
{
|
||||||
|
$this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
|
||||||
|
$this->app->argc = count($this->app->argv);
|
||||||
$_SESSION['authenticated'] = false;
|
$_SESSION['authenticated'] = false;
|
||||||
api_favorites_create_destroy('json');
|
api_favorites_create_destroy('json');
|
||||||
}
|
}
|
||||||
|
@ -2016,8 +2022,8 @@ class ApiTest extends DatabaseTest
|
||||||
['id' => 2, 'screen_name' => 'recipient_name'],
|
['id' => 2, 'screen_name' => 'recipient_name'],
|
||||||
['id' => 3, 'screen_name' => 'sender_name']
|
['id' => 3, 'screen_name' => 'sender_name']
|
||||||
);
|
);
|
||||||
$this->assertNull($result['sender']);
|
$this->assertTrue(!isset($result['sender']));
|
||||||
$this->assertNull($result['recipient']);
|
$this->assertTrue(!isset($result['recipient']));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2053,7 +2059,8 @@ class ApiTest extends DatabaseTest
|
||||||
'repellat officia illum quos impedit quam iste esse unde qui '.
|
'repellat officia illum quos impedit quam iste esse unde qui '.
|
||||||
'suscipit aut facilis ut inventore omnis exercitationem quo magnam '.
|
'suscipit aut facilis ut inventore omnis exercitationem quo magnam '.
|
||||||
'consequatur maxime aut illum soluta quaerat natus unde aspernatur '.
|
'consequatur maxime aut illum soluta quaerat natus unde aspernatur '.
|
||||||
'et sed beatae nihil ullam temporibus corporis ratione blanditiis'
|
'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
|
||||||
|
'plink' => 'item_plink'
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
$this->assertStringStartsWith('item_title', $result['text']);
|
$this->assertStringStartsWith('item_title', $result['text']);
|
||||||
|
@ -2110,7 +2117,7 @@ class ApiTest extends DatabaseTest
|
||||||
*/
|
*/
|
||||||
public function testApiGetAttachmentsWithImage()
|
public function testApiGetAttachmentsWithImage()
|
||||||
{
|
{
|
||||||
$body = '[img]img_url[/img]';
|
$body = '[img]http://via.placeholder.com/1x1.png[/img]';
|
||||||
$this->assertInternalType('array', api_get_attachments($body));
|
$this->assertInternalType('array', api_get_attachments($body));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2121,7 +2128,7 @@ class ApiTest extends DatabaseTest
|
||||||
public function testApiGetAttachmentsWithImageAndAndStatus()
|
public function testApiGetAttachmentsWithImageAndAndStatus()
|
||||||
{
|
{
|
||||||
$_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
|
$_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
|
||||||
$body = '[img]img_url[/img]';
|
$body = '[img]http://via.placeholder.com/1x1.png[/img]';
|
||||||
$this->assertInternalType('array', api_get_attachments($body));
|
$this->assertInternalType('array', api_get_attachments($body));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2157,7 +2164,7 @@ class ApiTest extends DatabaseTest
|
||||||
public function testApiFormatItemsEmbededImages()
|
public function testApiFormatItemsEmbededImages()
|
||||||
{
|
{
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'text http://localhost/display/item_guid',
|
'text ' . \Friendica\Core\System::baseUrl() . '/display/item_guid',
|
||||||
api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
|
api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -2198,7 +2205,7 @@ class ApiTest extends DatabaseTest
|
||||||
*/
|
*/
|
||||||
public function testApiFormatItemsActivities()
|
public function testApiFormatItemsActivities()
|
||||||
{
|
{
|
||||||
$item = [];
|
$item = ['uid' => 0, 'uri' => ''];
|
||||||
$result = api_format_items_activities($item);
|
$result = api_format_items_activities($item);
|
||||||
$this->assertArrayHasKey('like', $result);
|
$this->assertArrayHasKey('like', $result);
|
||||||
$this->assertArrayHasKey('dislike', $result);
|
$this->assertArrayHasKey('dislike', $result);
|
||||||
|
@ -2213,7 +2220,7 @@ class ApiTest extends DatabaseTest
|
||||||
*/
|
*/
|
||||||
public function testApiFormatItemsActivitiesWithXml()
|
public function testApiFormatItemsActivitiesWithXml()
|
||||||
{
|
{
|
||||||
$item = [];
|
$item = ['uid' => 0, 'uri' => ''];
|
||||||
$result = api_format_items_activities($item, 'xml');
|
$result = api_format_items_activities($item, 'xml');
|
||||||
$this->assertArrayHasKey('friendica:like', $result);
|
$this->assertArrayHasKey('friendica:like', $result);
|
||||||
$this->assertArrayHasKey('friendica:dislike', $result);
|
$this->assertArrayHasKey('friendica:dislike', $result);
|
||||||
|
@ -2327,10 +2334,14 @@ class ApiTest extends DatabaseTest
|
||||||
[
|
[
|
||||||
'item_network' => 'item_network',
|
'item_network' => 'item_network',
|
||||||
'source' => 'web',
|
'source' => 'web',
|
||||||
'coord' => '5 7'
|
'coord' => '5 7',
|
||||||
|
'body' => '',
|
||||||
|
'verb' => '',
|
||||||
|
'author-id' => 42,
|
||||||
|
'plink' => '',
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
$result = api_format_items($items, [], true);
|
$result = api_format_items($items, ['id' => 0], true);
|
||||||
foreach ($result as $status) {
|
foreach ($result as $status) {
|
||||||
$this->assertStatus($status);
|
$this->assertStatus($status);
|
||||||
}
|
}
|
||||||
|
@ -2344,10 +2355,14 @@ class ApiTest extends DatabaseTest
|
||||||
{
|
{
|
||||||
$items = [
|
$items = [
|
||||||
[
|
[
|
||||||
'coord' => '5 7'
|
'coord' => '5 7',
|
||||||
|
'body' => '',
|
||||||
|
'verb' => '',
|
||||||
|
'author-id' => 42,
|
||||||
|
'plink' => '',
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
$result = api_format_items($items, [], true, 'xml');
|
$result = api_format_items($items, ['id' => 0], true, 'xml');
|
||||||
foreach ($result as $status) {
|
foreach ($result as $status) {
|
||||||
$this->assertStatus($status);
|
$this->assertStatus($status);
|
||||||
}
|
}
|
||||||
|
@ -2391,7 +2406,6 @@ class ApiTest extends DatabaseTest
|
||||||
*/
|
*/
|
||||||
public function testApiHelpTestWithXml()
|
public function testApiHelpTestWithXml()
|
||||||
{
|
{
|
||||||
$this->markTestIncomplete('Triggers this error: "key() expects parameter 1 to be array, string given"');
|
|
||||||
$result = api_help_test('xml');
|
$result = api_help_test('xml');
|
||||||
$this->assertXml($result, 'ok');
|
$this->assertXml($result, 'ok');
|
||||||
}
|
}
|
||||||
|
@ -2617,7 +2631,7 @@ class ApiTest extends DatabaseTest
|
||||||
$result = api_statusnet_config('json');
|
$result = api_statusnet_config('json');
|
||||||
$this->assertEquals('localhost', $result['config']['site']['server']);
|
$this->assertEquals('localhost', $result['config']['site']['server']);
|
||||||
$this->assertEquals('default', $result['config']['site']['theme']);
|
$this->assertEquals('default', $result['config']['site']['theme']);
|
||||||
$this->assertEquals('http://localhost/images/friendica-64.png', $result['config']['site']['logo']);
|
$this->assertEquals(\Friendica\Core\System::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
|
||||||
$this->assertTrue($result['config']['site']['fancy']);
|
$this->assertTrue($result['config']['site']['fancy']);
|
||||||
$this->assertEquals('en', $result['config']['site']['language']);
|
$this->assertEquals('en', $result['config']['site']['language']);
|
||||||
$this->assertEquals('UTC', $result['config']['site']['timezone']);
|
$this->assertEquals('UTC', $result['config']['site']['timezone']);
|
||||||
|
@ -2727,7 +2741,7 @@ class ApiTest extends DatabaseTest
|
||||||
public function testApiDirectMessagesNewWithScreenName()
|
public function testApiDirectMessagesNewWithScreenName()
|
||||||
{
|
{
|
||||||
$_POST['text'] = 'message_text';
|
$_POST['text'] = 'message_text';
|
||||||
$_POST['screen_name'] = $this->otherUser['nick'];
|
$_POST['screen_name'] = $this->friendUser['nick'];
|
||||||
$result = api_direct_messages_new('json');
|
$result = api_direct_messages_new('json');
|
||||||
$this->assertEquals(1, $result['direct_message']['id']);
|
$this->assertEquals(1, $result['direct_message']['id']);
|
||||||
$this->assertContains('message_text', $result['direct_message']['text']);
|
$this->assertContains('message_text', $result['direct_message']['text']);
|
||||||
|
@ -2742,7 +2756,7 @@ class ApiTest extends DatabaseTest
|
||||||
public function testApiDirectMessagesNewWithTitle()
|
public function testApiDirectMessagesNewWithTitle()
|
||||||
{
|
{
|
||||||
$_POST['text'] = 'message_text';
|
$_POST['text'] = 'message_text';
|
||||||
$_POST['screen_name'] = $this->otherUser['nick'];
|
$_POST['screen_name'] = $this->friendUser['nick'];
|
||||||
$_REQUEST['title'] = 'message_title';
|
$_REQUEST['title'] = 'message_title';
|
||||||
$result = api_direct_messages_new('json');
|
$result = api_direct_messages_new('json');
|
||||||
$this->assertEquals(1, $result['direct_message']['id']);
|
$this->assertEquals(1, $result['direct_message']['id']);
|
||||||
|
@ -2759,7 +2773,7 @@ class ApiTest extends DatabaseTest
|
||||||
public function testApiDirectMessagesNewWithRss()
|
public function testApiDirectMessagesNewWithRss()
|
||||||
{
|
{
|
||||||
$_POST['text'] = 'message_text';
|
$_POST['text'] = 'message_text';
|
||||||
$_POST['screen_name'] = $this->otherUser['nick'];
|
$_POST['screen_name'] = $this->friendUser['nick'];
|
||||||
$result = api_direct_messages_new('rss');
|
$result = api_direct_messages_new('rss');
|
||||||
$this->assertXml($result, 'direct-messages');
|
$this->assertXml($result, 'direct-messages');
|
||||||
}
|
}
|
||||||
|
@ -3564,7 +3578,8 @@ class ApiTest extends DatabaseTest
|
||||||
*/
|
*/
|
||||||
public function testApiFriendicaNotificationWithArgumentCount()
|
public function testApiFriendicaNotificationWithArgumentCount()
|
||||||
{
|
{
|
||||||
$this->app->argc = 3;
|
$this->app->argv = ['api', 'friendica', 'notification'];
|
||||||
|
$this->app->argc = count($this->app->argv);
|
||||||
$result = api_friendica_notification('json');
|
$result = api_friendica_notification('json');
|
||||||
$this->assertEquals(['note' => false], $result);
|
$this->assertEquals(['note' => false], $result);
|
||||||
}
|
}
|
||||||
|
@ -3575,8 +3590,8 @@ class ApiTest extends DatabaseTest
|
||||||
*/
|
*/
|
||||||
public function testApiFriendicaNotificationWithXmlResult()
|
public function testApiFriendicaNotificationWithXmlResult()
|
||||||
{
|
{
|
||||||
$this->markTestIncomplete('Fails with "Invalid argument supplied for foreach()".');
|
$this->app->argv = ['api', 'friendica', 'notification'];
|
||||||
$this->app->argc = 3;
|
$this->app->argc = count($this->app->argv);
|
||||||
$result = api_friendica_notification('xml');
|
$result = api_friendica_notification('xml');
|
||||||
$this->assertXml($result, 'notes');
|
$this->assertXml($result, 'notes');
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ contact:
|
||||||
network: dfrn
|
network: dfrn
|
||||||
-
|
-
|
||||||
id: 43
|
id: 43
|
||||||
uid: 0
|
uid: 42
|
||||||
# Having the same name and nick allows us to test
|
# Having the same name and nick allows us to test
|
||||||
# the fallback to api_get_nick() in api_get_user()
|
# the fallback to api_get_nick() in api_get_user()
|
||||||
name: othercontact
|
name: othercontact
|
||||||
|
|
Loading…
Reference in a new issue