3 namespace Friendica\Test\src\App;
6 use Friendica\Core\Config\Configuration;
7 use Friendica\LegacyModule;
8 use Friendica\Module\PageNotFound;
9 use Friendica\Module\WellKnown\HostMeta;
10 use Friendica\Test\DatabaseTest;
12 class ModuleTest extends DatabaseTest
14 private function assertModule(array $assert, App\Module $module)
16 $this->assertEquals($assert['isBackend'], $module->isBackend());
17 $this->assertEquals($assert['name'], $module->getName());
18 $this->assertEquals($assert['class'], $module->getClassName());
22 * Test the default module mode
24 public function testDefault()
26 $module = new App\Module();
30 'name' => App\Module::DEFAULT,
31 'class' => App\Module::DEFAULT_CLASS,
35 public function dataModuleName()
42 'class' => App\Module::DEFAULT_CLASS,
44 'args' => new App\Arguments('network/data/in',
46 ['network', 'data', 'in'],
50 'withStrikeAndPoint' => [
53 'name' => 'with_strike_and_point',
54 'class' => App\Module::DEFAULT_CLASS,
56 'args' => new App\Arguments('with-strike.and-point/data/in',
57 'with-strike.and-point/data/in',
58 ['with-strike.and-point', 'data', 'in'],
65 'name' => App\Module::DEFAULT,
66 'class' => App\Module::DEFAULT_CLASS,
68 'args' => new App\Arguments(),
74 'name' => App\Module::DEFAULT,
75 'class' => App\Module::DEFAULT_CLASS,
77 'args' => new App\Arguments(),
78 'server' => ['PHP_SELF' => 'index.php']
80 'withIndexButBackendMod' => [
83 'name' => App\Module::BACKEND_MODULES[0],
84 'class' => App\Module::DEFAULT_CLASS,
86 'args' => new App\Arguments(App\Module::BACKEND_MODULES[0] . '/data/in',
87 App\Module::BACKEND_MODULES[0] . '/data/in',
88 [App\Module::BACKEND_MODULES[0], 'data', 'in'],
90 'server' => ['PHP_SELF' => 'index.php']
92 'withNotIndexAndBackendMod' => [
95 'name' => App\Module::BACKEND_MODULES[0],
96 'class' => App\Module::DEFAULT_CLASS,
98 'args' => new App\Arguments(App\Module::BACKEND_MODULES[0] . '/data/in',
99 App\Module::BACKEND_MODULES[0] . '/data/in',
100 [App\Module::BACKEND_MODULES[0], 'data', 'in'],
102 'server' => ['PHP_SELF' => 'daemon.php']
104 'withFirefoxApp' => [
106 'isBackend' => false,
108 'class' => App\Module::DEFAULT_CLASS,
110 'args' => new App\Arguments('users/sign_in',
112 ['users', 'sign_in'],
114 'server' => ['PHP_SELF' => 'index.php'],
120 * Test the module name and backend determination
122 * @dataProvider dataModuleName
124 public function testModuleName(array $assert, App\Arguments $args, array $server)
126 $module = (new App\Module())->determineModule($args, $server);
128 $this->assertModule($assert, $module);
131 public function dataModuleClass()
135 'assert' => App\Module::DEFAULT_CLASS,
136 'name' => App\Module::DEFAULT,
137 'command' => App\Module::DEFAULT,
141 'assert' => LegacyModule::class,
142 // API is one of the last modules to switch from legacy to new BaseModule
143 // so this should be a stable test case until we completely switch ;-)
145 'command' => 'api/test/it',
149 'assert' => HostMeta::class,
151 'command' => '.well-known/host-meta',
155 'assert' => PageNotFound::class,
157 'command' => 'invalid',
164 * Test the determination of the module class
166 * @dataProvider dataModuleClass
168 public function testModuleClass($assert, string $name, string $command, bool $privAdd)
170 $config = \Mockery::mock(Configuration::class);
171 $config->shouldReceive('get')->with('config', 'private_addons', false)->andReturn($privAdd)->atMost()->once();
173 $module = (new App\Module($name))->determineClass(new App\Arguments('', $command), new App\Router(), $config);
175 $this->assertEquals($assert, $module->getClassName());
179 * Test that modules are immutable
181 public function testImmutable()
183 $module = new App\Module();
185 $moduleNew = $module->determineModule(new App\Arguments(), []);
187 $this->assertNotSame($moduleNew, $module);