From 83fe88ceceafa08ee4091adda90fc09f04b5497f Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 7 May 2022 10:44:13 +0300 Subject: [PATCH] feat(entries): add macros functionality --- src/flextype/core/Entries/Entries.php | 55 +++++++++++++--- .../Entries/Fields/Default/ParsersField.php | 60 ----------------- .../EntriesMacros.php} | 19 ++---- .../RegistryMacros.php} | 10 +-- src/flextype/settings.yaml | 24 ++++--- .../entries/catalog/bikes/gt/entry.yaml | 45 ++++++------- .../entries/catalog/bikes/norco/entry.yaml | 21 +++--- tests/fixtures/entries/catalog/entry.yaml | 65 ++++++++++--------- tests/fixtures/entries/level1/entry.yaml | 9 +-- .../fixtures/entries/level1/level2/entry.yaml | 9 +-- .../entries/level1/level2/level3/entry.yaml | 9 +-- .../fixtures/entries/registry-root/entry.yaml | 27 ++++---- .../entries/registry-root/level-1/entry.yaml | 27 ++++---- .../registry-root/level-1/level-2/entry.yaml | 17 ++--- .../root/albums/category-1/album-1/entry.yaml | 37 ++++++----- .../root/albums/category-2/album-2/entry.yaml | 37 ++++++----- tests/fixtures/entries/root/entry.yaml | 29 +++++---- .../entries/shop/catalog/bikes/entry.yaml | 16 ++--- .../entries/shop/catalog/bikes/gt/entry.yaml | 16 ++--- .../shop/catalog/bikes/gt/fury/entry.yaml | 28 ++++---- .../shop/catalog/bikes/gt/sensor/entry.yaml | 28 ++++---- .../shop/catalog/bikes/norco/entry.yaml | 16 ++--- .../shop/catalog/bikes/norco/rage/entry.yaml | 28 ++++---- .../fixtures/entries/shop/catalog/entry.yaml | 18 ++--- .../shop/catalog/snowboards/burton/entry.yaml | 16 ++--- .../catalog/snowboards/burton/hero/entry.yaml | 28 ++++---- .../shop/catalog/snowboards/entry.yaml | 16 ++--- .../entries/shop/discounts/entry.yaml | 16 ++--- tests/fixtures/entries/shop/entry.yaml | 18 ++--- tests/fixtures/settings/settings.yaml | 23 +++---- .../core/Entries/Fields/ParsersFieldTest.php | 17 ----- .../EntriesMacrosTest.php} | 22 +++---- .../RegistryMacrosTest.php} | 2 +- 33 files changed, 383 insertions(+), 425 deletions(-) delete mode 100644 src/flextype/core/Entries/Fields/Default/ParsersField.php rename src/flextype/core/Entries/{Fields/Default/EntriesField.php => Macros/EntriesMacros.php} (68%) rename src/flextype/core/Entries/{Fields/Default/RegistryField.php => Macros/RegistryMacros.php} (77%) delete mode 100644 tests/src/flextype/core/Entries/Fields/ParsersFieldTest.php rename tests/src/flextype/core/Entries/{Fields/EntriesFieldTest.php => Macros/EntriesMacrosTest.php} (89%) rename tests/src/flextype/core/Entries/{Fields/RegistryFieldTest.php => Macros/RegistryMacrosTest.php} (97%) diff --git a/src/flextype/core/Entries/Entries.php b/src/flextype/core/Entries/Entries.php index 93569c9f..2d8dc125 100755 --- a/src/flextype/core/Entries/Entries.php +++ b/src/flextype/core/Entries/Entries.php @@ -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 diff --git a/src/flextype/core/Entries/Fields/Default/ParsersField.php b/src/flextype/core/Entries/Fields/Default/ParsersField.php deleted file mode 100644 index c2b5c195..00000000 --- a/src/flextype/core/Entries/Fields/Default/ParsersField.php +++ /dev/null @@ -1,60 +0,0 @@ -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)); - } - } - } - } - } - } - } - } - } - } -}); diff --git a/src/flextype/core/Entries/Fields/Default/EntriesField.php b/src/flextype/core/Entries/Macros/EntriesMacros.php similarity index 68% rename from src/flextype/core/Entries/Fields/Default/EntriesField.php rename to src/flextype/core/Entries/Macros/EntriesMacros.php index d4067f27..b4896305 100644 --- a/src/flextype/core/Entries/Fields/Default/EntriesField.php +++ b/src/flextype/core/Entries/Macros/EntriesMacros.php @@ -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']); diff --git a/src/flextype/core/Entries/Fields/Default/RegistryField.php b/src/flextype/core/Entries/Macros/RegistryMacros.php similarity index 77% rename from src/flextype/core/Entries/Fields/Default/RegistryField.php rename to src/flextype/core/Entries/Macros/RegistryMacros.php index 80ade5ae..4103fb90 100644 --- a/src/flextype/core/Entries/Fields/Default/RegistryField.php +++ b/src/flextype/core/Entries/Macros/RegistryMacros.php @@ -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); } diff --git a/src/flextype/settings.yaml b/src/flextype/settings.yaml index 05fa1b14..34e3065e 100644 --- a/src/flextype/settings.yaml +++ b/src/flextype/settings.yaml @@ -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. diff --git a/tests/fixtures/entries/catalog/bikes/gt/entry.yaml b/tests/fixtures/entries/catalog/bikes/gt/entry.yaml index cb1117ee..9335d728 100644 --- a/tests/fixtures/entries/catalog/bikes/gt/entry.yaml +++ b/tests/fixtures/entries/catalog/bikes/gt/entry.yaml @@ -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 \ No newline at end of file +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 \ No newline at end of file diff --git a/tests/fixtures/entries/catalog/bikes/norco/entry.yaml b/tests/fixtures/entries/catalog/bikes/norco/entry.yaml index ebdc2356..33569e8e 100644 --- a/tests/fixtures/entries/catalog/bikes/norco/entry.yaml +++ b/tests/fixtures/entries/catalog/bikes/norco/entry.yaml @@ -1,12 +1,13 @@ title: Norco brand: norco -entries: - fetch: - label: - id: discounts/30-off - options: - collection: true - discounts: - id: discounts - options: - collection: true \ No newline at end of file +macros: + entries: + fetch: + label: + id: discounts/30-off + options: + collection: true + discounts: + id: discounts + options: + collection: true \ No newline at end of file diff --git a/tests/fixtures/entries/catalog/entry.yaml b/tests/fixtures/entries/catalog/entry.yaml index 4ab9a6c2..2e28ffe9 100644 --- a/tests/fixtures/entries/catalog/entry.yaml +++ b/tests/fixtures/entries/catalog/entry.yaml @@ -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 \ No newline at end of file +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 \ No newline at end of file diff --git a/tests/fixtures/entries/level1/entry.yaml b/tests/fixtures/entries/level1/entry.yaml index e36d6e12..12836e51 100644 --- a/tests/fixtures/entries/level1/entry.yaml +++ b/tests/fixtures/entries/level1/entry.yaml @@ -1,5 +1,6 @@ title: level1 -entries: - fetch: - root: - id: level1/level2 \ No newline at end of file +macros: + entries: + fetch: + root: + id: level1/level2 \ No newline at end of file diff --git a/tests/fixtures/entries/level1/level2/entry.yaml b/tests/fixtures/entries/level1/level2/entry.yaml index 9c2f9dce..0bcc10d6 100644 --- a/tests/fixtures/entries/level1/level2/entry.yaml +++ b/tests/fixtures/entries/level1/level2/entry.yaml @@ -1,5 +1,6 @@ title: level2 -entries: - fetch: - root: - id: level1/level2/level3 \ No newline at end of file +macros: + entries: + fetch: + root: + id: level1/level2/level3 \ No newline at end of file diff --git a/tests/fixtures/entries/level1/level2/level3/entry.yaml b/tests/fixtures/entries/level1/level2/level3/entry.yaml index acde5770..8840e668 100644 --- a/tests/fixtures/entries/level1/level2/level3/entry.yaml +++ b/tests/fixtures/entries/level1/level2/level3/entry.yaml @@ -1,5 +1,6 @@ title: level3 -entries: - fetch: - root: - id: level1/level2/level3/level4 \ No newline at end of file +macros: + entries: + fetch: + root: + id: level1/level2/level3/level4 \ No newline at end of file diff --git a/tests/fixtures/entries/registry-root/entry.yaml b/tests/fixtures/entries/registry-root/entry.yaml index edbe6fa4..8496b983 100644 --- a/tests/fixtures/entries/registry-root/entry.yaml +++ b/tests/fixtures/entries/registry-root/entry.yaml @@ -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 diff --git a/tests/fixtures/entries/registry-root/level-1/entry.yaml b/tests/fixtures/entries/registry-root/level-1/entry.yaml index 392c9e97..2b30436e 100644 --- a/tests/fixtures/entries/registry-root/level-1/entry.yaml +++ b/tests/fixtures/entries/registry-root/level-1/entry.yaml @@ -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 \ No newline at end of file +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 \ No newline at end of file diff --git a/tests/fixtures/entries/registry-root/level-1/level-2/entry.yaml b/tests/fixtures/entries/registry-root/level-1/level-2/entry.yaml index 94a6a05c..96a9b530 100644 --- a/tests/fixtures/entries/registry-root/level-1/level-2/entry.yaml +++ b/tests/fixtures/entries/registry-root/level-1/level-2/entry.yaml @@ -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 \ No newline at end of file +macros: + registry: + get: + flextype: + id: flextype.manifest.name + author.name: + id: flextype.manifest.author.name + license: + id: flextype.manifest.license \ No newline at end of file diff --git a/tests/fixtures/entries/root/albums/category-1/album-1/entry.yaml b/tests/fixtures/entries/root/albums/category-1/album-1/entry.yaml index 745c6991..9337c82e 100644 --- a/tests/fixtures/entries/root/albums/category-1/album-1/entry.yaml +++ b/tests/fixtures/entries/root/albums/category-1/album-1/entry.yaml @@ -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" \ No newline at end of file +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" \ No newline at end of file diff --git a/tests/fixtures/entries/root/albums/category-2/album-2/entry.yaml b/tests/fixtures/entries/root/albums/category-2/album-2/entry.yaml index 7e22361d..e343fc35 100644 --- a/tests/fixtures/entries/root/albums/category-2/album-2/entry.yaml +++ b/tests/fixtures/entries/root/albums/category-2/album-2/entry.yaml @@ -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" \ No newline at end of file +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" \ No newline at end of file diff --git a/tests/fixtures/entries/root/entry.yaml b/tests/fixtures/entries/root/entry.yaml index ae8b52ee..7669961b 100644 --- a/tests/fixtures/entries/root/entry.yaml +++ b/tests/fixtures/entries/root/entry.yaml @@ -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' \ No newline at end of file +macros: + entries: + fetch: + albums: + id: albums + collection: + id: albums + options: + collection: true + collectionWithDepth: + id: albums + options: + collection: false + find: + depth: '>0' \ No newline at end of file diff --git a/tests/fixtures/entries/shop/catalog/bikes/entry.yaml b/tests/fixtures/entries/shop/catalog/bikes/entry.yaml index 023815fc..368807f6 100644 --- a/tests/fixtures/entries/shop/catalog/bikes/entry.yaml +++ b/tests/fixtures/entries/shop/catalog/bikes/entry.yaml @@ -1,9 +1,9 @@ title: Bikes -entries: - dump: false - fetch: - items: - result: toArray - id: shop/catalog/bikes - options: - collection: true \ No newline at end of file +macros: + entries: + fetch: + items: + result: toArray + id: shop/catalog/bikes + options: + collection: true \ No newline at end of file diff --git a/tests/fixtures/entries/shop/catalog/bikes/gt/entry.yaml b/tests/fixtures/entries/shop/catalog/bikes/gt/entry.yaml index de9bf00c..e92b7cef 100644 --- a/tests/fixtures/entries/shop/catalog/bikes/gt/entry.yaml +++ b/tests/fixtures/entries/shop/catalog/bikes/gt/entry.yaml @@ -1,9 +1,9 @@ title: GT -entries: - dump: false - fetch: - items: - result: toArray - id: shop/catalog/bikes/gt - options: - collection: true \ No newline at end of file +macros: + entries: + fetch: + items: + result: toArray + id: shop/catalog/bikes/gt + options: + collection: true \ No newline at end of file diff --git a/tests/fixtures/entries/shop/catalog/bikes/gt/fury/entry.yaml b/tests/fixtures/entries/shop/catalog/bikes/gt/fury/entry.yaml index 23805d7d..35f01ec4 100644 --- a/tests/fixtures/entries/shop/catalog/bikes/gt/fury/entry.yaml +++ b/tests/fixtures/entries/shop/catalog/bikes/gt/fury/entry.yaml @@ -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 \ No newline at end of file +macros: + entries: + fetch: + discounts_available: + result: toArray + id: shop/discounts + options: + collection: true + filter: + where: + - + key: category + operator: eq + value: bikes \ No newline at end of file diff --git a/tests/fixtures/entries/shop/catalog/bikes/gt/sensor/entry.yaml b/tests/fixtures/entries/shop/catalog/bikes/gt/sensor/entry.yaml index a9c1d89d..b36ed861 100644 --- a/tests/fixtures/entries/shop/catalog/bikes/gt/sensor/entry.yaml +++ b/tests/fixtures/entries/shop/catalog/bikes/gt/sensor/entry.yaml @@ -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 \ No newline at end of file +macros: + entries: + fetch: + discounts_available: + result: toArray + id: shop/discounts + options: + collection: true + filter: + where: + - + key: category + operator: eq + value: bikes \ No newline at end of file diff --git a/tests/fixtures/entries/shop/catalog/bikes/norco/entry.yaml b/tests/fixtures/entries/shop/catalog/bikes/norco/entry.yaml index e53b0de1..dc80e682 100644 --- a/tests/fixtures/entries/shop/catalog/bikes/norco/entry.yaml +++ b/tests/fixtures/entries/shop/catalog/bikes/norco/entry.yaml @@ -1,9 +1,9 @@ title: Norco -entries: - dump: false - fetch: - items: - result: toArray - id: shop/catalog/bikes/norco - options: - collection: true \ No newline at end of file +macros: + entries: + fetch: + items: + result: toArray + id: shop/catalog/bikes/norco + options: + collection: true \ No newline at end of file diff --git a/tests/fixtures/entries/shop/catalog/bikes/norco/rage/entry.yaml b/tests/fixtures/entries/shop/catalog/bikes/norco/rage/entry.yaml index f37ad735..b659a0dd 100644 --- a/tests/fixtures/entries/shop/catalog/bikes/norco/rage/entry.yaml +++ b/tests/fixtures/entries/shop/catalog/bikes/norco/rage/entry.yaml @@ -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 \ No newline at end of file +macros: + entries: + fetch: + discounts_available: + result: toArray + id: shop/discounts + options: + collection: true + filter: + where: + - + key: category + operator: eq + value: bikes \ No newline at end of file diff --git a/tests/fixtures/entries/shop/catalog/entry.yaml b/tests/fixtures/entries/shop/catalog/entry.yaml index c0732e63..ff6fa205 100644 --- a/tests/fixtures/entries/shop/catalog/entry.yaml +++ b/tests/fixtures/entries/shop/catalog/entry.yaml @@ -1,10 +1,10 @@ title: Catalog -entries: - dump: false - fetch: - bikes: - result: toArray - id: shop/catalog/bikes - snowboards: - result: toArray - id: shop/catalog/snowboards \ No newline at end of file +macros: + entries: + fetch: + bikes: + result: toArray + id: shop/catalog/bikes + snowboards: + result: toArray + id: shop/catalog/snowboards \ No newline at end of file diff --git a/tests/fixtures/entries/shop/catalog/snowboards/burton/entry.yaml b/tests/fixtures/entries/shop/catalog/snowboards/burton/entry.yaml index 0a195c05..498849b5 100644 --- a/tests/fixtures/entries/shop/catalog/snowboards/burton/entry.yaml +++ b/tests/fixtures/entries/shop/catalog/snowboards/burton/entry.yaml @@ -1,9 +1,9 @@ title: Burton -entries: - dump: false - fetch: - items: - result: toArray - id: shop/catalog/snowboards/burton - options: - collection: true \ No newline at end of file +macros: + entries: + fetch: + items: + result: toArray + id: shop/catalog/snowboards/burton + options: + collection: true \ No newline at end of file diff --git a/tests/fixtures/entries/shop/catalog/snowboards/burton/hero/entry.yaml b/tests/fixtures/entries/shop/catalog/snowboards/burton/hero/entry.yaml index 54ef8211..bc057a7c 100644 --- a/tests/fixtures/entries/shop/catalog/snowboards/burton/hero/entry.yaml +++ b/tests/fixtures/entries/shop/catalog/snowboards/burton/hero/entry.yaml @@ -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 \ No newline at end of file +macros: + entries: + fetch: + discounts_available: + result: toArray + id: shop/discounts + options: + collection: true + filter: + where: + - + key: category + operator: eq + value: snowboards \ No newline at end of file diff --git a/tests/fixtures/entries/shop/catalog/snowboards/entry.yaml b/tests/fixtures/entries/shop/catalog/snowboards/entry.yaml index 058313ab..e348f03e 100644 --- a/tests/fixtures/entries/shop/catalog/snowboards/entry.yaml +++ b/tests/fixtures/entries/shop/catalog/snowboards/entry.yaml @@ -1,9 +1,9 @@ title: Snowboards -entries: - dump: false - fetch: - items: - result: toArray - id: shop/catalog/snowboards - options: - collection: true \ No newline at end of file +macros: + entries: + fetch: + items: + result: toArray + id: shop/catalog/snowboards + options: + collection: true \ No newline at end of file diff --git a/tests/fixtures/entries/shop/discounts/entry.yaml b/tests/fixtures/entries/shop/discounts/entry.yaml index 745dec84..7fad90c6 100644 --- a/tests/fixtures/entries/shop/discounts/entry.yaml +++ b/tests/fixtures/entries/shop/discounts/entry.yaml @@ -1,9 +1,9 @@ title: Discounts -entries: - dump: false - fetch: - items: - result: toArray - id: shop/discounts - options: - collection: true \ No newline at end of file +macros: + entries: + fetch: + items: + result: toArray + id: shop/discounts + options: + collection: true \ No newline at end of file diff --git a/tests/fixtures/entries/shop/entry.yaml b/tests/fixtures/entries/shop/entry.yaml index cf97fea9..85125832 100644 --- a/tests/fixtures/entries/shop/entry.yaml +++ b/tests/fixtures/entries/shop/entry.yaml @@ -1,10 +1,10 @@ title: Shop -entries: - dump: false - fetch: - catalog: - id: shop/catalog - result: toArray - discounts: - id: shop/discounts - result: toArray \ No newline at end of file +macros: + entries: + fetch: + catalog: + id: shop/catalog + result: toArray + discounts: + id: shop/discounts + result: toArray \ No newline at end of file diff --git a/tests/fixtures/settings/settings.yaml b/tests/fixtures/settings/settings.yaml index 620d7f5b..ff5fe621 100644 --- a/tests/fixtures/settings/settings.yaml +++ b/tests/fixtures/settings/settings.yaml @@ -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" diff --git a/tests/src/flextype/core/Entries/Fields/ParsersFieldTest.php b/tests/src/flextype/core/Entries/Fields/ParsersFieldTest.php deleted file mode 100644 index 6f5d5cf2..00000000 --- a/tests/src/flextype/core/Entries/Fields/ParsersFieldTest.php +++ /dev/null @@ -1,17 +0,0 @@ -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']); -}); diff --git a/tests/src/flextype/core/Entries/Fields/EntriesFieldTest.php b/tests/src/flextype/core/Entries/Macros/EntriesMacrosTest.php similarity index 89% rename from tests/src/flextype/core/Entries/Fields/EntriesFieldTest.php rename to tests/src/flextype/core/Entries/Macros/EntriesMacrosTest.php index a9ccf501..8acb6ffd 100644 --- a/tests/src/flextype/core/Entries/Fields/EntriesFieldTest.php +++ b/tests/src/flextype/core/Entries/Macros/EntriesMacrosTest.php @@ -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']); diff --git a/tests/src/flextype/core/Entries/Fields/RegistryFieldTest.php b/tests/src/flextype/core/Entries/Macros/RegistryMacrosTest.php similarity index 97% rename from tests/src/flextype/core/Entries/Fields/RegistryFieldTest.php rename to tests/src/flextype/core/Entries/Macros/RegistryMacrosTest.php index 05b143fe..35bceafc 100644 --- a/tests/src/flextype/core/Entries/Fields/RegistryFieldTest.php +++ b/tests/src/flextype/core/Entries/Macros/RegistryMacrosTest.php @@ -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()));