]> git.mxchange.org Git - friendica.git/blobdiff - tests/include/ApiTest.php
BBCode - fixed syntax error
[friendica.git] / tests / include / ApiTest.php
index a539eb944777bb9e7a558b32e1ffc2668e25abc8..cf7571073addfdd38397aef30b4377a80948cf1b 100644 (file)
@@ -11,6 +11,8 @@ use Friendica\Core\PConfig;
 use Friendica\Core\Protocol;
 use Friendica\Core\System;
 use Friendica\Network\HTTPException;
+use Friendica\Util\LoggerFactory;
+use Monolog\Handler\TestHandler;
 
 require_once __DIR__ . '/../../include/api.php';
 
@@ -22,6 +24,11 @@ require_once __DIR__ . '/../../include/api.php';
  */
 class ApiTest extends DatabaseTest
 {
+       /**
+        * @var TestHandler Can handle log-outputs
+        */
+       protected $logOutput;
+
        /**
         * Create variables used by tests.
         */
@@ -30,6 +37,7 @@ class ApiTest extends DatabaseTest
                parent::setUp();
 
                $this->app = BaseObject::getApp();
+               $this->logOutput = LoggerFactory::enableTest($this->app->getLogger());
 
                // User data that the test database is populated with
                $this->selfUser = [
@@ -94,7 +102,7 @@ class ApiTest extends DatabaseTest
                $this->assertEquals($this->selfUser['id'], $user['uid']);
                $this->assertEquals($this->selfUser['id'], $user['cid']);
                $this->assertEquals(1, $user['self']);
-               $this->assertEquals('Friendica', $user['location']);
+               $this->assertEquals('DFRN', $user['location']);
                $this->assertEquals($this->selfUser['name'], $user['name']);
                $this->assertEquals($this->selfUser['nick'], $user['screen_name']);
                $this->assertEquals('dfrn', $user['network']);
@@ -1118,7 +1126,7 @@ class ApiTest extends DatabaseTest
         */
        public function testApiStatusesUpdate()
        {
-               $_GET['status'] = 'Status content';
+               $_GET['status'] = 'Status content #friendica';
                $_GET['in_reply_to_status_id'] = -1;
                $_GET['lat'] = 48;
                $_GET['long'] = 7;
@@ -1242,13 +1250,14 @@ class ApiTest extends DatabaseTest
                                'type' => 'image/png'
                        ]
                ];
-               $app = get_app();
+               $app = \get_app();
                $app->argc = 2;
 
                $result = api_media_upload();
                $this->assertEquals('image/png', $result['media']['image']['image_type']);
                $this->assertEquals(1, $result['media']['image']['w']);
                $this->assertEquals(1, $result['media']['image']['h']);
+               $this->assertNotEmpty($result['media']['image']['friendica_preview_url']);
        }
 
        /**
@@ -1289,7 +1298,7 @@ class ApiTest extends DatabaseTest
                $result = api_users_show('json');
                // We can't use assertSelfUser() here because the user object is missing some properties.
                $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
-               $this->assertEquals('Friendica', $result['user']['location']);
+               $this->assertEquals('DFRN', $result['user']['location']);
                $this->assertEquals($this->selfUser['name'], $result['user']['name']);
                $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
                $this->assertEquals('dfrn', $result['user']['network']);
@@ -1404,6 +1413,34 @@ class ApiTest extends DatabaseTest
                }
        }
 
+       /**
+        * Test the api_search() function with an q parameter contains hashtag.
+        * @return void
+        */
+       public function testApiSearchWithHashtag()
+       {
+               $_REQUEST['q'] = '%23friendica';
+               $result = api_search('json');
+               foreach ($result['status'] as $status) {
+                       $this->assertStatus($status);
+                       $this->assertContains('#friendica', $status['text'], null, true);
+               }
+       }
+
+       /**
+        * Test the api_search() function with an exclude_replies parameter.
+        * @return void
+        */
+       public function testApiSearchWithExcludeReplies()
+       {
+               $_REQUEST['max_id'] = 10;
+               $_REQUEST['exclude_replies'] = true;
+               $_REQUEST['q'] = 'friendica';
+               $result = api_search('json');
+               foreach ($result['status'] as $status) {
+                       $this->assertStatus($status);
+               }
+       }
 
        /**
         * Test the api_search() function without an authenticated user.
@@ -3296,7 +3333,7 @@ class ApiTest extends DatabaseTest
                $result = api_account_update_profile('json');
                // We can't use assertSelfUser() here because the user object is missing some properties.
                $this->assertEquals($this->selfUser['id'], $result['user']['cid']);
-               $this->assertEquals('Friendica', $result['user']['location']);
+               $this->assertEquals('DFRN', $result['user']['location']);
                $this->assertEquals($this->selfUser['nick'], $result['user']['screen_name']);
                $this->assertEquals('dfrn', $result['user']['network']);
                $this->assertEquals('new_name', $result['user']['name']);
@@ -3650,7 +3687,7 @@ class ApiTest extends DatabaseTest
                $result = api_friendica_profile_show('json');
                // We can't use assertSelfUser() here because the user object is missing some properties.
                $this->assertEquals($this->selfUser['id'], $result['$result']['friendica_owner']['cid']);
-               $this->assertEquals('Friendica', $result['$result']['friendica_owner']['location']);
+               $this->assertEquals('DFRN', $result['$result']['friendica_owner']['location']);
                $this->assertEquals($this->selfUser['name'], $result['$result']['friendica_owner']['name']);
                $this->assertEquals($this->selfUser['nick'], $result['$result']['friendica_owner']['screen_name']);
                $this->assertEquals('dfrn', $result['$result']['friendica_owner']['network']);