]> git.mxchange.org Git - friendica.git/commitdiff
Add MessageDirect\Search tests
authorPhilipp <admin@philipp.info>
Mon, 27 Dec 2021 19:02:37 +0000 (20:02 +0100)
committerPhilipp <admin@philipp.info>
Mon, 27 Dec 2021 19:02:37 +0000 (20:02 +0100)
src/Module/Api/Friendica/DirectMessages/Search.php
tests/datasets/mail/mail.fixture.php [new file with mode: 0644]
tests/src/Module/Api/Friendica/DirectMessages/SearchTest.php [new file with mode: 0644]

index c0322a95ec7b9566e0d0df4a4cc20fdac56a33b0..679accb33ad4e009d9d1f290d0414bb322e66509 100644 (file)
@@ -73,8 +73,6 @@ class Search extends BaseApi
 
                // message if nothing was found
                if (!DBA::isResult($mails)) {
-                       $success = ['success' => false, 'search_results' => 'problem with query'];
-               } elseif (count($mails) == 0) {
                        $success = ['success' => false, 'search_results' => 'nothing found'];
                } else {
                        $ret = [];
diff --git a/tests/datasets/mail/mail.fixture.php b/tests/datasets/mail/mail.fixture.php
new file mode 100644 (file)
index 0000000..215356b
--- /dev/null
@@ -0,0 +1,17 @@
+<?php
+
+return [
+       'mail' => [
+               [
+                       'uid'           => 42,
+                       'author-id'     => 44,
+                       'uri-id'        => 44,
+                       'parent-uri-id' => 44,
+                       'thr-parent-id' => 44,
+                       'guid'          => '123456',
+                       'from-name'     => 'Tester',
+                       'title'         => 'test message',
+                       'body'          => 'this is a test',
+               ],
+       ],
+];
diff --git a/tests/src/Module/Api/Friendica/DirectMessages/SearchTest.php b/tests/src/Module/Api/Friendica/DirectMessages/SearchTest.php
new file mode 100644 (file)
index 0000000..c66a1f4
--- /dev/null
@@ -0,0 +1,84 @@
+<?php
+/**
+ * @copyright Copyright (C) 2010-2021, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Friendica\Test\src\Module\Api\Friendica\DirectMessages;
+
+use Friendica\App\Router;
+use Friendica\DI;
+use Friendica\Factory\Api\Twitter\DirectMessage;
+use Friendica\Module\Api\Friendica\DirectMessages\Search;
+use Friendica\Test\src\Module\Api\ApiTest;
+use Psr\Log\NullLogger;
+
+class SearchTest extends ApiTest
+{
+       public function testEmpty()
+       {
+               $directMessage = new DirectMessage(new NullLogger(), DI::dba(), DI::twitterUser());
+
+               $response = (new Search($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]))->run();
+
+               $json = $this->toJson($response);
+
+               $assert          = new \stdClass();
+               $assert->result  = 'error';
+               $assert->message = 'searchstring not specified';
+
+               self::assertEquals($assert, $json);
+       }
+
+       public function testMail()
+       {
+               $this->loadFixture(__DIR__ . '/../../../../../datasets/mail/mail.fixture.php', DI::dba());
+
+               $directMessage = new DirectMessage(new NullLogger(), DI::dba(), DI::twitterUser());
+
+               $search   = new Search($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
+               $response = $search->run(['searchstring' => 'test']);
+
+               $json = $this->toJson($response);
+
+               self::assertTrue($json->success);
+
+               foreach ($json->search_results as $searchResult) {
+                       self::assertIsObject($searchResult->sender);
+                       self::assertIsInt($searchResult->id);
+                       self::assertIsInt($searchResult->sender_id);
+                       self::assertIsObject($searchResult->recipient);
+               }
+       }
+
+       public function testNothingFound()
+       {
+               $directMessage = new DirectMessage(new NullLogger(), DI::dba(), DI::twitterUser());
+
+               $search   = new Search($directMessage, DI::dba(), DI::app(), DI::l10n(), DI::baseUrl(), DI::args(), DI::logger(), DI::profiler(), DI::apiResponse(), ['REQUEST_METHOD' => Router::GET]);
+               $response = $search->run(['searchstring' => 'test']);
+
+               $json = $this->toJson($response);
+
+               $assert                 = new \stdClass();
+               $assert->success        = false;
+               $assert->search_results = 'nothing found';
+
+               self::assertEquals($assert, $json);
+       }
+}