1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-16 18:14:04 +02:00

feat(entries): Entries API fetch improvements. #491

This commit is contained in:
Awilum
2020-12-12 22:36:24 +03:00
parent e8946b34cc
commit bfee1cacb7
22 changed files with 134 additions and 96 deletions

View File

@@ -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));
});

View File

@@ -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);
});

View File

@@ -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);
});

View File

@@ -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));

View File

@@ -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']);
});

View File

@@ -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));

View File

@@ -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);
});

View File

@@ -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);
});

View File

@@ -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);
});

View File

@@ -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));
});

View File

@@ -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);
});

View File

@@ -0,0 +1,30 @@
---
title: Catalog
visibility: draft
fetch:
bikes:
id: catalog/bikes
from: collection
options:
filter:
where:
-
key: brand
operator: eq
value: gt
limit: 10
discounts:
id: discounts
from: collection
options:
filter:
where:
-
key: title
operator: eq
value: '30% off'
-
key: category
operator: eq
value: bikes
---