Skip to content

Commit ceff3fc

Browse files
committed
test: Fix unit tests
1 parent 2a0210e commit ceff3fc

File tree

8 files changed

+107
-56
lines changed

8 files changed

+107
-56
lines changed

tests/Api/ApiTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -522,17 +522,15 @@ public function testFieldApi(): void
522522
'slug' => 'test',
523523
'content' => [
524524
'title' => 'Test Title',
525-
'cover' => [
526-
'a.jpg'
527-
]
525+
'cover' => ['a.jpg']
528526
],
529527
'files' => [
530528
['filename' => 'a.jpg'],
531529
['filename' => 'b.jpg'],
532530
],
533531
'blueprint' => [
534-
'title' => 'Test',
535-
'name' => 'test',
532+
'title' => 'Test',
533+
'name' => 'test',
536534
'fields' => [
537535
'cover' => [
538536
'type' => 'files',
@@ -541,19 +539,21 @@ public function testFieldApi(): void
541539
]
542540
]
543541
]
542+
],
543+
'request' => [
544+
'query' => [
545+
'items' => 'a.jpg,b.jpg'
546+
],
544547
]
545548
]);
546549
$app->impersonate('kirby');
547550

548-
$page = $app->page('test');
549-
$response = $app->api()->fieldApi($page, 'cover');
551+
$page = $app->page('test');
552+
$response = $app->api()->fieldApi($page, 'cover', 'items');
550553

551554
$this->assertCount(2, $response);
552-
$this->assertArrayHasKey('data', $response);
553-
$this->assertArrayHasKey('pagination', $response);
554-
$this->assertCount(2, $response['data']);
555-
$this->assertSame('a.jpg', $response['data'][0]['filename']);
556-
$this->assertSame('b.jpg', $response['data'][1]['filename']);
555+
$this->assertSame('a.jpg', $response[0]['filename']);
556+
$this->assertSame('b.jpg', $response[1]['filename']);
557557
}
558558

559559
public function testFieldApiInvalidField(): void

tests/Form/Field/FilesFieldTest.php

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,37 @@ public function setUp(): void
2323
[
2424
'slug' => 'test',
2525
'files' => [
26-
['filename' => 'a.jpg'],
27-
['filename' => 'b.jpg'],
28-
['filename' => 'c.jpg']
26+
[
27+
'filename' => 'a.jpg',
28+
'content' => ['uuid' => 'test-a'],
29+
],
30+
[
31+
'filename' => 'b.jpg',
32+
'content' => ['uuid' => 'test-b'],
33+
],
34+
[
35+
'filename' => 'c.jpg',
36+
'content' => ['uuid' => 'test-c'],
37+
],
2938
]
3039
]
3140
],
3241
'drafts' => [
3342
[
3443
'slug' => 'test-draft',
3544
'files' => [
36-
['filename' => 'a.jpg'],
37-
['filename' => 'b.jpg'],
38-
['filename' => 'c.jpg']
45+
[
46+
'filename' => 'a.jpg',
47+
'content' => ['uuid' => 'draft-a'],
48+
],
49+
[
50+
'filename' => 'b.jpg',
51+
'content' => ['uuid' => 'draft-b'],
52+
],
53+
[
54+
'filename' => 'c.jpg',
55+
'content' => ['uuid' => 'draft-c'],
56+
],
3957
]
4058
]
4159
]
@@ -77,8 +95,8 @@ public function testValue(): void
7795
]);
7896

7997
$expected = [
80-
'test/a.jpg',
81-
'test/b.jpg'
98+
'file://test-a',
99+
'file://test-b'
82100
];
83101

84102
$this->assertSame($expected, $field->value());
@@ -129,8 +147,8 @@ public function testFilesInDraft(): void
129147
]);
130148

131149
$expected = [
132-
'test-draft/a.jpg',
133-
'test-draft/b.jpg'
150+
'file://draft-a',
151+
'file://draft-b'
134152
];
135153

136154
$this->assertSame($expected, $field->value());
@@ -200,9 +218,18 @@ public function testApiItems(): void
200218
[
201219
'slug' => 'test',
202220
'files' => [
203-
['filename' => 'a.jpg'],
204-
['filename' => 'b.jpg'],
205-
['filename' => 'c.jpg'],
221+
[
222+
'filename' => 'a.jpg',
223+
'content' => ['uuid' => 'my-a'],
224+
],
225+
[
226+
'filename' => 'b.jpg',
227+
'content' => ['uuid' => 'my-b'],
228+
],
229+
[
230+
'filename' => 'c.jpg',
231+
'content' => ['uuid' => 'my-c'],
232+
],
206233
],
207234
'blueprint' => [
208235
'title' => 'Test',
@@ -227,8 +254,8 @@ public function testApiItems(): void
227254
$api = $app->api()->call('pages/test/fields/gallery/items');
228255

229256
$this->assertCount(2, $api);
230-
$this->assertSame('a.jpg', $api[0]['id']);
231-
$this->assertSame('b.jpg', $api[1]['id']);
257+
$this->assertSame('file://my-a', $api[0]['id']);
258+
$this->assertSame('file://my-b', $api[1]['id']);
232259
}
233260

234261
public function testParentModel(): void

tests/Form/Field/Mixins/PickerMixinTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,14 @@ public function testToItem(): void
6868
$item = $field->toItem(new Page([
6969
'slug' => 'test',
7070
'content' => [
71-
'title' => 'Test Title'
71+
'title' => 'Test Title',
72+
'uuid' => 'test-page',
7273
]
7374
]));
7475

7576
$this->assertIsArray($item);
7677
$this->assertArrayHasKey('image', $item);
77-
$this->assertSame('test', $item['id']);
78+
$this->assertSame('page://test-page', $item['id']);
7879
$this->assertSame('Test Title', $item['text']);
7980
}
8081

tests/Form/Field/PagesFieldTest.php

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,23 @@ public function setUp(): void
2020
'site' => [
2121
'children' => [
2222
[
23-
'slug' => 'a',
23+
'slug' => 'a',
24+
'content' => ['uuid' => 'my-a'],
2425
'children' => [
2526
[
2627
'slug' => 'aa',
28+
'content' => ['uuid' => 'my-aa'],
2729
],
2830
[
2931
'slug' => 'ab',
30-
]
32+
'content' => ['uuid' => 'my-ab'],
33+
],
3134
]
3235
],
3336
[
3437
'slug' => 'b',
35-
]
38+
'content' => ['uuid' => 'my-b'],
39+
],
3640
]
3741
]
3842
]);
@@ -70,8 +74,8 @@ public function testValue(): void
7074
]);
7175

7276
$expected = [
73-
'a/aa',
74-
'a/ab'
77+
'page://my-aa',
78+
'page://my-ab'
7579
];
7680

7781
$this->assertSame($expected, $field->value());
@@ -189,9 +193,18 @@ public function testApiItems(): void
189193
]
190194
]
191195
],
192-
['slug' => 'a'],
193-
['slug' => 'b'],
194-
['slug' => 'c'],
196+
[
197+
'slug' => 'a',
198+
'content' => ['uuid' => 'my-a'],
199+
],
200+
[
201+
'slug' => 'b',
202+
'content' => ['uuid' => 'my-b'],
203+
],
204+
[
205+
'slug' => 'c',
206+
'content' => ['uuid' => 'my-c'],
207+
],
195208
]
196209
],
197210
'request' => [
@@ -205,9 +218,9 @@ public function testApiItems(): void
205218
$api = $app->api()->call('pages/test/fields/related/items');
206219

207220
$this->assertCount(3, $api);
208-
$this->assertSame('test', $api[0]['id']);
209-
$this->assertSame('a', $api[1]['id']);
210-
$this->assertSame('b', $api[2]['id']);
221+
$this->assertSame('page://my-test-uuid', $api[0]['id']);
222+
$this->assertSame('page://my-a', $api[1]['id']);
223+
$this->assertSame('page://my-b', $api[2]['id']);
211224
}
212225

213226
public function testToModel(): void

tests/Form/Field/UsersFieldTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ public function testMultipleDefaultUsers(): void
8787
]
8888
]);
8989

90-
$this->assertSame('raphael', $field->default()[0]);
91-
$this->assertSame('donatello', $field->default()[1]);
90+
$this->assertSame('user://raphael', $field->default()[0]);
91+
$this->assertSame('user://donatello', $field->default()[1]);
9292
}
9393

9494
public function testDefaultUserDisabled(): void
@@ -245,8 +245,8 @@ public function testApiItems(): void
245245
$api = $app->api()->call('pages/test/fields/authors/items');
246246

247247
$this->assertCount(2, $api);
248-
$this->assertSame('leonardo', $api[0]['id']);
249-
$this->assertSame('raphael', $api[1]['id']);
248+
$this->assertSame('user://leonardo', $api[0]['id']);
249+
$this->assertSame('user://raphael', $api[1]['id']);
250250
}
251251

252252
public function testToModel(): void
@@ -272,8 +272,8 @@ public function testValue(): void
272272
]);
273273

274274
$expected = [
275-
'leonardo',
276-
'raphael'
275+
'user://leonardo',
276+
'user://raphael'
277277
];
278278

279279
$this->assertSame($expected, $field->value());

tests/Panel/Controller/Dialog/FilesPickerDialogControllerTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ public function setUp(): void
2121
$this->app = $this->app->clone([
2222
'site' => [
2323
'files' => [
24-
['filename' => 'test.jpg']
24+
[
25+
'filename' => 'test.jpg',
26+
'content' => ['uuid' => 'test'],
27+
]
2528
]
2629
]
2730
]);
@@ -76,7 +79,7 @@ public function testItem(): void
7679
$this->assertArrayHasKey('image', $item);
7780
$this->assertSame('', $item['info']);
7881
$this->assertSame('list', $item['layout']);
79-
$this->assertSame('test.jpg', $item['id']);
82+
$this->assertSame('file://test', $item['id']);
8083
$this->assertSame('/site/files/test.jpg', $item['link']);
8184
$this->assertArrayHasKey('permissions', $item);
8285
}

tests/Panel/Controller/Dialog/PagesPickerDialogControllerTest.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,17 @@ public function setUp(): void
2222
$this->app = $this->app->clone([
2323
'site' => [
2424
'children' => [
25-
['slug' => 'alpha'],
26-
['slug' => 'beta'],
2725
[
28-
'slug' => 'gamma',
26+
'slug' => 'alpha',
27+
'content' => ['uuid' => 'alpha'],
28+
],
29+
[
30+
'slug' => 'beta',
31+
'content' => ['uuid' => 'beta'],
32+
],
33+
[
34+
'slug' => 'gamma',
35+
'content' => ['uuid' => 'gamma'],
2936
'children' => [
3037
['slug' => 'delta'],
3138
['slug' => 'epsilon'],
@@ -96,7 +103,7 @@ public function testItem(): void
96103
$this->assertArrayHasKey('image', $item);
97104
$this->assertSame('', $item['info']);
98105
$this->assertSame('list', $item['layout']);
99-
$this->assertSame('alpha', $item['id']);
106+
$this->assertSame('page://alpha', $item['id']);
100107
$this->assertSame('/pages/alpha', $item['link']);
101108
$this->assertArrayHasKey('permissions', $item);
102109
$this->assertFalse($item['hasChildren']);
@@ -110,9 +117,9 @@ public function testItems(): void
110117

111118
$items = $controller->items();
112119
$this->assertCount(3, $items);
113-
$this->assertSame('alpha', $items[0]['id']);
114-
$this->assertSame('beta', $items[1]['id']);
115-
$this->assertSame('gamma', $items[2]['id']);
120+
$this->assertSame('page://alpha', $items[0]['id']);
121+
$this->assertSame('page://beta', $items[1]['id']);
122+
$this->assertSame('page://gamma', $items[2]['id']);
116123
}
117124

118125
public function testLoad(): void

tests/Panel/Controller/Dialog/UsersPickerDialogControllerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function testItem(): void
8484
$this->assertArrayHasKey('image', $item);
8585
$this->assertSame('', $item['info']);
8686
$this->assertSame('list', $item['layout']);
87-
$this->assertSame('test', $item['id']);
87+
$this->assertSame('user://test', $item['id']);
8888
$this->assertSame('/users/test', $item['link']);
8989
$this->assertArrayHasKey('permissions', $item);
9090
$this->assertSame('user://test', $item['uuid']);

0 commit comments

Comments
 (0)