mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-20 17:15:51 +02:00
Added tests for all API endpoints of Structural elements
This commit is contained in:
parent
7b5ae70de3
commit
3d67ad870a
16 changed files with 887 additions and 3 deletions
|
@ -27,7 +27,7 @@ use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
|
|||
use ApiPlatform\Symfony\Bundle\Test\Client;
|
||||
use App\DataFixtures\APITokenFixtures;
|
||||
|
||||
class AuthenticatedApiTestCase extends ApiTestCase
|
||||
abstract class AuthenticatedApiTestCase extends ApiTestCase
|
||||
{
|
||||
/**
|
||||
* Creates an API client with authentication.
|
||||
|
|
75
tests/API/Endpoints/AttachmentTypeEndpointTest.php
Normal file
75
tests/API/Endpoints/AttachmentTypeEndpointTest.php
Normal file
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2024 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace App\Tests\API\Endpoints;
|
||||
|
||||
use App\Tests\API\Endpoints\CrudEndpointTestCase;
|
||||
|
||||
class AttachmentTypeEndpointTest extends CrudEndpointTestCase
|
||||
{
|
||||
|
||||
protected function getBasePath(): string
|
||||
{
|
||||
return '/api/attachment_types';
|
||||
}
|
||||
|
||||
public function testGetCollection(): void
|
||||
{
|
||||
$this->_testGetCollection();
|
||||
self::assertJsonContains([
|
||||
'hydra:totalItems' => 7,
|
||||
]);
|
||||
}
|
||||
|
||||
public function testGetChildrenCollection(): void
|
||||
{
|
||||
$this->_testGetChildrenCollection(1);
|
||||
}
|
||||
|
||||
public function testGetItem(): void
|
||||
{
|
||||
$this->_testGetItem(1);
|
||||
$this->_testGetItem(2);
|
||||
$this->_testGetItem(3);
|
||||
}
|
||||
|
||||
public function testCreateItem(): void
|
||||
{
|
||||
$this->_testPostItem([
|
||||
'name' => 'Test Part',
|
||||
'parent' => '/api/attachment_types/1',
|
||||
]);
|
||||
}
|
||||
|
||||
public function testUpdateItem(): void
|
||||
{
|
||||
$this->_testPatchItem(1, [
|
||||
'name' => 'Test Part Updated',
|
||||
]);
|
||||
}
|
||||
|
||||
public function testDeleteItem(): void
|
||||
{
|
||||
$this->_testDeleteItem(6);
|
||||
}
|
||||
}
|
76
tests/API/Endpoints/CategoryEndpointTest.php
Normal file
76
tests/API/Endpoints/CategoryEndpointTest.php
Normal file
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2024 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace App\Tests\Endpoints;
|
||||
|
||||
use App\Tests\API\Endpoints\CrudEndpointTestCase;
|
||||
|
||||
class CategoryEndpointTest extends CrudEndpointTestCase
|
||||
{
|
||||
|
||||
protected function getBasePath(): string
|
||||
{
|
||||
return '/api/categories';
|
||||
}
|
||||
|
||||
public function testGetCollection(): void
|
||||
{
|
||||
$this->_testGetCollection();
|
||||
self::assertJsonContains([
|
||||
'hydra:totalItems' => 7,
|
||||
]);
|
||||
}
|
||||
|
||||
public function testGetChildrenCollection(): void
|
||||
{
|
||||
$this->_testGetChildrenCollection(1);
|
||||
}
|
||||
|
||||
public function testGetItem(): void
|
||||
{
|
||||
$this->_testGetItem(1);
|
||||
$this->_testGetItem(2);
|
||||
$this->_testGetItem(3);
|
||||
}
|
||||
|
||||
public function testCreateItem(): void
|
||||
{
|
||||
$this->_testPostItem([
|
||||
'name' => 'Test API',
|
||||
'parent' => '/api/categories/1',
|
||||
]);
|
||||
}
|
||||
|
||||
public function testUpdateItem(): void
|
||||
{
|
||||
$this->_testPatchItem(1, [
|
||||
'name' => 'Updated',
|
||||
'parent' => '/api/categories/2',
|
||||
]);
|
||||
}
|
||||
|
||||
public function testDeleteItem(): void
|
||||
{
|
||||
$this->_testDeleteItem(5);
|
||||
}
|
||||
}
|
102
tests/API/Endpoints/CrudEndpointTestCase.php
Normal file
102
tests/API/Endpoints/CrudEndpointTestCase.php
Normal file
|
@ -0,0 +1,102 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2024 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace App\Tests\API\Endpoints;
|
||||
|
||||
use App\Tests\API\AuthenticatedApiTestCase;
|
||||
use Symfony\Contracts\HttpClient\ResponseInterface;
|
||||
|
||||
abstract class CrudEndpointTestCase extends AuthenticatedApiTestCase
|
||||
{
|
||||
/**
|
||||
* Returns the base path of the endpoint.
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function getBasePath(): string;
|
||||
|
||||
protected function getItemPath(int $id): string
|
||||
{
|
||||
$basePath = $this->getBasePath();
|
||||
if (!str_ends_with($basePath, '/')) {
|
||||
$basePath .= '/';
|
||||
}
|
||||
|
||||
return $basePath . $id;
|
||||
}
|
||||
|
||||
protected function _testGetCollection(): ResponseInterface
|
||||
{
|
||||
$response = self::createAuthenticatedClient()->request('GET', $this->getBasePath());
|
||||
self::assertResponseIsSuccessful();
|
||||
self::assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
protected function _testGetChildrenCollection(int $id): ResponseInterface
|
||||
{
|
||||
$response = self::createAuthenticatedClient()->request('GET', $this->getItemPath($id) . '/children');
|
||||
self::assertResponseIsSuccessful();
|
||||
self::assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
protected function _testGetItem(int $id): ResponseInterface
|
||||
{
|
||||
$response = self::createAuthenticatedClient()->request('GET', $this->getItemPath($id));
|
||||
self::assertResponseIsSuccessful();
|
||||
self::assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
protected function _testPostItem(array $data): ResponseInterface
|
||||
{
|
||||
$response = self::createAuthenticatedClient()->request('POST', $this->getBasePath(), ['json' => $data]);
|
||||
self::assertResponseIsSuccessful();
|
||||
self::assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
protected function _testPatchItem(int $id, array $data): ResponseInterface
|
||||
{
|
||||
$response = self::createAuthenticatedClient()->request('PATCH', $this->getItemPath($id), [
|
||||
'json' => $data,
|
||||
'headers' => ['Content-Type' => 'application/merge-patch+json']
|
||||
]);
|
||||
self::assertResponseIsSuccessful();
|
||||
self::assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
protected function _testDeleteItem(int $id): ResponseInterface
|
||||
{
|
||||
$response = self::createAuthenticatedClient()->request('DELETE', $this->getItemPath($id));
|
||||
self::assertResponseIsSuccessful();
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
64
tests/API/Endpoints/CurrencyEndpointTest.php
Normal file
64
tests/API/Endpoints/CurrencyEndpointTest.php
Normal file
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2024 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace App\Tests\API\Endpoints;
|
||||
|
||||
|
||||
class CurrencyEndpointTest extends CrudEndpointTestCase
|
||||
{
|
||||
|
||||
protected function getBasePath(): string
|
||||
{
|
||||
return '/api/currencies';
|
||||
}
|
||||
|
||||
public function testGetCollection(): void
|
||||
{
|
||||
$this->_testGetCollection();
|
||||
self::assertJsonContains([
|
||||
'hydra:totalItems' => 0,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function testCreateItem(): void
|
||||
{
|
||||
$this->_testPostItem([
|
||||
'name' => 'Test API',
|
||||
'iso_code' => 'USD',
|
||||
]);
|
||||
}
|
||||
|
||||
/*public function testUpdateItem(): void
|
||||
{
|
||||
$this->_testPatchItem(1, [
|
||||
'name' => 'Updated',
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
public function testDeleteItem(): void
|
||||
{
|
||||
$this->_testDeleteItem(5);
|
||||
}*/
|
||||
}
|
76
tests/API/Endpoints/FootprintsEndpointTest.php
Normal file
76
tests/API/Endpoints/FootprintsEndpointTest.php
Normal file
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2024 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace App\Tests\API\Endpoints;
|
||||
|
||||
use App\Tests\API\Endpoints\CrudEndpointTestCase;
|
||||
|
||||
class FootprintsEndpointTest extends CrudEndpointTestCase
|
||||
{
|
||||
|
||||
protected function getBasePath(): string
|
||||
{
|
||||
return '/api/footprints';
|
||||
}
|
||||
|
||||
public function testGetCollection(): void
|
||||
{
|
||||
$this->_testGetCollection();
|
||||
self::assertJsonContains([
|
||||
'hydra:totalItems' => 7,
|
||||
]);
|
||||
}
|
||||
|
||||
public function testGetChildrenCollection(): void
|
||||
{
|
||||
$this->_testGetChildrenCollection(1);
|
||||
}
|
||||
|
||||
public function testGetItem(): void
|
||||
{
|
||||
$this->_testGetItem(1);
|
||||
$this->_testGetItem(2);
|
||||
$this->_testGetItem(3);
|
||||
}
|
||||
|
||||
public function testCreateItem(): void
|
||||
{
|
||||
$this->_testPostItem([
|
||||
'name' => 'Test API',
|
||||
'parent' => '/api/footprints/1',
|
||||
]);
|
||||
}
|
||||
|
||||
public function testUpdateItem(): void
|
||||
{
|
||||
$this->_testPatchItem(1, [
|
||||
'name' => 'Updated',
|
||||
'parent' => '/api/footprints/2',
|
||||
]);
|
||||
}
|
||||
|
||||
public function testDeleteItem(): void
|
||||
{
|
||||
$this->_testDeleteItem(5);
|
||||
}
|
||||
}
|
40
tests/API/Endpoints/InfoEndpointTest.php
Normal file
40
tests/API/Endpoints/InfoEndpointTest.php
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2024 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace API\Endpoints;
|
||||
|
||||
use App\Tests\API\AuthenticatedApiTestCase;
|
||||
|
||||
class InfoEndpointTest extends AuthenticatedApiTestCase
|
||||
{
|
||||
public function testGetInfo(): void
|
||||
{
|
||||
$response = self::createAuthenticatedClient()->request('GET', '/api/info');
|
||||
|
||||
self::assertResponseIsSuccessful();
|
||||
self::assertJsonContains([
|
||||
'@id' => '/api/info',
|
||||
'title' => 'Part-DB',
|
||||
]);
|
||||
}
|
||||
}
|
76
tests/API/Endpoints/ManufacturersEndpointTest.php
Normal file
76
tests/API/Endpoints/ManufacturersEndpointTest.php
Normal file
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2024 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace App\Tests\API\Endpoints;
|
||||
|
||||
use App\Tests\API\Endpoints\CrudEndpointTestCase;
|
||||
|
||||
class ManufacturersEndpointTest extends CrudEndpointTestCase
|
||||
{
|
||||
|
||||
protected function getBasePath(): string
|
||||
{
|
||||
return '/api/manufacturers';
|
||||
}
|
||||
|
||||
public function testGetCollection(): void
|
||||
{
|
||||
$this->_testGetCollection();
|
||||
self::assertJsonContains([
|
||||
'hydra:totalItems' => 7,
|
||||
]);
|
||||
}
|
||||
|
||||
public function testGetChildrenCollection(): void
|
||||
{
|
||||
$this->_testGetChildrenCollection(1);
|
||||
}
|
||||
|
||||
public function testGetItem(): void
|
||||
{
|
||||
$this->_testGetItem(1);
|
||||
$this->_testGetItem(2);
|
||||
$this->_testGetItem(3);
|
||||
}
|
||||
|
||||
public function testCreateItem(): void
|
||||
{
|
||||
$this->_testPostItem([
|
||||
'name' => 'Test API',
|
||||
'parent' => '/api/manufacturers/1',
|
||||
]);
|
||||
}
|
||||
|
||||
public function testUpdateItem(): void
|
||||
{
|
||||
$this->_testPatchItem(5, [
|
||||
'name' => 'Updated',
|
||||
'parent' => '/api/manufacturers/2',
|
||||
]);
|
||||
}
|
||||
|
||||
public function testDeleteItem(): void
|
||||
{
|
||||
$this->_testDeleteItem(7);
|
||||
}
|
||||
}
|
74
tests/API/Endpoints/MeasurementUnitsEndpointTest.php
Normal file
74
tests/API/Endpoints/MeasurementUnitsEndpointTest.php
Normal file
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2024 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace App\Tests\API\Endpoints;
|
||||
|
||||
class MeasurementUnitsEndpointTest extends CrudEndpointTestCase
|
||||
{
|
||||
|
||||
protected function getBasePath(): string
|
||||
{
|
||||
return '/api/measurement_units';
|
||||
}
|
||||
|
||||
public function testGetCollection(): void
|
||||
{
|
||||
$this->_testGetCollection();
|
||||
self::assertJsonContains([
|
||||
'hydra:totalItems' => 7,
|
||||
]);
|
||||
}
|
||||
|
||||
public function testGetChildrenCollection(): void
|
||||
{
|
||||
$this->_testGetChildrenCollection(1);
|
||||
}
|
||||
|
||||
public function testGetItem(): void
|
||||
{
|
||||
$this->_testGetItem(1);
|
||||
$this->_testGetItem(2);
|
||||
$this->_testGetItem(3);
|
||||
}
|
||||
|
||||
public function testCreateItem(): void
|
||||
{
|
||||
$this->_testPostItem([
|
||||
'name' => 'Test API',
|
||||
'parent' => '/api/measurement_units/1',
|
||||
]);
|
||||
}
|
||||
|
||||
public function testUpdateItem(): void
|
||||
{
|
||||
$this->_testPatchItem(5, [
|
||||
'name' => 'Updated',
|
||||
'parent' => '/api/measurement_units/2',
|
||||
]);
|
||||
}
|
||||
|
||||
public function testDeleteItem(): void
|
||||
{
|
||||
$this->_testDeleteItem(4);
|
||||
}
|
||||
}
|
72
tests/API/Endpoints/PartEndpointTest.php
Normal file
72
tests/API/Endpoints/PartEndpointTest.php
Normal file
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2024 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace App\Tests\API\Endpoints;
|
||||
|
||||
class PartEndpointTest extends CrudEndpointTestCase
|
||||
{
|
||||
|
||||
protected function getBasePath(): string
|
||||
{
|
||||
return '/api/parts';
|
||||
}
|
||||
|
||||
public function testGetCollection(): void
|
||||
{
|
||||
$this->_testGetCollection();
|
||||
self::assertJsonContains([
|
||||
'hydra:totalItems' => 3,
|
||||
]);
|
||||
}
|
||||
|
||||
public function testGetItem(): void
|
||||
{
|
||||
$this->_testGetItem(1);
|
||||
$this->_testGetItem(2);
|
||||
$this->_testGetItem(3);
|
||||
}
|
||||
|
||||
public function testCreateItem(): void
|
||||
{
|
||||
$this->_testPostItem([
|
||||
'name' => 'Test Part',
|
||||
'description' => 'This is a test part',
|
||||
'category' => '/api/categories/1',
|
||||
'manufacturer' => '/api/manufacturers/1',
|
||||
]);
|
||||
}
|
||||
|
||||
public function testUpdateItem(): void
|
||||
{
|
||||
$this->_testPatchItem(1, [
|
||||
'name' => 'Test Part Updated',
|
||||
'category' => '/api/categories/2',
|
||||
'manufacturer' => '/api/manufacturers/2',
|
||||
]);
|
||||
}
|
||||
|
||||
public function testDeleteItem(): void
|
||||
{
|
||||
$this->_testDeleteItem(1);
|
||||
}
|
||||
}
|
76
tests/API/Endpoints/ProjectsEndpointTest.php
Normal file
76
tests/API/Endpoints/ProjectsEndpointTest.php
Normal file
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2024 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace App\Tests\API\Endpoints;
|
||||
|
||||
use App\Tests\API\Endpoints\CrudEndpointTestCase;
|
||||
|
||||
class ProjectsEndpointTest extends CrudEndpointTestCase
|
||||
{
|
||||
|
||||
protected function getBasePath(): string
|
||||
{
|
||||
return '/api/projects';
|
||||
}
|
||||
|
||||
public function testGetCollection(): void
|
||||
{
|
||||
$this->_testGetCollection();
|
||||
self::assertJsonContains([
|
||||
'hydra:totalItems' => 7,
|
||||
]);
|
||||
}
|
||||
|
||||
public function testGetChildrenCollection(): void
|
||||
{
|
||||
$this->_testGetChildrenCollection(1);
|
||||
}
|
||||
|
||||
public function testGetItem(): void
|
||||
{
|
||||
$this->_testGetItem(1);
|
||||
$this->_testGetItem(2);
|
||||
$this->_testGetItem(3);
|
||||
}
|
||||
|
||||
public function testCreateItem(): void
|
||||
{
|
||||
$this->_testPostItem([
|
||||
'name' => 'Test API',
|
||||
'parent' => '/api/projects/1',
|
||||
]);
|
||||
}
|
||||
|
||||
public function testUpdateItem(): void
|
||||
{
|
||||
$this->_testPatchItem(5, [
|
||||
'name' => 'Updated',
|
||||
'parent' => '/api/projects/2',
|
||||
]);
|
||||
}
|
||||
|
||||
public function testDeleteItem(): void
|
||||
{
|
||||
$this->_testDeleteItem(7);
|
||||
}
|
||||
}
|
76
tests/API/Endpoints/StorageLocationsEndpointTest.php
Normal file
76
tests/API/Endpoints/StorageLocationsEndpointTest.php
Normal file
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2024 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace API\Endpoints;
|
||||
|
||||
use App\Tests\API\Endpoints\CrudEndpointTestCase;
|
||||
|
||||
class StorageLocationsEndpointTest extends CrudEndpointTestCase
|
||||
{
|
||||
|
||||
protected function getBasePath(): string
|
||||
{
|
||||
return '/api/storage_locations';
|
||||
}
|
||||
|
||||
public function testGetCollection(): void
|
||||
{
|
||||
$this->_testGetCollection();
|
||||
self::assertJsonContains([
|
||||
'hydra:totalItems' => 7,
|
||||
]);
|
||||
}
|
||||
|
||||
public function testGetChildrenCollection(): void
|
||||
{
|
||||
$this->_testGetChildrenCollection(1);
|
||||
}
|
||||
|
||||
public function testGetItem(): void
|
||||
{
|
||||
$this->_testGetItem(1);
|
||||
$this->_testGetItem(2);
|
||||
$this->_testGetItem(3);
|
||||
}
|
||||
|
||||
public function testCreateItem(): void
|
||||
{
|
||||
$this->_testPostItem([
|
||||
'name' => 'Test API',
|
||||
'parent' => '/api/storage_locations/1',
|
||||
]);
|
||||
}
|
||||
|
||||
public function testUpdateItem(): void
|
||||
{
|
||||
$this->_testPatchItem(5, [
|
||||
'name' => 'Updated',
|
||||
'parent' => '/api/storage_locations/2',
|
||||
]);
|
||||
}
|
||||
|
||||
public function testDeleteItem(): void
|
||||
{
|
||||
$this->_testDeleteItem(7);
|
||||
}
|
||||
}
|
76
tests/API/Endpoints/SuppliersEndpointTest.php
Normal file
76
tests/API/Endpoints/SuppliersEndpointTest.php
Normal file
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2024 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace App\Tests\API\Endpoints;
|
||||
|
||||
use App\Tests\API\Endpoints\CrudEndpointTestCase;
|
||||
|
||||
class SuppliersEndpointTest extends CrudEndpointTestCase
|
||||
{
|
||||
|
||||
protected function getBasePath(): string
|
||||
{
|
||||
return '/api/suppliers';
|
||||
}
|
||||
|
||||
public function testGetCollection(): void
|
||||
{
|
||||
$this->_testGetCollection();
|
||||
self::assertJsonContains([
|
||||
'hydra:totalItems' => 7,
|
||||
]);
|
||||
}
|
||||
|
||||
public function testGetChildrenCollection(): void
|
||||
{
|
||||
$this->_testGetChildrenCollection(1);
|
||||
}
|
||||
|
||||
public function testGetItem(): void
|
||||
{
|
||||
$this->_testGetItem(1);
|
||||
$this->_testGetItem(2);
|
||||
$this->_testGetItem(3);
|
||||
}
|
||||
|
||||
public function testCreateItem(): void
|
||||
{
|
||||
$this->_testPostItem([
|
||||
'name' => 'Test API',
|
||||
'parent' => '/api/suppliers/1',
|
||||
]);
|
||||
}
|
||||
|
||||
public function testUpdateItem(): void
|
||||
{
|
||||
$this->_testPatchItem(5, [
|
||||
'name' => 'Updated',
|
||||
'parent' => '/api/suppliers/2',
|
||||
]);
|
||||
}
|
||||
|
||||
public function testDeleteItem(): void
|
||||
{
|
||||
$this->_testDeleteItem(7);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue