Move API DirectMessage tests
This commit is contained in:
parent
f0b97d8e13
commit
6412484fa6
|
@ -51,7 +51,7 @@ class DirectMessage extends BaseFactory
|
||||||
*
|
*
|
||||||
* @param int $id Mail id
|
* @param int $id Mail id
|
||||||
* @param int $uid Mail user
|
* @param int $uid Mail user
|
||||||
* @param string $text_mode Either empty, "html" or "text"
|
* @param string $text_mode Either empty, "html" or "plain"
|
||||||
*
|
*
|
||||||
* @return \Friendica\Object\Api\Twitter\DirectMessage
|
* @return \Friendica\Object\Api\Twitter\DirectMessage
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -10,8 +10,8 @@ return [
|
||||||
'thr-parent-id' => 44,
|
'thr-parent-id' => 44,
|
||||||
'guid' => '123456',
|
'guid' => '123456',
|
||||||
'from-name' => 'Tester',
|
'from-name' => 'Tester',
|
||||||
'title' => 'test message',
|
'title' => 'item_title',
|
||||||
'body' => 'this is a test',
|
'body' => '[b]item_body[/b]',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
|
@ -679,85 +679,6 @@ class ApiTest extends FixtureTest
|
||||||
// api_statuses_mediap('json');
|
// api_statuses_mediap('json');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Test the api_format_messages() function.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testApiFormatMessages()
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
$result = api_format_messages(
|
|
||||||
['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
|
|
||||||
['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
|
|
||||||
['id' => 3, 'uri-id' => 2, 'screen_name' => 'sender_name']
|
|
||||||
);
|
|
||||||
self::assertEquals('item_title' . "\n" . 'item_body', $result['text']);
|
|
||||||
self::assertEquals(1, $result['id']);
|
|
||||||
self::assertEquals(2, $result['recipient_id']);
|
|
||||||
self::assertEquals(3, $result['sender_id']);
|
|
||||||
self::assertEquals('recipient_name', $result['recipient_screen_name']);
|
|
||||||
self::assertEquals('sender_name', $result['sender_screen_name']);
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test the api_format_messages() function with HTML.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testApiFormatMessagesWithHtmlText()
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
$_GET['getText'] = 'html';
|
|
||||||
$result = api_format_messages(
|
|
||||||
['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
|
|
||||||
['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
|
|
||||||
['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name']
|
|
||||||
);
|
|
||||||
self::assertEquals('item_title', $result['title']);
|
|
||||||
self::assertEquals('<strong>item_body</strong>', $result['text']);
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test the api_format_messages() function with plain text.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testApiFormatMessagesWithPlainText()
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
$_GET['getText'] = 'plain';
|
|
||||||
$result = api_format_messages(
|
|
||||||
['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
|
|
||||||
['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
|
|
||||||
['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name']
|
|
||||||
);
|
|
||||||
self::assertEquals('item_title', $result['title']);
|
|
||||||
self::assertEquals('item_body', $result['text']);
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test the api_format_messages() function with the getUserObjects GET parameter set to false.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testApiFormatMessagesWithoutUserObjects()
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
$_GET['getUserObjects'] = 'false';
|
|
||||||
$result = api_format_messages(
|
|
||||||
['id' => 1, 'uri-id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
|
|
||||||
['id' => 2, 'uri-id' => 2, 'screen_name' => 'recipient_name'],
|
|
||||||
['id' => 3, 'uri-id' => 3, 'screen_name' => 'sender_name']
|
|
||||||
);
|
|
||||||
self::assertTrue(!isset($result['sender']));
|
|
||||||
self::assertTrue(!isset($result['recipient']));
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the api_convert_item() function.
|
* Test the api_convert_item() function.
|
||||||
*
|
*
|
||||||
|
|
|
@ -0,0 +1,95 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Friendica\Test\src\Factory\Api\Twitter;
|
||||||
|
|
||||||
|
use Friendica\DI;
|
||||||
|
use Friendica\Factory\Api\Twitter\DirectMessage;
|
||||||
|
use Friendica\Test\FixtureTest;
|
||||||
|
use Friendica\Test\src\Module\Api\ApiTest;
|
||||||
|
|
||||||
|
class DirectMessageTest extends FixtureTest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Test the api_format_messages() function.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testApiFormatMessages()
|
||||||
|
{
|
||||||
|
$this->loadFixture(__DIR__ . '/../../../../datasets/mail/mail.fixture.php', DI::dba());
|
||||||
|
$ids = DI::dba()->selectToArray('mail', ['id']);
|
||||||
|
$id = $ids[0]['id'];
|
||||||
|
|
||||||
|
$directMessageFactory = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser());
|
||||||
|
$directMessageObj = $directMessageFactory->createFromMailId($id, ApiTest::SELF_USER['id']);
|
||||||
|
$directMessage = $directMessageObj->toArray();
|
||||||
|
|
||||||
|
self::assertEquals('item_title' . "\n" . 'item_body', $directMessage['text']);
|
||||||
|
self::assertIsInt($directMessage['id']);
|
||||||
|
self::assertIsInt($directMessage['recipient_id']);
|
||||||
|
self::assertIsInt($directMessage['sender_id']);
|
||||||
|
self::assertEquals('selfcontact', $directMessage['recipient_screen_name']);
|
||||||
|
self::assertEquals('friendcontact', $directMessage['sender_screen_name']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test the api_format_messages() function with HTML.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testApiFormatMessagesWithHtmlText()
|
||||||
|
{
|
||||||
|
$this->loadFixture(__DIR__ . '/../../../../datasets/mail/mail.fixture.php', DI::dba());
|
||||||
|
$ids = DI::dba()->selectToArray('mail', ['id']);
|
||||||
|
$id = $ids[0]['id'];
|
||||||
|
|
||||||
|
$directMessageFactory = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser());
|
||||||
|
$directMessageObj = $directMessageFactory->createFromMailId($id, ApiTest::SELF_USER['id'], 'html');
|
||||||
|
$directMessage = $directMessageObj->toArray();
|
||||||
|
|
||||||
|
self::assertEquals('item_title', $directMessage['title']);
|
||||||
|
self::assertEquals('<strong>item_body</strong>', $directMessage['text']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test the api_format_messages() function with plain text.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testApiFormatMessagesWithPlainText()
|
||||||
|
{
|
||||||
|
$this->loadFixture(__DIR__ . '/../../../../datasets/mail/mail.fixture.php', DI::dba());
|
||||||
|
$ids = DI::dba()->selectToArray('mail', ['id']);
|
||||||
|
$id = $ids[0]['id'];
|
||||||
|
|
||||||
|
$directMessageFactory = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser());
|
||||||
|
$directMessageObj = $directMessageFactory->createFromMailId($id, ApiTest::SELF_USER['id'], 'plain');
|
||||||
|
$directMessage = $directMessageObj->toArray();
|
||||||
|
|
||||||
|
self::assertEquals('item_title', $directMessage['title']);
|
||||||
|
self::assertEquals('item_body', $directMessage['text']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test the api_format_messages() function with the getUserObjects GET parameter set to false.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testApiFormatMessagesWithoutUserObjects()
|
||||||
|
{
|
||||||
|
self::markTestIncomplete('Needs processing of "getUserObjects" first');
|
||||||
|
|
||||||
|
/*
|
||||||
|
$this->loadFixture(__DIR__ . '/../../../../datasets/mail/mail.fixture.php', DI::dba());
|
||||||
|
$ids = DI::dba()->selectToArray('mail', ['id']);
|
||||||
|
$id = $ids[0]['id'];
|
||||||
|
|
||||||
|
$directMessageFactory = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser());
|
||||||
|
$directMessageObj = $directMessageFactory->createFromMailId($id, ApiTest::SELF_USER['id'], 'plain', $$GETUSEROBJECTS$$);
|
||||||
|
$directMessage = $directMessageObj->toArray();
|
||||||
|
|
||||||
|
self::assertTrue(!isset($directMessage['sender']));
|
||||||
|
self::assertTrue(!isset($directMessage['recipient']));
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
|
@ -52,7 +52,7 @@ class SearchTest extends ApiTest
|
||||||
$directMessage = new DirectMessage(new NullLogger(), DI::dba(), DI::twitterUser());
|
$directMessage = new DirectMessage(new NullLogger(), DI::dba(), DI::twitterUser());
|
||||||
|
|
||||||
$search = new Search($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
|
$search = new Search($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
|
||||||
$response = $search->run(['searchstring' => 'test']);
|
$response = $search->run(['searchstring' => 'item_body']);
|
||||||
|
|
||||||
$json = $this->toJson($response);
|
$json = $this->toJson($response);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user