1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-08 06:06:45 +02:00

feat(fields): Add new field entries.fetch for Entries API #492

This commit is contained in:
Awilum
2020-12-17 10:31:46 +03:00
parent fcc3d2a6b5
commit 5b709ba227
12 changed files with 48 additions and 22 deletions

View File

@@ -38,7 +38,7 @@ test('test entries field for catalog', function () {
// Create banner
flextype('entries')->create('banner', ['title' => 'Banner']);
$catalogSingle = flextype('entries')->fetchSingle('catalog');
$catalogSingle = flextype('entries')->fetch('catalog');
$this->assertEquals(16, $catalogSingle->count());
$this->assertEquals('Catalog', $catalogSingle['title']);
@@ -50,12 +50,12 @@ test('test entries field for catalog', function () {
$this->assertTrue(isset($catalogSingle['discounts']['discounts/30-off']));
$this->assertEquals('30% off', $catalogSingle['discounts']['discounts/30-off']['title']);
$catalogCollection = flextype('entries')->fetchCollection('catalog');
$catalogCollection = flextype('entries')->fetch('catalog', ['collection' => true]);
$this->assertEquals(1, $catalogCollection->count());
$this->assertEquals('Bikes', $catalogCollection['catalog/bikes']['title']);
$this->assertEquals('catalog/bikes', $catalogCollection['catalog/bikes']['id']);
$catalogLongCollecion = flextype('entries')->fetchCollection('catalog', ['find' => ['depth' => ['>0', '<4']]]);
$catalogLongCollecion = flextype('entries')->fetch('catalog', ['collection' => true, 'find' => ['depth' => ['>0', '<4']]]);
$this->assertEquals(5, $catalogLongCollecion->count());
$banner = flextype('entries')->fetchSingle('banner');
@@ -74,7 +74,7 @@ test('test entries field for albmus', function () {
flextype('entries')->create('banners/1', ['title' => 'Banner1']);
flextype('entries')->create('banners/2', ['title' => 'Banner2']);
$root = flextype('entries')->fetchSingle('root');
$root = flextype('entries')->fetch('root');
$this->assertEquals(16, $root->count());
});
@@ -85,10 +85,23 @@ test('test entries field for long nested entries', function () {
flextype('entries')->create('level1/level2/level3', flextype('frontmatter')->decode(filesystem()->file(ROOT_DIR . '/tests/Foundation/Entries/Fields/fixtures/entries/level1/level2/level3/entry.md')->get()));
flextype('entries')->create('level1/level2/level3/level4', flextype('frontmatter')->decode(filesystem()->file(ROOT_DIR . '/tests/Foundation/Entries/Fields/fixtures/entries/level1/level2/level3/level4/entry.md')->get()));
$level = flextype('entries')->fetchSingle('level1');
$level = flextype('entries')->fetch('level1');
$this->assertEquals(14, $level->count());
$this->assertEquals('level1/level2', $level['root']['id']);
$this->assertEquals('level1/level2/level3', $level['root']['root']['id']);
$this->assertEquals('level1/level2/level3/level4', $level['root']['root']['root']['id']);
});
test('test entries field for macroable fetch entries', function () {
flextype('entries')->create('macroable', flextype('frontmatter')->decode(filesystem()->file(ROOT_DIR . '/tests/Foundation/Entries/Fields/fixtures/entries/macroable/entry.md')->get()));
flextype('entries')::macro('fetchExtraData', function ($id, $options) {
return ['id' => $id, 'options' => $options];
});
$macroable = flextype('entries')->fetch('macroable');
$this->assertEquals('table', $macroable['table']['id']);
$this->assertEquals('world', $macroable['table']['options']['hello']);
});

View File

@@ -1,8 +1,9 @@
---
title: blog
entries:
fetchCollection:
fetch:
posts:
id: blog
options: []
options:
collection: true
---

View File

@@ -2,17 +2,17 @@
title: GT
brand: gt
entries:
fetchCollection:
fetch:
discounts_available:
id: discounts
options:
collection: true
filter:
where:
-
key: category
operator: eq
value: bikes
fetchSingle:
label1:
id: discounts/50-off
options:

View File

@@ -2,14 +2,13 @@
title: Norco
brand: norco
entries:
fetchSingle:
fetch:
label:
id: discounts/30-off
options:
from: collection
fetchCollection:
collection: true
discounts:
id: discounts
options:
from: collection
collection: true
---

View File

@@ -2,16 +2,16 @@
title: Catalog
visibility: visible
entries:
fetchSingle:
fetch:
label1:
id: discounts/50-off
options:
filter:
limit: 4
fetchCollection:
bikes:
id: catalog/bikes
options:
collection: true
filter:
where:
-
@@ -22,6 +22,7 @@ entries:
discounts:
id: discounts
options:
collection: true
filter:
where:
-

View File

@@ -1,7 +1,7 @@
---
title: level1
entries:
fetchSingle:
fetch:
root:
id: level1/level2
---

View File

@@ -1,7 +1,7 @@
---
title: level2
entries:
fetchSingle:
fetch:
root:
id: level1/level2/level3
---

View File

@@ -1,7 +1,7 @@
---
title: level3
entries:
fetchSingle:
fetch:
root:
id: level1/level2/level3/level4
---

View File

@@ -0,0 +1,10 @@
---
title: Macroable
entries:
fetch:
table:
method: fetchExtraData
id: table
options:
hello: world
---

View File

@@ -9,7 +9,7 @@ registry:
license:
key: flextype.manifest.license
entries:
fetchSingle:
fetch:
level1:
id: registry-root/level-1
result: toArray

View File

@@ -1,7 +1,7 @@
---
title: Level 1
entries:
fetchSingle:
fetch:
level2:
id: registry-root/level-1/level-2
result: toArray

View File

@@ -1,15 +1,17 @@
---
title: Root
entries:
fetchSingle:
fetch:
albums:
id: albums
fetchCollection:
collection:
id: albums
options:
collection: true
collectionWithDepth:
id: albums
options:
collection: false
find:
depth: '>0'
---