Revert "add invalid api function tests"

This reverts commit cf810b984e.
This commit is contained in:
Dennis Eichhorn 2023-10-18 12:24:47 +00:00
parent cf810b984e
commit 863261ce9a
2 changed files with 44 additions and 90 deletions

View File

@ -133,14 +133,4 @@ trait ApiBillControllerTrait
$this->module->apiBillElementCreate($request, $response); $this->module->apiBillElementCreate($request, $response);
self::assertEquals(RequestStatusCode::R_400, $response->header->status); self::assertEquals(RequestStatusCode::R_400, $response->header->status);
} }
public function testInvalidapiNoteCreate() : void
{
$response = new HttpResponse();
$request = new HttpRequest(new HttpUri(''));
$request->header->account = 1;
$this->module->apiNoteCreate($request, $response);
self::assertEquals(RequestStatusCode::R_400, $response->header->status);
}
} }

View File

@ -12,100 +12,64 @@
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace Modules\Billing\tests\Controller; namespace Modules\Billing\tests\Controller\Api;
use Model\CoreSettings; use phpOMS\Account\AccountStatus;
use Modules\Admin\Models\AccountPermission; use phpOMS\Account\AccountType;
use Modules\Billing\tests\Controller\Api\ApiBillControllerTrait; use phpOMS\Message\Http\HttpRequest;
use Modules\Billing\tests\Controller\Api\ApiPurchaselControllerTrait; use phpOMS\Message\Http\HttpResponse;
use phpOMS\Account\Account; use phpOMS\Message\Http\RequestStatusCode;
use phpOMS\Account\AccountManager; use phpOMS\System\File\Local\Directory;
use phpOMS\Account\PermissionType; use phpOMS\Uri\HttpUri;
use phpOMS\Application\ApplicationAbstract; use phpOMS\Utils\RnG\DateTime;
use phpOMS\Dispatcher\Dispatcher;
use phpOMS\Event\EventManager;
use phpOMS\Localization\L11nManager;
use phpOMS\Module\ModuleAbstract;
use phpOMS\Module\ModuleManager;
use phpOMS\Router\WebRouter;
use phpOMS\Utils\TestUtils; use phpOMS\Utils\TestUtils;
/** trait ApiPurchaselControllerTrait
* @testdox Modules\tests\Billing\Controller\ApiControllerTest: Billing api controller
*
* @internal
*/
final class ApiControllerTest extends \PHPUnit\Framework\TestCase
{ {
protected ApplicationAbstract $app; public function testBillElementCreate() : void
/**
* @var \Modules\Billing\Controller\ApiController
*/
protected ModuleAbstract $module;
/**
* @var \Modules\Billing\Controller\ApiController
*/
protected ModuleAbstract $modulePurchase;
/**
* {@inheritdoc}
*/
protected function setUp() : void
{ {
$this->app = new class() extends ApplicationAbstract if (!\is_dir(__DIR__ . '/temp')) {
{ \mkdir(__DIR__ . '/temp');
protected string $appName = 'Api'; }
};
$this->app->dbPool = $GLOBALS['dbpool']; $tmpInvoices = \scandir(__DIR__ . '/billing');
$this->app->unitId = 1; $invoiceDocs = [];
$this->app->accountManager = new AccountManager($GLOBALS['session']); foreach ($tmpInvoices as $invoice) {
$this->app->appSettings = new CoreSettings(); if ($invoice !== '..' && $invoice !== '.') {
$this->app->moduleManager = new ModuleManager($this->app, __DIR__ . '/../../../../Modules/'); $invoiceDocs[] = $invoice;
$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(); $count = \count($invoiceDocs);
TestUtils::setMember($account, 'id', 1);
$permission = new AccountPermission(); for ($i = 0; $i < $count; ++$i) {
$permission->unit = 1; $toUpload = [];
$permission->app = 2; $file = $invoiceDocs[$i];
$permission->setPermission(
PermissionType::READ
| PermissionType::CREATE
| PermissionType::MODIFY
| PermissionType::DELETE
| PermissionType::PERMISSION
);
$account->addPermission($permission); $response = new HttpResponse();
$request = new HttpRequest(new HttpUri(''));
$this->app->accountManager->add($account); $request->header->account = 1;
$this->app->router = new WebRouter();
$this->module = $this->app->moduleManager->get('Billing', 'ApiBill'); \copy(__DIR__ . '/billing/' . $file, __DIR__ . '/temp/' . $file);
$this->modulePurchase = $this->app->moduleManager->get('Billing', 'ApiPurchase');
TestUtils::setMember($this->module, 'app', $this->app); $toUpload['file0'] = [
TestUtils::setMember($this->modulePurchase, 'app', $this->app); 'name' => $file,
} 'type' => \explode('.', $file)[1],
'tmp_name' => __DIR__ . '/temp/' . $file,
'error' => \UPLOAD_ERR_OK,
'size' => \filesize(__DIR__ . '/temp/' . $file),
];
use ApiBillControllerTrait; TestUtils::setMember($request, 'files', $toUpload);
use ApiPurchaselControllerTrait;
}
public function testInvalidapiTaxCombinationDelete() : void $this->modulePurchase->apiSupplierBillUpload($request, $response);
{ self::assertEquals('ok', $response->getData('')['status']);
$response = new HttpResponse(); self::assertGreaterThan(0, $response->getDataArray('')['response']->id);
$request = new HttpRequest(new HttpUri(''));
$request->header->account = 1; if (\is_dir(__DIR__ . '/temp')) {
$this->module->apiTaxCombinationDelete($request, $response); Directory::delete(__DIR__ . '/temp');
self::assertEquals(RequestStatusCode::R_400, $response->header->status); }
}
} }
} }