Skip to content

Commit eb6fdce

Browse files
committed
add and fix tests
1 parent b7cee31 commit eb6fdce

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1016
-276
lines changed

src/Backend/Action/Taxonomy/Create.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
use Fusio\Engine\ContextInterface;
2525
use Fusio\Engine\ParametersInterface;
2626
use Fusio\Engine\RequestInterface;
27-
use Fusio\Impl\Service\Category;
2827
use Fusio\Impl\Service\System\ContextFactory;
29-
use Fusio\Model\Backend\CategoryCreate;
28+
use Fusio\Impl\Service\Taxonomy;
29+
use Fusio\Model\Backend\TaxonomyCreate;
3030
use PSX\Http\Environment\HttpResponse;
3131

3232
/**
@@ -36,31 +36,26 @@
3636
* @license http://www.apache.org/licenses/LICENSE-2.0
3737
* @link https://www.fusio-project.org
3838
*/
39-
class Create implements ActionInterface
39+
readonly class Create implements ActionInterface
4040
{
41-
private Category $categoryService;
42-
private ContextFactory $contextFactory;
43-
44-
public function __construct(Category $categoryService, ContextFactory $contextFactory)
41+
public function __construct(private Taxonomy $taxonomyService, private ContextFactory $contextFactory)
4542
{
46-
$this->categoryService = $categoryService;
47-
$this->contextFactory = $contextFactory;
4843
}
4944

5045
public function handle(RequestInterface $request, ParametersInterface $configuration, ContextInterface $context): mixed
5146
{
5247
$body = $request->getPayload();
5348

54-
assert($body instanceof CategoryCreate);
49+
assert($body instanceof TaxonomyCreate);
5550

56-
$id = $this->categoryService->create(
51+
$id = $this->taxonomyService->create(
5752
$body,
5853
$this->contextFactory->newActionContext($context)
5954
);
6055

6156
return new HttpResponse(201, [], [
6257
'success' => true,
63-
'message' => 'Category successfully created',
58+
'message' => 'Taxonomy successfully created',
6459
'id' => '' . $id,
6560
]);
6661
}

src/Backend/Action/Taxonomy/Delete.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
use Fusio\Engine\ContextInterface;
2525
use Fusio\Engine\ParametersInterface;
2626
use Fusio\Engine\RequestInterface;
27-
use Fusio\Impl\Service\Category;
2827
use Fusio\Impl\Service\System\ContextFactory;
28+
use Fusio\Impl\Service\Taxonomy;
2929

3030
/**
3131
* Delete
@@ -34,27 +34,22 @@
3434
* @license http://www.apache.org/licenses/LICENSE-2.0
3535
* @link https://www.fusio-project.org
3636
*/
37-
class Delete implements ActionInterface
37+
readonly class Delete implements ActionInterface
3838
{
39-
private Category $categoryService;
40-
private ContextFactory $contextFactory;
41-
42-
public function __construct(Category $categoryService, ContextFactory $contextFactory)
39+
public function __construct(private Taxonomy $taxonomyService, private ContextFactory $contextFactory)
4340
{
44-
$this->categoryService = $categoryService;
45-
$this->contextFactory = $contextFactory;
4641
}
4742

4843
public function handle(RequestInterface $request, ParametersInterface $configuration, ContextInterface $context): mixed
4944
{
50-
$id = $this->categoryService->delete(
51-
$request->get('category_id'),
45+
$id = $this->taxonomyService->delete(
46+
$request->get('taxonomy_id'),
5247
$this->contextFactory->newActionContext($context)
5348
);
5449

5550
return [
5651
'success' => true,
57-
'message' => 'Category successfully deleted',
52+
'message' => 'Taxonomy successfully deleted',
5853
'id' => '' . $id,
5954
];
6055
}

src/Backend/Action/Taxonomy/Get.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,30 +35,27 @@
3535
* @license http://www.apache.org/licenses/LICENSE-2.0
3636
* @link https://www.fusio-project.org
3737
*/
38-
class Get implements ActionInterface
38+
readonly class Get implements ActionInterface
3939
{
40-
private View\Category $view;
41-
42-
public function __construct(View\Category $view)
40+
public function __construct(private View\Taxonomy $view)
4341
{
44-
$this->view = $view;
4542
}
4643

4744
public function handle(RequestInterface $request, ParametersInterface $configuration, ContextInterface $context): mixed
4845
{
49-
$category = $this->view->getEntity(
50-
$request->get('category_id'),
46+
$taxonomy = $this->view->getEntity(
47+
$request->get('taxonomy_id'),
5148
$context
5249
);
5350

54-
if (empty($category)) {
55-
throw new StatusCode\NotFoundException('Could not find category');
51+
if (empty($taxonomy)) {
52+
throw new StatusCode\NotFoundException('Could not find taxonomy');
5653
}
5754

58-
if ($category['status'] == Table\Category::STATUS_DELETED) {
59-
throw new StatusCode\GoneException('Category was deleted');
55+
if ($taxonomy['status'] == Table\Category::STATUS_DELETED) {
56+
throw new StatusCode\GoneException('Taxonomy was deleted');
6057
}
6158

62-
return $category;
59+
return $taxonomy;
6360
}
6461
}

src/Backend/Action/Taxonomy/GetAll.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,10 @@
3434
* @license http://www.apache.org/licenses/LICENSE-2.0
3535
* @link https://www.fusio-project.org
3636
*/
37-
class GetAll implements ActionInterface
37+
readonly class GetAll implements ActionInterface
3838
{
39-
private View\Category $view;
40-
41-
public function __construct(View\Category $view)
39+
public function __construct(private View\Taxonomy $view)
4240
{
43-
$this->view = $view;
4441
}
4542

4643
public function handle(RequestInterface $request, ParametersInterface $configuration, ContextInterface $context): mixed

src/Backend/Action/Taxonomy/Update.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,10 @@
3737
* @license http://www.apache.org/licenses/LICENSE-2.0
3838
* @link https://www.fusio-project.org
3939
*/
40-
class Update implements ActionInterface
40+
readonly class Update implements ActionInterface
4141
{
42-
private Taxonomy $taxonomyService;
43-
private ContextFactory $contextFactory;
44-
45-
public function __construct(Taxonomy $taxonomyService, ContextFactory $contextFactory)
42+
public function __construct(private Taxonomy $taxonomyService, private ContextFactory $contextFactory)
4643
{
47-
$this->taxonomyService = $taxonomyService;
48-
$this->contextFactory = $contextFactory;
4944
}
5045

5146
public function handle(RequestInterface $request, ParametersInterface $configuration, ContextInterface $context): mixed

src/Backend/View/Taxonomy.php

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
/*
3+
* Fusio - Self-Hosted API Management for Builders.
4+
* For the current version and information visit <https://www.fusio-project.org/>
5+
*
6+
* Copyright (c) Christoph Kappestein <christoph.kappestein@gmail.com>
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
namespace Fusio\Impl\Backend\View;
22+
23+
use Fusio\Engine\ContextInterface;
24+
use Fusio\Impl\Backend\Filter\QueryFilter;
25+
use Fusio\Impl\Table;
26+
use PSX\Nested\Builder;
27+
use PSX\Sql\OrderBy;
28+
use PSX\Sql\ViewAbstract;
29+
30+
/**
31+
* Taxonomy
32+
*
33+
* @author Christoph Kappestein <christoph.kappestein@gmail.com>
34+
* @license http://www.apache.org/licenses/LICENSE-2.0
35+
* @link https://www.fusio-project.org
36+
*/
37+
class Taxonomy extends ViewAbstract
38+
{
39+
public function getCollection(QueryFilter $filter, ContextInterface $context)
40+
{
41+
$startIndex = $filter->getStartIndex();
42+
$count = $filter->getCount();
43+
$sortBy = Table\Generated\TaxonomyColumn::tryFrom($filter->getSortBy(Table\Generated\TaxonomyTable::COLUMN_NAME) ?? '');
44+
$sortOrder = $filter->getSortOrder(OrderBy::ASC);
45+
46+
$condition = $filter->getCondition([QueryFilter::COLUMN_SEARCH => Table\Generated\TaxonomyTable::COLUMN_NAME]);
47+
$condition->equals(Table\Generated\TaxonomyTable::COLUMN_TENANT_ID, $context->getTenantId());
48+
$condition->in(Table\Generated\TaxonomyTable::COLUMN_STATUS, [Table\Taxonomy::STATUS_ACTIVE]);
49+
50+
$builder = new Builder($this->connection);
51+
52+
$definition = [
53+
'totalResults' => $this->getTable(Table\Taxonomy::class)->getCount($condition),
54+
'startIndex' => $startIndex,
55+
'itemsPerPage' => $count,
56+
'entry' => $builder->doCollection([$this->getTable(Table\Taxonomy::class), 'findAll'], [$condition, $startIndex, $count, $sortBy, $sortOrder], [
57+
'id' => $builder->fieldInteger(Table\Generated\TaxonomyTable::COLUMN_ID),
58+
'parentId' => $builder->fieldInteger(Table\Generated\TaxonomyTable::COLUMN_PARENT_ID),
59+
'status' => $builder->fieldInteger(Table\Generated\TaxonomyTable::COLUMN_STATUS),
60+
'name' => Table\Generated\TaxonomyTable::COLUMN_NAME,
61+
]),
62+
];
63+
64+
return $builder->build($definition);
65+
}
66+
67+
public function getEntity(string $id, ContextInterface $context)
68+
{
69+
$builder = new Builder($this->connection);
70+
71+
$definition = $builder->doEntity([$this->getTable(Table\Taxonomy::class), 'findOneByIdentifier'], [$context->getTenantId(), $id], [
72+
'id' => $builder->fieldInteger(Table\Generated\TaxonomyTable::COLUMN_ID),
73+
'parentId' => $builder->fieldInteger(Table\Generated\TaxonomyTable::COLUMN_PARENT_ID),
74+
'status' => $builder->fieldInteger(Table\Generated\TaxonomyTable::COLUMN_STATUS),
75+
'name' => Table\Generated\TaxonomyTable::COLUMN_NAME,
76+
]);
77+
78+
return $builder->build($definition);
79+
}
80+
}

src/Installation/DataBag.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public function __construct()
4343
{
4444
$this->data = [
4545
'fusio_category' => [],
46+
'fusio_taxonomy' => [],
4647
'fusio_role' => [],
4748
'fusio_plan' => [],
4849
'fusio_user' => [],
@@ -670,6 +671,17 @@ public function addScopeOperation(string $scope, string $operation, ?string $ten
670671
];
671672
}
672673

674+
public function addTaxonomy(string $taxonomy, ?string $parent = null, ?string $insertDate = null, ?string $tenantId = null): void
675+
{
676+
$this->data['fusio_taxonomy'][$taxonomy] = [
677+
'tenant_id' => $tenantId,
678+
'parent_id' => $parent !== null ? $this->getReference('fusio_taxonomy', $parent, $tenantId) : null,
679+
'status' => Table\Taxonomy::STATUS_ACTIVE,
680+
'name' => $taxonomy,
681+
'insert_date' => (new \DateTime($insertDate ?? 'now'))->format('Y-m-d H:i:s'),
682+
];
683+
}
684+
673685
public function addTest(string $category, string $operation, ?string $tenantId = null): void
674686
{
675687
$this->data['fusio_test'][$category . $operation] = [

src/Migrations/Version20230508210151.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ public function up(Schema $schema) : void
551551
$taxonomyTable = $schema->createTable('fusio_taxonomy');
552552
$taxonomyTable->addColumn('id', 'integer', ['autoincrement' => true]);
553553
$taxonomyTable->addColumn('tenant_id', 'string', ['length' => 64, 'notnull' => false, 'default' => null]);
554-
$taxonomyTable->addColumn('parent_id', 'integer');
554+
$taxonomyTable->addColumn('parent_id', 'integer', ['notnull' => false]);
555555
$taxonomyTable->addColumn('status', 'integer', ['default' => 1]);
556556
$taxonomyTable->addColumn('name', 'string');
557557
$taxonomyTable->addColumn('insert_date', 'datetime');

src/Migrations/Version20260210222824.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function up(Schema $schema): void
2323
$taxonomyTable = $schema->createTable('fusio_taxonomy');
2424
$taxonomyTable->addColumn('id', 'integer', ['autoincrement' => true]);
2525
$taxonomyTable->addColumn('tenant_id', 'string', ['length' => 64, 'notnull' => false, 'default' => null]);
26-
$taxonomyTable->addColumn('parent_id', 'integer');
26+
$taxonomyTable->addColumn('parent_id', 'integer', ['notnull' => false]);
2727
$taxonomyTable->addColumn('status', 'integer', ['default' => 1]);
2828
$taxonomyTable->addColumn('name', 'string');
2929
$taxonomyTable->addColumn('insert_date', 'datetime');

src/Service/Taxonomy.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use Fusio\Model\Backend\TaxonomyCreate;
2929
use Fusio\Model\Backend\TaxonomyUpdate;
3030
use Psr\EventDispatcher\EventDispatcherInterface;
31+
use PSX\DateTime\LocalDateTime;
3132
use PSX\Http\Exception as StatusCode;
3233

3334
/**
@@ -59,6 +60,7 @@ public function create(TaxonomyCreate $taxonomy, UserContext $context): int
5960
$row->setParentId($taxonomy->getParentId());
6061
$row->setStatus(Table\Taxonomy::STATUS_ACTIVE);
6162
$row->setName($taxonomy->getName());
63+
$row->setInsertDate(LocalDateTime::now());
6264
$this->taxonomyTable->create($row);
6365

6466
$taxonomyId = $this->taxonomyTable->getLastInsertId();

0 commit comments

Comments
 (0)