Skip to content

Commit 68e195b

Browse files
committed
add taxonomy tests
1 parent a91db5f commit 68e195b

File tree

11 files changed

+260
-99
lines changed

11 files changed

+260
-99
lines changed

src/Installation/DataBag.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ public function addOperations(?string $tenantId, string $category, array $operat
129129
$operation->costs,
130130
tenantId: $tenantId,
131131
description: $operation->description,
132+
taxonomy: $operation->taxonomy
132133
);
133134

134135
if (in_array($category, ['backend', 'consumer'])) {
@@ -201,11 +202,12 @@ public function toArray(): array
201202
return $result;
202203
}
203204

204-
public function addAction(string $category, string $name, string $class, ?string $config = null, ?array $metadata = null, ?string $date = null, ?string $tenantId = null): void
205+
public function addAction(string $category, string $name, string $class, ?string $config = null, ?array $metadata = null, ?string $date = null, ?string $tenantId = null, ?string $taxonomy = null): void
205206
{
206207
$this->data['fusio_action'][$name] = [
207208
'tenant_id' => $tenantId,
208209
'category_id' => $this->getReference('fusio_category', $category, $tenantId),
210+
'taxonomy_id' => $taxonomy !== null ? $this->getReference('fusio_taxonomy', $taxonomy, $tenantId) : null,
209211
'status' => Table\Action::STATUS_ACTIVE,
210212
'name' => $name,
211213
'class' => ClassName::serialize($class),
@@ -326,11 +328,12 @@ public function addConnection(string $name, string $class, ?string $config = nul
326328
];
327329
}
328330

329-
public function addCronjob(string $category, string $name, string $cron, string $action, ?array $metadata = null, ?string $tenantId = null): void
331+
public function addCronjob(string $category, string $name, string $cron, string $action, ?array $metadata = null, ?string $tenantId = null, ?string $taxonomy = null): void
330332
{
331333
$this->data['fusio_cronjob'][$name] = [
332334
'tenant_id' => $tenantId,
333335
'category_id' => $this->getReference('fusio_category', $category, $tenantId),
336+
'taxonomy_id' => $taxonomy !== null ? $this->getReference('fusio_taxonomy', $taxonomy, $tenantId) : null,
334337
'status' => Table\Cronjob::STATUS_ACTIVE,
335338
'name' => $name,
336339
'cron' => $cron,
@@ -353,11 +356,12 @@ public function addCronjobError(string $cronjob, string $message, ?string $tenan
353356
];
354357
}
355358

356-
public function addEvent(string $category, string $name, string $description = '', ?array $metadata = null, ?string $tenantId = null): void
359+
public function addEvent(string $category, string $name, string $description = '', ?array $metadata = null, ?string $tenantId = null, ?string $taxonomy = null): void
357360
{
358361
$this->data['fusio_event'][$name] = [
359362
'tenant_id' => $tenantId,
360363
'category_id' => $this->getReference('fusio_category', $category, $tenantId),
364+
'taxonomy_id' => $taxonomy !== null ? $this->getReference('fusio_taxonomy', $taxonomy, $tenantId) : null,
361365
'status' => Table\Event::STATUS_ACTIVE,
362366
'name' => $name,
363367
'description' => $description,
@@ -602,11 +606,12 @@ public function addRoleScope(string $role, string $scope, ?string $tenantId = nu
602606
];
603607
}
604608

605-
public function addOperation(string $category, bool $public, int $stability, string $name, string $httpMethod, string $httpPath, int $httpCode, object $parameters, ?string $incoming, ?string $outgoing, object $throws, string $action, ?int $costs = null, ?array $metadata = null, ?string $tenantId = null, ?string $description = null): void
609+
public function addOperation(string $category, bool $public, int $stability, string $name, string $httpMethod, string $httpPath, int $httpCode, object $parameters, ?string $incoming, ?string $outgoing, object $throws, string $action, ?int $costs = null, ?array $metadata = null, ?string $tenantId = null, ?string $description = null, ?string $taxonomy = null): void
606610
{
607611
$this->data['fusio_operation'][$name] = [
608612
'tenant_id' => $tenantId,
609613
'category_id' => $this->getReference('fusio_category', $category, $tenantId),
614+
'taxonomy_id' => $taxonomy !== null ? $this->getReference('fusio_taxonomy', $taxonomy, $tenantId) : null,
610615
'status' => Table\Operation::STATUS_ACTIVE,
611616
'active' => 1,
612617
'public' => $public ? 1 : 0,
@@ -698,11 +703,12 @@ public function addTest(string $category, string $operation, ?string $tenantId =
698703
];
699704
}
700705

701-
public function addTrigger(string $category, string $name, string $event, string $action, ?array $metadata = null, ?string $tenantId = null): void
706+
public function addTrigger(string $category, string $name, string $event, string $action, ?array $metadata = null, ?string $tenantId = null, ?string $taxonomy = null): void
702707
{
703708
$this->data['fusio_trigger'][$name] = [
704709
'tenant_id' => $tenantId,
705710
'category_id' => $this->getReference('fusio_category', $category, $tenantId),
711+
'taxonomy_id' => $taxonomy !== null ? $this->getReference('fusio_taxonomy', $taxonomy, $tenantId) : null,
706712
'status' => Table\Trigger::STATUS_ACTIVE,
707713
'name' => $name,
708714
'event' => $event,

src/Installation/Operation.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public function __construct(
4545
public int $stability = OperationInterface::STABILITY_STABLE,
4646
public ?int $costs = null,
4747
public ?string $description = null,
48+
public ?string $taxonomy = null,
4849
) {
4950
}
5051
}

tests/Backend/Api/Action/CollectionTest.php

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function testGet()
4747

4848
$expect = <<<'JSON'
4949
{
50-
"totalResults": 5,
50+
"totalResults": 4,
5151
"startIndex": 0,
5252
"itemsPerPage": 16,
5353
"entry": [
@@ -72,13 +72,6 @@ public function testGet()
7272
"class": "Fusio.Adapter.Sql.Action.SqlInsert",
7373
"date": "[datetime]"
7474
},
75-
{
76-
"id": 2,
77-
"status": 1,
78-
"name": "Sql-Select-All",
79-
"class": "Fusio.Adapter.Sql.Action.SqlSelectAll",
80-
"date": "[datetime]"
81-
},
8275
{
8376
"id": 1,
8477
"status": 1,
@@ -109,7 +102,7 @@ public function testGetSearch()
109102

110103
$expect = <<<'JSON'
111104
{
112-
"totalResults": 2,
105+
"totalResults": 1,
113106
"startIndex": 0,
114107
"itemsPerPage": 16,
115108
"entry": [
@@ -119,7 +112,31 @@ public function testGetSearch()
119112
"name": "Sql-Insert",
120113
"class": "Fusio.Adapter.Sql.Action.SqlInsert",
121114
"date": "[datetime]"
122-
},
115+
}
116+
]
117+
}
118+
JSON;
119+
120+
$this->assertEquals(200, $response->getStatusCode(), $body);
121+
$this->assertJsonStringEqualsJsonString($expect, $body, $body);
122+
}
123+
124+
public function testGetTaxonomy()
125+
{
126+
$response = $this->sendRequest('/backend/action?taxonomy=1', 'GET', array(
127+
'User-Agent' => 'Fusio TestCase',
128+
'Authorization' => 'Bearer da250526d583edabca8ac2f99e37ee39aa02a3c076c0edc6929095e20ca18dcf'
129+
));
130+
131+
$body = (string) $response->getBody();
132+
$body = Normalizer::normalize($body);
133+
134+
$expect = <<<'JSON'
135+
{
136+
"totalResults": 1,
137+
"startIndex": 0,
138+
"itemsPerPage": 16,
139+
"entry": [
123140
{
124141
"id": 2,
125142
"status": 1,
@@ -147,7 +164,7 @@ public function testGetCount()
147164

148165
$expect = <<<'JSON'
149166
{
150-
"totalResults": 5,
167+
"totalResults": 4,
151168
"startIndex": 0,
152169
"itemsPerPage": 80,
153170
"entry": [
@@ -172,13 +189,6 @@ public function testGetCount()
172189
"class": "Fusio.Adapter.Sql.Action.SqlInsert",
173190
"date": "[datetime]"
174191
},
175-
{
176-
"id": 2,
177-
"status": 1,
178-
"name": "Sql-Select-All",
179-
"class": "Fusio.Adapter.Sql.Action.SqlSelectAll",
180-
"date": "[datetime]"
181-
},
182192
{
183193
"id": 1,
184194
"status": 1,

tests/Backend/Api/Backup/resource/export.json

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,6 @@
2222
},
2323
"date": "[datetime]"
2424
},
25-
{
26-
"name": "Sql-Select-All",
27-
"class": "Fusio.Adapter.Sql.Action.SqlSelectAll",
28-
"async": false,
29-
"config": {
30-
"connection": 2,
31-
"table": "app_news"
32-
},
33-
"date": "[datetime]"
34-
},
3525
{
3626
"name": "Util-Static-Response",
3727
"class": "Fusio.Adapter.Util.Action.UtilStaticResponse",
@@ -917,32 +907,6 @@
917907
"action": "action:\/\/Sql-Insert",
918908
"costs": 1
919909
},
920-
{
921-
"status": 1,
922-
"name": "test.listFoo",
923-
"scopes": [
924-
"bar"
925-
],
926-
"active": true,
927-
"public": true,
928-
"stability": 1,
929-
"description": "",
930-
"httpMethod": "GET",
931-
"httpPath": "\/foo",
932-
"httpCode": 200,
933-
"parameters": {
934-
"startIndex": {
935-
"type": "integer"
936-
},
937-
"count": {
938-
"type": "integer"
939-
}
940-
},
941-
"outgoing": "schema:\/\/Collection-Schema",
942-
"throws": {},
943-
"action": "action:\/\/Sql-Select-All",
944-
"costs": 0
945-
},
946910
{
947911
"status": 1,
948912
"name": "meta.getAbout",

tests/Backend/Api/Cronjob/CollectionTest.php

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,40 @@ public function testGetSearch()
9999
$this->assertJsonStringEqualsJsonString($expect, $body, $body);
100100
}
101101

102+
public function testGetTaxonomy()
103+
{
104+
$response = $this->sendRequest('/backend/cronjob?taxonomy=1', 'GET', array(
105+
'User-Agent' => 'Fusio TestCase',
106+
'Authorization' => 'Bearer da250526d583edabca8ac2f99e37ee39aa02a3c076c0edc6929095e20ca18dcf'
107+
));
108+
109+
$body = (string) $response->getBody();
110+
$expect = <<<'JSON'
111+
{
112+
"totalResults": 1,
113+
"startIndex": 0,
114+
"itemsPerPage": 16,
115+
"entry": [
116+
{
117+
"id": 3,
118+
"status": 1,
119+
"name": "Second-Cron",
120+
"cron": "* * * * *",
121+
"action": "Sql-Select-All",
122+
"executeDate": "2015-02-27T19:59:15Z",
123+
"exitCode": 0,
124+
"metadata": {
125+
"foo": "bar"
126+
}
127+
}
128+
]
129+
}
130+
JSON;
131+
132+
$this->assertEquals(200, $response->getStatusCode(), $body);
133+
$this->assertJsonStringEqualsJsonString($expect, $body, $body);
134+
}
135+
102136
public function testGetCount()
103137
{
104138
$response = $this->sendRequest('/backend/cronjob?count=80', 'GET', array(
@@ -154,7 +188,7 @@ public function testPost()
154188
{
155189
"success": true,
156190
"message": "Cronjob successfully created",
157-
"id": "3"
191+
"id": "4"
158192
}
159193
JSON;
160194

@@ -172,7 +206,7 @@ public function testPost()
172206

173207
$row = $this->connection->fetchAssociative($sql);
174208

175-
$this->assertEquals(3, $row['id']);
209+
$this->assertEquals(4, $row['id']);
176210
$this->assertEquals('New-Cron', $row['name']);
177211
$this->assertEquals('5 * * * *', $row['cron']);
178212
$this->assertEquals('action://Sql-Select-All', $row['action']);

0 commit comments

Comments
 (0)