resetRuntimeContext(); $this->app = new App(TEST_PROJECT_ROOT); RuntimeService::init($this->app); $this->app->initialize(); $this->app->config->set(['with_route' => true], 'app'); $this->app->config->set(['default_app' => 'index'], 'route'); $request = $this->app->make('request', [], true); $request->setRoot(''); $request->setPathinfo('system/login/index'); $this->app->instance('request', $request); } protected function tearDown(): void { $this->resetRuntimeContext(); parent::tearDown(); } public function testLibraryHelpersAreLoadedFromLibraryPackage(): void { foreach (['sysuri', 'apiuri', 'xss_safe', 'format_bytes'] as $name) { $this->assertTrue(function_exists($name), "{$name} should be autoloaded"); $reflection = new \ReflectionFunction($name); $this->assertSame( realpath(TEST_PROJECT_ROOT . '/plugin/think-library/src/common.php'), realpath((string)$reflection->getFileName()) ); } } public function testPlguriIsLoadedFromSystemPackage(): void { $this->assertTrue(function_exists('plguri')); $reflection = new \ReflectionFunction('plguri'); $this->assertSame( realpath(TEST_PROJECT_ROOT . '/plugin/think-plugs-system/src/common.php'), realpath((string)$reflection->getFileName()) ); } public function testSysuriAndUrlBuildSupportShortWebPaths(): void { $this->assertSame('/system', Url::normalizeWebTarget('system/index/index')); $this->assertSame('/system/plugin?from=force', Url::normalizeWebTarget('/system/plugin/index?from=force')); $this->assertSame('/system/plugin/layout?encode=test', Url::normalizeWebTarget('/system/plugin/layout?encode=test')); $this->assertSame('/system.html', sysuri('system/index/index')); $this->assertSame('/system.html', sysuri('/system/index/index')); $this->assertSame('/system/login.html', sysuri('/system/login/index')); $this->assertSame('/system/plugin/layout?encode=test', sysuri('/system/plugin/layout', ['encode' => 'test'], false)); $this->assertSame('/system/plugin.html?from=force', sysuri('/system/plugin/index', ['from' => 'force'])); $this->assertSame('/system/plugin.html', sysuri('/system/plugin/index')); $this->assertSame('/system/plugin.html', url('system/plugin/index')->build()); $this->assertSame('/system/plugin.html', url('/system/plugin/index')->build()); AppService::activatePlugin('system', 'system'); $this->assertSame('/api/system/upload/file', Url::normalizeApiTarget('upload/file')); $this->assertSame('/api/system/upload/file?from=test', Url::normalizeApiTarget('/api/system/upload/file?from=test')); $this->assertSame('/api/system/upload/index', Url::normalizeApiTarget('/system/upload')); $this->assertSame('/api/system/upload/file', Url::normalizeApiTarget('api/upload/file')); $this->assertSame('/api/system/upload/file.html', apiuri('upload/file')); $this->assertSame('/api/system/upload/file.html', apiuri('/api/system/upload/file')); $this->assertSame('/api/system/upload/index.html', apiuri('/system/upload')); $this->assertSame('/api/system/upload/file.html', apiuri('api/upload/file')); } public function testXssSafeStripsScriptsAndNeutralizesInlineEvents(): void { $safe = xss_safe('