diff --git a/src/flextype/Foundation/Entries/Fields/FetchField.php b/src/flextype/Foundation/Entries/Fields/FetchField.php index 93187498..6c91a2a9 100644 --- a/src/flextype/Foundation/Entries/Fields/FetchField.php +++ b/src/flextype/Foundation/Entries/Fields/FetchField.php @@ -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) { diff --git a/tests/Foundation/Entries/Fields/FetchFieldTest.php b/tests/Foundation/Entries/Fields/FetchFieldTest.php new file mode 100644 index 00000000..a14ac738 --- /dev/null +++ b/tests/Foundation/Entries/Fields/FetchFieldTest.php @@ -0,0 +1,63 @@ +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']); +});