3 namespace Friendica\Test\src\App;
6 use Friendica\Core\Config\Configuration;
7 use Friendica\LegacyModule;
8 use Friendica\Module\HTTPException\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'],
49 'withStrikeAndPoint' => [
52 'name' => 'with_strike_and_point',
53 'class' => App\Module::DEFAULT_CLASS,
55 'args' => new App\Arguments('with-strike.and-point/data/in',
56 'with-strike.and-point/data/in',
57 ['with-strike.and-point', 'data', 'in'],
63 'name' => App\Module::DEFAULT,
64 'class' => App\Module::DEFAULT_CLASS,
66 'args' => new App\Arguments(),
71 'name' => App\Module::DEFAULT,
72 'class' => App\Module::DEFAULT_CLASS,
74 'args' => new App\Arguments(),
79 'name' => App\Module::BACKEND_MODULES[0],
80 'class' => App\Module::DEFAULT_CLASS,
82 'args' => new App\Arguments(App\Module::BACKEND_MODULES[0] . '/data/in',
83 App\Module::BACKEND_MODULES[0] . '/data/in',
84 [App\Module::BACKEND_MODULES[0], 'data', 'in'],
91 'class' => App\Module::DEFAULT_CLASS,
93 'args' => new App\Arguments('users/sign_in',
102 * Test the module name and backend determination
104 * @dataProvider dataModuleName
106 public function testModuleName(array $assert, App\Arguments $args)
108 $module = (new App\Module())->determineModule($args);
110 $this->assertModule($assert, $module);
113 public function dataModuleClass()
117 'assert' => App\Module::DEFAULT_CLASS,
118 'name' => App\Module::DEFAULT,
119 'command' => App\Module::DEFAULT,
123 'assert' => LegacyModule::class,
124 // API is one of the last modules to switch from legacy to new BaseModule
125 // so this should be a stable test case until we completely switch ;-)
127 'command' => 'api/test/it',
131 'assert' => HostMeta::class,
133 'command' => '.well-known/host-meta',
137 'assert' => PageNotFound::class,
139 'command' => 'invalid',
146 * Test the determination of the module class
148 * @dataProvider dataModuleClass
150 public function testModuleClass($assert, string $name, string $command, bool $privAdd)
152 $config = \Mockery::mock(Configuration::class);
153 $config->shouldReceive('get')->with('config', 'private_addons', false)->andReturn($privAdd)->atMost()->once();
155 $router = (new App\Router([]))->loadRoutes(include __DIR__ . '/../../../static/routes.config.php');
157 $module = (new App\Module($name))->determineClass(new App\Arguments('', $command), $router, $config);
159 $this->assertEquals($assert, $module->getClassName());
163 * Test that modules are immutable
165 public function testImmutable()
167 $module = new App\Module();
169 $moduleNew = $module->determineModule(new App\Arguments());
171 $this->assertNotSame($moduleNew, $module);