]> git.mxchange.org Git - friendica.git/blobdiff - tests/src/App/ModuleTest.php
Replaced most "api_get_user" calls with newer BaseApi calls
[friendica.git] / tests / src / App / ModuleTest.php
index e43f22d0ceb2d96e3b84990b8dfc82deeaa9b6cd..c5d4e11faa3f98d43b5aeb91a831bae545f35a4a 100644 (file)
@@ -1,21 +1,44 @@
 <?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\App;
 
 use Friendica\App;
-use Friendica\Core\Config\Configuration;
+use Friendica\Core\Cache\Capability\ICanCache;
+use Friendica\Core\Config\Capability\IManageConfigValues;
+use Friendica\Core\L10n;
+use Friendica\Core\Lock\Capability\ICanLock;
 use Friendica\LegacyModule;
-use Friendica\Module\PageNotFound;
+use Friendica\Module\HTTPException\PageNotFound;
 use Friendica\Module\WellKnown\HostMeta;
 use Friendica\Test\DatabaseTest;
+use Mockery;
 
 class ModuleTest extends DatabaseTest
 {
        private function assertModule(array $assert, App\Module $module)
        {
-               $this->assertEquals($assert['isBackend'], $module->isBackend());
-               $this->assertEquals($assert['name'], $module->getName());
-               $this->assertEquals($assert['class'], $module->getClassName());
+               self::assertEquals($assert['isBackend'], $module->isBackend());
+               self::assertEquals($assert['name'], $module->getName());
+               self::assertEquals($assert['class'], $module->getClassName());
        }
 
        /**
@@ -25,7 +48,7 @@ class ModuleTest extends DatabaseTest
        {
                $module = new App\Module();
 
-               $this->assertModule([
+               self::assertModule([
                        'isBackend' => false,
                        'name'      => App\Module::DEFAULT,
                        'class'     => App\Module::DEFAULT_CLASS,
@@ -107,7 +130,7 @@ class ModuleTest extends DatabaseTest
        {
                $module = (new App\Module())->determineModule($args);
 
-               $this->assertModule($assert, $module);
+               self::assertModule($assert, $module);
        }
 
        public function dataModuleClass()
@@ -121,10 +144,8 @@ class ModuleTest extends DatabaseTest
                        ],
                        'legacy'  => [
                                'assert'  => LegacyModule::class,
-                               // API is one of the last modules to switch from legacy to new BaseModule
-                               // so this should be a stable test case until we completely switch ;-)
-                               'name'    => 'api',
-                               'command' => 'api/test/it',
+                               'name'    => 'display',
+                               'command' => 'display/test/it',
                                'privAdd' => false,
                        ],
                        'new'     => [
@@ -149,14 +170,26 @@ class ModuleTest extends DatabaseTest
         */
        public function testModuleClass($assert, string $name, string $command, bool $privAdd)
        {
-               $config = \Mockery::mock(Configuration::class);
+               $config = Mockery::mock(IManageConfigValues::class);
                $config->shouldReceive('get')->with('config', 'private_addons', false)->andReturn($privAdd)->atMost()->once();
 
-               $router = (new App\Router([]))->addRoutes(include __DIR__ . '/../../../static/routes.config.php');
+               $l10n = Mockery::mock(L10n::class);
+               $l10n->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
+
+               $cache = Mockery::mock(ICanCache::class);
+               $cache->shouldReceive('get')->with('routerDispatchData')->andReturn('')->atMost()->once();
+               $cache->shouldReceive('get')->with('lastRoutesFileModifiedTime')->andReturn('')->atMost()->once();
+               $cache->shouldReceive('set')->withAnyArgs()->andReturn(false)->atMost()->twice();
+
+               $lock = Mockery::mock(ICanLock::class);
+               $lock->shouldReceive('acquire')->andReturn(true);
+               $lock->shouldReceive('isLocked')->andReturn(false);
+
+               $router = (new App\Router([], __DIR__ . '/../../../static/routes.config.php', $l10n, $cache, $lock));
 
                $module = (new App\Module($name))->determineClass(new App\Arguments('', $command), $router, $config);
 
-               $this->assertEquals($assert, $module->getClassName());
+               self::assertEquals($assert, $module->getClassName());
        }
 
        /**
@@ -166,8 +199,8 @@ class ModuleTest extends DatabaseTest
        {
                $module = new App\Module();
 
-               $moduleNew = $module->determineModule(new App\Arguments(), []);
+               $moduleNew = $module->determineModule(new App\Arguments());
 
-               $this->assertNotSame($moduleNew, $module);
+               self::assertNotSame($moduleNew, $module);
        }
 }