app = new class() extends ApplicationAbstract { protected string $appName = 'Api'; }; $this->app->dbPool = $GLOBALS['dbpool']; $this->app->unitId = 1; $this->app->accountManager = new AccountManager($GLOBALS['session']); $this->app->appSettings = new CoreSettings(); $this->app->moduleManager = new ModuleManager($this->app, __DIR__ . '/../../../../Modules/'); $this->app->dispatcher = new Dispatcher($this->app); $this->app->eventManager = new EventManager($this->app->dispatcher); $this->app->eventManager->importFromFile(__DIR__ . '/../../../../Web/Api/Hooks.php'); $this->app->sessionManager = new HttpSession(36000); $this->app->l11nManager = new L11nManager(); $account = new Account(); TestUtils::setMember($account, 'id', 1); $permission = new AccountPermission(); $permission->unit = 1; $permission->app = 2; $permission->setPermission( PermissionType::READ | PermissionType::CREATE | PermissionType::MODIFY | PermissionType::DELETE | PermissionType::PERMISSION ); $account->addPermission($permission); $this->app->accountManager->add($account); $this->app->router = new WebRouter(); $this->module = $this->app->moduleManager->get('Dashboard'); TestUtils::setMember($this->module, 'app', $this->app); } #[\PHPUnit\Framework\Attributes\Group('module')] public function testApiBoardCreate() : void { $response = new HttpResponse(); $request = new HttpRequest(); $request->header->account = 1; $request->setData('title', 'Default Board'); $this->module->apiBoardCreate($request, $response); self::assertGreaterThan(0, $response->getDataArray('')['response']->id); } #[\PHPUnit\Framework\Attributes\Group('module')] public function testApiBoardCreateInvalidData() : void { $response = new HttpResponse(); $request = new HttpRequest(); $request->header->account = 1; $request->setData('invalid', '1'); $this->module->apiBoardCreate($request, $response); self::assertEquals(RequestStatusCode::R_400, $response->header->status); } #[\PHPUnit\Framework\Attributes\Group('module')] public function testApiComponentCreate() : void { $response = new HttpResponse(); $request = new HttpRequest(); $request->header->account = 1; $request->setData('board', '1'); $request->setData('order', '2'); $request->setData('module', 'TestModule'); $this->module->apiComponentCreate($request, $response); self::assertGreaterThan(0, $response->getDataArray('')['response']->id); } #[\PHPUnit\Framework\Attributes\Group('module')] public function testApiComponentCreateInvalidData() : void { $response = new HttpResponse(); $request = new HttpRequest(); $request->header->account = 1; $request->setData('invalid', '1'); $this->module->apiComponentCreate($request, $response); self::assertEquals(RequestStatusCode::R_400, $response->header->status); } }