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.

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