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

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

This commit is contained in:
Awilum
2020-12-11 16:57:22 +03:00
parent e596b2ffa4
commit 40d203438c
2 changed files with 64 additions and 1 deletions

View File

@@ -6,7 +6,7 @@ declare(strict_types=1);
* Flextype (https://flextype.org)
* Founded by Sergey Romanenko and maintained by Flextype Community.
*/
if (flextype('registry')->get('flextype.settings.entries.fields.fetch.enabled')) {
flextype('emitter')->addListener('onEntriesFetchSingleHasResult', static function (): void {
if (flextype('entries')->getStorage('fetch.data.fetch') !== null) {

View File

@@ -0,0 +1,63 @@
<?php
use Flextype\Component\Filesystem\Filesystem;
beforeEach(function() {
filesystem()->directory(PATH['project'] . '/entries')->create();
});
afterEach(function (): void {
filesystem()->directory(PATH['project'] . '/entries')->delete();
});
test('test fetchField', function () {
flextype('entries')->create('bikes', ['title' => 'Bikes']);
flextype('entries')->create('bikes/gt', ['title' => 'GT', 'brand' => 'gt']);
flextype('entries')->create('bikes/norco', ['title' => 'Norco', 'brand' => 'norco']);
flextype('entries')->create('discounts', ['title' => 'Discounts']);
flextype('entries')->create('discounts/30-off', ['title' => '30% off', 'visibility' => 'published']);
flextype('entries')->create('discounts/50-off', ['title' => '50% off']);
flextype('entries')->create('banner', ['title' => 'Banner']);
flextype('entries')->create('catalog',
flextype('yaml')->decode("title: Catalog
fetch:
-
id: bikes
result: bikes
options:
collection: true
where:
-
key: brand
operator: eq
value: gt
limit: 10
-
id: discounts
result: discounts
options:
collection: true
where:
-
key: title
operator: eq
value: '30% off'
-
key: visibility
operator: eq
value: published
-
id: banner
result: banner
")
);
$fetch = flextype('entries')->fetch('catalog');
//$this->assertEquals(1, $fetch['discounts']->count());
$this->assertEquals('Banner', $fetch['banner']['title']);
});