]> git.mxchange.org Git - friendica.git/commitdiff
Fix BaseApi and corresponding tests
authorPhilipp <admin@philipp.info>
Sun, 28 Nov 2021 12:11:12 +0000 (13:11 +0100)
committerPhilipp <admin@philipp.info>
Sun, 28 Nov 2021 12:11:12 +0000 (13:11 +0100)
src/Module/BaseApi.php
tests/Util/AppDouble.php [new file with mode: 0644]
tests/src/Module/Api/ApiTest.php

index 5c94bc77276bc91d89c764b35f7ba52c6129b9c1..c67671954fd8979fb057042433090cf7b82c4c55 100644 (file)
@@ -67,6 +67,8 @@ class BaseApi extends BaseModule
        public function __construct(App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
        {
                parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
+
+               $this->app = $app;
        }
 
        protected function delete()
diff --git a/tests/Util/AppDouble.php b/tests/Util/AppDouble.php
new file mode 100644 (file)
index 0000000..dc9f635
--- /dev/null
@@ -0,0 +1,31 @@
+<?php
+
+namespace Friendica\Test\Util;
+
+use Friendica\App;
+
+/**
+ * Making the App class overridable for specific situations
+ *
+ * @see App
+ */
+class AppDouble extends App
+{
+       /** @var bool Marks/Overwrites if the user is currently logged in */
+       protected $isLoggedIn = false;
+
+       /**
+        * Manually overwrite the "isLoggedIn" behavior
+        *
+        * @param bool $isLoggedIn
+        */
+       public function setIsLoggedIn(bool $isLoggedIn)
+       {
+               $this->isLoggedIn = $isLoggedIn;
+       }
+
+       public function isLoggedIn()
+       {
+               return $this->isLoggedIn;
+       }
+}
index c530ace2ee71ba69fe9803046dff2769380b3e3a..7d8acc37a4d6482f3ecba4b21083d93de2baa953 100644 (file)
 
 namespace Friendica\Test\src\Module\Api;
 
+use Friendica\App;
 use Friendica\Core\Addon;
 use Friendica\Core\Hook;
 use Friendica\Database\Database;
 use Friendica\DI;
 use Friendica\Security\Authentication;
 use Friendica\Test\FixtureTest;
+use Friendica\Test\Util\AppDouble;
 use Friendica\Test\Util\AuthenticationDouble;
 
 abstract class ApiTest extends FixtureTest
@@ -51,9 +53,13 @@ abstract class ApiTest extends FixtureTest
                parent::setUp(); // TODO: Change the autogenerated stub
 
                $this->dice = $this->dice
-                       ->addRule(Authentication::class, ['instanceOf' => AuthenticationDouble::class, 'shared' => true]);
+                       ->addRule(Authentication::class, ['instanceOf' => AuthenticationDouble::class, 'shared' => true])
+                       ->addRule(App::class, ['instanceOf' => AppDouble::class, 'shared' => true]);
                DI::init($this->dice);
 
+               // Manual overwrite for API testrs :-)
+               DI::app()->setIsLoggedIn(true);
+
                $this->installAuthTest();
        }