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

feat(core): updates for #586 #585 #584

This commit is contained in:
Awilum
2022-09-09 15:59:43 +03:00
parent 7de0b86eed
commit 7f443bea9b
55 changed files with 796 additions and 461 deletions

View File

@@ -18,13 +18,13 @@ locale: en_US
# Application Base url
#
# Define application base url
# Define application base url (without trailing slash)
base_url: ''
# Application Base Path
#
# Define application base path if application located in subdirectory
base_path: '/'
# Define application base path (without trailing and without starting slash) if application located in subdirectory
base_path: ''
# Valid date format
#
@@ -76,81 +76,11 @@ entries:
directory: 'entries'
cache:
string: ""
vars:
debug: false
expressions:
math:
enabled: true
class: "Flextype\\Entries\\Expressions\\MathExpression"
date:
enabled: true
class: "Flextype\\Entries\\Expressions\\DateExpression"
actions:
enabled: true
class: "Flextype\\Entries\\Expressions\\ActionsExpression"
registry:
enabled: true
class: "Flextype\\Entries\\Expressions\\RegistryExpression"
entries:
enabled: true
class: "Flextype\\Entries\\Expressions\\EntriesExpression"
fetch:
enabled: true
has:
enabled: true
registry:
enabled: true
create:
enabled: false
move:
enabled: false
update:
enabled: false
delete:
enabled: false
fetch:
enabled: true
class: "Flextype\\Entries\\Expressions\\FetchExpression"
filesystem:
enabled: true
class: "Flextype\\Entries\\Expressions\\FilesystemExpression"
i18n:
enabled: true
class: "Flextype\\Entries\\Expressions\\I18nExpression"
serializers:
enabled: true
class: "Flextype\\Entries\\Expressions\\SerializersExpression"
parsers:
enabled: true
class: "Flextype\\Entries\\Expressions\\ParsersExpression"
slugify:
enabled: true
class: "Flextype\\Entries\\Expressions\\SlugifyExpression"
strings:
enabled: true
class: "Flextype\\Entries\\Expressions\\StringsExpression"
collection:
enabled: true
class: "Flextype\\Entries\\Expressions\\CollectionExpression"
csrf:
enabled: true
class: "Flextype\\Entries\\Expressions\\CsrfExpression"
var:
enabled: true
class: "Flextype\\Entries\\Expressions\\VarExpression"
field:
enabled: true
class: "Flextype\\Entries\\Expressions\\FieldExpression"
const:
enabled: true
class: "Flextype\\Entries\\Expressions\\ConstExpression"
directives:
expressions:
enabled: true
enabled_globally: true
path: "src/flextype/core/Entries/Directives/ExpressionsDirective.php"
opening_tag: "[["
closing_tag: "]]"
shortcodes:
enabled: true
enabled_globally: true
@@ -172,9 +102,6 @@ entries:
path: "src/flextype/core/Entries/Directives/TypesDirective.php"
macros:
debug: false
vars:
enabled: true
path: "src/flextype/core/Entries/Macros/VarsMacros.php"
php:
enabled: true
path: "src/flextype/core/Entries/Macros/PhpMacros.php"
@@ -333,17 +260,6 @@ cache:
ssl_enabled: false
ssl_verify: false
default_ttl: 900
cookie:
aware_of_untrustable_data: false
limited_memory_by_object: 4096
default_ttl: 900
couchbase:
host: '127.0.0.1'
port: 8091
username: ''
password: ''
bucket_name: default
default_ttl: 900
couchdb:
database: 'flextype'
path: '/'
@@ -356,25 +272,20 @@ cache:
timeout: 10
default_ttl: 900
devnull: {}
devfalse: {}
devtrue: {}
phparray:
path: '/data'
security_key: 'auto'
htaccess: true
secure_file_manipulation: false
default_ttl: 900
files:
path: '/data'
security_key: 'auto'
htaccess: true
secure_file_manipulation: false
cache_file_extension: txt
default_ttl: 900
leveldb:
path: '/data'
security_key: 'auto'
htaccess: true
default_ttl: 900
memcache:
host: '127.0.0.1'
@@ -421,15 +332,9 @@ cache:
database: 0
opt_prefix: ''
default_ttl: 900
riak:
host: '127.0.0.1'
port: 8098
prefix: 'riak'
default_ttl: 900
sqlite:
path: '/data'
security_key: auto
htaccess: true
default_ttl: 900
ssdb:
host: 127.0.0.1
@@ -674,12 +579,12 @@ parsers:
path: "src/flextype/core/Parsers/Shortcodes/EntriesShortcode.php"
fetch:
enabled: true
php:
enabled: true
path: "src/flextype/core/Parsers/Shortcodes/PhpShortcode.php"
date:
enabled: true
path: "src/flextype/core/Parsers/Shortcodes/DateShortcode.php"
php:
enabled: true
path: "src/flextype/core/Parsers/Shortcodes/PhpShortcode.php"
raw:
enabled: true
path: "src/flextype/core/Parsers/Shortcodes/RawShortcode.php"
@@ -741,6 +646,85 @@ parsers:
type:
enabled: true
path: "src/flextype/core/Parsers/Shortcodes/TypeShortcode.php"
expressions:
cache:
enabled: true
string: ''
opening_variable_tag: "[["
closing_variable_tag: "]]"
opening_block_tag: "[%"
closing_block_tag: "%]"
opening_comment_tag: "[#"
closing_comment_tag: "#]"
expressions:
math:
enabled: true
class: "Flextype\\Parsers\\Expressions\\MathExpression"
date:
enabled: true
class: "Flextype\\Parsers\\Expressions\\DateExpression"
actions:
enabled: true
class: "Flextype\\Parsers\\Expressions\\ActionsExpression"
registry:
enabled: true
class: "Flextype\\Parsers\\Expressions\\RegistryExpression"
entries:
enabled: true
class: "Flextype\\Parsers\\Expressions\\EntriesExpression"
fetch:
enabled: true
has:
enabled: true
registry:
enabled: true
create:
enabled: false
move:
enabled: false
update:
enabled: false
delete:
enabled: false
fetch:
enabled: true
class: "Flextype\\Parsers\\Expressions\\FetchExpression"
filesystem:
enabled: true
class: "Flextype\\Parsers\\Expressions\\FilesystemExpression"
i18n:
enabled: true
class: "Flextype\\Parsers\\Expressions\\I18nExpression"
serializers:
enabled: true
class: "Flextype\\Parsers\\Expressions\\SerializersExpression"
parsers:
enabled: true
class: "Flextype\\Parsers\\Expressions\\ParsersExpression"
slugify:
enabled: true
class: "Flextype\\Parsers\\Expressions\\SlugifyExpression"
strings:
enabled: true
class: "Flextype\\Parsers\\Expressions\\StringsExpression"
collection:
enabled: true
class: "Flextype\\Parsers\\Expressions\\CollectionExpression"
csrf:
enabled: true
class: "Flextype\\Parsers\\Expressions\\CsrfExpression"
field:
enabled: true
class: "Flextype\\Parsers\\Expressions\\FieldExpression"
var:
enabled: true
class: "Flextype\\Parsers\\Expressions\\VarExpression"
const:
enabled: true
class: "Flextype\\Parsers\\Expressions\\ConstExpression"
url:
enabled: true
class: "Flextype\\Parsers\\Expressions\\UrlExpression"
# CORS
#

View File

@@ -1,18 +0,0 @@
<?php
use Flextype\Component\Filesystem\Filesystem;
use function Glowy\Filesystem\filesystem;
use function Flextype\entries;
beforeEach(function() {
filesystem()->directory(FLEXTYPE_PATH_PROJECT . '/entries')->create();
});
afterEach(function (): void {
filesystem()->directory(FLEXTYPE_PATH_PROJECT . '/entries')->delete();
});
test('field expression', function () {
entries()->create('field', ['test' => '[[ field("id") ]]']);
expect(entries()->fetch('field')['test'])->toBe('field');
});

View File

@@ -1,37 +0,0 @@
<?php
use Flextype\Component\Filesystem\Filesystem;
use function Glowy\Filesystem\filesystem;
use function Flextype\entries;
beforeEach(function() {
filesystem()->directory(FLEXTYPE_PATH_PROJECT . '/entries')->create();
});
afterEach(function (): void {
filesystem()->directory(FLEXTYPE_PATH_PROJECT . '/entries')->delete();
});
test('var + field expression', function () {
entries()->create('var', [
'title' => 'Foo',
'vars' => [
'foo' => 'Foo'
],
'test1' => '[[ var("foo") ]]',
'test2' => "[[ get('vars.foo', 'Foo') ]]",
'test3' => '[[ vars.foo ]]',
'test4' => '[[ set("bar", "Bar") ]][[ bar ]]',
'test5' => '[[ unset("bar") ]]',
'test6' => '[[ delete("bar") ]]',
'test7' => '[[ title ]] [[ get("title") ]]',
]);
expect(entries()->fetch('var')['test1'])->toBe('Foo');
expect(entries()->fetch('var')['test2'])->toBe('Foo');
expect(entries()->fetch('var')['test3'])->toBe('Foo');
expect(entries()->fetch('var')['test4'])->toBe('Bar');
expect(entries()->fetch('var')['test5'])->toBe('');
expect(entries()->fetch('var')['test6'])->toBe('');
expect(entries()->fetch('var')['test7'])->toBe('Foo Foo');
});

View File

@@ -33,9 +33,9 @@ test('entries expression', function () {
'test' => '(type:bool) [[ entries().delete("foo") ]]',
]);
registry()->set('flextype.settings.entries.expressions.entries.delete.enabled', true);
registry()->set('flextype.settings.parsers.expressions.expressions.entries.delete.enabled', true);
expect(entries()->fetch('delete')['test'])->toBeTrue();
registry()->set('flextype.settings.entries.expressions.entries.delete.enabled', false);
registry()->set('flextype.settings.parsers.expressions.expressions.entries.delete.enabled', false);
// copy
entries()->create('copy-foo');
@@ -43,9 +43,9 @@ test('entries expression', function () {
'test' => '(type:bool) [[ entries().copy("copy-foo", "copy-foo-2") ]]',
]);
registry()->set('flextype.settings.entries.expressions.entries.copy.enabled', true);
registry()->set('flextype.settings.parsers.expressions.expressions.entries.copy.enabled', true);
expect(entries()->fetch('copy')['test'])->toBeTrue();
registry()->set('flextype.settings.entries.expressions.entries.copy.enabled', false);
registry()->set('flextype.settings.parsers.expressions.expressions.entries.copy.enabled', false);
// move
entries()->create('move-foo');
@@ -53,9 +53,9 @@ test('entries expression', function () {
'test' => '(type:bool) [[ entries().move("move-foo", "move-foo-2") ]]',
]);
registry()->set('flextype.settings.entries.expressions.entries.move.enabled', true);
registry()->set('flextype.settings.parsers.expressions.expressions.entries.move.enabled', true);
expect(entries()->fetch('move')['test'])->toBeTrue();
registry()->set('flextype.settings.entries.expressions.entries.move.enabled', false);
registry()->set('flextype.settings.parsers.expressions.expressions.entries.move.enabled', false);
// update
entries()->create('update-foo');
@@ -63,8 +63,8 @@ test('entries expression', function () {
'test' => '(type:bool) [[ entries().update("update-foo", {"title": "Foo"}) ]]',
]);
registry()->set('flextype.settings.entries.expressions.entries.update.enabled', true);
registry()->set('flextype.settings.parsers.expressions.expressions.entries.update.enabled', true);
expect(entries()->fetch('update')['test'])->toBeTrue();
expect(entries()->fetch('update-foo')['title'])->toBe('Foo');
registry()->set('flextype.settings.entries.expressions.entries.update.enabled', false);
registry()->set('flextype.settings.parsers.expressions.expressions.entries.update.enabled', false);
});

View File

@@ -0,0 +1,49 @@
<?php
use Flextype\Component\Filesystem\Filesystem;
use function Glowy\Filesystem\filesystem;
use function Flextype\entries;
beforeEach(function() {
filesystem()->directory(FLEXTYPE_PATH_PROJECT . '/entries')->create();
});
afterEach(function (): void {
filesystem()->directory(FLEXTYPE_PATH_PROJECT . '/entries')->delete();
});
test('field expression', function () {
entries()->create('field', [
'title' => 'Title',
'_' => [
'foo' => 'Foo',
'level2' => [
'value' => 'Bar',
]
],
// Get
'test-get-1' => '[[ field("title") ]]',
'test-get-2' => '[[ title ]]',
'test-get-3' => '[[ _.foo ]]',
'test-get-4' => "[[ fields().get('_.foo') ]]",
'test-get-5' => "[[ fields().get('_.bar', 'Default') ]]",
// Set add Get
'test-set-1' => '[% fields().set("qwerty", "Qwerty") %]',
'test-set-2' => '[[ fields().get("qwerty") ]] [[qwerty ]] [[ qwerty]] [[qwerty]] [[ qwerty ]]',
// Delete
'test-delete-1' => '[% fields().delete("qwerty") %]',
]);
expect(entries()->fetch('field')['test-get-1'])->toBe('Title');
expect(entries()->fetch('field')['test-get-2'])->toBe('Title');
expect(entries()->fetch('field')['test-get-3'])->toBe('Foo');
expect(entries()->fetch('field')['test-get-4'])->toBe('Foo');
expect(entries()->fetch('field')['test-get-5'])->toBe('Default');
expect(entries()->fetch('field')['test-set-1'])->toBe('');
expect(entries()->fetch('field')['test-set-2'])->toBe('Qwerty Qwerty Qwerty Qwerty Qwerty');
expect(entries()->fetch('field')['test-delete-1'])->toBe('');
});

View File

@@ -31,9 +31,10 @@ test('entries shortcode', function () {
$this->assertTrue(entries()->create('blog-3', ['title' => 'Blog', 'category-cat' => "(entries fetch id:'categories/cat' field:'title2' default:'Foo' /)"]));
expect(entries()->fetch('blog-3')['category-cat'])->toBe('Foo');
$this->assertTrue(entries()->create('shop', ['vars' => ['id' => 'shop', 'options' => 'collection=true'], 'title' => 'Shop', 'products' => "@type[array] (entries fetch id:'(var:id)' options:'(var:options)' /)"]));
$this->assertTrue(entries()->create('shop', ['_vars' => ['id' => 'shop', 'options' => 'collection=true'], 'title' => 'Shop', 'products' => "@type[array] (entries fetch id:'(field:_vars.id)' options:'(field:_vars.options)' /)"]));
$this->assertTrue(entries()->create('shop/product-1', ['title' => 'Product 1']));
expect(count(entries()->fetch('shop')['products']))->toBe(1);
$this->assertTrue(entries()->create('shop/product-2', ['title' => 'Product 2']));
expect(count(entries()->fetch('shop')['products']))->toBe(2);
});
test('entries shortcode disabled', function () {

View File

@@ -15,8 +15,40 @@ afterEach(function () {
});
test('field shortcode', function () {
expect(entries()->create('foo', ['title' => '(field:id)']))->toBeTrue();
expect(entries()->fetch('foo')['title'])->toBe('foo');
expect(entries()->create('foo', [
'title' => 'Title',
// get
'test-get-1' => '(field:title)',
'test-get-2' => '(field get:title)',
'test-get-3' => '(field get:foo default:Foo)',
'test-get-4' => '(field get:foo)Foo(/field)',
// set
'test-set-1' => '(field set:bar1 value:Bar1)(field:bar1)',
'test-set-2' => '(field set:bar2)Bar2(/field)(field:bar2)',
'test-set-3' => '(field set:level1.level2.level3)Multilevel(/field)(field:level1.level2.level3)',
'test-set-4' => '(field set:_.foo)Foo(/field)(field:_.foo)',
// unset
'test-unset-1' => '(field unset:bar1)(field:bar1)',
// delete
'test-delete-1' => '(field delete:bar1)(field:bar1)',
]))->toBeTrue();
$foo = entries()->fetch('foo');
expect($foo['test-get-1'])->toBe('Title');
expect($foo['test-get-2'])->toBe('Title');
expect($foo['test-get-3'])->toBe('Foo');
expect($foo['test-get-4'])->toBe('Foo');
expect($foo['test-set-1'])->toBe('Bar1');
expect($foo['test-set-2'])->toBe('Bar2');
expect($foo['test-set-3'])->toBe('Multilevel');
expect($foo['test-set-4'])->toBe('Foo');
expect($foo['test-unset-1'])->toBe('');
expect($foo['test-delete-1'])->toBe('');
});
test('field shortcode disabled', function () {