mirror of
https://github.com/Karaka-Management/oms-Billing.git
synced 2026-02-12 22:38:41 +00:00
add invalid api function tests
This commit is contained in:
parent
577fd3b041
commit
cf810b984e
|
|
@ -133,4 +133,14 @@ 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,64 +12,100 @@
|
||||||
*/
|
*/
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Modules\Billing\tests\Controller\Api;
|
namespace Modules\Billing\tests\Controller;
|
||||||
|
|
||||||
use phpOMS\Account\AccountStatus;
|
use Model\CoreSettings;
|
||||||
use phpOMS\Account\AccountType;
|
use Modules\Admin\Models\AccountPermission;
|
||||||
use phpOMS\Message\Http\HttpRequest;
|
use Modules\Billing\tests\Controller\Api\ApiBillControllerTrait;
|
||||||
use phpOMS\Message\Http\HttpResponse;
|
use Modules\Billing\tests\Controller\Api\ApiPurchaselControllerTrait;
|
||||||
use phpOMS\Message\Http\RequestStatusCode;
|
use phpOMS\Account\Account;
|
||||||
use phpOMS\System\File\Local\Directory;
|
use phpOMS\Account\AccountManager;
|
||||||
use phpOMS\Uri\HttpUri;
|
use phpOMS\Account\PermissionType;
|
||||||
use phpOMS\Utils\RnG\DateTime;
|
use phpOMS\Application\ApplicationAbstract;
|
||||||
|
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
|
||||||
{
|
{
|
||||||
public function testBillElementCreate() : void
|
protected ApplicationAbstract $app;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \Modules\Billing\Controller\ApiController
|
||||||
|
*/
|
||||||
|
protected ModuleAbstract $module;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \Modules\Billing\Controller\ApiController
|
||||||
|
*/
|
||||||
|
protected ModuleAbstract $modulePurchase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function setUp() : void
|
||||||
{
|
{
|
||||||
if (!\is_dir(__DIR__ . '/temp')) {
|
$this->app = new class() extends ApplicationAbstract
|
||||||
\mkdir(__DIR__ . '/temp');
|
{
|
||||||
}
|
protected string $appName = 'Api';
|
||||||
|
};
|
||||||
|
|
||||||
$tmpInvoices = \scandir(__DIR__ . '/billing');
|
$this->app->dbPool = $GLOBALS['dbpool'];
|
||||||
$invoiceDocs = [];
|
$this->app->unitId = 1;
|
||||||
foreach ($tmpInvoices as $invoice) {
|
$this->app->accountManager = new AccountManager($GLOBALS['session']);
|
||||||
if ($invoice !== '..' && $invoice !== '.') {
|
$this->app->appSettings = new CoreSettings();
|
||||||
$invoiceDocs[] = $invoice;
|
$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');
|
||||||
|
|
||||||
$count = \count($invoiceDocs);
|
$account = new Account();
|
||||||
|
TestUtils::setMember($account, 'id', 1);
|
||||||
|
|
||||||
for ($i = 0; $i < $count; ++$i) {
|
$permission = new AccountPermission();
|
||||||
$toUpload = [];
|
$permission->unit = 1;
|
||||||
$file = $invoiceDocs[$i];
|
$permission->app = 2;
|
||||||
|
$permission->setPermission(
|
||||||
|
PermissionType::READ
|
||||||
|
| PermissionType::CREATE
|
||||||
|
| PermissionType::MODIFY
|
||||||
|
| PermissionType::DELETE
|
||||||
|
| PermissionType::PERMISSION
|
||||||
|
);
|
||||||
|
|
||||||
$response = new HttpResponse();
|
$account->addPermission($permission);
|
||||||
$request = new HttpRequest(new HttpUri(''));
|
|
||||||
|
|
||||||
$request->header->account = 1;
|
$this->app->accountManager->add($account);
|
||||||
|
$this->app->router = new WebRouter();
|
||||||
|
|
||||||
\copy(__DIR__ . '/billing/' . $file, __DIR__ . '/temp/' . $file);
|
$this->module = $this->app->moduleManager->get('Billing', 'ApiBill');
|
||||||
|
$this->modulePurchase = $this->app->moduleManager->get('Billing', 'ApiPurchase');
|
||||||
|
|
||||||
$toUpload['file0'] = [
|
TestUtils::setMember($this->module, 'app', $this->app);
|
||||||
'name' => $file,
|
TestUtils::setMember($this->modulePurchase, 'app', $this->app);
|
||||||
'type' => \explode('.', $file)[1],
|
}
|
||||||
'tmp_name' => __DIR__ . '/temp/' . $file,
|
|
||||||
'error' => \UPLOAD_ERR_OK,
|
|
||||||
'size' => \filesize(__DIR__ . '/temp/' . $file),
|
|
||||||
];
|
|
||||||
|
|
||||||
TestUtils::setMember($request, 'files', $toUpload);
|
use ApiBillControllerTrait;
|
||||||
|
use ApiPurchaselControllerTrait;
|
||||||
|
}
|
||||||
|
|
||||||
$this->modulePurchase->apiSupplierBillUpload($request, $response);
|
public function testInvalidapiTaxCombinationDelete() : void
|
||||||
self::assertEquals('ok', $response->getData('')['status']);
|
{
|
||||||
self::assertGreaterThan(0, $response->getDataArray('')['response']->id);
|
$response = new HttpResponse();
|
||||||
|
$request = new HttpRequest(new HttpUri(''));
|
||||||
|
|
||||||
if (\is_dir(__DIR__ . '/temp')) {
|
$request->header->account = 1;
|
||||||
Directory::delete(__DIR__ . '/temp');
|
$this->module->apiTaxCombinationDelete($request, $response);
|
||||||
}
|
self::assertEquals(RequestStatusCode::R_400, $response->header->status);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user