mirror of
https://github.com/flextype/flextype.git
synced 2025-08-11 07:34:22 +02:00
feat(entries): add fetch() method with ability to execute different methods with fetch prefix. #495
This commit is contained in:
@@ -27,28 +27,28 @@ test('test update() method', function () {
|
||||
$this->assertFalse(flextype('entries')->update('bar', ['title' => 'Test']));
|
||||
});
|
||||
|
||||
test('test fetchSingle() and fetchCollection() entry', function () {
|
||||
test('test fetch() 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')->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(12, flextype('entries')->fetch('foo')->count());
|
||||
$this->assertEquals('foo', flextype('entries')->fetch('foo')['id']);
|
||||
$this->assertEquals(12, flextype('entries')->fetch('foo', [])->count());
|
||||
$this->assertEquals('foo', flextype('entries')->fetch('foo')['id']);
|
||||
$this->assertEquals(3, flextype('entries')->fetch('foo', ['collection' => true])->count());
|
||||
|
||||
$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']);
|
||||
$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']);
|
||||
|
||||
flextype('entries')->setStorage('fetch.id', 'wrong-entry');
|
||||
$this->assertEquals(0, flextype('entries')->fetchSingle('wrong-entry')->count());
|
||||
$this->assertEquals(0, flextype('entries')->fetch('wrong-entry')->count());
|
||||
flextype('entries')->setStorage('fetch.id', 'wrong-entry');
|
||||
$this->assertEquals(0, flextype('entries')->fetchSingle('wrong-entry')->count());
|
||||
$this->assertEquals(0, flextype('entries')->fetch('wrong-entry')->count());
|
||||
|
||||
$this->assertTrue(count(flextype('entries')->fetchCollection('foo')) > 0);
|
||||
$this->assertTrue(count(flextype('entries')->fetch('foo', ['collection' => true])) > 0);
|
||||
|
||||
/*
|
||||
flextype('emitter')->addListener('onEntriesFetchCollectionHasResult', static function (): void {
|
||||
@@ -137,7 +137,7 @@ test('test macro() entry', function () {
|
||||
|
||||
flextype('entries')::macro('fetchRecentPosts', function($limit = 1) {
|
||||
return flextype('entries')
|
||||
->fetchCollection('foo')
|
||||
->fetch('foo')
|
||||
->sortBy('published_at')
|
||||
->limit($limit);
|
||||
});
|
||||
|
@@ -13,7 +13,7 @@ afterEach(function (): void {
|
||||
test('test CreatedAtField', function () {
|
||||
// 1
|
||||
flextype('entries')->create('foo', []);
|
||||
$created_at = flextype('entries')->fetchSingle('foo')['created_at'];
|
||||
$created_at = flextype('entries')->fetch('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')->fetchSingle('foo')['created_by'];
|
||||
$created_by = flextype('entries')->fetch('foo')['created_by'];
|
||||
$this->assertEquals('', $created_by);
|
||||
|
||||
flextype('entries')->create('bar', ['created_by' => 'Zed']);
|
||||
$created_by = flextype('entries')->fetchSingle('bar')['created_by'];
|
||||
$created_by = flextype('entries')->fetch('bar')['created_by'];
|
||||
$this->assertEquals('Zed', $created_by);
|
||||
});
|
||||
|
@@ -15,7 +15,7 @@ test('test entries field for blog', function () {
|
||||
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')->fetchSingle('blog');
|
||||
$blog = flextype('entries')->fetch('blog');
|
||||
|
||||
$this->assertEquals(14, $blog->count());
|
||||
});
|
||||
@@ -58,7 +58,7 @@ test('test entries field for catalog', function () {
|
||||
$catalogLongCollecion = flextype('entries')->fetch('catalog', ['collection' => true, 'find' => ['depth' => ['>0', '<4']]]);
|
||||
$this->assertEquals(5, $catalogLongCollecion->count());
|
||||
|
||||
$banner = flextype('entries')->fetchSingle('banner');
|
||||
$banner = flextype('entries')->fetch('banner');
|
||||
$this->assertEquals('Banner', $banner['title']);
|
||||
$this->assertEquals('banner', $banner['id']);
|
||||
});
|
||||
|
@@ -12,10 +12,10 @@ afterEach(function (): void {
|
||||
|
||||
test('test IdField', function () {
|
||||
flextype('entries')->create('foo', []);
|
||||
$id = flextype('entries')->fetchSingle('foo')['id'];
|
||||
$id = flextype('entries')->fetch('foo')['id'];
|
||||
$this->assertEquals('foo', $id);
|
||||
|
||||
flextype('entries')->create('foo/bar', []);
|
||||
$id = flextype('entries')->fetchSingle('foo/bar')['id'];
|
||||
$id = flextype('entries')->fetch('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')->fetchSingle('foo')['modified_at'];
|
||||
$modified_at = flextype('entries')->fetch('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')->fetchSingle('foo')['content']);
|
||||
$this->assertEquals('<h1>Foo</h1>', flextype('entries')->fetch('foo')['content']);
|
||||
|
||||
flextype('entries')->create('bar', ['content' => '[registry_get name="Bar" default="Zed"]', 'parsers' => ['shortcode' => ['enabled' => true, 'fields' => ['content']]]]);
|
||||
$this->assertEquals('Zed', flextype('entries')->fetchSingle('bar')['content']);
|
||||
$this->assertEquals('Zed', flextype('entries')->fetch('bar')['content']);
|
||||
});
|
||||
|
@@ -13,7 +13,7 @@ afterEach(function (): void {
|
||||
test('test PublishedAtField', function () {
|
||||
flextype('entries')->create('foo', []);
|
||||
|
||||
$published_at = flextype('entries')->fetchSingle('foo')['published_at'];
|
||||
$published_at = flextype('entries')->fetch('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')->fetchSingle('foo')['published_by'];
|
||||
$published_by = flextype('entries')->fetch('foo')['published_by'];
|
||||
$this->assertEquals('', $published_by);
|
||||
|
||||
flextype('entries')->create('bar', ['published_by' => 'Zed']);
|
||||
$published_by = flextype('entries')->fetchSingle('bar')['published_by'];
|
||||
$published_by = flextype('entries')->fetch('bar')['published_by'];
|
||||
$this->assertEquals('Zed', $published_by);
|
||||
});
|
||||
|
@@ -15,7 +15,7 @@ test('test registry field', function () {
|
||||
flextype('entries')->create('registry-root/level-1', flextype('frontmatter')->decode(filesystem()->file(ROOT_DIR . '/tests/Foundation/Entries/Fields/fixtures/entries/registry-root/level-1/entry.md')->get()));
|
||||
flextype('entries')->create('registry-root/level-1/level-2', flextype('frontmatter')->decode(filesystem()->file(ROOT_DIR . '/tests/Foundation/Entries/Fields/fixtures/entries/registry-root/level-1/level-2/entry.md')->get()));
|
||||
|
||||
$data = flextype('entries')->fetchSingle('registry-root');
|
||||
$data = flextype('entries')->fetch('registry-root');
|
||||
|
||||
$this->assertEquals('Flextype', $data['flextype']);
|
||||
$this->assertEquals('Sergey Romanenko', $data['author']['name']);
|
||||
|
@@ -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')->fetchSingle('foo')['routable'];
|
||||
$routable = flextype('entries')->fetch('foo')['routable'];
|
||||
$this->assertTrue($routable);
|
||||
|
||||
flextype('entries')->create('bar', []);
|
||||
$routable = flextype('entries')->fetchSingle('bar')['routable'];
|
||||
$routable = flextype('entries')->fetch('bar')['routable'];
|
||||
$this->assertTrue($routable);
|
||||
|
||||
flextype('entries')->create('zed', ['routable' => false]);
|
||||
$routable = flextype('entries')->fetchSingle('zed')['routable'];
|
||||
$routable = flextype('entries')->fetch('zed')['routable'];
|
||||
$this->assertFalse($routable);
|
||||
});
|
||||
|
@@ -12,10 +12,10 @@ afterEach(function (): void {
|
||||
|
||||
test('test SlugField', function () {
|
||||
flextype('entries')->create('foo', []);
|
||||
$slug = flextype('entries')->fetchSingle('foo')['slug'];
|
||||
$slug = flextype('entries')->fetch('foo')['slug'];
|
||||
$this->assertEquals('foo', $slug);
|
||||
|
||||
flextype('entries')->create('bar', []);
|
||||
$slug = flextype('entries')->fetchSingle('bar')['slug'];
|
||||
$slug = flextype('entries')->fetch('bar')['slug'];
|
||||
$this->assertEquals('bar', $slug);
|
||||
});
|
||||
|
@@ -14,6 +14,6 @@ afterEach(function (): void {
|
||||
|
||||
test('test UuidField', function () {
|
||||
flextype('entries')->create('foo', []);
|
||||
$uuid = flextype('entries')->fetchSingle('foo')['uuid'];
|
||||
$uuid = flextype('entries')->fetch('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')->fetchSingle('foo')['visibility'];
|
||||
$visibility = flextype('entries')->fetch('foo')['visibility'];
|
||||
$this->assertEquals('visible', $visibility);
|
||||
|
||||
flextype('entries')->create('bar', ['visibility' => 'draft']);
|
||||
$visibility = flextype('entries')->fetchSingle('bar')['visibility'];
|
||||
$visibility = flextype('entries')->fetch('bar')['visibility'];
|
||||
$this->assertEquals('draft', $visibility);
|
||||
|
||||
flextype('entries')->create('zed', ['visibility' => 'foobar']);
|
||||
$visibility = flextype('entries')->fetchSingle('zed')['visibility'];
|
||||
$visibility = flextype('entries')->fetch('zed')['visibility'];
|
||||
$this->assertEquals('visible', $visibility);
|
||||
});
|
||||
|
@@ -1,17 +1,19 @@
|
||||
---
|
||||
title: Album 1
|
||||
entries:
|
||||
fetchSingle:
|
||||
fetch:
|
||||
banner-single:
|
||||
id: banners
|
||||
banner-single-2:
|
||||
id: banners/2
|
||||
fetchCollection:
|
||||
banners-collection:
|
||||
id: banners
|
||||
options:
|
||||
collection: true
|
||||
banners-collection-2:
|
||||
id: banners
|
||||
options:
|
||||
collection: true
|
||||
filter:
|
||||
limit: 1
|
||||
find:
|
||||
|
Reference in New Issue
Block a user