Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3752 lines
95KB

  1. <?php
  2. /**
  3. * ApiTest class.
  4. */
  5. namespace Friendica\Test;
  6. use Friendica\App;
  7. use Friendica\Core\Config;
  8. use Friendica\Core\Config\Cache;
  9. use Friendica\Core\PConfig;
  10. use Friendica\Core\Protocol;
  11. use Friendica\Core\System;
  12. use Friendica\Factory;
  13. use Friendica\Network\HTTPException;
  14. use Friendica\Util\BasePath;
  15. use Monolog\Handler\TestHandler;
  16. require_once __DIR__ . '/../../include/api.php';
  17. /**
  18. * Tests for the API functions.
  19. *
  20. * Functions that use header() need to be tested in a separate process.
  21. * @see https://phpunit.de/manual/5.7/en/appendixes.annotations.html#appendixes.annotations.runTestsInSeparateProcesses
  22. */
  23. class ApiTest extends DatabaseTest
  24. {
  25. /**
  26. * @var TestHandler Can handle log-outputs
  27. */
  28. protected $logOutput;
  29. /**
  30. * Create variables used by tests.
  31. */
  32. public function setUp()
  33. {
  34. $basedir = BasePath::create(dirname(__DIR__) . '/../');
  35. $configLoader = new Cache\ConfigCacheLoader($basedir);
  36. $configCache = Factory\ConfigFactory::createCache($configLoader);
  37. Factory\DBFactory::init($configCache, $_SERVER);
  38. $config = Factory\ConfigFactory::createConfig($configCache);
  39. Factory\ConfigFactory::createPConfig($configCache);
  40. $logger = Factory\LoggerFactory::create('test', $config);
  41. $profiler = Factory\ProfilerFactory::create($logger, $config);
  42. $this->app = new App($config, $logger, $profiler, false);
  43. $this->logOutput = FActory\LoggerFactory::enableTest($this->app->getLogger());
  44. parent::setUp();
  45. // User data that the test database is populated with
  46. $this->selfUser = [
  47. 'id' => 42,
  48. 'name' => 'Self contact',
  49. 'nick' => 'selfcontact',
  50. 'nurl' => 'http://localhost/profile/selfcontact'
  51. ];
  52. $this->friendUser = [
  53. 'id' => 44,
  54. 'name' => 'Friend contact',
  55. 'nick' => 'friendcontact',
  56. 'nurl' => 'http://localhost/profile/friendcontact'
  57. ];
  58. $this->otherUser = [
  59. 'id' => 43,
  60. 'name' => 'othercontact',
  61. 'nick' => 'othercontact',
  62. 'nurl' => 'http://localhost/profile/othercontact'
  63. ];
  64. // User ID that we know is not in the database
  65. $this->wrongUserId = 666;
  66. // Most API require login so we force the session
  67. $_SESSION = [
  68. 'allow_api' => true,
  69. 'authenticated' => true,
  70. 'uid' => $this->selfUser['id']
  71. ];
  72. Config::set('system', 'url', 'http://localhost');
  73. Config::set('system', 'hostname', 'localhost');
  74. Config::set('system', 'worker_dont_fork', true);
  75. // Default config
  76. Config::set('config', 'hostname', 'localhost');
  77. Config::set('system', 'throttle_limit_day', 100);
  78. Config::set('system', 'throttle_limit_week', 100);
  79. Config::set('system', 'throttle_limit_month', 100);
  80. Config::set('system', 'theme', 'system_theme');
  81. }
  82. /**
  83. * Cleanup variables used by tests.
  84. */
  85. protected function tearDown()
  86. {
  87. parent::tearDown();
  88. $this->app->argc = 1;
  89. $this->app->argv = ['home'];
  90. }
  91. /**
  92. * Assert that an user array contains expected keys.
  93. * @param array $user User array
  94. * @return void
  95. */
  96. private function assertSelfUser(array $user)
  97. {
  98. $this->assertEquals($this->selfUser['id'], $user['uid']);
  99. $this->assertEquals($this->selfUser['id'], $user['cid']);
  100. $this->assertEquals(1, $user['self']);
  101. $this->assertEquals('DFRN', $user['location']);
  102. $this->assertEquals($this->selfUser['name'], $user['name']);
  103. $this->assertEquals($this->selfUser['nick'], $user['screen_name']);
  104. $this->assertEquals('dfrn', $user['network']);
  105. $this->assertTrue($user['verified']);
  106. }
  107. /**
  108. * Assert that an user array contains expected keys.
  109. * @param array $user User array
  110. * @return void
  111. */
  112. private function assertOtherUser(array $user)
  113. {
  114. $this->assertEquals($this->otherUser['id'], $user['id']);
  115. $this->assertEquals($this->otherUser['id'], $user['id_str']);
  116. $this->assertEquals(0, $user['self']);
  117. $this->assertEquals($this->otherUser['name'], $user['name']);
  118. $this->assertEquals($this->otherUser['nick'], $user['screen_name']);
  119. $this->assertFalse($user['verified']);
  120. }
  121. /**
  122. * Assert that a status array contains expected keys.
  123. * @param array $status Status array
  124. * @return void
  125. */
  126. private function assertStatus(array $status)
  127. {
  128. $this->assertInternalType('string', $status['text']);
  129. $this->assertInternalType('int', $status['id']);
  130. // We could probably do more checks here.
  131. }
  132. /**
  133. * Assert that a list array contains expected keys.
  134. * @param array $list List array
  135. * @return void
  136. */
  137. private function assertList(array $list)
  138. {
  139. $this->assertInternalType('string', $list['name']);
  140. $this->assertInternalType('int', $list['id']);
  141. $this->assertInternalType('string', $list['id_str']);
  142. $this->assertContains($list['mode'], ['public', 'private']);
  143. // We could probably do more checks here.
  144. }
  145. /**
  146. * Assert that the string is XML and contain the root element.
  147. * @param string $result XML string
  148. * @param string $root_element Root element name
  149. * @return void
  150. */
  151. private function assertXml($result, $root_element)
  152. {
  153. $this->assertStringStartsWith('<?xml version="1.0"?>', $result);
  154. $this->assertContains('<'.$root_element, $result);
  155. // We could probably do more checks here.
  156. }
  157. /**
  158. * Get the path to a temporary empty PNG image.
  159. * @return string Path
  160. */
  161. private function getTempImage()
  162. {
  163. $tmpFile = tempnam(sys_get_temp_dir(), 'tmp_file');
  164. file_put_contents(
  165. $tmpFile,
  166. base64_decode(
  167. // Empty 1x1 px PNG image
  168. 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
  169. )
  170. );
  171. return $tmpFile;
  172. }
  173. /**
  174. * Test the api_user() function.
  175. * @return void
  176. */
  177. public function testApiUser()
  178. {
  179. $this->assertEquals($this->selfUser['id'], api_user());
  180. }
  181. /**
  182. * Test the api_user() function with an unallowed user.
  183. * @return void
  184. */
  185. public function testApiUserWithUnallowedUser()
  186. {
  187. $_SESSION = ['allow_api' => false];
  188. $this->assertEquals(false, api_user());
  189. }
  190. /**
  191. * Test the api_source() function.
  192. * @return void
  193. */
  194. public function testApiSource()
  195. {
  196. $this->assertEquals('api', api_source());
  197. }
  198. /**
  199. * Test the api_source() function with a Twidere user agent.
  200. * @return void
  201. */
  202. public function testApiSourceWithTwidere()
  203. {
  204. $_SERVER['HTTP_USER_AGENT'] = 'Twidere';
  205. $this->assertEquals('Twidere', api_source());
  206. }
  207. /**
  208. * Test the api_source() function with a GET parameter.
  209. * @return void
  210. */
  211. public function testApiSourceWithGet()
  212. {
  213. $_GET['source'] = 'source_name';
  214. $this->assertEquals('source_name', api_source());
  215. }
  216. /**
  217. * Test the api_date() function.
  218. * @return void
  219. */
  220. public function testApiDate()
  221. {
  222. $this->assertEquals('Wed Oct 10 00:00:00 +0000 1990', api_date('1990-10-10'));
  223. }
  224. /**
  225. * Test the api_register_func() function.
  226. * @return void
  227. */
  228. public function testApiRegisterFunc()
  229. {
  230. global $API;
  231. $this->assertNull(
  232. api_register_func(
  233. 'api_path',
  234. function () {
  235. },
  236. true,
  237. 'method'
  238. )
  239. );
  240. $this->assertTrue($API['api_path']['auth']);
  241. $this->assertEquals('method', $API['api_path']['method']);
  242. $this->assertTrue(is_callable($API['api_path']['func']));
  243. }
  244. /**
  245. * Test the api_login() function without any login.
  246. * @return void
  247. * @runInSeparateProcess
  248. * @expectedException Friendica\Network\HTTPException\UnauthorizedException
  249. */
  250. public function testApiLoginWithoutLogin()
  251. {
  252. api_login($this->app);
  253. }
  254. /**
  255. * Test the api_login() function with a bad login.
  256. * @return void
  257. * @runInSeparateProcess
  258. * @expectedException Friendica\Network\HTTPException\UnauthorizedException
  259. */
  260. public function testApiLoginWithBadLogin()
  261. {
  262. $_SERVER['PHP_AUTH_USER'] = 'user@server';
  263. api_login($this->app);
  264. }
  265. /**
  266. * Test the api_login() function with oAuth.
  267. * @return void
  268. */
  269. public function testApiLoginWithOauth()
  270. {
  271. $this->markTestIncomplete('Can we test this easily?');
  272. }
  273. /**
  274. * Test the api_login() function with authentication provided by an addon.
  275. * @return void
  276. */
  277. public function testApiLoginWithAddonAuth()
  278. {
  279. $this->markTestIncomplete('Can we test this easily?');
  280. }
  281. /**
  282. * Test the api_login() function with a correct login.
  283. * @return void
  284. * @runInSeparateProcess
  285. */
  286. public function testApiLoginWithCorrectLogin()
  287. {
  288. $_SERVER['PHP_AUTH_USER'] = 'Test user';
  289. $_SERVER['PHP_AUTH_PW'] = 'password';
  290. api_login($this->app);
  291. }
  292. /**
  293. * Test the api_login() function with a remote user.
  294. * @return void
  295. * @runInSeparateProcess
  296. * @expectedException Friendica\Network\HTTPException\UnauthorizedException
  297. */
  298. public function testApiLoginWithRemoteUser()
  299. {
  300. $_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
  301. api_login($this->app);
  302. }
  303. /**
  304. * Test the api_check_method() function.
  305. * @return void
  306. */
  307. public function testApiCheckMethod()
  308. {
  309. $this->assertFalse(api_check_method('method'));
  310. }
  311. /**
  312. * Test the api_check_method() function with a correct method.
  313. * @return void
  314. */
  315. public function testApiCheckMethodWithCorrectMethod()
  316. {
  317. $_SERVER['REQUEST_METHOD'] = 'method';
  318. $this->assertTrue(api_check_method('method'));
  319. }
  320. /**
  321. * Test the api_check_method() function with a wildcard.
  322. * @return void
  323. */
  324. public function testApiCheckMethodWithWildcard()
  325. {
  326. $this->assertTrue(api_check_method('*'));
  327. }
  328. /**
  329. * Test the api_call() function.
  330. * @return void
  331. * @runInSeparateProcess
  332. */
  333. public function testApiCall()
  334. {
  335. global $API;
  336. $API['api_path'] = [
  337. 'method' => 'method',
  338. 'func' => function () {
  339. return ['data' => ['some_data']];
  340. }
  341. ];
  342. $_SERVER['REQUEST_METHOD'] = 'method';
  343. $_GET['callback'] = 'callback_name';
  344. $this->app->query_string = 'api_path';
  345. $this->assertEquals(
  346. 'callback_name(["some_data"])',
  347. api_call($this->app)
  348. );
  349. }
  350. /**
  351. * Test the api_call() function with the profiled enabled.
  352. * @return void
  353. * @runInSeparateProcess
  354. */
  355. public function testApiCallWithProfiler()
  356. {
  357. global $API;
  358. $API['api_path'] = [
  359. 'method' => 'method',
  360. 'func' => function () {
  361. return ['data' => ['some_data']];
  362. }
  363. ];
  364. $_SERVER['REQUEST_METHOD'] = 'method';
  365. Config::set('system', 'profiler', true);
  366. Config::set('rendertime', 'callstack', true);
  367. $this->app->callstack = [
  368. 'database' => ['some_function' => 200],
  369. 'database_write' => ['some_function' => 200],
  370. 'cache' => ['some_function' => 200],
  371. 'cache_write' => ['some_function' => 200],
  372. 'network' => ['some_function' => 200]
  373. ];
  374. $this->app->query_string = 'api_path';
  375. $this->assertEquals(
  376. '["some_data"]',
  377. api_call($this->app)
  378. );
  379. }
  380. /**
  381. * Test the api_call() function without any result.
  382. * @return void
  383. * @runInSeparateProcess
  384. */
  385. public function testApiCallWithNoResult()
  386. {
  387. global $API;
  388. $API['api_path'] = [
  389. 'method' => 'method',
  390. 'func' => function () {
  391. return false;
  392. }
  393. ];
  394. $_SERVER['REQUEST_METHOD'] = 'method';
  395. $this->app->query_string = 'api_path';
  396. $this->assertEquals(
  397. '{"status":{"error":"Internal Server Error","code":"500 Internal Server Error","request":"api_path"}}',
  398. api_call($this->app)
  399. );
  400. }
  401. /**
  402. * Test the api_call() function with an unimplemented API.
  403. * @return void
  404. * @runInSeparateProcess
  405. */
  406. public function testApiCallWithUninplementedApi()
  407. {
  408. $this->assertEquals(
  409. '{"status":{"error":"Not Implemented","code":"501 Not Implemented","request":""}}',
  410. api_call($this->app)
  411. );
  412. }
  413. /**
  414. * Test the api_call() function with a JSON result.
  415. * @return void
  416. * @runInSeparateProcess
  417. */
  418. public function testApiCallWithJson()
  419. {
  420. global $API;
  421. $API['api_path'] = [
  422. 'method' => 'method',
  423. 'func' => function () {
  424. return ['data' => ['some_data']];
  425. }
  426. ];
  427. $_SERVER['REQUEST_METHOD'] = 'method';
  428. $this->app->query_string = 'api_path.json';
  429. $this->assertEquals(
  430. '["some_data"]',
  431. api_call($this->app)
  432. );
  433. }
  434. /**
  435. * Test the api_call() function with an XML result.
  436. * @return void
  437. * @runInSeparateProcess
  438. */
  439. public function testApiCallWithXml()
  440. {
  441. global $API;
  442. $API['api_path'] = [
  443. 'method' => 'method',
  444. 'func' => function () {
  445. return 'some_data';
  446. }
  447. ];
  448. $_SERVER['REQUEST_METHOD'] = 'method';
  449. $this->app->query_string = 'api_path.xml';
  450. $this->assertEquals(
  451. 'some_data',
  452. api_call($this->app)
  453. );
  454. }
  455. /**
  456. * Test the api_call() function with an RSS result.
  457. * @return void
  458. * @runInSeparateProcess
  459. */
  460. public function testApiCallWithRss()
  461. {
  462. global $API;
  463. $API['api_path'] = [
  464. 'method' => 'method',
  465. 'func' => function () {
  466. return 'some_data';
  467. }
  468. ];
  469. $_SERVER['REQUEST_METHOD'] = 'method';
  470. $this->app->query_string = 'api_path.rss';
  471. $this->assertEquals(
  472. '<?xml version="1.0" encoding="UTF-8"?>'."\n".
  473. 'some_data',
  474. api_call($this->app)
  475. );
  476. }
  477. /**
  478. * Test the api_call() function with an Atom result.
  479. * @return void
  480. * @runInSeparateProcess
  481. */
  482. public function testApiCallWithAtom()
  483. {
  484. global $API;
  485. $API['api_path'] = [
  486. 'method' => 'method',
  487. 'func' => function () {
  488. return 'some_data';
  489. }
  490. ];
  491. $_SERVER['REQUEST_METHOD'] = 'method';
  492. $this->app->query_string = 'api_path.atom';
  493. $this->assertEquals(
  494. '<?xml version="1.0" encoding="UTF-8"?>'."\n".
  495. 'some_data',
  496. api_call($this->app)
  497. );
  498. }
  499. /**
  500. * Test the api_call() function with an unallowed method.
  501. * @return void
  502. * @runInSeparateProcess
  503. */
  504. public function testApiCallWithWrongMethod()
  505. {
  506. global $API;
  507. $API['api_path'] = ['method' => 'method'];
  508. $this->app->query_string = 'api_path';
  509. $this->assertEquals(
  510. '{"status":{"error":"Method Not Allowed","code":"405 Method Not Allowed","request":"api_path"}}',
  511. api_call($this->app)
  512. );
  513. }
  514. /**
  515. * Test the api_call() function with an unauthorized user.
  516. * @return void
  517. * @runInSeparateProcess
  518. */
  519. public function testApiCallWithWrongAuth()
  520. {
  521. global $API;
  522. $API['api_path'] = [
  523. 'method' => 'method',
  524. 'auth' => true
  525. ];
  526. $_SERVER['REQUEST_METHOD'] = 'method';
  527. $_SESSION['authenticated'] = false;
  528. $this->app->query_string = 'api_path';
  529. $this->assertEquals(
  530. '{"status":{"error":"This API requires login","code":"401 Unauthorized","request":"api_path"}}',
  531. api_call($this->app)
  532. );
  533. }
  534. /**
  535. * Test the api_error() function with a JSON result.
  536. * @return void
  537. * @runInSeparateProcess
  538. */
  539. public function testApiErrorWithJson()
  540. {
  541. $this->assertEquals(
  542. '{"status":{"error":"error_message","code":"200 Friendica\\\\Network\\\\HTTP","request":""}}',
  543. api_error('json', new HTTPException('error_message'))
  544. );
  545. }
  546. /**
  547. * Test the api_error() function with an XML result.
  548. * @return void
  549. * @runInSeparateProcess
  550. */
  551. public function testApiErrorWithXml()
  552. {
  553. $this->assertEquals(
  554. '<?xml version="1.0"?>'."\n".
  555. '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
  556. 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
  557. 'xmlns:georss="http://www.georss.org/georss">'."\n".
  558. ' <error>error_message</error>'."\n".
  559. ' <code>200 Friendica\Network\HTTP</code>'."\n".
  560. ' <request/>'."\n".
  561. '</status>'."\n",
  562. api_error('xml', new HTTPException('error_message'))
  563. );
  564. }
  565. /**
  566. * Test the api_error() function with an RSS result.
  567. * @return void
  568. * @runInSeparateProcess
  569. */
  570. public function testApiErrorWithRss()
  571. {
  572. $this->assertEquals(
  573. '<?xml version="1.0"?>'."\n".
  574. '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
  575. 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
  576. 'xmlns:georss="http://www.georss.org/georss">'."\n".
  577. ' <error>error_message</error>'."\n".
  578. ' <code>200 Friendica\Network\HTTP</code>'."\n".
  579. ' <request/>'."\n".
  580. '</status>'."\n",
  581. api_error('rss', new HTTPException('error_message'))
  582. );
  583. }
  584. /**
  585. * Test the api_error() function with an Atom result.
  586. * @return void
  587. * @runInSeparateProcess
  588. */
  589. public function testApiErrorWithAtom()
  590. {
  591. $this->assertEquals(
  592. '<?xml version="1.0"?>'."\n".
  593. '<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
  594. 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
  595. 'xmlns:georss="http://www.georss.org/georss">'."\n".
  596. ' <error>error_message</error>'."\n".
  597. ' <code>200 Friendica\Network\HTTP</code>'."\n".
  598. ' <request/>'."\n".
  599. '</status>'."\n",
  600. api_error('atom', new HTTPException('error_message'))
  601. );
  602. }
  603. /**
  604. * Test the api_rss_extra() function.
  605. * @return void
  606. */
  607. public function testApiRssExtra()
  608. {
  609. $user_info = ['url' => 'user_url', 'lang' => 'en'];
  610. $result = api_rss_extra($this->app, [], $user_info);
  611. $this->assertEquals($user_info, $result['$user']);
  612. $this->assertEquals($user_info['url'], $result['$rss']['alternate']);
  613. $this->assertArrayHasKey('self', $result['$rss']);
  614. $this->assertArrayHasKey('base', $result['$rss']);
  615. $this->assertArrayHasKey('updated', $result['$rss']);
  616. $this->assertArrayHasKey('atom_updated', $result['$rss']);
  617. $this->assertArrayHasKey('language', $result['$rss']);
  618. $this->assertArrayHasKey('logo', $result['$rss']);
  619. }
  620. /**
  621. * Test the api_rss_extra() function without any user info.
  622. * @return void
  623. * @runInSeparateProcess
  624. */
  625. public function testApiRssExtraWithoutUserInfo()
  626. {
  627. $result = api_rss_extra($this->app, [], null);
  628. $this->assertInternalType('array', $result['$user']);
  629. $this->assertArrayHasKey('alternate', $result['$rss']);
  630. $this->assertArrayHasKey('self', $result['$rss']);
  631. $this->assertArrayHasKey('base', $result['$rss']);
  632. $this->assertArrayHasKey('updated', $result['$rss']);
  633. $this->assertArrayHasKey('atom_updated', $result['$rss']);
  634. $this->assertArrayHasKey('language', $result['$rss']);
  635. $this->assertArrayHasKey('logo', $result['$rss']);
  636. }
  637. /**
  638. * Test the api_unique_id_to_nurl() function.
  639. * @return void
  640. */
  641. public function testApiUniqueIdToNurl()
  642. {
  643. $this->assertFalse(api_unique_id_to_nurl($this->wrongUserId));
  644. }
  645. /**
  646. * Test the api_unique_id_to_nurl() function with a correct ID.
  647. * @return void
  648. */
  649. public function testApiUniqueIdToNurlWithCorrectId()
  650. {
  651. $this->assertEquals($this->otherUser['nurl'], api_unique_id_to_nurl($this->otherUser['id']));
  652. }
  653. /**
  654. * Test the api_get_user() function.
  655. * @return void
  656. * @runInSeparateProcess
  657. */
  658. public function testApiGetUser()
  659. {
  660. $user = api_get_user($this->app);
  661. $this->assertSelfUser($user);
  662. $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
  663. $this->assertEquals('6fdbe8', $user['profile_link_color']);
  664. $this->assertEquals('ededed', $user['profile_background_color']);
  665. }
  666. /**
  667. * Test the api_get_user() function with a Frio schema.
  668. * @return void
  669. * @runInSeparateProcess
  670. */
  671. public function testApiGetUserWithFrioSchema()
  672. {
  673. PConfig::set($this->selfUser['id'], 'frio', 'schema', 'red');
  674. $user = api_get_user($this->app);
  675. $this->assertSelfUser($user);
  676. $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
  677. $this->assertEquals('6fdbe8', $user['profile_link_color']);
  678. $this->assertEquals('ededed', $user['profile_background_color']);
  679. }
  680. /**
  681. * Test the api_get_user() function with a custom Frio schema.
  682. * @return void
  683. * @runInSeparateProcess
  684. */
  685. public function testApiGetUserWithCustomFrioSchema()
  686. {
  687. $ret1 = PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
  688. $ret2 = PConfig::set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
  689. $ret3 = PConfig::set($this->selfUser['id'], 'frio', 'link_color', '#123456');
  690. $ret4 = PConfig::set($this->selfUser['id'], 'frio', 'background_color', '#123456');
  691. $user = api_get_user($this->app);
  692. $this->assertSelfUser($user);
  693. $this->assertEquals('123456', $user['profile_sidebar_fill_color']);
  694. $this->assertEquals('123456', $user['profile_link_color']);
  695. $this->assertEquals('123456', $user['profile_background_color']);
  696. }
  697. /**
  698. * Test the api_get_user() function with an empty Frio schema.
  699. * @return void
  700. * @runInSeparateProcess
  701. */
  702. public function testApiGetUserWithEmptyFrioSchema()
  703. {
  704. PConfig::set($this->selfUser['id'], 'frio', 'schema', '---');
  705. $user = api_get_user($this->app);
  706. $this->assertSelfUser($user);
  707. $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
  708. $this->assertEquals('6fdbe8', $user['profile_link_color']);
  709. $this->assertEquals('ededed', $user['profile_background_color']);
  710. }
  711. /**
  712. * Test the api_get_user() function with an user that is not allowed to use the API.
  713. * @return void
  714. * @runInSeparateProcess
  715. */
  716. public function testApiGetUserWithoutApiUser()
  717. {
  718. $_SERVER['PHP_AUTH_USER'] = 'Test user';
  719. $_SERVER['PHP_AUTH_PW'] = 'password';
  720. $_SESSION['allow_api'] = false;
  721. $this->assertFalse(api_get_user($this->app));
  722. }
  723. /**
  724. * Test the api_get_user() function with an user ID in a GET parameter.
  725. * @return void
  726. * @runInSeparateProcess
  727. */
  728. public function testApiGetUserWithGetId()
  729. {
  730. $_GET['user_id'] = $this->otherUser['id'];
  731. $this->assertOtherUser(api_get_user($this->app));
  732. }
  733. /**
  734. * Test the api_get_user() function with a wrong user ID in a GET parameter.
  735. * @return void
  736. * @runInSeparateProcess
  737. * @expectedException Friendica\Network\HTTPException\BadRequestException
  738. */
  739. public function testApiGetUserWithWrongGetId()
  740. {
  741. $_GET['user_id'] = $this->wrongUserId;
  742. $this->assertOtherUser(api_get_user($this->app));
  743. }
  744. /**
  745. * Test the api_get_user() function with an user name in a GET parameter.
  746. * @return void
  747. * @runInSeparateProcess
  748. */
  749. public function testApiGetUserWithGetName()
  750. {
  751. $_GET['screen_name'] = $this->selfUser['nick'];
  752. $this->assertSelfUser(api_get_user($this->app));
  753. }
  754. /**
  755. * Test the api_get_user() function with a profile URL in a GET parameter.
  756. * @return void
  757. * @runInSeparateProcess
  758. */
  759. public function testApiGetUserWithGetUrl()
  760. {
  761. $_GET['profileurl'] = $this->selfUser['nurl'];
  762. $this->assertSelfUser(api_get_user($this->app));
  763. }
  764. /**
  765. * Test the api_get_user() function with an user ID in the API path.
  766. * @return void
  767. * @runInSeparateProcess
  768. */
  769. public function testApiGetUserWithNumericCalledApi()
  770. {
  771. global $called_api;
  772. $called_api = ['api_path'];
  773. $this->app->argv[1] = $this->otherUser['id'].'.json';
  774. $this->assertOtherUser(api_get_user($this->app));
  775. }
  776. /**
  777. * Test the api_get_user() function with the $called_api global variable.
  778. * @return void
  779. * @runInSeparateProcess
  780. */
  781. public function testApiGetUserWithCalledApi()
  782. {
  783. global $called_api;
  784. $called_api = ['api', 'api_path'];
  785. $this->assertSelfUser(api_get_user($this->app));
  786. }
  787. /**
  788. * Test the api_get_user() function with a valid user.
  789. * @return void
  790. * @runInSeparateProcess
  791. */
  792. public function testApiGetUserWithCorrectUser()
  793. {
  794. $this->assertOtherUser(api_get_user($this->app, $this->otherUser['id']));
  795. }
  796. /**
  797. * Test the api_get_user() function with a wrong user ID.
  798. * @return void
  799. * @runInSeparateProcess
  800. * @expectedException Friendica\Network\HTTPException\BadRequestException
  801. */
  802. public function testApiGetUserWithWrongUser()
  803. {
  804. $this->assertOtherUser(api_get_user($this->app, $this->wrongUserId));
  805. }
  806. /**
  807. * Test the api_get_user() function with a 0 user ID.
  808. * @return void
  809. * @runInSeparateProcess
  810. */
  811. public function testApiGetUserWithZeroUser()
  812. {
  813. $this->assertSelfUser(api_get_user($this->app, 0));
  814. }
  815. /**
  816. * Test the api_item_get_user() function.
  817. * @return void
  818. * @runInSeparateProcess
  819. */
  820. public function testApiItemGetUser()
  821. {
  822. $users = api_item_get_user($this->app, []);
  823. $this->assertSelfUser($users[0]);
  824. }
  825. /**
  826. * Test the api_item_get_user() function with a different item parent.
  827. * @return void
  828. */
  829. public function testApiItemGetUserWithDifferentParent()
  830. {
  831. $users = api_item_get_user($this->app, ['thr-parent' => 'item_parent', 'uri' => 'item_uri']);
  832. $this->assertSelfUser($users[0]);
  833. $this->assertEquals($users[0], $users[1]);
  834. }
  835. /**
  836. * Test the api_walk_recursive() function.
  837. * @return void
  838. */
  839. public function testApiWalkRecursive()
  840. {
  841. $array = ['item1'];
  842. $this->assertEquals(
  843. $array,
  844. api_walk_recursive(
  845. $array,
  846. function () {
  847. // Should we test this with a callback that actually does something?
  848. return true;
  849. }
  850. )
  851. );
  852. }
  853. /**
  854. * Test the api_walk_recursive() function with an array.
  855. * @return void
  856. */
  857. public function testApiWalkRecursiveWithArray()
  858. {
  859. $array = [['item1'], ['item2']];
  860. $this->assertEquals(
  861. $array,
  862. api_walk_recursive(
  863. $array,
  864. function () {
  865. // Should we test this with a callback that actually does something?
  866. return true;
  867. }
  868. )
  869. );
  870. }
  871. /**
  872. * Test the api_reformat_xml() function.
  873. * @return void
  874. */
  875. public function testApiReformatXml()
  876. {
  877. $item = true;
  878. $key = '';
  879. $this->assertTrue(api_reformat_xml($item, $key));
  880. $this->assertEquals('true', $item);
  881. }
  882. /**
  883. * Test the api_reformat_xml() function with a statusnet_api key.
  884. * @return void
  885. */
  886. public function testApiReformatXmlWithStatusnetKey()
  887. {
  888. $item = '';
  889. $key = 'statusnet_api';
  890. $this->assertTrue(api_reformat_xml($item, $key));
  891. $this->assertEquals('statusnet:api', $key);
  892. }
  893. /**
  894. * Test the api_reformat_xml() function with a friendica_api key.
  895. * @return void
  896. */
  897. public function testApiReformatXmlWithFriendicaKey()
  898. {
  899. $item = '';
  900. $key = 'friendica_api';
  901. $this->assertTrue(api_reformat_xml($item, $key));
  902. $this->assertEquals('friendica:api', $key);
  903. }
  904. /**
  905. * Test the api_create_xml() function.
  906. * @return void
  907. */
  908. public function testApiCreateXml()
  909. {
  910. $this->assertEquals(
  911. '<?xml version="1.0"?>'."\n".
  912. '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
  913. 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
  914. 'xmlns:georss="http://www.georss.org/georss">'."\n".
  915. ' <data>some_data</data>'."\n".
  916. '</root_element>'."\n",
  917. api_create_xml(['data' => ['some_data']], 'root_element')
  918. );
  919. }
  920. /**
  921. * Test the api_create_xml() function without any XML namespace.
  922. * @return void
  923. */
  924. public function testApiCreateXmlWithoutNamespaces()
  925. {
  926. $this->assertEquals(
  927. '<?xml version="1.0"?>'."\n".
  928. '<ok>'."\n".
  929. ' <data>some_data</data>'."\n".
  930. '</ok>'."\n",
  931. api_create_xml(['data' => ['some_data']], 'ok')
  932. );
  933. }
  934. /**
  935. * Test the api_format_data() function.
  936. * @return void
  937. */
  938. public function testApiFormatData()
  939. {
  940. $data = ['some_data'];
  941. $this->assertEquals($data, api_format_data('root_element', 'json', $data));
  942. }
  943. /**
  944. * Test the api_format_data() function with an XML result.
  945. * @return void
  946. */
  947. public function testApiFormatDataWithXml()
  948. {
  949. $this->assertEquals(
  950. '<?xml version="1.0"?>'."\n".
  951. '<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
  952. 'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
  953. 'xmlns:georss="http://www.georss.org/georss">'."\n".
  954. ' <data>some_data</data>'."\n".
  955. '</root_element>'."\n",
  956. api_format_data('root_element', 'xml', ['data' => ['some_data']])
  957. );
  958. }
  959. /**
  960. * Test the api_account_verify_credentials() function.
  961. * @return void
  962. */
  963. public function testApiAccountVerifyCredentials()
  964. {
  965. $this->assertArrayHasKey('user', api_account_verify_credentials('json'));
  966. }
  967. /**
  968. * Test the api_account_verify_credentials() function without an authenticated user.
  969. * @return void
  970. * @expectedException Friendica\Network\HTTPException\ForbiddenException
  971. */
  972. public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
  973. {
  974. $_SESSION['authenticated'] = false;
  975. api_account_verify_credentials('json');
  976. }
  977. /**
  978. * Test the requestdata() function.
  979. * @return void
  980. */
  981. public function testRequestdata()
  982. {
  983. $this->assertNull(requestdata('variable_name'));
  984. }
  985. /**
  986. * Test the requestdata() function with a POST parameter.
  987. * @return void
  988. */
  989. public function testRequestdataWithPost()
  990. {
  991. $_POST['variable_name'] = 'variable_value';
  992. $this->assertEquals('variable_value', requestdata('variable_name'));
  993. }
  994. /**
  995. * Test the requestdata() function with a GET parameter.
  996. * @return void
  997. */
  998. public function testRequestdataWithGet()
  999. {
  1000. $_GET['variable_name'] = 'variable_value';
  1001. $this->assertEquals('variable_value', requestdata('variable_name'));
  1002. }
  1003. /**
  1004. * Test the api_statuses_mediap() function.
  1005. * @return void
  1006. */
  1007. public function testApiStatusesMediap()
  1008. {
  1009. $this->app->argc = 2;
  1010. $_FILES = [
  1011. 'media' => [
  1012. 'id' => 666,
  1013. 'size' => 666,
  1014. 'width' => 666,
  1015. 'height' => 666,
  1016. 'tmp_name' => $this->getTempImage(),
  1017. 'name' => 'spacer.png',
  1018. 'type' => 'image/png'
  1019. ]
  1020. ];
  1021. $_GET['status'] = '<b>Status content</b>';
  1022. $result = api_statuses_mediap('json');
  1023. $this->assertStatus($result['status']);
  1024. }
  1025. /**
  1026. * Test the api_statuses_mediap() function without an authenticated user.
  1027. * @return void
  1028. * @expectedException Friendica\Network\HTTPException\ForbiddenException
  1029. */
  1030. public function testApiStatusesMediapWithoutAuthenticatedUser()
  1031. {
  1032. $_SESSION['authenticated'] = false;
  1033. api_statuses_mediap('json');
  1034. }
  1035. /**
  1036. * Test the api_statuses_update() function.
  1037. * @return void
  1038. */
  1039. public function testApiStatusesUpdate()
  1040. {
  1041. $_GET['status'] = 'Status content #friendica';
  1042. $_GET['in_reply_to_status_id'] = -1;
  1043. $_GET['lat'] = 48;
  1044. $_GET['long'] = 7;
  1045. $_FILES = [
  1046. 'media' => [
  1047. 'id' => 666,
  1048. 'size' => 666,
  1049. 'width' => 666,
  1050. 'height' => 666,
  1051. 'tmp_name' => $this->getTempImage(),
  1052. 'name' => 'spacer.png',
  1053. 'type' => 'image/png'
  1054. ]
  1055. ];
  1056. $result = api_statuses_update('json');
  1057. $this->assertStatus($result['status']);
  1058. }
  1059. /**
  1060. * Test the api_statuses_update() function with an HTML status.
  1061. * @return void
  1062. */
  1063. public function testApiStatusesUpdateWithHtml()
  1064. {
  1065. $_GET['htmlstatus'] = '<b>Status content</b>';
  1066. $result = api_statuses_update('json');
  1067. $this->assertStatus($result['status']);
  1068. }
  1069. /**
  1070. * Test the api_statuses_update() function without an authenticated user.
  1071. * @return void
  1072. * @expectedException Friendica\Network\HTTPException\ForbiddenException
  1073. */
  1074. public function testApiStatusesUpdateWithoutAuthenticatedUser()
  1075. {
  1076. $_SESSION['authenticated'] = false;
  1077. api_statuses_update('json');
  1078. }
  1079. /**
  1080. * Test the api_statuses_update() function with a parent status.
  1081. * @return void
  1082. */
  1083. public function testApiStatusesUpdateWithParent()
  1084. {
  1085. $this->markTestIncomplete('This triggers an exit() somewhere and kills PHPUnit.');
  1086. }
  1087. /**
  1088. * Test the api_statuses_update() function with a media_ids parameter.
  1089. * @return void
  1090. */
  1091. public function testApiStatusesUpdateWithMediaIds()
  1092. {
  1093. $this->markTestIncomplete();
  1094. }
  1095. /**
  1096. * Test the api_statuses_update() function with the throttle limit reached.
  1097. * @return void
  1098. */
  1099. public function testApiStatusesUpdateWithDayThrottleReached()
  1100. {
  1101. $this->markTestIncomplete();
  1102. }
  1103. /**
  1104. * Test the api_media_upload() function.
  1105. * @return void
  1106. * @expectedException Friendica\Network\HTTPException\BadRequestException
  1107. */
  1108. public function testApiMediaUpload()
  1109. {
  1110. api_media_upload();
  1111. }
  1112. /**
  1113. * Test the api_media_upload() function without an authenticated user.
  1114. * @return void
  1115. * @expectedException Friendica\Network\HTTPException\ForbiddenException
  1116. */
  1117. public function testApiMediaUploadWithoutAuthenticatedUser()
  1118. {
  1119. $_SESSION['authenticated'] = false;
  1120. api_media_upload();
  1121. }
  1122. /**
  1123. * Test the api_media_upload() function with an invalid uploaded media.
  1124. * @return void
  1125. * @expectedException Friendica\Network\HTTPException\InternalServerErrorException
  1126. */
  1127. public function testApiMediaUploadWithMedia()
  1128. {
  1129. $_FILES = [
  1130. 'media' => [
  1131. 'id' => 666,
  1132. 'tmp_name' => 'tmp_name'
  1133. ]
  1134. ];
  1135. api_media_upload();
  1136. }
  1137. /**
  1138. * Test the api_media_upload() function with an valid uploaded media.
  1139. * @return void
  1140. */
  1141. public function testApiMediaUploadWithValidMedia()
  1142. {
  1143. $_FILES = [
  1144. 'media' => [
  1145. 'id' => 666,
  1146. 'size' => 666,
  1147. 'width' => 666,
  1148. 'height' => 666,
  1149. 'tmp_name' => $this->getTempImage(),
  1150. 'name' => 'spacer.png',
  1151. 'type' => 'image/png'
  1152. ]
  1153. ];
  1154. $app = \get_app();
  1155. $app->argc = 2;
  1156. $result = api_media_upload();
  1157. $this->assertEquals('image/png', $result['media']['image']['image_type']);
  1158. $this->assertEquals(1, $result['media']['image']['w']);
  1159. $this->assertEquals(1, $result['media']['image']['h']);
  1160. $this->assertNotEmpty($result['media']['image']['friendica_preview_url']);
  1161. }
  1162. /**
  1163. * Test the api_status_show() function.
  1164. * @return void
  1165. */
  1166. public function testApiStatusShow()
  1167. {
  1168. $result = api_status_show('json');
  1169. $this->assertStatus($result['status']);
  1170. }
  1171. /**
  1172. * Test the api_status_show() function with an XML result.
  1173. * @return void
  1174. */
  1175. public function testApiStatusShowWithXml()
  1176. {
  1177. $result = api_status_show('xml');
  1178. $this->assertXml($result, 'statuses');
  1179. }
  1180. /**
  1181. * Test the api_status_show() function with a raw result.
  1182. * @return void
  1183. */
  1184. public function testApiStatusShowWithRaw()
  1185. {
  1186. $this->assertStatus(api_status_show('raw'));
  1187. }
  1188. /**
  1189. * Test the api_users_show() function.
  1190. * @return void
  1191. */
  1192. public function testApiUsersShow()
  1193. {
  1194. $result = api_users_show('json');
  1195. // We can't use assertSelfUser() here because the user object is missing some properties.
  1196. $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
  1197. $this->assertEquals('DFRN', $result['user']['location']);
  1198. $this->assertEquals($this->selfUser['name'], $result['user']['name']);
  1199. $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
  1200. $this->assertEquals('dfrn', $result['user']['network']);
  1201. $this->assertTrue($result['user']['verified']);
  1202. }
  1203. /**
  1204. * Test the api_users_show() function with an XML result.
  1205. * @return void
  1206. */
  1207. public function testApiUsersShowWithXml()
  1208. {
  1209. $result = api_users_show('xml');
  1210. $this->assertXml($result, 'statuses');
  1211. }
  1212. /**
  1213. * Test the api_users_search() function.
  1214. * @return void
  1215. */
  1216. public function testApiUsersSearch()
  1217. {
  1218. $_GET['q'] = 'othercontact';
  1219. $result = api_users_search('json');
  1220. $this->assertOtherUser($result['users'][0]);
  1221. }
  1222. /**
  1223. * Test the api_users_search() function with an XML result.
  1224. * @return void
  1225. */
  1226. public function testApiUsersSearchWithXml()
  1227. {
  1228. $_GET['q'] = 'othercontact';
  1229. $result = api_users_search('xml');
  1230. $this->assertXml($result, 'users');
  1231. }
  1232. /**
  1233. * Test the api_users_search() function without a GET q parameter.
  1234. * @return void
  1235. * @expectedException Friendica\Network\HTTPException\BadRequestException
  1236. */
  1237. public function testApiUsersSearchWithoutQuery()
  1238. {
  1239. api_users_search('json');
  1240. }
  1241. /**
  1242. * Test the api_users_lookup() function.
  1243. * @return void
  1244. * @expectedException Friendica\Network\HTTPException\NotFoundException
  1245. */
  1246. public function testApiUsersLookup()
  1247. {
  1248. api_users_lookup('json');
  1249. }
  1250. /**
  1251. * Test the api_users_lookup() function with an user ID.
  1252. * @return void
  1253. */
  1254. public function testApiUsersLookupWithUserId()
  1255. {
  1256. $_REQUEST['user_id'] = $this->otherUser['id'];
  1257. $result = api_users_lookup('json');
  1258. $this->assertOtherUser($result['users'][0]);
  1259. }
  1260. /**
  1261. * Test the api_search() function.
  1262. * @return void
  1263. */
  1264. public function testApiSearch()
  1265. {
  1266. $_REQUEST['q'] = 'reply';
  1267. $_REQUEST['max_id'] = 10;
  1268. $result = api_search('json');
  1269. foreach ($result['status'] as $status) {
  1270. $this->assertStatus($status);
  1271. $this->assertContains('reply', $status['text'], null, true);
  1272. }
  1273. }
  1274. /**
  1275. * Test the api_search() function a count parameter.
  1276. * @return void
  1277. */
  1278. public function testApiSearchWithCount()
  1279. {
  1280. $_REQUEST['q'] = 'reply';
  1281. $_REQUEST['count'] = 20;
  1282. $result = api_search('json');
  1283. foreach ($result['status'] as $status) {
  1284. $this->assertStatus($status);
  1285. $this->assertContains('reply', $status['text'], null, true);
  1286. }
  1287. }
  1288. /**
  1289. * Test the api_search() function with an rpp parameter.
  1290. * @return void
  1291. */
  1292. public function testApiSearchWithRpp()
  1293. {
  1294. $_REQUEST['q'] = 'reply';
  1295. $_REQUEST['rpp'] = 20;
  1296. $result = api_search('json');
  1297. foreach ($result['status'] as $status) {
  1298. $this->assertStatus($status);
  1299. $this->assertContains('reply', $status['text'], null, true);
  1300. }
  1301. }
  1302. /**
  1303. * Test the api_search() function with an q parameter contains hashtag.
  1304. * @return void
  1305. */
  1306. public function testApiSearchWithHashtag()
  1307. {
  1308. $_REQUEST['q'] = '%23friendica';
  1309. $result = api_search('json');
  1310. foreach ($result['status'] as $status) {
  1311. $this->assertStatus($status);
  1312. $this->assertContains('#friendica', $status['text'], null, true);
  1313. }
  1314. }
  1315. /**
  1316. * Test the api_search() function with an exclude_replies parameter.
  1317. * @return void
  1318. */
  1319. public function testApiSearchWithExcludeReplies()
  1320. {
  1321. $_REQUEST['max_id'] = 10;
  1322. $_REQUEST['exclude_replies'] = true;
  1323. $_REQUEST['q'] = 'friendica';
  1324. $result = api_search('json');
  1325. foreach ($result['status'] as $status) {
  1326. $this->assertStatus($status);
  1327. }
  1328. }
  1329. /**
  1330. * Test the api_search() function without an authenticated user.
  1331. * @return void
  1332. * @expectedException Friendica\Network\HTTPException\ForbiddenException
  1333. */
  1334. public function testApiSearchWithUnallowedUser()
  1335. {
  1336. $_SESSION['allow_api'] = false;
  1337. $_GET['screen_name'] = $this->selfUser['nick'];
  1338. api_search('json');
  1339. }
  1340. /**
  1341. * Test the api_search() function without any GET query parameter.
  1342. * @return void
  1343. * @expectedException Friendica\Network\HTTPException\BadRequestException
  1344. */
  1345. public function testApiSearchWithoutQuery()
  1346. {
  1347. api_search('json');
  1348. }
  1349. /**
  1350. * Test the api_statuses_home_timeline() function.
  1351. * @return void
  1352. */
  1353. public function testApiStatusesHomeTimeline()
  1354. {
  1355. $_REQUEST['max_id'] = 10;
  1356. $_REQUEST['exclude_replies'] = true;
  1357. $_REQUEST['conversation_id'] = 1;
  1358. $result = api_statuses_home_timeline('json');
  1359. $this->assertNotEmpty($result['status']);
  1360. foreach ($result['status'] as $status) {
  1361. $this->assertStatus($status);
  1362. }
  1363. }
  1364. /**
  1365. * Test the api_statuses_home_timeline() function with a negative page parameter.
  1366. * @return void
  1367. */
  1368. public function testApiStatusesHomeTimelineWithNegativePage()
  1369. {
  1370. $_REQUEST['page'] = -2;
  1371. $result = api_statuses_home_timeline('json');
  1372. $this->assertNotEmpty($result['status']);
  1373. foreach ($result['status'] as $status) {
  1374. $this->assertStatus($status);
  1375. }
  1376. }
  1377. /**
  1378. * Test the api_statuses_home_timeline() with an unallowed user.
  1379. * @return void
  1380. * @expectedException Friendica\Network\HTTPException\ForbiddenException
  1381. */
  1382. public function testApiStatusesHomeTimelineWithUnallowedUser()
  1383. {
  1384. $_SESSION['allow_api'] = false;
  1385. $_GET['screen_name'] = $this->selfUser['nick'];
  1386. api_statuses_home_timeline('json');
  1387. }
  1388. /**
  1389. * Test the api_statuses_home_timeline() function with an RSS result.
  1390. * @return void
  1391. */
  1392. public function testApiStatusesHomeTimelineWithRss()
  1393. {
  1394. $result = api_statuses_home_timeline('rss');
  1395. $this->assertXml($result, 'statuses');
  1396. }
  1397. /**
  1398. * Test the api_statuses_public_timeline() function.
  1399. * @return void
  1400. */
  1401. public function testApiStatusesPublicTimeline()
  1402. {
  1403. $_REQUEST['max_id'] = 10;
  1404. $_REQUEST['conversation_id'] = 1;
  1405. $result = api_statuses_public_timeline('json');
  1406. $this->assertNotEmpty($result['status']);
  1407. foreach ($result['status'] as $status) {
  1408. $this->assertStatus($status);
  1409. }
  1410. }
  1411. /**
  1412. * Test the api_statuses_public_timeline() function with the exclude_replies parameter.
  1413. * @return void
  1414. */
  1415. public function testApiStatusesPublicTimelineWithExcludeReplies()
  1416. {
  1417. $_REQUEST['max_id'] = 10;
  1418. $_REQUEST['exclude_replies'] = true;
  1419. $result = api_statuses_public_timeline('json');
  1420. $this->assertNotEmpty($result['status']);
  1421. foreach ($result['status'] as $status) {
  1422. $this->assertStatus($status);
  1423. }
  1424. }
  1425. /**
  1426. * Test the api_statuses_public_timeline() function with a negative page parameter.
  1427. * @return void
  1428. */
  1429. public function testApiStatusesPublicTimelineWithNegativePage()
  1430. {
  1431. $_REQUEST['page'] = -2;
  1432. $result = api_statuses_public_timeline('json');
  1433. $this->assertNotEmpty($result['status']);
  1434. foreach ($result['status'] as $status) {
  1435. $this->assertStatus($status);
  1436. }
  1437. }
  1438. /**
  1439. * Test the api_statuses_public_timeline() function with an unallowed user.
  1440. * @return void
  1441. * @expectedException Friendica\Network\HTTPException\ForbiddenException
  1442. */
  1443. public function testApiStatusesPublicTimelineWithUnallowedUser()
  1444. {
  1445. $_SESSION['allow_api'] = false;
  1446. $_GET['screen_name'] = $this->selfUser['nick'];
  1447. api_statuses_public_timeline('json');
  1448. }
  1449. /**
  1450. * Test the api_statuses_public_timeline() function with an RSS result.
  1451. * @return void
  1452. */
  1453. public function testApiStatusesPublicTimelineWithRss()
  1454. {
  1455. $result = api_statuses_public_timeline('rss');
  1456. $this->assertXml($result, 'statuses');
  1457. }
  1458. /**
  1459. * Test the api_statuses_networkpublic_timeline() function.
  1460. * @return void
  1461. */
  1462. public function testApiStatusesNetworkpublicTimeline()
  1463. {
  1464. $_REQUEST['max_id'] = 10;
  1465. $result = api_statuses_networkpublic_timeline('json');
  1466. $this->assertNotEmpty($result['status']);
  1467. foreach ($result['status'] as $status) {
  1468. $this->assertStatus($status);
  1469. }
  1470. }
  1471. /**
  1472. * Test the api_statuses_networkpublic_timeline() function with a negative page parameter.
  1473. * @return void
  1474. */
  1475. public function testApiStatusesNetworkpublicTimelineWithNegativePage()
  1476. {
  1477. $_REQUEST['page'] = -2;
  1478. $result = api_statuses_networkpublic_timeline('json');
  1479. $this->assertNotEmpty($result['status']);
  1480. foreach ($result['status'] as $status) {
  1481. $this->assertStatus($status);
  1482. }
  1483. }
  1484. /**
  1485. * Test the api_statuses_networkpublic_timeline() function with an unallowed user.
  1486. * @return void
  1487. * @expectedException Friendica\Network\HTTPException\ForbiddenException
  1488. */
  1489. public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
  1490. {
  1491. $_SESSION['allow_api'] = false;
  1492. $_GET['screen_name'] = $this->selfUser['nick'];
  1493. api_statuses_networkpublic_timeline('json');
  1494. }
  1495. /**
  1496. * Test the api_statuses_networkpublic_timeline() function with an RSS result.
  1497. * @return void
  1498. */
  1499. public function testApiStatusesNetworkpublicTimelineWithRss()
  1500. {
  1501. $result = api_statuses_networkpublic_timeline('rss');
  1502. $this->assertXml($result, 'statuses');
  1503. }
  1504. /**
  1505. * Test the api_statuses_show() function.
  1506. * @return void
  1507. * @expectedException Friendica\Network\HTTPException\BadRequestException
  1508. */
  1509. public function testApiStatusesShow()
  1510. {
  1511. api_statuses_show('json');
  1512. }
  1513. /**
  1514. * Test the api_statuses_show() function with an ID.
  1515. * @return void
  1516. */
  1517. public function testApiStatusesShowWithId()
  1518. {
  1519. $this->app->argv[3] = 1;
  1520. $result = api_statuses_show('json');
  1521. $this->assertStatus($result['status']);
  1522. }
  1523. /**
  1524. * Test the api_statuses_show() function with the conversation parameter.
  1525. * @return void
  1526. */
  1527. public function testApiStatusesShowWithConversation()
  1528. {
  1529. $this->app->argv[3] = 1;
  1530. $_REQUEST['conversation'] = 1;
  1531. $result = api_statuses_show('json');
  1532. $this->assertNotEmpty($result['status']);
  1533. foreach ($result['status'] as $status) {
  1534. $this->assertStatus($status);
  1535. }
  1536. }
  1537. /**
  1538. * Test the api_statuses_show() function with an unallowed user.
  1539. * @return void
  1540. * @expectedException Friendica\Network\HTTPException\ForbiddenException
  1541. */
  1542. public function testApiStatusesShowWithUnallowedUser()
  1543. {
  1544. $_SESSION['allow_api'] = false;
  1545. $_GET['screen_name'] = $this->selfUser['nick'];
  1546. api_statuses_show('json');
  1547. }
  1548. /**
  1549. * Test the api_conversation_show() function.
  1550. * @return void
  1551. * @expectedException Friendica\Network\HTTPException\BadRequestException
  1552. */
  1553. public function testApiConversationShow()
  1554. {
  1555. api_conversation_show('json');
  1556. }
  1557. /**
  1558. * Test the api_conversation_show() function with an ID.
  1559. * @return void
  1560. */
  1561. public function testApiConversationShowWithId()
  1562. {
  1563. $this->app->argv[3] = 1;
  1564. $_REQUEST['max_id'] = 10;
  1565. $_REQUEST['page'] = -2;
  1566. $result = api_conversation_show('json');
  1567. $this->assertNotEmpty($result['status']);
  1568. foreach ($result['status'] as $status) {
  1569. $this->assertStatus($status);
  1570. }
  1571. }
  1572. /**
  1573. * Test the api_conversation_show() function with an unallowed user.
  1574. * @return void
  1575. * @expectedException Friendica\Network\HTTPException\ForbiddenException
  1576. */
  1577. public function testApiConversationShowWithUnallowedUser()
  1578. {
  1579. $_SESSION['allow_api'] = false;
  1580. $_GET['screen_name'] = $this->selfUser['nick'];
  1581. api_conversation_show('json');
  1582. }
  1583. /**
  1584. * Test the api_statuses_repeat() function.
  1585. * @return void
  1586. * @expectedException Friendica\Network\HTTPException\ForbiddenException
  1587. */
  1588. public function testApiStatusesRepeat()
  1589. {
  1590. api_statuses_repeat('json');
  1591. }
  1592. /**
  1593. * Test the api_statuses_repeat() function without an authenticated user.
  1594. * @return void
  1595. * @expectedException Friendica\Network\HTTPException\ForbiddenException
  1596. */
  1597. public function testApiStatusesRepeatWithoutAuthenticatedUser()
  1598. {
  1599. $_SESSION['authenticated'] = false;
  1600. api_statuses_repeat('json');
  1601. }
  1602. /**
  1603. * Test the api_statuses_repeat() function with an ID.
  1604. * @return void
  1605. */
  1606. public function testApiStatusesRepeatWithId()
  1607. {
  1608. $this->app->argv[3] = 1;
  1609. $result = api_statuses_repeat('json');
  1610. $this->assertStatus($result['status']);
  1611. // Also test with a shared status
  1612. $this->app->argv[3] = 5;
  1613. $result = api_statuses_repeat('json');
  1614. $this->assertStatus($result['status']);
  1615. }
  1616. /**
  1617. * Test the api_statuses_destroy() function.
  1618. * @return void
  1619. * @expectedException Friendica\Network\HTTPException\BadRequestException
  1620. */
  1621. public function testApiStatusesDestroy()
  1622. {
  1623. api_statuses_destroy('json');
  1624. }
  1625. /**
  1626. * Test the api_statuses_destroy() function without an authenticated user.
  1627. * @return void
  1628. * @expectedException Friendica\Network\HTTPException\ForbiddenException
  1629. */
  1630. public function testApiStatusesDestroyWithoutAuthenticatedUser()
  1631. {
  1632. $_SESSION['authenticated'] = false;
  1633. api_statuses_destroy('json');
  1634. }
  1635. /**
  1636. * Test the api_statuses_destroy() function with an ID.
  1637. * @return void
  1638. */
  1639. public function testApiStatusesDestroyWithId()
  1640. {
  1641. $this->app->argv[3] = 1;
  1642. $result = api_statuses_destroy('json');
  1643. $this->assertStatus($result['status']);
  1644. }
  1645. /**
  1646. * Test the api_statuses_mentions() function.
  1647. * @return void
  1648. */
  1649. public function testApiStatusesMentions()
  1650. {
  1651. $this->app->user = ['nickname' => $this->selfUser['nick']];
  1652. $_REQUEST['max_id'] = 10;
  1653. $result = api_statuses_mentions('json');
  1654. $this->assertEmpty($result['status']);
  1655. // We should test with mentions in the database.
  1656. }
  1657. /**
  1658. * Test the api_statuses_mentions() function with a negative page parameter.
  1659. * @return void
  1660. */
  1661. public function testApiStatusesMentionsWithNegativePage()
  1662. {
  1663. $_REQUEST['page'] = -2;
  1664. $result = api_statuses_mentions('json');
  1665. $this->assertEmpty($result['status']);
  1666. }
  1667. /**
  1668. * Test the api_statuses_mentions() function with an unallowed user.
  1669. * @return void
  1670. * @expectedException Friendica\Network\HTTPException\ForbiddenException
  1671. */
  1672. public function testApiStatusesMentionsWithUnallowedUser()
  1673. {
  1674. $_SESSION['allow_api'] = false;
  1675. $_GET['screen_name'] = $this->selfUser['nick'];
  1676. api_statuses_mentions('json');
  1677. }
  1678. /**
  1679. * Test the api_statuses_mentions() function with an RSS result.
  1680. * @return void
  1681. */
  1682. public function testApiStatusesMentionsWithRss()
  1683. {
  1684. $result = api_statuses_mentions('rss');
  1685. $this->assertXml($result, 'statuses');
  1686. }
  1687. /**
  1688. * Test the api_statuses_user_timeline() function.
  1689. * @return void
  1690. */
  1691. public function testApiStatusesUserTimeline()
  1692. {
  1693. $_REQUEST['max_id'] = 10;
  1694. $_REQUEST['exclude_replies'] = true;
  1695. $_REQUEST['conversation_id'] = 1;
  1696. $result = api_statuses_user_timeline('json');
  1697. $this->assertNotEmpty($result['status']);
  1698. foreach ($result['status'] as $status) {
  1699. $this->assertStatus($status);
  1700. }
  1701. }
  1702. /**
  1703. * Test the api_statuses_user_timeline() function with a negative page parameter.
  1704. * @return void
  1705. */
  1706. public function testApiStatusesUserTimelineWithNegativePage()
  1707. {
  1708. $_REQUEST['page'] = -2;
  1709. $result = api_statuses_user_timeline('json');
  1710. $this->assertNotEmpty($result['status']);
  1711. foreach ($result['status'] as $status) {
  1712. $this->assertStatus($status);
  1713. }
  1714. }
  1715. /**
  1716. * Test the api_statuses_user_timeline() function with an RSS result.
  1717. * @return void
  1718. */
  1719. public function testApiStatusesUserTimelineWithRss()
  1720. {
  1721. $result = api_statuses_user_timeline('rss');
  1722. $this->assertXml($result, 'statuses');
  1723. }
  1724. /**
  1725. * Test the api_statuses_user_timeline() function with an unallowed user.
  1726. * @return void
  1727. * @expectedException Friendica\Network\HTTPException\ForbiddenException
  1728. */
  1729. public function testApiStatusesUserTimelineWithUnallowedUser()
  1730. {
  1731. $_SESSION['allow_api'] = false;
  1732. $_GET['screen_name'] = $this->selfUser['nick'];
  1733. api_statuses_user_timeline('json');
  1734. }
  1735. /**
  1736. * Test the api_favorites_create_destroy() function.
  1737. * @return void
  1738. * @expectedException Friendica\Network\HTTPException\BadRequestException
  1739. */
  1740. public function testApiFavoritesCreateDestroy()
  1741. {
  1742. $this->app->argv = ['api', '1.1', 'favorites', 'create'];
  1743. $this->app->argc = count($this->app->argv);
  1744. api_favorites_create_destroy('json');
  1745. }
  1746. /**
  1747. * Test the api_favorites_create_destroy() function with an invalid ID.
  1748. * @return void
  1749. * @expectedException Friendica\Network\HTTPException\BadRequestException
  1750. */
  1751. public function testApiFavoritesCreateDestroyWithInvalidId()
  1752. {
  1753. $this->app->argv = ['api', '1.1', 'favorites', 'create', '12.json'];
  1754. $this->app->argc = count($this->app->argv);
  1755. api_favorites_create_destroy('json');
  1756. }
  1757. /**
  1758. * Test the api_favorites_create_destroy() function with an invalid action.
  1759. * @return void
  1760. * @expectedException Friendica\Network\HTTPException\BadRequestException
  1761. */
  1762. public function testApiFavoritesCreateDestroyWithInvalidAction()
  1763. {
  1764. $this->app->argv = ['api', '1.1', 'favorites', 'change.json'];
  1765. $this->app->argc = count($this->app->argv);
  1766. $_REQUEST['id'] = 1;
  1767. api_favorites_create_destroy('json');
  1768. }
  1769. /**
  1770. * Test the api_favorites_create_destroy() function with the create action.
  1771. * @return void
  1772. */
  1773. public function testApiFavoritesCreateDestroyWithCreateAction()
  1774. {
  1775. $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
  1776. $this->app->argc = count($this->app->argv);
  1777. $_REQUEST['id'] = 3;
  1778. $result = api_favorites_create_destroy('json');
  1779. $this->assertStatus($result['status']);
  1780. }
  1781. /**
  1782. * Test the api_favorites_create_destroy() function with the create action and an RSS result.
  1783. * @return void
  1784. */
  1785. public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
  1786. {
  1787. $this->app->argv = ['api', '1.1', 'favorites', 'create.rss'];
  1788. $this->app->argc = count($this->app->argv);
  1789. $_REQUEST['id'] = 3;
  1790. $result = api_favorites_create_destroy('rss');
  1791. $this->assertXml($result, 'status');
  1792. }
  1793. /**
  1794. * Test the api_favorites_create_destroy() function with the destroy action.
  1795. * @return void
  1796. */
  1797. public function testApiFavoritesCreateDestroyWithDestroyAction()
  1798. {
  1799. $this->app->argv = ['api', '1.1', 'favorites', 'destroy.json'];
  1800. $this->app->argc = count($this->app->argv);
  1801. $_REQUEST['id'] = 3;
  1802. $result = api_favorites_create_destroy('json');
  1803. $this->assertStatus($result['status']);
  1804. }
  1805. /**
  1806. * Test the api_favorites_create_destroy() function without an authenticated user.
  1807. * @return void
  1808. * @expectedException Friendica\Network\HTTPException\ForbiddenException
  1809. */
  1810. public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
  1811. {
  1812. $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
  1813. $this->app->argc = count($this->app->argv);
  1814. $_SESSION['authenticated'] = false;
  1815. api_favorites_create_destroy('json');
  1816. }
  1817. /**
  1818. * Test the api_favorites() function.
  1819. * @return void
  1820. */
  1821. public function testApiFavorites()
  1822. {
  1823. $_REQUEST['page'] = -1;
  1824. $_REQUEST['max_id'] = 10;
  1825. $result = api_favorites('json');
  1826. foreach ($result['status'] as $status) {
  1827. $this->assertStatus($status);
  1828. }
  1829. }
  1830. /**
  1831. * Test the api_favorites() function with an RSS result.
  1832. * @return void
  1833. */
  1834. public function testApiFavoritesWithRss()
  1835. {
  1836. $result = api_favorites('rss');
  1837. $this->assertXml($result, 'statuses');
  1838. }
  1839. /**
  1840. * Test the api_favorites() function with an unallowed user.
  1841. * @return void
  1842. * @expectedException Friendica\Network\HTTPException\ForbiddenException
  1843. */
  1844. public function testApiFavoritesWithUnallowedUser()
  1845. {
  1846. $_SESSION['allow_api'] = false;
  1847. $_GET['screen_name'] = $this->selfUser['nick'];
  1848. api_favorites('json');
  1849. }
  1850. /**
  1851. * Test the api_format_messages() function.
  1852. * @return void
  1853. */
  1854. public function testApiFormatMessages()
  1855. {
  1856. $result = api_format_messages(
  1857. ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
  1858. ['id' => 2, 'screen_name' => 'recipient_name'],
  1859. ['id' => 3, 'screen_name' => 'sender_name']
  1860. );
  1861. $this->assertEquals('item_title'."\n".'item_body', $result['text']);
  1862. $this->assertEquals(1, $result['id']);
  1863. $this->assertEquals(2, $result['recipient_id']);
  1864. $this->assertEquals(3, $result['sender_id']);
  1865. $this->assertEquals('recipient_name', $result['recipient_screen_name']);
  1866. $this->assertEquals('sender_name', $result['sender_screen_name']);
  1867. }
  1868. /**
  1869. * Test the api_format_messages() function with HTML.
  1870. * @return void
  1871. */
  1872. public function testApiFormatMessagesWithHtmlText()
  1873. {
  1874. $_GET['getText'] = 'html';
  1875. $result = api_format_messages(
  1876. ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
  1877. ['id' => 2, 'screen_name' => 'recipient_name'],
  1878. ['id' => 3, 'screen_name' => 'sender_name']
  1879. );
  1880. $this->assertEquals('item_title', $result['title']);
  1881. $this->assertEquals('<strong>item_body</strong>', $result['text']);
  1882. }
  1883. /**
  1884. * Test the api_format_messages() function with plain text.
  1885. * @return void
  1886. */
  1887. public function testApiFormatMessagesWithPlainText()
  1888. {
  1889. $_GET['getText'] = 'plain';
  1890. $result = api_format_messages(
  1891. ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
  1892. ['id' => 2, 'screen_name' => 'recipient_name'],
  1893. ['id' => 3, 'screen_name' => 'sender_name']
  1894. );
  1895. $this->assertEquals('item_title', $result['title']);
  1896. $this->assertEquals('item_body', $result['text']);
  1897. }
  1898. /**
  1899. * Test the api_format_messages() function with the getUserObjects GET parameter set to false.
  1900. * @return void
  1901. */
  1902. public function testApiFormatMessagesWithoutUserObjects()
  1903. {
  1904. $_GET['getUserObjects'] = 'false';
  1905. $result = api_format_messages(
  1906. ['id' => 1, 'title' => 'item_title', 'body' => '[b]item_body[/b]'],
  1907. ['id' => 2, 'screen_name' => 'recipient_name'],
  1908. ['id' => 3, 'screen_name' => 'sender_name']
  1909. );
  1910. $this->assertTrue(!isset($result['sender']));
  1911. $this->assertTrue(!isset($result['recipient']));
  1912. }
  1913. /**
  1914. * Test the api_convert_item() function.
  1915. * @return void
  1916. */
  1917. public function testApiConvertItem()
  1918. {
  1919. $result = api_convert_item(
  1920. [
  1921. 'network' => 'feed',
  1922. 'title' => 'item_title',
  1923. // We need a long string to test that it is correctly cut
  1924. 'body' => 'perspiciatis impedit voluptatem quis molestiae ea qui '.
  1925. 'reiciendis dolorum aut ducimus sunt consequatur inventore dolor '.
  1926. 'officiis pariatur doloremque nemo culpa aut quidem qui dolore '.
  1927. 'laudantium atque commodi alias voluptatem non possimus aperiam '.
  1928. 'ipsum rerum consequuntur aut amet fugit quia aliquid praesentium '.
  1929. 'repellendus quibusdam et et inventore mollitia rerum sit autem '.
  1930. 'pariatur maiores ipsum accusantium perferendis vel sit possimus '.
  1931. 'veritatis nihil distinctio qui eum repellat officia illum quos '.
  1932. 'impedit quam iste esse unde qui suscipit aut facilis ut inventore '.
  1933. 'omnis exercitationem quo magnam consequatur maxime aut illum '.
  1934. 'soluta quaerat natus unde aspernatur et sed beatae nihil ullam '.
  1935. 'temporibus corporis ratione blanditiis perspiciatis impedit '.
  1936. 'voluptatem quis molestiae ea qui reiciendis dolorum aut ducimus '.
  1937. 'sunt consequatur inventore dolor officiis pariatur doloremque '.
  1938. 'nemo culpa aut quidem qui dolore laudantium atque commodi alias '.
  1939. 'voluptatem non possimus aperiam ipsum rerum consequuntur aut '.
  1940. 'amet fugit quia aliquid praesentium repellendus quibusdam et et '.
  1941. 'inventore mollitia rerum sit autem pariatur maiores ipsum accusantium '.
  1942. 'perferendis vel sit possimus veritatis nihil distinctio qui eum '.
  1943. 'repellat officia illum quos impedit quam iste esse unde qui '.
  1944. 'suscipit aut facilis ut inventore omnis exercitationem quo magnam '.
  1945. 'consequatur maxime aut illum soluta quaerat natus unde aspernatur '.
  1946. 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
  1947. 'plink' => 'item_plink'
  1948. ]
  1949. );
  1950. $this->assertStringStartsWith('item_title', $result['text']);
  1951. $this->assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $result['html']);
  1952. }
  1953. /**
  1954. * Test the api_convert_item() function with an empty item body.
  1955. * @return void
  1956. */
  1957. public function testApiConvertItemWithoutBody()
  1958. {
  1959. $result = api_convert_item(
  1960. [
  1961. 'network' => 'feed',
  1962. 'title' => 'item_title',
  1963. 'body' => '',
  1964. 'plink' => 'item_plink'
  1965. ]
  1966. );
  1967. $this->assertEquals('item_title', $result['text']);
  1968. $this->assertEquals('<h4>item_title</h4><br>item_plink', $result['html']);
  1969. }
  1970. /**
  1971. * Test the api_convert_item() function with the title in the body.
  1972. * @return void
  1973. */
  1974. public function testApiConvertItemWithTitleInBody()
  1975. {
  1976. $result = api_convert_item(
  1977. [
  1978. 'title' => 'item_title',
  1979. 'body' => 'item_title item_body'
  1980. ]
  1981. );
  1982. $this->assertEquals('item_title item_body', $result['text']);
  1983. $this->assertEquals('<h4>item_title</h4><br>item_title item_body', $result['html']);
  1984. }
  1985. /**
  1986. * Test the api_get_attachments() function.
  1987. * @return void
  1988. */
  1989. public function testApiGetAttachments()
  1990. {
  1991. $body = 'body';
  1992. $this->assertEmpty(api_get_attachments($body));
  1993. }
  1994. /**
  1995. * Test the api_get_attachments() function with an img tag.
  1996. * @return void
  1997. */
  1998. public function testApiGetAttachmentsWithImage()
  1999. {
  2000. $body = '[img]http://via.placeholder.com/1x1.png[/img]';
  2001. $this->assertInternalType('array', api_get_attachments($body));
  2002. }
  2003. /**
  2004. * Test the api_get_attachments() function with an img tag and an AndStatus user agent.
  2005. * @return void
  2006. */
  2007. public function testApiGetAttachmentsWithImageAndAndStatus()
  2008. {
  2009. $_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
  2010. $body = '[img]http://via.placeholder.com/1x1.png[/img]';
  2011. $this->assertInternalType('array', api_get_attachments($body));
  2012. }
  2013. /**
  2014. * Test the api_get_entitities() function.
  2015. * @return void
  2016. */
  2017. public function testApiGetEntitities()
  2018. {
  2019. $text = 'text';
  2020. $this->assertInternalType('array', api_get_entitities($text, 'bbcode'));
  2021. }
  2022. /**
  2023. * Test the api_get_entitities() function with the include_entities parameter.
  2024. * @return void
  2025. */
  2026. public function testApiGetEntititiesWithIncludeEntities()
  2027. {
  2028. $_REQUEST['include_entities'] = 'true';
  2029. $text = 'text';
  2030. $result = api_get_entitities($text, 'bbcode');
  2031. $this->assertInternalType('array', $result['hashtags']);
  2032. $this->assertInternalType('array', $result['symbols']);
  2033. $this->assertInternalType('array', $result['urls']);
  2034. $this->assertInternalType('array', $result['user_mentions']);
  2035. }
  2036. /**
  2037. * Test the api_format_items_embeded_images() function.
  2038. * @return void
  2039. */
  2040. public function testApiFormatItemsEmbededImages()
  2041. {
  2042. $this->assertEquals(
  2043. 'text ' . System::baseUrl() . '/display/item_guid',
  2044. api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
  2045. );
  2046. }
  2047. /**
  2048. * Test the api_contactlink_to_array() function.
  2049. * @return void
  2050. */
  2051. public function testApiContactlinkToArray()
  2052. {
  2053. $this->assertEquals(
  2054. [
  2055. 'name' => 'text',
  2056. 'url' => '',
  2057. ],
  2058. api_contactlink_to_array('text')
  2059. );
  2060. }
  2061. /**
  2062. * Test the api_contactlink_to_array() function with an URL.
  2063. * @return void
  2064. */
  2065. public function testApiContactlinkToArrayWithUrl()
  2066. {
  2067. $this->assertEquals(
  2068. [
  2069. 'name' => ['link_text'],
  2070. 'url' => ['url'],
  2071. ],
  2072. api_contactlink_to_array('text <a href="url">link_text</a>')
  2073. );
  2074. }
  2075. /**
  2076. * Test the api_format_items_activities() function.
  2077. * @return void
  2078. */
  2079. public function testApiFormatItemsActivities()
  2080. {
  2081. $item = ['uid' => 0, 'uri' => ''];
  2082. $result = api_format_items_activities($item);
  2083. $this->assertArrayHasKey('like', $result);
  2084. $this->assertArrayHasKey('dislike', $result);
  2085. $this->assertArrayHasKey('attendyes', $result);
  2086. $this->assertArrayHasKey('attendno', $result);
  2087. $this->assertArrayHasKey('attendmaybe', $result);
  2088. }
  2089. /**
  2090. * Test the api_format_items_activities() function with an XML result.
  2091. * @return void
  2092. */
  2093. public function testApiFormatItemsActivitiesWithXml()
  2094. {
  2095. $item = ['uid' => 0, 'uri' => ''];
  2096. $result = api_format_items_activities($item, 'xml');
  2097. $this->assertArrayHasKey('friendica:like', $result);
  2098. $this->assertArrayHasKey('friendica:dislike', $result);
  2099. $this->assertArrayHasKey('friendica:attendyes', $result);
  2100. $this->assertArrayHasKey('friendica:attendno', $result);
  2101. $this->assertArrayHasKey('friendica:attendmaybe', $result);
  2102. }
  2103. /**
  2104. * Test the api_format_items_profiles() function.
  2105. * @return void
  2106. */
  2107. public function testApiFormatItemsProfiles()
  2108. {
  2109. $profile_row = [
  2110. 'id' => 'profile_id',
  2111. 'profile-name' => 'profile_name',
  2112. 'is-default' => true,
  2113. 'hide-friends' => true,
  2114. 'photo' => 'profile_photo',
  2115. 'thumb' => 'profile_thumb',
  2116. 'publish' => true,
  2117. 'net-publish' => true,
  2118. 'pdesc' => 'description',
  2119. 'dob' => 'date_of_birth',
  2120. 'address' => 'address',
  2121. 'locality' => 'city',
  2122. 'region' => 'region',
  2123. 'postal-code' => 'postal_code',
  2124. 'country-name' => 'country',
  2125. 'hometown' => 'hometown',
  2126. 'gender' => 'gender',
  2127. 'marital' => 'marital',
  2128. 'with' => 'marital_with',
  2129. 'howlong' => 'marital_since',
  2130. 'sexual' => 'sexual',
  2131. 'politic' => 'politic',
  2132. 'religion' => 'religion',
  2133. 'pub_keywords' => 'public_keywords',
  2134. 'prv_keywords' => 'private_keywords',
  2135. 'likes' => 'likes',
  2136. 'dislikes' => 'dislikes',
  2137. 'about' => 'about',
  2138. 'music' => 'music',
  2139. 'book' => 'book',
  2140. 'tv' => 'tv',
  2141. 'film' => 'film',
  2142. 'interest' => 'interest',
  2143. 'romance' => 'romance',
  2144. 'work' => 'work',
  2145. 'education' => 'education',
  2146. 'contact' => 'social_networks',
  2147. 'homepage' => 'homepage'
  2148. ];
  2149. $result = api_format_items_profiles($profile_row);
  2150. $this->assertEquals(
  2151. [
  2152. 'profile_id' => 'profile_id',
  2153. 'profile_name' => 'profile_name',
  2154. 'is_default' => true,
  2155. 'hide_friends' => true,
  2156. 'profile_photo' => 'profile_photo',
  2157. 'profile_thumb' => 'profile_thumb',
  2158. 'publish' => true,
  2159. 'net_publish' => true,
  2160. 'description' => 'description',
  2161. 'date_of_birth' => 'date_of_birth',
  2162. 'address' => 'address',
  2163. 'city' => 'city',
  2164. 'region' => 'region',
  2165. 'postal_code' => 'postal_code',
  2166. 'country' => 'country',
  2167. 'hometown' => 'hometown',
  2168. 'gender' => 'gender',
  2169. 'marital' => 'marital',
  2170. 'marital_with' => 'marital_with',
  2171. 'marital_since' => 'marital_since',
  2172. 'sexual' => 'sexual',
  2173. 'politic' => 'politic',
  2174. 'religion' => 'religion',
  2175. 'public_keywords' => 'public_keywords',
  2176. 'private_keywords' => 'private_keywords',
  2177. 'likes' => 'likes',
  2178. 'dislikes' => 'dislikes',
  2179. 'about' => 'about',
  2180. 'music' => 'music',
  2181. 'book' => 'book',
  2182. 'tv' => 'tv',
  2183. 'film' => 'film',
  2184. 'interest' => 'interest',
  2185. 'romance' => 'romance',
  2186. 'work' => 'work',
  2187. 'education' => 'education',
  2188. 'social_networks' => 'social_networks',
  2189. 'homepage' => 'homepage',
  2190. 'users' => null
  2191. ],
  2192. $result
  2193. );
  2194. }
  2195. /**
  2196. * Test the api_format_items() function.
  2197. * @return void
  2198. */
  2199. public function testApiFormatItems()
  2200. {
  2201. $items = [
  2202. [
  2203. 'item_network' => 'item_network',
  2204. 'source' => 'web',
  2205. 'coord' => '5 7',
  2206. 'body' => '',
  2207. 'verb' => '',
  2208. 'author-id' => 43,
  2209. 'author-network' => Protocol::DFRN,
  2210. 'author-link' => 'http://localhost/profile/othercontact',
  2211. 'plink' => '',
  2212. ]
  2213. ];
  2214. $result = api_format_items($items, ['id' => 0], true);
  2215. foreach ($result as $status) {
  2216. $this->assertStatus($status);
  2217. }
  2218. }
  2219. /**
  2220. * Test the api_format_items() function with an XML result.
  2221. * @return void
  2222. */
  2223. public function testApiFormatItemsWithXml()
  2224. {
  2225. $items = [
  2226. [
  2227. 'coord' => '5 7',
  2228. 'body' => '',
  2229. 'verb' => '',
  2230. 'author-id' => 43,
  2231. 'author-network' => Protocol::DFRN,
  2232. 'author-link' => 'http://localhost/profile/othercontact',
  2233. 'plink' => '',
  2234. ]
  2235. ];
  2236. $result = api_format_items($items, ['id' => 0], true, 'xml');
  2237. foreach ($result as $status) {
  2238. $this->assertStatus($status);
  2239. }
  2240. }
  2241. /**
  2242. * Test the api_format_items() function.
  2243. * @return void
  2244. */
  2245. public function testApiAccountRateLimitStatus()
  2246. {
  2247. $result = api_account_rate_limit_status('json');
  2248. $this->assertEquals(150, $result['hash']['remaining_hits']);
  2249. $this->assertEquals(150, $result['hash']['hourly_limit']);
  2250. $this->assertInternalType('int', $result['hash']['reset_time_in_seconds']);
  2251. }
  2252. /**
  2253. * Test the api_format_items() function with an XML result.
  2254. * @return void
  2255. */
  2256. public function testApiAccountRateLimitStatusWithXml()
  2257. {
  2258. $result = api_account_rate_limit_status('xml');
  2259. $this->assertXml($result, 'hash');
  2260. }
  2261. /**
  2262. * Test the api_help_test() function.
  2263. * @return void
  2264. */
  2265. public function testApiHelpTest()
  2266. {
  2267. $result = api_help_test('json');
  2268. $this->assertEquals(['ok' => 'ok'], $result);
  2269. }
  2270. /**
  2271. * Test the api_help_test() function with an XML result.
  2272. * @return void
  2273. */
  2274. public function testApiHelpTestWithXml()
  2275. {
  2276. $result = api_help_test('xml');
  2277. $this->assertXml($result, 'ok');
  2278. }
  2279. /**
  2280. * Test the api_lists_list() function.
  2281. * @return void
  2282. */
  2283. public function testApiListsList()
  2284. {
  2285. $result = api_lists_list('json');
  2286. $this->assertEquals(['lists_list' => []], $result);
  2287. }
  2288. /**
  2289. * Test the api_lists_ownerships() function.
  2290. * @return void
  2291. */
  2292. public function testApiListsOwnerships()
  2293. {
  2294. $result = api_lists_ownerships('json');
  2295. foreach ($result['lists']['lists'] as $list) {
  2296. $this->assertList($list);
  2297. }
  2298. }
  2299. /**
  2300. * Test the api_lists_ownerships() function without an authenticated user.
  2301. * @return void
  2302. * @expectedException Friendica\Network\HTTPException\ForbiddenException
  2303. */
  2304. public function testApiListsOwnershipsWithoutAuthenticatedUser()
  2305. {
  2306. $_SESSION['authenticated'] = false;
  2307. api_lists_ownerships('json');
  2308. }
  2309. /**
  2310. * Test the api_lists_statuses() function.
  2311. * @expectedException Friendica\Network\HTTPException\BadRequestException
  2312. * @return void
  2313. */
  2314. public function testApiListsStatuses()
  2315. {
  2316. api_lists_statuses('json');
  2317. }
  2318. /**
  2319. * Test the api_lists_statuses() function with a list ID.
  2320. * @return void
  2321. */
  2322. public function testApiListsStatusesWithListId()
  2323. {
  2324. $_REQUEST['list_id'] = 1;
  2325. $_REQUEST['page'] = -1;
  2326. $_REQUEST['max_id'] = 10;
  2327. $result = api_lists_statuses('json');
  2328. foreach ($result['status'] as $status) {
  2329. $this->assertStatus($status);
  2330. }
  2331. }
  2332. /**
  2333. * Test the api_lists_statuses() function with a list ID and a RSS result.
  2334. * @return void
  2335. */
  2336. public function testApiListsStatusesWithListIdAndRss()
  2337. {
  2338. $_REQUEST['list_id'] = 1;
  2339. $result = api_lists_statuses('rss');
  2340. $this->assertXml($result, 'statuses');
  2341. }
  2342. /**
  2343. * Test the api_lists_statuses() function with an unallowed user.
  2344. * @return void
  2345. * @expectedException Friendica\Network\HTTPException\ForbiddenException
  2346. */
  2347. public function testApiListsStatusesWithUnallowedUser()
  2348. {
  2349. $_SESSION['allow_api'] = false;
  2350. $_GET['screen_name'] = $this->selfUser['nick'];
  2351. api_lists_statuses('json');
  2352. }
  2353. /**
  2354. * Test the api_statuses_f() function.
  2355. * @return void
  2356. */
  2357. public function testApiStatusesFWithFriends()
  2358. {
  2359. $_GET['page'] = -1;
  2360. $result = api_statuses_f('friends');
  2361. $this->assertArrayHasKey('user', $result);
  2362. }
  2363. /**
  2364. * Test the api_statuses_f() function.
  2365. * @return void
  2366. */
  2367. public function testApiStatusesFWithFollowers()
  2368. {
  2369. $result = api_statuses_f('followers');
  2370. $this->assertArrayHasKey('user', $result);
  2371. }
  2372. /**
  2373. * Test the api_statuses_f() function.
  2374. * @return void
  2375. */
  2376. public function testApiStatusesFWithBlocks()
  2377. {
  2378. $result = api_statuses_f('blocks');
  2379. $this->assertArrayHasKey('user', $result);
  2380. }
  2381. /**
  2382. * Test the api_statuses_f() function.
  2383. * @return void
  2384. */
  2385. public function testApiStatusesFWithIncoming()
  2386. {
  2387. $result = api_statuses_f('incoming');
  2388. $this->assertArrayHasKey('user', $result);
  2389. }
  2390. /**
  2391. * Test the api_statuses_f() function an undefined cursor GET variable.
  2392. * @return void
  2393. */
  2394. public function testApiStatusesFWithUndefinedCursor()
  2395. {
  2396. $_GET['cursor'] = 'undefined';
  2397. $this->assertFalse(api_statuses_f('friends'));
  2398. }
  2399. /**
  2400. * Test the api_statuses_friends() function.
  2401. * @return void
  2402. */
  2403. public function testApiStatusesFriends()
  2404. {
  2405. $result = api_statuses_friends('json');
  2406. $this->assertArrayHasKey('user', $result);
  2407. }
  2408. /**
  2409. * Test the api_statuses_friends() function an undefined cursor GET variable.
  2410. * @return void
  2411. */
  2412. public function testApiStatusesFriendsWithUndefinedCursor()
  2413. {
  2414. $_GET['cursor'] = 'undefined';
  2415. $this->assertFalse(api_statuses_friends('json'));
  2416. }
  2417. /**
  2418. * Test the api_statuses_followers() function.
  2419. * @return void
  2420. */
  2421. public function testApiStatusesFollowers()
  2422. {
  2423. $result = api_statuses_followers('json');
  2424. $this->assertArrayHasKey('user', $result);
  2425. }
  2426. /**
  2427. * Test the api_statuses_followers() function an undefined cursor GET variable.
  2428. * @return void
  2429. */
  2430. public function testApiStatusesFollowersWithUndefinedCursor()
  2431. {
  2432. $_GET['cursor'] = 'undefined';
  2433. $this->assertFalse(api_statuses_followers('json'));
  2434. }
  2435. /**
  2436. * Test the api_blocks_list() function.
  2437. * @return void
  2438. */
  2439. public function testApiBlocksList()
  2440. {
  2441. $result = api_blocks_list('json');
  2442. $this->assertArrayHasKey('user', $result);
  2443. }
  2444. /**
  2445. * Test the api_blocks_list() function an undefined cursor GET variable.
  2446. * @return void
  2447. */
  2448. public function testApiBlocksListWithUndefinedCursor()
  2449. {
  2450. $_GET['cursor'] = 'undefined';
  2451. $this->assertFalse(api_blocks_list('json'));
  2452. }
  2453. /**
  2454. * Test the api_friendships_incoming() function.
  2455. * @return void
  2456. */
  2457. public function testApiFriendshipsIncoming()
  2458. {
  2459. $result = api_friendships_incoming('json');
  2460. $this->assertArrayHasKey('id', $result);
  2461. }
  2462. /**
  2463. * Test the api_friendships_incoming() function an undefined cursor GET variable.
  2464. * @return void
  2465. */
  2466. public function testApiFriendshipsIncomingWithUndefinedCursor()
  2467. {
  2468. $_GET['cursor'] = 'undefined';
  2469. $this->assertFalse(api_friendships_incoming('json'));
  2470. }
  2471. /**
  2472. * Test the api_statusnet_config() function.
  2473. * @return void
  2474. */
  2475. public function testApiStatusnetConfig()
  2476. {
  2477. $result = api_statusnet_config('json');
  2478. $this->assertEquals('localhost', $result['config']['site']['server']);
  2479. $this->assertEquals('default', $result['config']['site']['theme']);
  2480. $this->assertEquals(System::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
  2481. $this->assertTrue($result['config']['site']['fancy']);
  2482. $this->assertEquals('en', $result['config']['site']['language']);
  2483. $this->assertEquals('UTC', $result['config']['site']['timezone']);
  2484. $this->assertEquals(200000, $result['config']['site']['textlimit']);
  2485. $this->assertEquals('false', $result['config']['site']['private']);
  2486. $this->assertEquals('false', $result['config']['site']['ssl']);
  2487. $this->assertEquals(30, $result['config']['site']['shorturllength']);
  2488. }
  2489. /**
  2490. * Test the api_statusnet_version() function.
  2491. * @return void
  2492. */
  2493. public function testApiStatusnetVersion()
  2494. {
  2495. $result = api_statusnet_version('json');
  2496. $this->assertEquals('0.9.7', $result['version']);
  2497. }
  2498. /**
  2499. * Test the api_ff_ids() function.
  2500. * @return void
  2501. */
  2502. public function testApiFfIds()
  2503. {
  2504. $result = api_ff_ids('json');
  2505. $this->assertNull($result);
  2506. }
  2507. /**
  2508. * Test the api_ff_ids() function with a result.
  2509. * @return void
  2510. */
  2511. public function testApiFfIdsWithResult()
  2512. {
  2513. $this->markTestIncomplete();
  2514. }
  2515. /**
  2516. * Test the api_ff_ids() function without an authenticated user.
  2517. * @return void
  2518. * @expectedException Friendica\Network\HTTPException\ForbiddenException
  2519. */
  2520. public function testApiFfIdsWithoutAuthenticatedUser()
  2521. {
  2522. $_SESSION['authenticated'] = false;
  2523. api_ff_ids('json');
  2524. }
  2525. /**
  2526. * Test the api_friends_ids() function.
  2527. * @return void
  2528. */
  2529. public function testApiFriendsIds()
  2530. {
  2531. $result = api_friends_ids('json');
  2532. $this->assertNull($result);
  2533. }
  2534. /**
  2535. * Test the api_followers_ids() function.
  2536. * @return void
  2537. */
  2538. public function testApiFollowersIds()
  2539. {
  2540. $result = api_followers_ids('json');
  2541. $this->assertNull($result);
  2542. }
  2543. /**
  2544. * Test the api_direct_messages_new() function.
  2545. * @return void
  2546. */
  2547. public function testApiDirectMessagesNew()
  2548. {
  2549. $result = api_direct_messages_new('json');
  2550. $this->assertNull($result);
  2551. }
  2552. /**
  2553. * Test the api_direct_messages_new() function without an authenticated user.
  2554. * @return void
  2555. * @expectedException Friendica\Network\HTTPException\ForbiddenException
  2556. */
  2557. public function testApiDirectMessagesNewWithoutAuthenticatedUser()
  2558. {
  2559. $_SESSION['authenticated'] = false;
  2560. api_direct_messages_new('json');
  2561. }
  2562. /**
  2563. * Test the api_direct_messages_new() function with an user ID.
  2564. * @return void
  2565. */
  2566. public function testApiDirectMessagesNewWithUserId()
  2567. {
  2568. $_POST['text'] = 'message_text';
  2569. $_POST['user_id'] = $this->otherUser['id'];
  2570. $result = api_direct_messages_new('json');
  2571. $this->assertEquals(['direct_message' => ['error' => -1]], $result);
  2572. }
  2573. /**
  2574. * Test the api_direct_messages_new() function with a screen name.
  2575. * @return void
  2576. */
  2577. public function testApiDirectMessagesNewWithScreenName()
  2578. {
  2579. $_POST['text'] = 'message_text';
  2580. $_POST['screen_name'] = $this->friendUser['nick'];
  2581. $result = api_direct_messages_new('json');
  2582. $this->assertEquals(1, $result['direct_message']['id']);
  2583. $this->assertContains('message_text', $result['direct_message']['text']);
  2584. $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
  2585. $this->assertEquals(1, $result['direct_message']['friendica_seen']);
  2586. }
  2587. /**
  2588. * Test the api_direct_messages_new() function with a title.
  2589. * @return void
  2590. */
  2591. public function testApiDirectMessagesNewWithTitle()
  2592. {
  2593. $_POST['text'] = 'message_text';
  2594. $_POST['screen_name'] = $this->friendUser['nick'];
  2595. $_REQUEST['title'] = 'message_title';
  2596. $result = api_direct_messages_new('json');
  2597. $this->assertEquals(1, $result['direct_message']['id']);
  2598. $this->assertContains('message_text', $result['direct_message']['text']);
  2599. $this->assertContains('message_title', $result['direct_message']['text']);
  2600. $this->assertEquals('selfcontact', $result['direct_message']['sender_screen_name']);
  2601. $this->assertEquals(1, $result['direct_message']['friendica_seen']);
  2602. }
  2603. /**
  2604. * Test the api_direct_messages_new() function with an RSS result.
  2605. * @return void
  2606. */
  2607. public function testApiDirectMessagesNewWithRss()
  2608. {
  2609. $_POST['text'] = 'message_text';
  2610. $_POST['screen_name'] = $this->friendUser['nick'];
  2611. $result = api_direct_messages_new('rss');
  2612. $this->assertXml($result, 'direct-messages');
  2613. }
  2614. /**
  2615. * Test the api_direct_messages_destroy() function.
  2616. * @return void
  2617. * @expectedException Friendica\Network\HTTPException\BadRequestException
  2618. */
  2619. public function testApiDirectMessagesDestroy()
  2620. {
  2621. api_direct_messages_destroy('json');
  2622. }
  2623. /**
  2624. * Test the api_direct_messages_destroy() function with the friendica_verbose GET param.
  2625. * @return void
  2626. */
  2627. public function testApiDirectMessagesDestroyWithVerbose()
  2628. {
  2629. $_GET['friendica_verbose'] = 'true';
  2630. $result = api_direct_messages_destroy('json');
  2631. $this->assertEquals(
  2632. [
  2633. '$result' => [
  2634. 'result' => 'error',
  2635. 'message' => 'message id or parenturi not specified'
  2636. ]
  2637. ],
  2638. $result
  2639. );
  2640. }
  2641. /**
  2642. * Test the api_direct_messages_destroy() function without an authenticated user.
  2643. * @return void
  2644. * @expectedException Friendica\Network\HTTPException\ForbiddenException
  2645. */
  2646. public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
  2647. {
  2648. $_SESSION['authenticated'] = false;
  2649. api_direct_messages_destroy('json');
  2650. }
  2651. /**
  2652. * Test the api_direct_messages_destroy() function with a non-zero ID.
  2653. * @return void
  2654. * @expectedException Friendica\Network\HTTPException\BadRequestException
  2655. */
  2656. public function testApiDirectMessagesDestroyWithId()
  2657. {
  2658. $_REQUEST['id'] = 1;
  2659. api_direct_messages_destroy('json');
  2660. }
  2661. /**
  2662. * Test the api_direct_messages_destroy() with a non-zero ID and the friendica_verbose GET param.
  2663. * @return void
  2664. */
  2665. public function testApiDirectMessagesDestroyWithIdAndVerbose()
  2666. {
  2667. $_REQUEST['id'] = 1;
  2668. $_REQUEST['friendica_parenturi'] = 'parent_uri';
  2669. $_GET['friendica_verbose'] = 'true';
  2670. $result = api_direct_messages_destroy('json');
  2671. $this->assertEquals(
  2672. [
  2673. '$result' => [
  2674. 'result' => 'error',
  2675. 'message' => 'message id not in database'
  2676. ]
  2677. ],
  2678. $result
  2679. );
  2680. }
  2681. /**
  2682. * Test the api_direct_messages_destroy() function with a non-zero ID.
  2683. * @return void
  2684. */
  2685. public function testApiDirectMessagesDestroyWithCorrectId()
  2686. {
  2687. $this->markTestIncomplete('We need to add a dataset for this.');
  2688. }
  2689. /**
  2690. * Test the api_direct_messages_box() function.
  2691. * @return void
  2692. */
  2693. public function testApiDirectMessagesBoxWithSentbox()
  2694. {
  2695. $_REQUEST['page'] = -1;
  2696. $_REQUEST['max_id'] = 10;
  2697. $result = api_direct_messages_box('json', 'sentbox', 'false');
  2698. $this->assertArrayHasKey('direct_message', $result);
  2699. }
  2700. /**
  2701. * Test the api_direct_messages_box() function.
  2702. * @return void
  2703. */
  2704. public function testApiDirectMessagesBoxWithConversation()
  2705. {
  2706. $result = api_direct_messages_box('json', 'conversation', 'false');
  2707. $this->assertArrayHasKey('direct_message', $result);
  2708. }
  2709. /**
  2710. * Test the api_direct_messages_box() function.
  2711. * @return void
  2712. */
  2713. public function testApiDirectMessagesBoxWithAll()
  2714. {
  2715. $result = api_direct_messages_box('json', 'all', 'false');
  2716. $this->assertArrayHasKey('direct_message', $result);
  2717. }
  2718. /**
  2719. * Test the api_direct_messages_box() function.
  2720. * @return void
  2721. */
  2722. public function testApiDirectMessagesBoxWithInbox()
  2723. {
  2724. $result = api_direct_messages_box('json', 'inbox', 'false');
  2725. $this->assertArrayHasKey('direct_message', $result);
  2726. }
  2727. /**
  2728. * Test the api_direct_messages_box() function.
  2729. * @return void
  2730. */
  2731. public function testApiDirectMessagesBoxWithVerbose()
  2732. {
  2733. $result = api_direct_messages_box('json', 'sentbox', 'true');
  2734. $this->assertEquals(
  2735. [
  2736. '$result' => [
  2737. 'result' => 'error',
  2738. 'message' => 'no mails available'
  2739. ]
  2740. ],
  2741. $result
  2742. );
  2743. }
  2744. /**
  2745. * Test the api_direct_messages_box() function with a RSS result.
  2746. * @return void
  2747. */
  2748. public function testApiDirectMessagesBoxWithRss()
  2749. {
  2750. $result = api_direct_messages_box('rss', 'sentbox', 'false');
  2751. $this->assertXml($result, 'direct-messages');
  2752. }
  2753. /**
  2754. * Test the api_direct_messages_box() function without an authenticated user.
  2755. * @return void
  2756. * @expectedException Friendica\Network\HTTPException\ForbiddenException
  2757. */
  2758. public function testApiDirectMessagesBoxWithUnallowedUser()
  2759. {
  2760. $_SESSION['allow_api'] = false;
  2761. $_GET['screen_name'] = $this->selfUser['nick'];
  2762. api_direct_messages_box('json', 'sentbox', 'false');
  2763. }
  2764. /**
  2765. * Test the api_direct_messages_sentbox() function.
  2766. * @return void
  2767. */
  2768. public function testApiDirectMessagesSentbox()
  2769. {
  2770. $result = api_direct_messages_sentbox('json');
  2771. $this->assertArrayHasKey('direct_message', $result);
  2772. }
  2773. /**
  2774. * Test the api_direct_messages_inbox() function.
  2775. * @return void
  2776. */
  2777. public function testApiDirectMessagesInbox()
  2778. {
  2779. $result = api_direct_messages_inbox('json');
  2780. $this->assertArrayHasKey('direct_message', $result);
  2781. }
  2782. /**
  2783. * Test the api_direct_messages_all() function.
  2784. * @return void
  2785. */
  2786. public function testApiDirectMessagesAll()
  2787. {
  2788. $result = api_direct_messages_all('json');
  2789. $this->assertArrayHasKey('direct_message', $result);
  2790. }
  2791. /**
  2792. * Test the api_direct_messages_conversation() function.
  2793. * @return void
  2794. */
  2795. public function testApiDirectMessagesConversation()
  2796. {
  2797. $result = api_direct_messages_conversation('json');
  2798. $this->assertArrayHasKey('direct_message', $result);
  2799. }
  2800. /**
  2801. * Test the api_oauth_request_token() function.
  2802. * @return void
  2803. */
  2804. public function testApiOauthRequestToken()
  2805. {
  2806. $this->markTestIncomplete('killme() kills phpunit as well');
  2807. }
  2808. /**
  2809. * Test the api_oauth_access_token() function.
  2810. * @return void
  2811. */
  2812. public function testApiOauthAccessToken()
  2813. {
  2814. $this->markTestIncomplete('killme() kills phpunit as well');
  2815. }
  2816. /**
  2817. * Test the api_fr_photoalbum_delete() function.
  2818. * @return void
  2819. * @expectedException Friendica\Network\HTTPException\BadRequestException
  2820. */
  2821. public function testApiFrPhotoalbumDelete()
  2822. {
  2823. api_fr_photoalbum_delete('json');
  2824. }
  2825. /**
  2826. * Test the api_fr_photoalbum_delete() function with an album name.
  2827. * @return void
  2828. * @expectedException Friendica\Network\HTTPException\BadRequestException
  2829. */
  2830. public function testApiFrPhotoalbumDeleteWithAlbum()
  2831. {
  2832. $_REQUEST['album'] = 'album_name';
  2833. api_fr_photoalbum_delete('json');
  2834. }
  2835. /**
  2836. * Test the api_fr_photoalbum_delete() function with an album name.
  2837. * @return void
  2838. */
  2839. public function testApiFrPhotoalbumDeleteWithValidAlbum()
  2840. {
  2841. $this->markTestIncomplete('We need to add a dataset for this.');
  2842. }
  2843. /**
  2844. * Test the api_fr_photoalbum_delete() function.
  2845. * @return void
  2846. * @expectedException Friendica\Network\HTTPException\BadRequestException
  2847. */
  2848. public function testApiFrPhotoalbumUpdate()
  2849. {
  2850. api_fr_photoalbum_update('json');
  2851. }
  2852. /**
  2853. * Test the api_fr_photoalbum_delete() function with an album name.
  2854. * @return void
  2855. * @expectedException Friendica\Network\HTTPException\BadRequestException
  2856. */
  2857. public function testApiFrPhotoalbumUpdateWithAlbum()
  2858. {
  2859. $_REQUEST['album'] = 'album_name';
  2860. api_fr_photoalbum_update('json');
  2861. }
  2862. /**
  2863. * Test the api_fr_photoalbum_delete() function with an album name.
  2864. * @return void
  2865. * @expectedException Friendica\Network\HTTPException\BadRequestException
  2866. */
  2867. public function testApiFrPhotoalbumUpdateWithAlbumAndNewAlbum()
  2868. {
  2869. $_REQUEST['album'] = 'album_name';
  2870. $_REQUEST['album_new'] = 'album_name';
  2871. api_fr_photoalbum_update('json');
  2872. }
  2873. /**
  2874. * Test the api_fr_photoalbum_update() function without an authenticated user.
  2875. * @return void
  2876. * @expectedException Friendica\Network\HTTPException\ForbiddenException
  2877. */
  2878. public function testApiFrPhotoalbumUpdateWithoutAuthenticatedUser()
  2879. {
  2880. $_SESSION['authenticated'] = false;
  2881. api_fr_photoalbum_update('json');
  2882. }
  2883. /**
  2884. * Test the api_fr_photoalbum_delete() function with an album name.
  2885. * @return void
  2886. */
  2887. public function testApiFrPhotoalbumUpdateWithValidAlbum()
  2888. {
  2889. $this->markTestIncomplete('We need to add a dataset for this.');
  2890. }
  2891. /**
  2892. * Test the api_fr_photos_list() function.
  2893. * @return void
  2894. */
  2895. public function testApiFrPhotosList()
  2896. {
  2897. $result = api_fr_photos_list('json');
  2898. $this->assertArrayHasKey('photo', $result);
  2899. }
  2900. /**
  2901. * Test the api_fr_photos_list() function without an authenticated user.
  2902. * @return void
  2903. * @expectedException Friendica\Network\HTTPException\ForbiddenException
  2904. */
  2905. public function testApiFrPhotosListWithoutAuthenticatedUser()
  2906. {
  2907. $_SESSION['authenticated'] = false;
  2908. api_fr_photos_list('json');
  2909. }
  2910. /**
  2911. * Test the api_fr_photo_create_update() function.
  2912. * @return void
  2913. * @expectedException Friendica\Network\HTTPException\BadRequestException
  2914. */
  2915. public function testApiFrPhotoCreateUpdate()
  2916. {
  2917. api_fr_photo_create_update('json');
  2918. }
  2919. /**
  2920. * Test the api_fr_photo_create_update() function without an authenticated user.
  2921. * @return void
  2922. * @expectedException Friendica\Network\HTTPException\ForbiddenException
  2923. */
  2924. public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
  2925. {
  2926. $_SESSION['authenticated'] = false;
  2927. api_fr_photo_create_update('json');
  2928. }
  2929. /**
  2930. * Test the api_fr_photo_create_update() function with an album name.
  2931. * @return void
  2932. * @expectedException Friendica\Network\HTTPException\BadRequestException
  2933. */
  2934. public function testApiFrPhotoCreateUpdateWithAlbum()
  2935. {
  2936. $_REQUEST['album'] = 'album_name';
  2937. api_fr_photo_create_update('json');
  2938. }
  2939. /**
  2940. * Test the api_fr_photo_create_update() function with the update mode.
  2941. * @return void
  2942. */
  2943. public function testApiFrPhotoCreateUpdateWithUpdate()
  2944. {
  2945. $this->markTestIncomplete('We need to create a dataset for this');
  2946. }
  2947. /**
  2948. * Test the api_fr_photo_create_update() function with an uploaded file.
  2949. * @return void
  2950. */
  2951. public function testApiFrPhotoCreateUpdateWithFile()
  2952. {
  2953. $this->markTestIncomplete();
  2954. }
  2955. /**
  2956. * Test the api_fr_photo_delete() function.
  2957. * @return void
  2958. * @expectedException Friendica\Network\HTTPException\BadRequestException
  2959. */
  2960. public function testApiFrPhotoDelete()
  2961. {
  2962. api_fr_photo_delete('json');
  2963. }
  2964. /**
  2965. * Test the api_fr_photo_delete() function without an authenticated user.
  2966. * @return void
  2967. * @expectedException Friendica\Network\HTTPException\ForbiddenException
  2968. */
  2969. public function testApiFrPhotoDeleteWithoutAuthenticatedUser()
  2970. {
  2971. $_SESSION['authenticated'] = false;
  2972. api_fr_photo_delete('json');
  2973. }
  2974. /**
  2975. * Test the api_fr_photo_delete() function with a photo ID.
  2976. * @return void
  2977. * @expectedException Friendica\Network\HTTPException\BadRequestException
  2978. */
  2979. public function testApiFrPhotoDeleteWithPhotoId()
  2980. {
  2981. $_REQUEST['photo_id'] = 1;
  2982. api_fr_photo_delete('json');
  2983. }
  2984. /**
  2985. * Test the api_fr_photo_delete() function with a correct photo ID.
  2986. * @return void
  2987. */
  2988. public function testApiFrPhotoDeleteWithCorrectPhotoId()
  2989. {
  2990. $this->markTestIncomplete('We need to create a dataset for this.');
  2991. }
  2992. /**
  2993. * Test the api_fr_photo_detail() function.
  2994. * @return void
  2995. * @expectedException Friendica\Network\HTTPException\BadRequestException
  2996. */
  2997. public function testApiFrPhotoDetail()
  2998. {
  2999. api_fr_photo_detail('json');
  3000. }
  3001. /**
  3002. * Test the api_fr_photo_detail() function without an authenticated user.
  3003. * @return void
  3004. * @expectedException Friendica\Network\HTTPException\ForbiddenException
  3005. */
  3006. public function testApiFrPhotoDetailWithoutAuthenticatedUser()
  3007. {
  3008. $_SESSION['authenticated'] = false;
  3009. api_fr_photo_detail('json');
  3010. }
  3011. /**
  3012. * Test the api_fr_photo_detail() function with a photo ID.
  3013. * @return void
  3014. * @expectedException Friendica\Network\HTTPException\NotFoundException
  3015. */
  3016. public function testApiFrPhotoDetailWithPhotoId()
  3017. {
  3018. $_REQUEST['photo_id'] = 1;
  3019. api_fr_photo_detail('json');
  3020. }
  3021. /**
  3022. * Test the api_fr_photo_detail() function with a correct photo ID.
  3023. * @return void
  3024. */
  3025. public function testApiFrPhotoDetailCorrectPhotoId()
  3026. {
  3027. $this->markTestIncomplete('We need to create a dataset for this.');
  3028. }
  3029. /**
  3030. * Test the api_account_update_profile_image() function.
  3031. * @return void
  3032. * @expectedException Friendica\Network\HTTPException\BadRequestException
  3033. */
  3034. public function testApiAccountUpdateProfileImage()
  3035. {
  3036. api_account_update_profile_image('json');
  3037. }
  3038. /**
  3039. * Test the api_account_update_profile_image() function without an authenticated user.
  3040. * @return void
  3041. * @expectedException Friendica\Network\HTTPException\ForbiddenException
  3042. */
  3043. public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
  3044. {
  3045. $_SESSION['authenticated'] = false;
  3046. api_account_update_profile_image('json');
  3047. }
  3048. /**
  3049. * Test the api_account_update_profile_image() function with an uploaded file.
  3050. * @return void
  3051. * @expectedException Friendica\Network\HTTPException\BadRequestException
  3052. */
  3053. public function testApiAccountUpdateProfileImageWithUpload()
  3054. {
  3055. $this->markTestIncomplete();
  3056. }
  3057. /**
  3058. * Test the api_account_update_profile() function.
  3059. * @return void
  3060. */
  3061. public function testApiAccountUpdateProfile()
  3062. {
  3063. $_POST['name'] = 'new_name';
  3064. $_POST['description'] = 'new_description';
  3065. $result = api_account_update_profile('json');
  3066. // We can't use assertSelfUser() here because the user object is missing some properties.
  3067. $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
  3068. $this->assertEquals('DFRN', $result['user']['location']);
  3069. $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
  3070. $this->assertEquals('dfrn', $result['user']['network']);
  3071. $this->assertEquals('new_name', $result['user']['name']);
  3072. $this->assertEquals('new_description', $result['user']['description']);
  3073. }
  3074. /**
  3075. * Test the check_acl_input() function.
  3076. * @return void
  3077. */
  3078. public function testCheckAclInput()
  3079. {
  3080. $result = check_acl_input('<aclstring>');
  3081. // Where does this result come from?
  3082. $this->assertEquals(1, $result);
  3083. }
  3084. /**
  3085. * Test the check_acl_input() function with an empty ACL string.
  3086. * @return void
  3087. */
  3088. public function testCheckAclInputWithEmptyAclString()
  3089. {
  3090. $result = check_acl_input(' ');
  3091. $this->assertFalse($result);
  3092. }
  3093. /**
  3094. * Test the save_media_to_database() function.
  3095. * @return void
  3096. */
  3097. public function testSaveMediaToDatabase()
  3098. {
  3099. $this->markTestIncomplete();
  3100. }
  3101. /**
  3102. * Test the post_photo_item() function.
  3103. * @return void
  3104. */
  3105. public function testPostPhotoItem()
  3106. {
  3107. $this->markTestIncomplete();
  3108. }
  3109. /**
  3110. * Test the prepare_photo_data() function.
  3111. * @return void
  3112. */
  3113. public function testPreparePhotoData()
  3114. {
  3115. $this->markTestIncomplete();
  3116. }
  3117. /**
  3118. * Test the api_friendica_remoteauth() function.
  3119. * @return void
  3120. * @expectedException Friendica\Network\HTTPException\BadRequestException
  3121. */
  3122. public function testApiFriendicaRemoteauth()
  3123. {
  3124. api_friendica_remoteauth();
  3125. }
  3126. /**
  3127. * Test the api_friendica_remoteauth() function with an URL.
  3128. * @return void
  3129. * @expectedException Friendica\Network\HTTPException\BadRequestException
  3130. */
  3131. public function testApiFriendicaRemoteauthWithUrl()
  3132. {
  3133. $_GET['url'] = 'url';
  3134. $_GET['c_url'] = 'url';
  3135. api_friendica_remoteauth();
  3136. }
  3137. /**
  3138. * Test the api_friendica_remoteauth() function with a correct URL.
  3139. * @return void
  3140. */
  3141. public function testApiFriendicaRemoteauthWithCorrectUrl()
  3142. {
  3143. $this->markTestIncomplete("We can't use an assertion here because of App->redirect().");
  3144. $_GET['url'] = 'url';
  3145. $_GET['c_url'] = $this->selfUser['nurl'];
  3146. api_friendica_remoteauth();
  3147. }
  3148. /**
  3149. * Test the api_share_as_retweet() function.
  3150. * @return void
  3151. */
  3152. public function testApiShareAsRetweet()
  3153. {
  3154. $item = ['body' => '', 'author-id' => 1, 'owner-id' => 1];
  3155. $result = api_share_as_retweet($item);
  3156. $this->assertFalse($result);
  3157. }
  3158. /**
  3159. * Test the api_share_as_retweet() function with a valid item.
  3160. * @return void
  3161. */
  3162. public function testApiShareAsRetweetWithValidItem()
  3163. {
  3164. $this->markTestIncomplete();
  3165. }
  3166. /**
  3167. * Test the api_get_nick() function.
  3168. * @return void
  3169. */
  3170. public function testApiGetNick()
  3171. {
  3172. $result = api_get_nick($this->otherUser['nurl']);
  3173. $this->assertEquals('othercontact', $result);
  3174. }
  3175. /**
  3176. * Test the api_get_nick() function with a wrong URL.
  3177. * @return void
  3178. */
  3179. public function testApiGetNickWithWrongUrl()
  3180. {
  3181. $result = api_get_nick('wrong_url');
  3182. $this->assertFalse($result);
  3183. }
  3184. /**
  3185. * Test the api_in_reply_to() function.
  3186. * @return void
  3187. */
  3188. public function testApiInReplyTo()
  3189. {
  3190. $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
  3191. $this->assertArrayHasKey('status_id', $result);
  3192. $this->assertArrayHasKey('user_id', $result);
  3193. $this->assertArrayHasKey('status_id_str', $result);
  3194. $this->assertArrayHasKey('user_id_str', $result);
  3195. $this->assertArrayHasKey('screen_name', $result);
  3196. }
  3197. /**
  3198. * Test the api_in_reply_to() function with a valid item.
  3199. * @return void
  3200. */
  3201. public function testApiInReplyToWithValidItem()
  3202. {
  3203. $this->markTestIncomplete();
  3204. }
  3205. /**
  3206. * Test the api_clean_plain_items() function.
  3207. * @return void
  3208. */
  3209. public function testApiCleanPlainItems()
  3210. {
  3211. $_REQUEST['include_entities'] = 'true';
  3212. $result = api_clean_plain_items('some_text [url="some_url"]some_text[/url]');
  3213. $this->assertEquals('some_text [url="some_url"]"some_url"[/url]', $result);
  3214. }
  3215. /**
  3216. * Test the api_clean_attachments() function.
  3217. * @return void
  3218. */
  3219. public function testApiCleanAttachments()
  3220. {
  3221. $this->markTestIncomplete();
  3222. }
  3223. /**
  3224. * Test the api_best_nickname() function.
  3225. * @return void
  3226. */
  3227. public function testApiBestNickname()
  3228. {
  3229. $contacts = [];
  3230. $result = api_best_nickname($contacts);
  3231. $this->assertNull($result);
  3232. }
  3233. /**
  3234. * Test the api_best_nickname() function with contacts.
  3235. * @return void
  3236. */
  3237. public function testApiBestNicknameWithContacts()
  3238. {
  3239. $this->markTestIncomplete();
  3240. }
  3241. /**
  3242. * Test the api_friendica_group_show() function.
  3243. * @return void
  3244. */
  3245. public function testApiFriendicaGroupShow()
  3246. {
  3247. $this->markTestIncomplete();
  3248. }
  3249. /**
  3250. * Test the api_friendica_group_delete() function.
  3251. * @return void
  3252. */
  3253. public function testApiFriendicaGroupDelete()
  3254. {
  3255. $this->markTestIncomplete();
  3256. }
  3257. /**
  3258. * Test the api_lists_destroy() function.
  3259. * @return void
  3260. */
  3261. public function testApiListsDestroy()
  3262. {
  3263. $this->markTestIncomplete();
  3264. }
  3265. /**
  3266. * Test the group_create() function.
  3267. * @return void
  3268. */
  3269. public function testGroupCreate()
  3270. {
  3271. $this->markTestIncomplete();
  3272. }
  3273. /**
  3274. * Test the api_friendica_group_create() function.
  3275. * @return void
  3276. */
  3277. public function testApiFriendicaGroupCreate()
  3278. {
  3279. $this->markTestIncomplete();
  3280. }
  3281. /**
  3282. * Test the api_lists_create() function.
  3283. * @return void
  3284. */
  3285. public function testApiListsCreate()
  3286. {
  3287. $this->markTestIncomplete();
  3288. }
  3289. /**
  3290. * Test the api_friendica_group_update() function.
  3291. * @return void
  3292. */
  3293. public function testApiFriendicaGroupUpdate()
  3294. {
  3295. $this->markTestIncomplete();
  3296. }
  3297. /**
  3298. * Test the api_lists_update() function.
  3299. * @return void
  3300. */
  3301. public function testApiListsUpdate()
  3302. {
  3303. $this->markTestIncomplete();
  3304. }
  3305. /**
  3306. * Test the api_friendica_activity() function.
  3307. * @return void
  3308. */
  3309. public function testApiFriendicaActivity()
  3310. {
  3311. $this->markTestIncomplete();
  3312. }
  3313. /**
  3314. * Test the api_friendica_notification() function.
  3315. * @return void
  3316. * @expectedException Friendica\Network\HTTPException\BadRequestException
  3317. */
  3318. public function testApiFriendicaNotification()
  3319. {
  3320. api_friendica_notification('json');
  3321. }
  3322. /**
  3323. * Test the api_friendica_notification() function without an authenticated user.
  3324. * @return void
  3325. * @expectedException Friendica\Network\HTTPException\ForbiddenException
  3326. */
  3327. public function testApiFriendicaNotificationWithoutAuthenticatedUser()
  3328. {
  3329. $_SESSION['authenticated'] = false;
  3330. api_friendica_notification('json');
  3331. }
  3332. /**
  3333. * Test the api_friendica_notification() function with an argument count.
  3334. * @return void
  3335. */
  3336. public function testApiFriendicaNotificationWithArgumentCount()
  3337. {
  3338. $this->app->argv = ['api', 'friendica', 'notification'];
  3339. $this->app->argc = count($this->app->argv);
  3340. $result = api_friendica_notification('json');
  3341. $this->assertEquals(['note' => false], $result);
  3342. }
  3343. /**
  3344. * Test the api_friendica_notification() function with an XML result.
  3345. * @return void
  3346. */
  3347. public function testApiFriendicaNotificationWithXmlResult()
  3348. {
  3349. $this->app->argv = ['api', 'friendica', 'notification'];
  3350. $this->app->argc = count($this->app->argv);
  3351. $result = api_friendica_notification('xml');
  3352. $this->assertXml($result, 'notes');
  3353. }
  3354. /**
  3355. * Test the api_friendica_notification_seen() function.
  3356. * @return void
  3357. */
  3358. public function testApiFriendicaNotificationSeen()
  3359. {
  3360. $this->markTestIncomplete();
  3361. }
  3362. /**
  3363. * Test the api_friendica_direct_messages_setseen() function.
  3364. * @return void
  3365. */
  3366. public function testApiFriendicaDirectMessagesSetseen()
  3367. {
  3368. $this->markTestIncomplete();
  3369. }
  3370. /**
  3371. * Test the api_friendica_direct_messages_search() function.
  3372. * @return void
  3373. */
  3374. public function testApiFriendicaDirectMessagesSearch()
  3375. {
  3376. $this->markTestIncomplete();
  3377. }
  3378. /**
  3379. * Test the api_friendica_profile_show() function.
  3380. * @return void
  3381. */
  3382. public function testApiFriendicaProfileShow()
  3383. {
  3384. $result = api_friendica_profile_show('json');
  3385. // We can't use assertSelfUser() here because the user object is missing some properties.
  3386. $this->assertEquals($this->selfUser['id'], $result['$result']['friendica_owner']['cid']);
  3387. $this->assertEquals('DFRN', $result['$result']['friendica_owner']['location']);
  3388. $this->assertEquals($this->selfUser['name'], $result['$result']['friendica_owner']['name']);
  3389. $this->assertEquals($this->selfUser['nick'], $result['$result']['friendica_owner']['screen_name']);
  3390. $this->assertEquals('dfrn', $result['$result']['friendica_owner']['network']);
  3391. $this->assertTrue($result['$result']['friendica_owner']['verified']);
  3392. $this->assertFalse($result['$result']['multi_profiles']);
  3393. }
  3394. /**
  3395. * Test the api_friendica_profile_show() function with a profile ID.
  3396. * @return void
  3397. */
  3398. public function testApiFriendicaProfileShowWithProfileId()
  3399. {
  3400. $this->markTestIncomplete('We need to add a dataset for this.');
  3401. }
  3402. /**
  3403. * Test the api_friendica_profile_show() function with a wrong profile ID.
  3404. * @return void
  3405. * @expectedException Friendica\Network\HTTPException\BadRequestException
  3406. */
  3407. public function testApiFriendicaProfileShowWithWrongProfileId()
  3408. {
  3409. $_REQUEST['profile_id'] = 666;
  3410. api_friendica_profile_show('json');
  3411. }
  3412. /**
  3413. * Test the api_friendica_profile_show() function without an authenticated user.
  3414. * @return void
  3415. * @expectedException Friendica\Network\HTTPException\ForbiddenException
  3416. */
  3417. public function testApiFriendicaProfileShowWithoutAuthenticatedUser()
  3418. {
  3419. $_SESSION['authenticated'] = false;
  3420. api_friendica_profile_show('json');
  3421. }
  3422. /**
  3423. * Test the api_saved_searches_list() function.
  3424. * @return void
  3425. */
  3426. public function testApiSavedSearchesList()
  3427. {
  3428. $result = api_saved_searches_list('json');
  3429. $this->assertEquals(1, $result['terms'][0]['id']);
  3430. $this->assertEquals(1, $result['terms'][0]['id_str']);
  3431. $this->assertEquals('Saved search', $result['terms'][0]['name']);
  3432. $this->assertEquals('Saved search', $result['terms'][0]['query']);
  3433. }
  3434. }