From: Philipp Date: Wed, 17 Nov 2021 07:16:33 +0000 (+0100) Subject: Add feedback X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=e73eda01565db47486ec5f95f4b96496a9c5f81f;p=friendica.git Add feedback --- diff --git a/src/Module/Acctlink.php b/src/Module/Acctlink.php index 4093e3cd8e..81b2c2391c 100644 --- a/src/Module/Acctlink.php +++ b/src/Module/Acctlink.php @@ -34,15 +34,15 @@ class Acctlink extends BaseModule public function rawContent() { $addr = trim($_GET['addr'] ?? ''); + if (!$addr) { + throw new NotFoundException('Parameter "addr" is missing or empty'); + } - if ($addr) { - $url = Contact::getByURL($addr)['url'] ?? ''; - if ($url) { - System::externalRedirect($url['url']); - exit(); - } + $contact = Contact::getByURL($addr, null, ['url']) ?? ''; + if (!$contact) { + throw new NotFoundException('Contact not found'); } - throw new NotFoundException('Parameter "url" is missing'); + System::externalRedirect($contact['url']); } } diff --git a/tests/src/App/ModuleControllerTest.php b/tests/src/App/ModuleControllerTest.php new file mode 100644 index 0000000000..13ef16a6d4 --- /dev/null +++ b/tests/src/App/ModuleControllerTest.php @@ -0,0 +1,219 @@ +. + * + */ + +namespace Friendica\Test\src\App; + +use Dice\Dice; +use Friendica\App; +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\HTTPException\PageNotFound; +use Friendica\Module\WellKnown\HostMeta; +use Friendica\Test\DatabaseTest; +use Mockery; + +class ModuleControllerTest extends DatabaseTest +{ + private function assertModule(array $assert, App\ModuleController $module) + { + self::assertEquals($assert['isBackend'], $module->isBackend()); + self::assertEquals($assert['name'], $module->getName()); + self::assertEquals($assert['class'], $module->getModule()); + } + + /** + * Test the default module mode + */ + public function testDefault() + { + $module = new App\ModuleController(); + + $defaultClass = App\ModuleController::DEFAULT_CLASS; + + self::assertModule([ + 'isBackend' => false, + 'name' => App\ModuleController::DEFAULT, + 'class' => new $defaultClass(), + ], $module); + } + + public function dataModuleName() + { + $defaultClass = App\ModuleController::DEFAULT_CLASS; + + return [ + 'default' => [ + 'assert' => [ + 'isBackend' => false, + 'name' => 'network', + 'class' => new $defaultClass(), + ], + 'args' => new App\Arguments('network/data/in', + 'network/data/in', + ['network', 'data', 'in'], + 3), + ], + 'withStrikeAndPoint' => [ + 'assert' => [ + 'isBackend' => false, + 'name' => 'with_strike_and_point', + 'class' => new $defaultClass(), + ], + 'args' => new App\Arguments('with-strike.and-point/data/in', + 'with-strike.and-point/data/in', + ['with-strike.and-point', 'data', 'in'], + 3), + ], + 'withNothing' => [ + 'assert' => [ + 'isBackend' => false, + 'name' => App\ModuleController::DEFAULT, + 'class' => new $defaultClass(), + ], + 'args' => new App\Arguments(), + ], + 'withIndex' => [ + 'assert' => [ + 'isBackend' => false, + 'name' => App\ModuleController::DEFAULT, + 'class' => new $defaultClass(), + ], + 'args' => new App\Arguments(), + ], + 'withBackendMod' => [ + 'assert' => [ + 'isBackend' => true, + 'name' => App\ModuleController::BACKEND_MODULES[0], + 'class' => new $defaultClass(), + ], + 'args' => new App\Arguments(App\ModuleController::BACKEND_MODULES[0] . '/data/in', + App\ModuleController::BACKEND_MODULES[0] . '/data/in', + [App\ModuleController::BACKEND_MODULES[0], 'data', 'in'], + 3), + ], + 'withFirefoxApp' => [ + 'assert' => [ + 'isBackend' => false, + 'name' => 'login', + 'class' => new $defaultClass(), + ], + 'args' => new App\Arguments('users/sign_in', + 'users/sign_in', + ['users', 'sign_in'], + 3), + ], + ]; + } + + /** + * Test the module name and backend determination + * + * @dataProvider dataModuleName + */ + public function testModuleName(array $assert, App\Arguments $args) + { + $module = (new App\ModuleController())->determineName($args); + + self::assertModule($assert, $module); + } + + public function dataModuleClass() + { + return [ + 'default' => [ + 'assert' => App\ModuleController::DEFAULT_CLASS, + 'name' => App\ModuleController::DEFAULT, + 'command' => App\ModuleController::DEFAULT, + 'privAdd' => false, + 'args' => [], + ], + 'legacy' => [ + 'assert' => LegacyModule::class, + 'name' => 'display', + 'command' => 'display/test/it', + 'privAdd' => false, + 'args' => [__DIR__ . '/../../datasets/legacy/legacy.php'], + ], + 'new' => [ + 'assert' => HostMeta::class, + 'not_required', + 'command' => '.well-known/host-meta', + 'privAdd' => false, + 'args' => [], + ], + '404' => [ + 'assert' => PageNotFound::class, + 'name' => 'invalid', + 'command' => 'invalid', + 'privAdd' => false, + 'args' => [], + ] + ]; + } + + /** + * Test the determination of the module class + * + * @dataProvider dataModuleClass + */ + public function testModuleClass($assert, string $name, string $command, bool $privAdd, array $args) + { + $config = Mockery::mock(IManageConfigValues::class); + $config->shouldReceive('get')->with('config', 'private_addons', false)->andReturn($privAdd)->atMost()->once(); + + $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)); + + $dice = Mockery::mock(Dice::class); + + $dice->shouldReceive('create')->andReturn(new $assert(...$args)); + + $module = (new App\ModuleController($name))->determineClass(new App\Arguments('', $command), $router, $config, $dice); + + self::assertEquals($assert, $module->getModule()->getClassName()); + } + + /** + * Test that modules are immutable + */ + public function testImmutable() + { + $module = new App\ModuleController(); + + $moduleNew = $module->determineName(new App\Arguments()); + + self::assertNotSame($moduleNew, $module); + } +} diff --git a/tests/src/App/ModuleTest.php b/tests/src/App/ModuleTest.php deleted file mode 100644 index 13ef16a6d4..0000000000 --- a/tests/src/App/ModuleTest.php +++ /dev/null @@ -1,219 +0,0 @@ -. - * - */ - -namespace Friendica\Test\src\App; - -use Dice\Dice; -use Friendica\App; -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\HTTPException\PageNotFound; -use Friendica\Module\WellKnown\HostMeta; -use Friendica\Test\DatabaseTest; -use Mockery; - -class ModuleControllerTest extends DatabaseTest -{ - private function assertModule(array $assert, App\ModuleController $module) - { - self::assertEquals($assert['isBackend'], $module->isBackend()); - self::assertEquals($assert['name'], $module->getName()); - self::assertEquals($assert['class'], $module->getModule()); - } - - /** - * Test the default module mode - */ - public function testDefault() - { - $module = new App\ModuleController(); - - $defaultClass = App\ModuleController::DEFAULT_CLASS; - - self::assertModule([ - 'isBackend' => false, - 'name' => App\ModuleController::DEFAULT, - 'class' => new $defaultClass(), - ], $module); - } - - public function dataModuleName() - { - $defaultClass = App\ModuleController::DEFAULT_CLASS; - - return [ - 'default' => [ - 'assert' => [ - 'isBackend' => false, - 'name' => 'network', - 'class' => new $defaultClass(), - ], - 'args' => new App\Arguments('network/data/in', - 'network/data/in', - ['network', 'data', 'in'], - 3), - ], - 'withStrikeAndPoint' => [ - 'assert' => [ - 'isBackend' => false, - 'name' => 'with_strike_and_point', - 'class' => new $defaultClass(), - ], - 'args' => new App\Arguments('with-strike.and-point/data/in', - 'with-strike.and-point/data/in', - ['with-strike.and-point', 'data', 'in'], - 3), - ], - 'withNothing' => [ - 'assert' => [ - 'isBackend' => false, - 'name' => App\ModuleController::DEFAULT, - 'class' => new $defaultClass(), - ], - 'args' => new App\Arguments(), - ], - 'withIndex' => [ - 'assert' => [ - 'isBackend' => false, - 'name' => App\ModuleController::DEFAULT, - 'class' => new $defaultClass(), - ], - 'args' => new App\Arguments(), - ], - 'withBackendMod' => [ - 'assert' => [ - 'isBackend' => true, - 'name' => App\ModuleController::BACKEND_MODULES[0], - 'class' => new $defaultClass(), - ], - 'args' => new App\Arguments(App\ModuleController::BACKEND_MODULES[0] . '/data/in', - App\ModuleController::BACKEND_MODULES[0] . '/data/in', - [App\ModuleController::BACKEND_MODULES[0], 'data', 'in'], - 3), - ], - 'withFirefoxApp' => [ - 'assert' => [ - 'isBackend' => false, - 'name' => 'login', - 'class' => new $defaultClass(), - ], - 'args' => new App\Arguments('users/sign_in', - 'users/sign_in', - ['users', 'sign_in'], - 3), - ], - ]; - } - - /** - * Test the module name and backend determination - * - * @dataProvider dataModuleName - */ - public function testModuleName(array $assert, App\Arguments $args) - { - $module = (new App\ModuleController())->determineName($args); - - self::assertModule($assert, $module); - } - - public function dataModuleClass() - { - return [ - 'default' => [ - 'assert' => App\ModuleController::DEFAULT_CLASS, - 'name' => App\ModuleController::DEFAULT, - 'command' => App\ModuleController::DEFAULT, - 'privAdd' => false, - 'args' => [], - ], - 'legacy' => [ - 'assert' => LegacyModule::class, - 'name' => 'display', - 'command' => 'display/test/it', - 'privAdd' => false, - 'args' => [__DIR__ . '/../../datasets/legacy/legacy.php'], - ], - 'new' => [ - 'assert' => HostMeta::class, - 'not_required', - 'command' => '.well-known/host-meta', - 'privAdd' => false, - 'args' => [], - ], - '404' => [ - 'assert' => PageNotFound::class, - 'name' => 'invalid', - 'command' => 'invalid', - 'privAdd' => false, - 'args' => [], - ] - ]; - } - - /** - * Test the determination of the module class - * - * @dataProvider dataModuleClass - */ - public function testModuleClass($assert, string $name, string $command, bool $privAdd, array $args) - { - $config = Mockery::mock(IManageConfigValues::class); - $config->shouldReceive('get')->with('config', 'private_addons', false)->andReturn($privAdd)->atMost()->once(); - - $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)); - - $dice = Mockery::mock(Dice::class); - - $dice->shouldReceive('create')->andReturn(new $assert(...$args)); - - $module = (new App\ModuleController($name))->determineClass(new App\Arguments('', $command), $router, $config, $dice); - - self::assertEquals($assert, $module->getModule()->getClassName()); - } - - /** - * Test that modules are immutable - */ - public function testImmutable() - { - $module = new App\ModuleController(); - - $moduleNew = $module->determineName(new App\Arguments()); - - self::assertNotSame($moduleNew, $module); - } -}