X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=tests%2Finclude%2FApiTest.php;h=ecfe3e962153756ec9c70c30e3a972e699ffe8b8;hb=d6d31f43a1a4d55ce56c1945b2c6b5b5a8728ee0;hp=e4e654f464c23bd9685fed0828bf3ea84ec15a14;hpb=e447375cddb847edbc9d4486be3938674ae66b8c;p=friendica.git diff --git a/tests/include/ApiTest.php b/tests/include/ApiTest.php index e4e654f464..ecfe3e9621 100644 --- a/tests/include/ApiTest.php +++ b/tests/include/ApiTest.php @@ -5,12 +5,16 @@ namespace Friendica\Test; -use Friendica\BaseObject; +use Friendica\App; use Friendica\Core\Config; use Friendica\Core\PConfig; use Friendica\Core\Protocol; use Friendica\Core\System; +use Friendica\Factory; use Friendica\Network\HTTPException; +use Friendica\Util\BasePath; +use Friendica\Util\Config\ConfigFileLoader; +use Monolog\Handler\TestHandler; require_once __DIR__ . '/../../include/api.php'; @@ -22,14 +26,41 @@ require_once __DIR__ . '/../../include/api.php'; */ class ApiTest extends DatabaseTest { + /** + * @var TestHandler Can handle log-outputs + */ + protected $logOutput; + + /** @var App */ + protected $app; + + /** @var array */ + protected $selfUser; + /** @var array */ + protected $friendUser; + /** @var array */ + protected $otherUser; + + protected $wrongUserId; + /** * Create variables used by tests. */ public function setUp() { - parent::setUp(); + $basePath = BasePath::create(dirname(__DIR__) . '/../'); + $mode = new App\Mode($basePath); + $router = new App\Router(); + $configLoader = new ConfigFileLoader($basePath, $mode); + $configCache = Factory\ConfigFactory::createCache($configLoader); + $profiler = Factory\ProfilerFactory::create($configCache); + Factory\DBFactory::init($basePath, $configCache, $profiler, $_SERVER); + $config = Factory\ConfigFactory::createConfig($configCache); + Factory\ConfigFactory::createPConfig($configCache); + $logger = Factory\LoggerFactory::create('test', $config, $profiler); + $this->app = new App($config, $mode, $router, $logger, $profiler, false); - $this->app = BaseObject::getApp(); + parent::setUp(); // User data that the test database is populated with $this->selfUser = [ @@ -1118,7 +1149,7 @@ class ApiTest extends DatabaseTest */ public function testApiStatusesUpdate() { - $_GET['status'] = 'Status content'; + $_GET['status'] = 'Status content #friendica'; $_GET['in_reply_to_status_id'] = -1; $_GET['lat'] = 48; $_GET['long'] = 7; @@ -1249,35 +1280,35 @@ class ApiTest extends DatabaseTest $this->assertEquals('image/png', $result['media']['image']['image_type']); $this->assertEquals(1, $result['media']['image']['w']); $this->assertEquals(1, $result['media']['image']['h']); + $this->assertNotEmpty($result['media']['image']['friendica_preview_url']); } /** * Test the api_status_show() function. - * @return void */ - public function testApiStatusShow() + public function testApiStatusShowWithJson() { - $result = api_status_show('json'); + $result = api_status_show('json', 1); $this->assertStatus($result['status']); } /** * Test the api_status_show() function with an XML result. - * @return void */ public function testApiStatusShowWithXml() { - $result = api_status_show('xml'); + $result = api_status_show('xml', 1); $this->assertXml($result, 'statuses'); } /** - * Test the api_status_show() function with a raw result. - * @return void + * Test the api_get_last_status() function */ - public function testApiStatusShowWithRaw() + public function testApiGetLastStatus() { - $this->assertStatus(api_status_show('raw')); + $item = api_get_last_status($this->selfUser['id'], $this->selfUser['id']); + + $this->assertNotNull($item); } /** @@ -1404,6 +1435,34 @@ class ApiTest extends DatabaseTest } } + /** + * Test the api_search() function with an q parameter contains hashtag. + * @return void + */ + public function testApiSearchWithHashtag() + { + $_REQUEST['q'] = '%23friendica'; + $result = api_search('json'); + foreach ($result['status'] as $status) { + $this->assertStatus($status); + $this->assertContains('#friendica', $status['text'], null, true); + } + } + + /** + * Test the api_search() function with an exclude_replies parameter. + * @return void + */ + public function testApiSearchWithExcludeReplies() + { + $_REQUEST['max_id'] = 10; + $_REQUEST['exclude_replies'] = true; + $_REQUEST['q'] = 'friendica'; + $result = api_search('json'); + foreach ($result['status'] as $status) { + $this->assertStatus($status); + } + } /** * Test the api_search() function without an authenticated user.