diff --git a/tests/Controller/Api/ApiExpenseControllerTrait.php b/tests/Controller/Api/ApiExpenseControllerTrait.php new file mode 100644 index 0000000..57563fa --- /dev/null +++ b/tests/Controller/Api/ApiExpenseControllerTrait.php @@ -0,0 +1,86 @@ +header->account = 1; + $request->setData('type', 1); + $request->setData('description', 'Some test description'); + + $this->module->apiExpenseCreate($request, $response); + self::assertEquals('ok', $response->getData('')['status']); + self::assertGreaterThan(0, $response->getDataArray('')['response']->id); + } + + public function testExpenseElementCreate() : void + { + if (!\is_dir(__DIR__ . '/temp')) { + \mkdir(__DIR__ . '/temp'); + } + + $response = new HttpResponse(); + $request = new HttpRequest(new HttpUri('')); + + $request->header->account = 1; + + $request->setData('type', 1); + $request->setData('description', 'Test description'); + $request->setData('expense', 1); + + $tmpInvoices = \scandir(__DIR__ . '/billing'); + $invoiceDocs = []; + foreach ($tmpInvoices as $invoice) { + if ($invoice !== '..' && $invoice !== '.') { + $invoiceDocs[] = $invoice; + } + } + + $file = $invoiceDocs[0]; + \copy(__DIR__ . '/billing/' . $file, __DIR__ . '/temp/' . $file); + + $toUpload['file0'] = [ + 'name' => $file, + 'type' => \explode('.', $file)[1], + 'tmp_name' => __DIR__ . '/temp/' . $file, + 'error' => \UPLOAD_ERR_OK, + 'size' => \filesize(__DIR__ . '/temp/' . $file), + ]; + + TestUtils::setMember($request, 'files', $toUpload); + $this->module->apiExpenseElementCreate($request, $response); + self::assertEquals('ok', $response->getData('')['status']); + self::assertGreaterThan(0, $response->getDataArray('')['response']->id); + + if (\is_dir(__DIR__ . '/temp')) { + Directory::delete(__DIR__ . '/temp'); + } + } +} diff --git a/tests/Controller/Api/billing/Invoice # INV0041-1-text.pdf b/tests/Controller/Api/billing/Invoice # INV0041-1-text.pdf new file mode 100644 index 0000000..99506f7 Binary files /dev/null and b/tests/Controller/Api/billing/Invoice # INV0041-1-text.pdf differ diff --git a/tests/Controller/Api/billing/Invoice - INV0041-1-image.pdf b/tests/Controller/Api/billing/Invoice - INV0041-1-image.pdf new file mode 100644 index 0000000..10a3a94 Binary files /dev/null and b/tests/Controller/Api/billing/Invoice - INV0041-1-image.pdf differ diff --git a/tests/Controller/ApiControllerTest.php b/tests/Controller/ApiControllerTest.php new file mode 100644 index 0000000..d9e6027 --- /dev/null +++ b/tests/Controller/ApiControllerTest.php @@ -0,0 +1,91 @@ +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->l11nManager = new L11nManager(); + $this->app->eventManager->importFromFile(__DIR__ . '/../../../../Web/Api/Hooks.php'); + + $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('BusinessExpenses', 'Api'); + + TestUtils::setMember($this->module, 'app', $this->app); + } + + use ApiExpenseControllerTrait; +}