mirror of
https://github.com/flextype/flextype.git
synced 2025-08-12 16:14:16 +02:00
feat(entries): Entries API improvements. #491
This commit is contained in:
@@ -27,28 +27,28 @@ test('test update() method', function () {
|
||||
$this->assertFalse(flextype('entries')->update('bar', ['title' => 'Test']));
|
||||
});
|
||||
|
||||
test('test fetch() entry', function () {
|
||||
test('test fetchSingle() and fetchCollection() entry', function () {
|
||||
flextype('entries')->create('foo', ['title' => 'Foo']);
|
||||
flextype('entries')->create('foo/bar', ['title' => 'Bar']);
|
||||
flextype('entries')->create('foo/baz', ['title' => 'Baz']);
|
||||
flextype('entries')->create('foo/zed', ['title' => 'Zed']);
|
||||
|
||||
$this->assertEquals(12, flextype('entries')->fetch('foo')->count());
|
||||
$this->assertEquals('foo', flextype('entries')->fetch('foo')['id']);
|
||||
$this->assertEquals(12, flextype('entries')->fetch('foo', ['from' => 'single'])->count());
|
||||
$this->assertEquals('foo', flextype('entries')->fetch('foo')['id']);
|
||||
$this->assertEquals(3, flextype('entries')->fetch('foo', ['from' => 'collection'])->count());
|
||||
$this->assertEquals(12, flextype('entries')->fetchSingle('foo')->count());
|
||||
$this->assertEquals('foo', flextype('entries')->fetchSingle('foo')['id']);
|
||||
$this->assertEquals(12, flextype('entries')->fetchSingle('foo', [])->count());
|
||||
$this->assertEquals('foo', flextype('entries')->fetchSingle('foo')['id']);
|
||||
$this->assertEquals(3, flextype('entries')->fetchCollection('foo')->count());
|
||||
|
||||
$this->assertEquals('Bar', flextype('entries')->fetch('foo/bar')['title']);
|
||||
$this->assertEquals('Baz', flextype('entries')->fetch('foo/baz')['title']);
|
||||
$this->assertEquals('Zed', flextype('entries')->fetch('foo/zed')['title']);
|
||||
$this->assertEquals('Bar', flextype('entries')->fetchSingle('foo/bar')['title']);
|
||||
$this->assertEquals('Baz', flextype('entries')->fetchSingle('foo/baz')['title']);
|
||||
$this->assertEquals('Zed', flextype('entries')->fetchSingle('foo/zed')['title']);
|
||||
|
||||
flextype('entries')->setStorage('fetch.id', 'wrong-entry');
|
||||
$this->assertEquals(0, flextype('entries')->fetch('wrong-entry')->count());
|
||||
$this->assertEquals(0, flextype('entries')->fetchSingle('wrong-entry')->count());
|
||||
flextype('entries')->setStorage('fetch.id', 'wrong-entry');
|
||||
$this->assertEquals(0, flextype('entries')->fetch('wrong-entry')->count());
|
||||
$this->assertEquals(0, flextype('entries')->fetchSingle('wrong-entry')->count());
|
||||
|
||||
$this->assertTrue(count(flextype('entries')->fetch('foo', ['from' => 'collection'])) > 0);
|
||||
$this->assertTrue(count(flextype('entries')->fetchCollection('foo')) > 0);
|
||||
|
||||
/*
|
||||
flextype('emitter')->addListener('onEntriesFetchCollectionHasResult', static function (): void {
|
||||
|
@@ -13,7 +13,7 @@ afterEach(function (): void {
|
||||
test('test CreatedAtField', function () {
|
||||
// 1
|
||||
flextype('entries')->create('foo', []);
|
||||
$created_at = flextype('entries')->fetch('foo')['created_at'];
|
||||
$created_at = flextype('entries')->fetchSingle('foo')['created_at'];
|
||||
$this->assertTrue(strlen($created_at) > 0);
|
||||
$this->assertTrue((ctype_digit($created_at) && strtotime(date('Y-m-d H:i:s', $created_at)) === (int)$created_at));
|
||||
});
|
||||
|
@@ -12,10 +12,10 @@ afterEach(function (): void {
|
||||
|
||||
test('test CreatedByField', function () {
|
||||
flextype('entries')->create('foo', []);
|
||||
$created_by = flextype('entries')->fetch('foo')['created_by'];
|
||||
$created_by = flextype('entries')->fetchSingle('foo')['created_by'];
|
||||
$this->assertEquals('', $created_by);
|
||||
|
||||
flextype('entries')->create('bar', ['created_by' => 'Zed']);
|
||||
$created_by = flextype('entries')->fetch('bar')['created_by'];
|
||||
$created_by = flextype('entries')->fetchSingle('bar')['created_by'];
|
||||
$this->assertEquals('Zed', $created_by);
|
||||
});
|
||||
|
@@ -10,17 +10,17 @@ afterEach(function (): void {
|
||||
filesystem()->directory(PATH['project'] . '/entries')->delete();
|
||||
});
|
||||
|
||||
test('test fetchField for blog', function () {
|
||||
test('test entries field for blog', function () {
|
||||
flextype('entries')->create('blog', flextype('frontmatter')->decode(filesystem()->file(ROOT_DIR . '/tests/Foundation/Entries/Fields/fixtures/entries/blog/entry.md')->get()));
|
||||
flextype('entries')->create('blog/post-1', flextype('frontmatter')->decode(filesystem()->file(ROOT_DIR . '/tests/Foundation/Entries/Fields/fixtures/entries/blog/post-1/entry.md')->get()));
|
||||
flextype('entries')->create('blog/post-2', flextype('frontmatter')->decode(filesystem()->file(ROOT_DIR . '/tests/Foundation/Entries/Fields/fixtures/entries/blog/post-2/entry.md')->get()));
|
||||
|
||||
$blog = flextype('entries')->fetch('blog');
|
||||
$blog = flextype('entries')->fetchSingle('blog');
|
||||
|
||||
$this->assertEquals(14, $blog->count());
|
||||
});
|
||||
|
||||
test('test fetchField for catalog', function () {
|
||||
test('test entries field for catalog', function () {
|
||||
|
||||
// Create catalog
|
||||
flextype('entries')->create('catalog', flextype('frontmatter')->decode(filesystem()->file(ROOT_DIR . '/tests/Foundation/Entries/Fields/fixtures/entries/catalog/entry.md')->get()));
|
||||
@@ -38,7 +38,7 @@ test('test fetchField for catalog', function () {
|
||||
// Create banner
|
||||
flextype('entries')->create('banner', ['title' => 'Banner']);
|
||||
|
||||
$catalogSingle = flextype('entries')->fetch('catalog');
|
||||
$catalogSingle = flextype('entries')->fetchSingle('catalog');
|
||||
|
||||
$this->assertEquals(16, $catalogSingle->count());
|
||||
$this->assertEquals('Catalog', $catalogSingle['title']);
|
||||
@@ -50,20 +50,20 @@ test('test fetchField for catalog', function () {
|
||||
$this->assertTrue(isset($catalogSingle['discounts']['discounts/30-off']));
|
||||
$this->assertEquals('30% off', $catalogSingle['discounts']['discounts/30-off']['title']);
|
||||
|
||||
$catalogCollection = flextype('entries')->fetch('catalog', ['from' => 'collection']);
|
||||
$catalogCollection = flextype('entries')->fetchCollection('catalog');
|
||||
$this->assertEquals(1, $catalogCollection->count());
|
||||
$this->assertEquals('Bikes', $catalogCollection['catalog/bikes']['title']);
|
||||
$this->assertEquals('catalog/bikes', $catalogCollection['catalog/bikes']['id']);
|
||||
|
||||
$catalogLongCollecion = flextype('entries')->fetch('catalog', ['from' => 'collection', 'find' => ['depth' => ['>0', '<4']]]);
|
||||
$catalogLongCollecion = flextype('entries')->fetchCollection('catalog', ['find' => ['depth' => ['>0', '<4']]]);
|
||||
$this->assertEquals(5, $catalogLongCollecion->count());
|
||||
|
||||
$banner = flextype('entries')->fetch('banner');
|
||||
$banner = flextype('entries')->fetchSingle('banner');
|
||||
$this->assertEquals('Banner', $banner['title']);
|
||||
$this->assertEquals('banner', $banner['id']);
|
||||
});
|
||||
|
||||
test('test fetchField for albmus', function () {
|
||||
test('test entries field for albmus', function () {
|
||||
flextype('entries')->create('root', flextype('frontmatter')->decode(filesystem()->file(ROOT_DIR . '/tests/Foundation/Entries/Fields/fixtures/entries/root/entry.md')->get()));
|
||||
|
||||
flextype('entries')->create('albums', flextype('frontmatter')->decode(filesystem()->file(ROOT_DIR . '/tests/Foundation/Entries/Fields/fixtures/entries/root/albums/entry.md')->get()));
|
||||
@@ -74,16 +74,18 @@ test('test fetchField for albmus', function () {
|
||||
flextype('entries')->create('banners/1', ['title' => 'Banner1']);
|
||||
flextype('entries')->create('banners/2', ['title' => 'Banner2']);
|
||||
|
||||
$root = flextype('entries')->fetchSingle('root');
|
||||
|
||||
$this->assertEquals(16, $root->count());
|
||||
});
|
||||
|
||||
test('test fetchField for long nested entries', function () {
|
||||
test('test entries field for long nested entries', function () {
|
||||
flextype('entries')->create('level1', flextype('frontmatter')->decode(filesystem()->file(ROOT_DIR . '/tests/Foundation/Entries/Fields/fixtures/entries/level1/entry.md')->get()));
|
||||
flextype('entries')->create('level1/level2', flextype('frontmatter')->decode(filesystem()->file(ROOT_DIR . '/tests/Foundation/Entries/Fields/fixtures/entries/level1/level2/entry.md')->get()));
|
||||
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')->fetch('level1')->sortKeys();
|
||||
$level = flextype('entries')->fetchSingle('level1');
|
||||
|
||||
$this->assertEquals(14, $level->count());
|
||||
$this->assertEquals('level1/level2', $level['root']['id']);
|
@@ -12,10 +12,10 @@ afterEach(function (): void {
|
||||
|
||||
test('test IdField', function () {
|
||||
flextype('entries')->create('foo', []);
|
||||
$id = flextype('entries')->fetch('foo')['id'];
|
||||
$id = flextype('entries')->fetchSingle('foo')['id'];
|
||||
$this->assertEquals('foo', $id);
|
||||
|
||||
flextype('entries')->create('foo/bar', []);
|
||||
$id = flextype('entries')->fetch('foo/bar')['id'];
|
||||
$id = flextype('entries')->fetchSingle('foo/bar')['id'];
|
||||
$this->assertEquals('foo/bar', $id);
|
||||
});
|
||||
|
@@ -13,7 +13,7 @@ afterEach(function (): void {
|
||||
test('test ModifiedAtField', function () {
|
||||
flextype('entries')->create('foo', []);
|
||||
|
||||
$modified_at = flextype('entries')->fetch('foo')['modified_at'];
|
||||
$modified_at = flextype('entries')->fetchSingle('foo')['modified_at'];
|
||||
|
||||
$this->assertTrue(strlen($modified_at) > 0);
|
||||
$this->assertTrue((ctype_digit($modified_at) && strtotime(date('Y-m-d H:i:s', $modified_at)) === (int)$modified_at));
|
||||
|
@@ -12,8 +12,8 @@ afterEach(function (): void {
|
||||
|
||||
test('test ParsersField', function () {
|
||||
flextype('entries')->create('foo', ['content' => '#Foo', 'parsers' => ['markdown' => ['enabled' => true, 'fields' => ['content']]]]);
|
||||
$this->assertEquals('<h1>Foo</h1>', flextype('entries')->fetch('foo')['content']);
|
||||
$this->assertEquals('<h1>Foo</h1>', flextype('entries')->fetchSingle('foo')['content']);
|
||||
|
||||
flextype('entries')->create('bar', ['content' => '[registry_get name="Bar" default="Zed"]', 'parsers' => ['shortcode' => ['enabled' => true, 'fields' => ['content']]]]);
|
||||
$this->assertEquals('Zed', flextype('entries')->fetch('bar')['content']);
|
||||
$this->assertEquals('Zed', flextype('entries')->fetchSingle('bar')['content']);
|
||||
});
|
||||
|
@@ -13,7 +13,7 @@ afterEach(function (): void {
|
||||
test('test PublishedAtField', function () {
|
||||
flextype('entries')->create('foo', []);
|
||||
|
||||
$published_at = flextype('entries')->fetch('foo')['published_at'];
|
||||
$published_at = flextype('entries')->fetchSingle('foo')['published_at'];
|
||||
|
||||
$this->assertTrue(strlen($published_at) > 0);
|
||||
$this->assertTrue((ctype_digit($published_at) && strtotime(date('Y-m-d H:i:s', $published_at)) === (int)$published_at));
|
||||
|
@@ -12,10 +12,10 @@ afterEach(function (): void {
|
||||
|
||||
test('test PublishedByField', function () {
|
||||
flextype('entries')->create('foo', []);
|
||||
$published_by = flextype('entries')->fetch('foo')['published_by'];
|
||||
$published_by = flextype('entries')->fetchSingle('foo')['published_by'];
|
||||
$this->assertEquals('', $published_by);
|
||||
|
||||
flextype('entries')->create('bar', ['published_by' => 'Zed']);
|
||||
$published_by = flextype('entries')->fetch('bar')['published_by'];
|
||||
$published_by = flextype('entries')->fetchSingle('bar')['published_by'];
|
||||
$this->assertEquals('Zed', $published_by);
|
||||
});
|
||||
|
@@ -14,14 +14,14 @@ test('test RoutableField', function () {
|
||||
flextype('registry')->set('flextype.settings.cache.enabled', false);
|
||||
|
||||
flextype('entries')->create('foo', ['routable' => true]);
|
||||
$routable = flextype('entries')->fetch('foo')['routable'];
|
||||
$routable = flextype('entries')->fetchSingle('foo')['routable'];
|
||||
$this->assertTrue($routable);
|
||||
|
||||
flextype('entries')->create('bar', []);
|
||||
$routable = flextype('entries')->fetch('bar')['routable'];
|
||||
$routable = flextype('entries')->fetchSingle('bar')['routable'];
|
||||
$this->assertTrue($routable);
|
||||
|
||||
flextype('entries')->create('zed', ['routable' => false]);
|
||||
$routable = flextype('entries')->fetch('zed')['routable'];
|
||||
$routable = flextype('entries')->fetchSingle('zed')['routable'];
|
||||
$this->assertFalse($routable);
|
||||
});
|
||||
|
@@ -12,10 +12,10 @@ afterEach(function (): void {
|
||||
|
||||
test('test SlugField', function () {
|
||||
flextype('entries')->create('foo', []);
|
||||
$slug = flextype('entries')->fetch('foo')['slug'];
|
||||
$slug = flextype('entries')->fetchSingle('foo')['slug'];
|
||||
$this->assertEquals('foo', $slug);
|
||||
|
||||
flextype('entries')->create('bar', []);
|
||||
$slug = flextype('entries')->fetch('bar')['slug'];
|
||||
$slug = flextype('entries')->fetchSingle('bar')['slug'];
|
||||
$this->assertEquals('bar', $slug);
|
||||
});
|
||||
|
@@ -14,6 +14,6 @@ afterEach(function (): void {
|
||||
|
||||
test('test UuidField', function () {
|
||||
flextype('entries')->create('foo', []);
|
||||
$uuid = flextype('entries')->fetch('foo')['uuid'];
|
||||
$uuid = flextype('entries')->fetchSingle('foo')['uuid'];
|
||||
$this->assertTrue(v::uuid()->validate($uuid));
|
||||
});
|
||||
|
@@ -12,14 +12,14 @@ afterEach(function (): void {
|
||||
|
||||
test('test VisibilityField', function () {
|
||||
flextype('entries')->create('foo', []);
|
||||
$visibility = flextype('entries')->fetch('foo')['visibility'];
|
||||
$visibility = flextype('entries')->fetchSingle('foo')['visibility'];
|
||||
$this->assertEquals('visible', $visibility);
|
||||
|
||||
flextype('entries')->create('bar', ['visibility' => 'draft']);
|
||||
$visibility = flextype('entries')->fetch('bar')['visibility'];
|
||||
$visibility = flextype('entries')->fetchSingle('bar')['visibility'];
|
||||
$this->assertEquals('draft', $visibility);
|
||||
|
||||
flextype('entries')->create('zed', ['visibility' => 'foobar']);
|
||||
$visibility = flextype('entries')->fetch('zed')['visibility'];
|
||||
$visibility = flextype('entries')->fetchSingle('zed')['visibility'];
|
||||
$this->assertEquals('visible', $visibility);
|
||||
});
|
||||
|
@@ -1,8 +1,8 @@
|
||||
---
|
||||
title: blog
|
||||
fetch:
|
||||
posts:
|
||||
id: blog
|
||||
options:
|
||||
from: collection
|
||||
entries:
|
||||
fetchCollection:
|
||||
posts:
|
||||
id: blog
|
||||
options: []
|
||||
---
|
||||
|
@@ -1,27 +1,26 @@
|
||||
---
|
||||
title: GT
|
||||
brand: gt
|
||||
fetch:
|
||||
discounts_available:
|
||||
id: discounts
|
||||
options:
|
||||
from: collection
|
||||
filter:
|
||||
where:
|
||||
-
|
||||
key: category
|
||||
operator: eq
|
||||
value: bikes
|
||||
label1:
|
||||
id: discounts/50-off
|
||||
options:
|
||||
from: single
|
||||
filter:
|
||||
limit: 3
|
||||
label2:
|
||||
id: discounts/30-off
|
||||
options:
|
||||
from: single
|
||||
filter:
|
||||
limit: 2
|
||||
entries:
|
||||
fetchCollection:
|
||||
discounts_available:
|
||||
id: discounts
|
||||
options:
|
||||
filter:
|
||||
where:
|
||||
-
|
||||
key: category
|
||||
operator: eq
|
||||
value: bikes
|
||||
fetchSingle:
|
||||
label1:
|
||||
id: discounts/50-off
|
||||
options:
|
||||
filter:
|
||||
limit: 3
|
||||
label2:
|
||||
id: discounts/30-off
|
||||
options:
|
||||
filter:
|
||||
limit: 2
|
||||
---
|
||||
|
@@ -1,14 +1,15 @@
|
||||
---
|
||||
title: Norco
|
||||
brand: norco
|
||||
fetch:
|
||||
label:
|
||||
from: single
|
||||
id: discounts/30-off
|
||||
options:
|
||||
from: collection
|
||||
discounts:
|
||||
id: discounts
|
||||
options:
|
||||
from: collection
|
||||
entries:
|
||||
fetchSingle:
|
||||
label:
|
||||
id: discounts/30-off
|
||||
options:
|
||||
from: collection
|
||||
fetchCollection:
|
||||
discounts:
|
||||
id: discounts
|
||||
options:
|
||||
from: collection
|
||||
---
|
||||
|
@@ -1,36 +1,35 @@
|
||||
---
|
||||
title: Catalog
|
||||
visibility: draft
|
||||
fetch:
|
||||
label1:
|
||||
id: discounts/50-off
|
||||
options:
|
||||
from: single
|
||||
filter:
|
||||
limit: 4
|
||||
bikes:
|
||||
id: catalog/bikes
|
||||
options:
|
||||
from: collection
|
||||
filter:
|
||||
where:
|
||||
-
|
||||
key: brand
|
||||
operator: eq
|
||||
value: gt
|
||||
limit: 10
|
||||
discounts:
|
||||
id: discounts
|
||||
options:
|
||||
from: collection
|
||||
filter:
|
||||
where:
|
||||
-
|
||||
key: title
|
||||
operator: eq
|
||||
value: '30% off'
|
||||
-
|
||||
key: category
|
||||
operator: eq
|
||||
value: bikes
|
||||
entries:
|
||||
fetchSingle:
|
||||
label1:
|
||||
id: discounts/50-off
|
||||
options:
|
||||
filter:
|
||||
limit: 4
|
||||
fetchCollection:
|
||||
bikes:
|
||||
id: catalog/bikes
|
||||
options:
|
||||
filter:
|
||||
where:
|
||||
-
|
||||
key: brand
|
||||
operator: eq
|
||||
value: gt
|
||||
limit: 10
|
||||
discounts:
|
||||
id: discounts
|
||||
options:
|
||||
filter:
|
||||
where:
|
||||
-
|
||||
key: title
|
||||
operator: eq
|
||||
value: '30% off'
|
||||
-
|
||||
key: category
|
||||
operator: eq
|
||||
value: bikes
|
||||
---
|
||||
|
@@ -1,6 +1,7 @@
|
||||
---
|
||||
title: level1
|
||||
fetch:
|
||||
root:
|
||||
id: level1/level2
|
||||
entries:
|
||||
fetchSingle:
|
||||
root:
|
||||
id: level1/level2
|
||||
---
|
||||
|
@@ -1,6 +1,7 @@
|
||||
---
|
||||
title: level2
|
||||
fetch:
|
||||
root:
|
||||
id: level1/level2/level3
|
||||
entries:
|
||||
fetchSingle:
|
||||
root:
|
||||
id: level1/level2/level3
|
||||
---
|
||||
|
@@ -1,6 +1,7 @@
|
||||
---
|
||||
title: level3
|
||||
fetch:
|
||||
root:
|
||||
id: level1/level2/level3/level4
|
||||
entries:
|
||||
fetchSingle:
|
||||
root:
|
||||
id: level1/level2/level3/level4
|
||||
---
|
||||
|
@@ -1,22 +1,19 @@
|
||||
---
|
||||
title: Album 1
|
||||
fetch:
|
||||
banner-single:
|
||||
id: banners
|
||||
options:
|
||||
from: single
|
||||
banners-collection:
|
||||
id: banners
|
||||
options:
|
||||
from: collection
|
||||
banners-collection-2:
|
||||
id: banners
|
||||
options:
|
||||
from: collection
|
||||
filter:
|
||||
limit: 1
|
||||
find:
|
||||
depth: ">0"
|
||||
banner-single-2:
|
||||
id: banners/2
|
||||
entries:
|
||||
fetchSingle:
|
||||
banner-single:
|
||||
id: banners
|
||||
banner-single-2:
|
||||
id: banners/2
|
||||
fetchCollection:
|
||||
banners-collection:
|
||||
id: banners
|
||||
banners-collection-2:
|
||||
id: banners
|
||||
options:
|
||||
filter:
|
||||
limit: 1
|
||||
find:
|
||||
depth: ">0"
|
||||
---
|
||||
|
@@ -1,18 +1,15 @@
|
||||
---
|
||||
title: Root
|
||||
fetch:
|
||||
single:
|
||||
id: albums
|
||||
options:
|
||||
from: single
|
||||
collection:
|
||||
id: albums
|
||||
options:
|
||||
from: collection
|
||||
collectionWithDepth:
|
||||
id: albums
|
||||
options:
|
||||
from: collection
|
||||
find:
|
||||
depth: '>0'
|
||||
entries:
|
||||
fetchSingle:
|
||||
albums:
|
||||
id: albums
|
||||
fetchCollection:
|
||||
collection:
|
||||
id: albums
|
||||
collectionWithDepth:
|
||||
id: albums
|
||||
options:
|
||||
find:
|
||||
depth: '>0'
|
||||
---
|
||||
|
Reference in New Issue
Block a user