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

feat(entries): add macros functionality

This commit is contained in:
Awilum
2022-05-07 10:44:13 +03:00
parent 293f3f1221
commit 83fe88cece
33 changed files with 383 additions and 425 deletions

View File

@@ -80,10 +80,49 @@ class Entries
$this->setRegistry($registry);
$this->setOptions($options);
$this->loadCollectionsMacros();
$this->loadCollectionsEvents();
$this->loadCollectionsFields();
}
/**
* Remove Collection Macros.
*
* @param mixed $data Entry data.
*
* @return mixed
*
* @access private
*/
private function removeCollectionsMacros($data)
{
if (is_array($data)) {
if (boolval(arrays($data)->get('macros.dump', registry()->get('flextype.settings.entries.macros.dump'))) === false) {
unset($data['macros']);
}
}
return $data;
}
/**
* Load Collections Macros
*
* @access public
*/
private function loadCollectionsMacros(): void
{
foreach (registry()->get('flextype.settings.entries.macros') as $key => $value) {
if ($key == 'debug') {
continue;
}
if (filesystem()->file(ROOT_DIR . $value['path'])->exists()) {
include_once ROOT_DIR . $value['path'];
}
}
}
/**
* Load Collections Events
*
@@ -122,7 +161,6 @@ class Entries
foreach ($events as $event) {
if (filesystem()->file($event)->exists()) {
include_once $event;
}
}
@@ -152,7 +190,6 @@ class Entries
}
foreach ($collection['fields'] as $field) {
if (! isset($field['path'])) {
continue;
}
@@ -231,7 +268,7 @@ class Entries
// Check if `result` contains data to return then return existing result.
if (! is_null($this->registry()->get('methods.fetch.result'))) {
return $this->registry()->get('methods.fetch.result');
return $this->removeCollectionsMacros($this->registry()->get('methods.fetch.result'));
}
// Fetch collection or single
@@ -272,7 +309,7 @@ class Entries
// Check if `result` contains data to return.
if (! is_null($this->registry()->get('methods.fetch.result'))) {
return $this->registry()->get('methods.fetch.result');
return $this->removeCollectionsMacros($this->registry()->get('methods.fetch.result'));
}
// Get Cache ID for current requested entry
@@ -290,7 +327,7 @@ class Entries
emitter()->emit('onEntriesFetchSingleCacheHasResult');
// Return result from the cache.
return collection($this->registry()->get('methods.fetch.result'));
return collection($this->removeCollectionsMacros($this->registry()->get('methods.fetch.result')));
}
// 2. Try to get requested entry from the filesystem
@@ -305,7 +342,7 @@ class Entries
if ($entryFileContent === false) {
// Run event
emitter()->emit('onEntriesFetchSingleNoResult');
return collection($this->registry()->get('methods.fetch.params.result'));
return collection($this->removeCollectionsMacros($this->registry()->get('methods.fetch.params.result')));
}
// Decode entry file content
@@ -330,14 +367,14 @@ class Entries
}
// Return entry fetch result
return collection($this->registry()->get('methods.fetch.result'));
return collection($this->removeCollectionsMacros($this->registry()->get('methods.fetch.result')));
}
// Run event
emitter()->emit('onEntriesFetchSingleNoResult');
// Return entry fetch result
return collection($this->registry()->get('methods.fetch.result'));
return collection($this->removeCollectionsMacros($this->registry()->get('methods.fetch.result')));
}
/**
@@ -366,7 +403,7 @@ class Entries
// Check if `result` contains data to return.
if (! is_null($this->registry()->get('methods.fetch.result'))) {
return $this->registry()->get('methods.fetch.result');
return $this->removeCollectionsMacros($this->registry()->get('methods.fetch.result'));
}
// Determine if collection exists

View File

@@ -1,60 +0,0 @@
<?php
declare(strict_types=1);
/**
* Flextype - Hybrid Content Management System with the freedom of a headless CMS
* and with the full functionality of a traditional CMS!
*
* Copyright (c) Sergey Romanenko (https://awilum.github.io)
*
* Licensed under The MIT License.
*
* For full copyright and license information, please see the LICENSE
* Redistributions of files must retain the above copyright notice.
*/
emitter()->addListener('onEntriesFetchSingleHasResult', static function (): void {
if (! entries()->registry()->get('methods.fetch.collection.fields.parsers.enabled')) {
return;
}
if (entries()->registry()->get('methods.fetch.result.cache.enabled') == null) {
$cache = false;
} else {
$cache = (bool) entries()->registry()->get('methods.fetch.result.cache.enabled');
}
if (entries()->registry()->get('methods.fetch.result.parsers') != null) {
foreach (entries()->registry()->get('methods.fetch.result.parsers') as $parserName => $parserData) {
if (in_array($parserName, ['shortcodes', 'markdown'])) {
if (entries()->registry()->get('methods.fetch.result.parsers.'.$parserName.'.enabled') === true) {
if (entries()->registry()->get('methods.fetch.result.parsers.'.$parserName.'.fields') != null) {
if (is_array(entries()->registry()->get('methods.fetch.result.parsers.'.$parserName.'.fields'))) {
foreach (entries()->registry()->get('methods.fetch.result.parsers.'.$parserName.'.fields') as $field) {
if (! in_array($field, registry()->get('flextype.settings.entries.collections.default.fields'))) {
if ($parserName == 'markdown') {
if (collection(entries()->registry()->get('methods.fetch.result'))->has($field)) {
entries()->registry()->set('methods.fetch.result.'.$field,
parsers()->markdown()->parse(entries()->registry()->get('methods.fetch.result.'.$field), $cache));
}
}
if ($parserName == 'shortcodes') {
if (collection(entries()->registry()->get('methods.fetch.result'))->has($field)) {
entries()->registry()->set('methods.fetch.result.'.$field,
parsers()->shortcodes()->parse(entries()->registry()->get('methods.fetch.result.'.$field), $cache));
}
}
}
}
}
}
}
}
}
}
});

View File

@@ -18,17 +18,17 @@ use Glowy\Arrays\Arrays as Collection;
emitter()->addListener('onEntriesFetchSingleHasResult', static function (): void {
if (! entries()->registry()->get('methods.fetch.collection.fields.entries.enabled')) {
if (! registry()->get('flextype.settings.entries.macros.entries.enabled')) {
return;
}
if (entries()->registry()->has('methods.fetch.result.entries.fetch')) {
if (entries()->registry()->has('methods.fetch.result.macros.entries.fetch')) {
// Get
$original = entries()->registry()->get('methods.fetch');
$data = [];
switch (entries()->registry()->get('methods.fetch.collection.fields.entries.result')) {
switch (registry()->get('flextype.settings.entries.macros.entries.result')) {
case 'toArray':
$resultTo = 'toArray';
break;
@@ -38,9 +38,9 @@ emitter()->addListener('onEntriesFetchSingleHasResult', static function (): void
break;
default:
if (entries()->registry()->has('methods.fetch.collection.fields.entries.fetch.result')) {
if (in_array(entries()->registry()->get('methods.fetch.collection.fields.entries.fetch.result'), ['toArray', 'toObject'])) {
$resultTo = entries()->registry()->get('methods.fetch.collection.fields.entries.fetch.result');
if (registry()->has('flextype.settings.entries.macros.entries.fetch.result')) {
if (in_array(registry()->get('flextype.settings.entries.macros.entries.fetch.result'), ['toArray', 'toObject'])) {
$resultTo = registry()->get('flextype.settings.entries.macros.entries.fetch.result');
if ($resultTo == 'toObject') {
$resultTo = 'copy';
@@ -53,7 +53,7 @@ emitter()->addListener('onEntriesFetchSingleHasResult', static function (): void
}
// Modify data
foreach (entries()->registry()->get('methods.fetch.result.entries.fetch') as $field => $body) {
foreach (entries()->registry()->get('methods.fetch.result.macros.entries.fetch') as $field => $body) {
$result = isset($body['result']) && in_array($body['result'], ['toArray', 'toObject']) ? $body['result'] == 'toObject' ? 'copy' : 'toArray' : $resultTo;
$data[$field] = entries()->fetch($body['id'], isset($body['options']) ? $body['options'] : []);
$data[$field] = ($data[$field] instanceof Collection) ? $data[$field]->{$result}() : $data[$field];
@@ -61,11 +61,6 @@ emitter()->addListener('onEntriesFetchSingleHasResult', static function (): void
$result = collection($original['result'])->merge($data)->toArray();
// Remove entries field when dump === false
if (boolval(arrays($result)->get('entries.dump', entries()->registry()->get('methods.fetch.collection.fields.entries.dump'))) === false) {
unset($result['entries']);
}
// Save fetch data.
entries()->registry()->set('methods.fetch.params.id', $original['params']['id']);
entries()->registry()->set('methods.fetch.params.options', $original['params']['options']);

View File

@@ -16,11 +16,11 @@ declare(strict_types=1);
emitter()->addListener('onEntriesFetchSingleHasResult', static function (): void {
if (! entries()->registry()->get('methods.fetch.collection.fields.registry.enabled')) {
if (! registry()->get('flextype.settings.entries.macros.registry.enabled')) {
return;
}
if (entries()->registry()->has('methods.fetch.result.registry.get')) {
if (entries()->registry()->has('methods.fetch.result.macros.registry.get')) {
// Get fetch.
$original = entries()->registry()->get('methods.fetch');
@@ -28,7 +28,7 @@ emitter()->addListener('onEntriesFetchSingleHasResult', static function (): void
$data = [];
// Modify fetch.
foreach (entries()->registry()->get('methods.fetch.result.registry.get') as $field => $body) {
foreach (entries()->registry()->get('methods.fetch.result.macros.registry.get') as $field => $body) {
$data = collection($data)->merge(collection($data)->set($field, registry()->get($body['id'],
isset($body['default']) ?
$body['default'] :
@@ -38,10 +38,6 @@ emitter()->addListener('onEntriesFetchSingleHasResult', static function (): void
$result = collection($original['result'])->merge($data)->toArray();
if (boolval(entries()->registry()->get('methods.fetch.collection.fields.registry.dump')) === false) {
unset($result['registry']);
}
// Save fetch.
entries()->registry()->set('methods.fetch.result', $result);
}

View File

@@ -74,22 +74,22 @@ errors:
# Entries
entries:
directory: '/entries'
macros:
debug: false
registry:
enabled: true
path: "/src/flextype/core/Entries/Macros/RegistryMacros.php"
entries:
enabled: true
path: "/src/flextype/core/Entries/Macros/EntriesMacros.php"
fetch:
result: toArray
collections:
default:
filename: entry
extension: md
serializer: frontmatter
fields:
registry:
enabled: true
dump: false
path: "/src/flextype/core/Entries/Fields/Default/RegistryField.php"
entries:
enabled: true
dump: false
path: "/src/flextype/core/Entries/Fields/Default/EntriesField.php"
fetch:
result: toObject
slug:
enabled: true
path: "/src/flextype/core/Entries/Fields/Default/SlugField.php"
@@ -111,9 +111,6 @@ entries:
routable:
enabled: true
path: "/src/flextype/core/Entries/Fields/Default/RoutableField.php"
parsers:
enabled: true
path: "/src/flextype/core/Entries/Fields/Default/ParsersField.php"
visibility:
enabled: true
path: "/src/flextype/core/Entries/Fields/Default/VisibilityField.php"
@@ -541,6 +538,7 @@ parsers:
enabled: true
path: "/src/flextype/core/Parsers/Shortcodes/StringsShortcode.php"
# CORS
#
# CORS (Cross-origin resource sharing) allows JavaScript web apps to make HTTP requests to other domains.

View File

@@ -1,24 +1,25 @@
title: GT
brand: gt
entries:
fetch:
discounts_available:
id: discounts
options:
collection: true
filter:
where:
-
key: category
operator: eq
value: bikes
label1:
id: discounts/50-off
options:
filter:
limit: 3
label2:
id: discounts/30-off
options:
filter:
limit: 2
macros:
entries:
fetch:
discounts_available:
id: discounts
options:
collection: true
filter:
where:
-
key: category
operator: eq
value: bikes
label1:
id: discounts/50-off
options:
filter:
limit: 3
label2:
id: discounts/30-off
options:
filter:
limit: 2

View File

@@ -1,12 +1,13 @@
title: Norco
brand: norco
entries:
fetch:
label:
id: discounts/30-off
options:
collection: true
discounts:
id: discounts
options:
collection: true
macros:
entries:
fetch:
label:
id: discounts/30-off
options:
collection: true
discounts:
id: discounts
options:
collection: true

View File

@@ -1,34 +1,35 @@
title: Catalog
visibility: visible
entries:
fetch:
label1:
id: discounts/50-off
options:
filter:
limit: 4
bikes:
id: catalog/bikes
options:
collection: true
filter:
where:
-
key: brand
operator: eq
value: gt
limit: 10
discounts:
id: discounts
options:
collection: true
filter:
where:
-
key: title
operator: eq
value: '30% off'
-
key: category
operator: eq
value: bikes
macros:
entries:
fetch:
label1:
id: discounts/50-off
options:
filter:
limit: 4
bikes:
id: catalog/bikes
options:
collection: true
filter:
where:
-
key: brand
operator: eq
value: gt
limit: 10
discounts:
id: discounts
options:
collection: true
filter:
where:
-
key: title
operator: eq
value: '30% off'
-
key: category
operator: eq
value: bikes

View File

@@ -1,5 +1,6 @@
title: level1
entries:
fetch:
root:
id: level1/level2
macros:
entries:
fetch:
root:
id: level1/level2

View File

@@ -1,5 +1,6 @@
title: level2
entries:
fetch:
root:
id: level1/level2/level3
macros:
entries:
fetch:
root:
id: level1/level2/level3

View File

@@ -1,5 +1,6 @@
title: level3
entries:
fetch:
root:
id: level1/level2/level3/level4
macros:
entries:
fetch:
root:
id: level1/level2/level3/level4

View File

@@ -1,14 +1,15 @@
title: Root
registry:
get:
flextype:
id: flextype.manifest.name
author.name:
id: flextype.manifest.author.name
license:
id: flextype.manifest.license
entries:
fetch:
level1:
id: registry-root/level-1
result: toArray
macros:
registry:
get:
flextype:
id: flextype.manifest.name
author.name:
id: flextype.manifest.author.name
license:
id: flextype.manifest.license
entries:
fetch:
level1:
id: registry-root/level-1
result: toArray

View File

@@ -1,14 +1,15 @@
title: Level 1
entries:
fetch:
level2:
id: registry-root/level-1/level-2
result: toArray
registry:
get:
flextype:
id: flextype.manifest.name
author.name:
id: flextype.manifest.author.name
license:
id: flextype.manifest.license
macros:
entries:
fetch:
level2:
id: registry-root/level-1/level-2
result: toArray
registry:
get:
flextype:
id: flextype.manifest.name
author.name:
id: flextype.manifest.author.name
license:
id: flextype.manifest.license

View File

@@ -1,9 +1,10 @@
title: Level 2
registry:
get:
flextype:
id: flextype.manifest.name
author.name:
id: flextype.manifest.author.name
license:
id: flextype.manifest.license
macros:
registry:
get:
flextype:
id: flextype.manifest.name
author.name:
id: flextype.manifest.author.name
license:
id: flextype.manifest.license

View File

@@ -1,19 +1,20 @@
title: Album 1
entries:
fetch:
banner-single:
id: banners
banner-single-2:
id: banners/2
banners-collection:
id: banners
options:
collection: true
banners-collection-2:
id: banners
options:
collection: true
filter:
limit: 1
find:
depth: ">0"
macros:
entries:
fetch:
banner-single:
id: banners
banner-single-2:
id: banners/2
banners-collection:
id: banners
options:
collection: true
banners-collection-2:
id: banners
options:
collection: true
filter:
limit: 1
find:
depth: ">0"

View File

@@ -1,19 +1,20 @@
title: Album 2
entries:
fetch:
banner-single:
id: banners
banner-single-2:
id: banners/2
banners-collection:
id: banners
options:
collection: true
banners-collection-2:
id: banners
options:
collection: true
filter:
limit: 1
find:
depth: ">0"
macros:
entries:
fetch:
banner-single:
id: banners
banner-single-2:
id: banners/2
banners-collection:
id: banners
options:
collection: true
banners-collection-2:
id: banners
options:
collection: true
filter:
limit: 1
find:
depth: ">0"

View File

@@ -1,15 +1,16 @@
title: Root
entries:
fetch:
albums:
id: albums
collection:
id: albums
options:
collection: true
collectionWithDepth:
id: albums
options:
collection: false
find:
depth: '>0'
macros:
entries:
fetch:
albums:
id: albums
collection:
id: albums
options:
collection: true
collectionWithDepth:
id: albums
options:
collection: false
find:
depth: '>0'

View File

@@ -1,9 +1,9 @@
title: Bikes
entries:
dump: false
fetch:
items:
result: toArray
id: shop/catalog/bikes
options:
collection: true
macros:
entries:
fetch:
items:
result: toArray
id: shop/catalog/bikes
options:
collection: true

View File

@@ -1,9 +1,9 @@
title: GT
entries:
dump: false
fetch:
items:
result: toArray
id: shop/catalog/bikes/gt
options:
collection: true
macros:
entries:
fetch:
items:
result: toArray
id: shop/catalog/bikes/gt
options:
collection: true

View File

@@ -1,16 +1,16 @@
title: GT
price: 2000
entries:
dump: false
fetch:
discounts_available:
result: toArray
id: shop/discounts
options:
collection: true
filter:
where:
-
key: category
operator: eq
value: bikes
macros:
entries:
fetch:
discounts_available:
result: toArray
id: shop/discounts
options:
collection: true
filter:
where:
-
key: category
operator: eq
value: bikes

View File

@@ -1,16 +1,16 @@
title: Sensor
price: 1700
entries:
dump: false
fetch:
discounts_available:
result: toArray
id: shop/discounts
options:
collection: true
filter:
where:
-
key: category
operator: eq
value: bikes
macros:
entries:
fetch:
discounts_available:
result: toArray
id: shop/discounts
options:
collection: true
filter:
where:
-
key: category
operator: eq
value: bikes

View File

@@ -1,9 +1,9 @@
title: Norco
entries:
dump: false
fetch:
items:
result: toArray
id: shop/catalog/bikes/norco
options:
collection: true
macros:
entries:
fetch:
items:
result: toArray
id: shop/catalog/bikes/norco
options:
collection: true

View File

@@ -1,16 +1,16 @@
title: Rage
price: 2100
entries:
dump: false
fetch:
discounts_available:
result: toArray
id: shop/discounts
options:
collection: true
filter:
where:
-
key: category
operator: eq
value: bikes
macros:
entries:
fetch:
discounts_available:
result: toArray
id: shop/discounts
options:
collection: true
filter:
where:
-
key: category
operator: eq
value: bikes

View File

@@ -1,10 +1,10 @@
title: Catalog
entries:
dump: false
fetch:
bikes:
result: toArray
id: shop/catalog/bikes
snowboards:
result: toArray
id: shop/catalog/snowboards
macros:
entries:
fetch:
bikes:
result: toArray
id: shop/catalog/bikes
snowboards:
result: toArray
id: shop/catalog/snowboards

View File

@@ -1,9 +1,9 @@
title: Burton
entries:
dump: false
fetch:
items:
result: toArray
id: shop/catalog/snowboards/burton
options:
collection: true
macros:
entries:
fetch:
items:
result: toArray
id: shop/catalog/snowboards/burton
options:
collection: true

View File

@@ -1,16 +1,16 @@
title: Burton Family Tree Hometown Hero Camber Splitboard
price: 849.95
entries:
dump: false
fetch:
discounts_available:
result: toArray
id: shop/discounts
options:
collection: true
filter:
where:
-
key: category
operator: eq
value: snowboards
macros:
entries:
fetch:
discounts_available:
result: toArray
id: shop/discounts
options:
collection: true
filter:
where:
-
key: category
operator: eq
value: snowboards

View File

@@ -1,9 +1,9 @@
title: Snowboards
entries:
dump: false
fetch:
items:
result: toArray
id: shop/catalog/snowboards
options:
collection: true
macros:
entries:
fetch:
items:
result: toArray
id: shop/catalog/snowboards
options:
collection: true

View File

@@ -1,9 +1,9 @@
title: Discounts
entries:
dump: false
fetch:
items:
result: toArray
id: shop/discounts
options:
collection: true
macros:
entries:
fetch:
items:
result: toArray
id: shop/discounts
options:
collection: true

View File

@@ -1,10 +1,10 @@
title: Shop
entries:
dump: false
fetch:
catalog:
id: shop/catalog
result: toArray
discounts:
id: shop/discounts
result: toArray
macros:
entries:
fetch:
catalog:
id: shop/catalog
result: toArray
discounts:
id: shop/discounts
result: toArray

View File

@@ -70,22 +70,22 @@ errors:
# Entries
entries:
directory: '/entries'
macros:
debug: false
registry:
enabled: true
path: "/src/flextype/core/Entries/Macros/RegistryMacros.php"
entries:
enabled: true
path: "/src/flextype/core/Entries/Macros/EntriesMacros.php"
fetch:
result: toArray
collections:
default:
filename: entry
extension: yaml
serializer: yaml
fields:
registry:
enabled: true
dump: true
path: "/src/flextype/core/Entries/Fields/Default/RegistryField.php"
entries:
enabled: true
dump: true
path: "/src/flextype/core/Entries/Fields/Default/EntriesField.php"
fetch:
result: toObject
slug:
enabled: true
path: "/src/flextype/core/Entries/Fields/Default/SlugField.php"
@@ -107,9 +107,6 @@ entries:
routable:
enabled: true
path: "/src/flextype/core/Entries/Fields/Default/RoutableField.php"
parsers:
enabled: true
path: "/src/flextype/core/Entries/Fields/Default/ParsersField.php"
visibility:
enabled: true
path: "/src/flextype/core/Entries/Fields/Default/VisibilityField.php"

View File

@@ -1,17 +0,0 @@
<?php
use Flextype\Component\Filesystem\Filesystem;
beforeEach(function() {
filesystem()->directory(PATH['project'] . '/entries')->create();
});
afterEach(function (): void {
filesystem()->directory(PATH['project'] . '/entries')->delete();
});
test('ParsersField', function () {
entries()->create('bar-parsers', ['content' => '[registry-get id="Bar" default="Zed"]', 'parsers' => ['shortcodes' => ['enabled' => true, 'fields' => ['content']]]]);
$this->assertEquals('Zed', entries()->fetch('bar-parsers')['content']);
});

View File

@@ -10,7 +10,7 @@ afterEach(function (): void {
filesystem()->directory(PATH['project'] . '/entries')->delete();
});
test('EntriesField for blog', function () {
test('EntriesMacros for blog', function () {
entries()->create('blog', serializers()->yaml()->decode(filesystem()->file(ROOT_DIR . '/tests/fixtures/entries/blog/blog.yaml')->get()));
entries()->create('blog/post-1', serializers()->frontmatter()->decode(filesystem()->file(ROOT_DIR . '/tests/fixtures/entries/blog/post-1/post.md')->get()));
entries()->create('blog/post-2', serializers()->frontmatter()->decode(filesystem()->file(ROOT_DIR . '/tests/fixtures/entries/blog/post-2/post.md')->get()));
@@ -22,7 +22,7 @@ test('EntriesField for blog', function () {
$this->assertEquals(2, $posts->count());
});
test('EntriesField for shop', function() {
test('EntriesMacros for shop', function() {
filesystem()
->directory(ROOT_DIR . '/tests/fixtures/entries/shop')
->copy(ROOT_DIR . '/project/entries/shop');
@@ -35,7 +35,7 @@ test('EntriesField for shop', function() {
$this->assertEquals('Discounts', $shop['discounts']['title']);
});
test('EntriesField for catalog', function () {
test('EntriesMacros for catalog', function () {
// Create catalog
entries()->create('catalog', serializers()->yaml()->decode(filesystem()->file(ROOT_DIR . '/tests/fixtures/entries/catalog/entry.yaml')->get()));
@@ -55,13 +55,13 @@ test('EntriesField for catalog', function () {
$catalogSingle = entries()->fetch('catalog');
$this->assertEquals(15, $catalogSingle->count());
$this->assertEquals(14, $catalogSingle->count());
$this->assertEquals('Catalog', $catalogSingle['title']);
$this->assertEquals('catalog', $catalogSingle['id']);
$this->assertEquals(1, $catalogSingle['bikes']->count());
$this->assertEquals(1, collection($catalogSingle['bikes'])->count());
$this->assertTrue(isset($catalogSingle['bikes']['catalog/bikes/gt']));
$this->assertEquals('GT', $catalogSingle['bikes']['catalog/bikes/gt']['title']);
$this->assertEquals(1, $catalogSingle['discounts']->count());
$this->assertEquals(1, collection($catalogSingle['discounts'])->count());
$this->assertTrue(isset($catalogSingle['discounts']['discounts/30-off']));
$this->assertEquals('30% off', $catalogSingle['discounts']['discounts/30-off']['title']);
@@ -71,14 +71,14 @@ test('EntriesField for catalog', function () {
$this->assertEquals('catalog/bikes', $catalogCollection['catalog/bikes']['id']);
$catalogLongCollecion = entries()->fetch('catalog', ['collection' => true, 'find' => ['depth' => ['>0', '<4']]]);
$this->assertEquals(5, $catalogLongCollecion->count());
$this->assertEquals(5, collection($catalogLongCollecion)->count());
$banner = entries()->fetch('banner');
$this->assertEquals('Banner', $banner['title']);
$this->assertEquals('banner', $banner['id']);
});
test('EntriesField for albmus', function () {
test('EntriesMacros for albmus', function () {
entries()->create('root', serializers()->yaml()->decode(filesystem()->file(ROOT_DIR . '/tests/fixtures/entries/root/entry.yaml')->get()));
entries()->create('albums', serializers()->yaml()->decode(filesystem()->file(ROOT_DIR . '/tests/fixtures/entries/root/albums/entry.yaml')->get()));
@@ -91,10 +91,10 @@ test('EntriesField for albmus', function () {
$root = entries()->fetch('root');
$this->assertEquals(15, $root->count());
$this->assertEquals(14, $root->count());
});
test('EntriesField for long nested entries', function () {
test('EntriesMacros for long nested entries', function () {
entries()->create('level1', serializers()->yaml()->decode(filesystem()->file(ROOT_DIR . '/tests/fixtures/entries/level1/entry.yaml')->get()));
entries()->create('level1/level2', serializers()->yaml()->decode(filesystem()->file(ROOT_DIR . '/tests/fixtures/entries/level1/level2/entry.yaml')->get()));
entries()->create('level1/level2/level3', serializers()->yaml()->decode(filesystem()->file(ROOT_DIR . '/tests/fixtures/entries/level1/level2/level3/entry.yaml')->get()));
@@ -102,7 +102,7 @@ test('EntriesField for long nested entries', function () {
$level = entries()->fetch('level1');
$this->assertEquals(13, $level->count());
$this->assertEquals(12, $level->count());
$this->assertEquals('level1/level2', $level['root']['id']);
$this->assertEquals('level1/level2/level3', $level['root']['root']['id']);
$this->assertEquals('level1/level2/level3/level4', $level['root']['root']['root']['id']);

View File

@@ -10,7 +10,7 @@ afterEach(function (): void {
filesystem()->directory(PATH['project'] . '/entries')->delete();
});
test('RegistryField', function () {
test('RegistryMacros', function () {
entries()->create('registry-root', serializers()->yaml()->decode(filesystem()->file(ROOT_DIR . '/tests/fixtures/entries/registry-root/entry.yaml')->get()));
entries()->create('registry-root/level-1', serializers()->yaml()->decode(filesystem()->file(ROOT_DIR . '/tests/fixtures/entries/registry-root/level-1/entry.yaml')->get()));
entries()->create('registry-root/level-1/level-2', serializers()->yaml()->decode(filesystem()->file(ROOT_DIR . '/tests/fixtures/entries/registry-root/level-1/level-2/entry.yaml')->get()));