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.

3734 lines
95KB

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