diff --git a/composer.json b/composer.json index ef0cb6a6..99fecac5 100755 --- a/composer.json +++ b/composer.json @@ -88,6 +88,7 @@ "victorjonsson/markdowndocs": "^1.3.8" }, "config": { + "platform-check": false, "allow-plugins": { "pestphp/pest-plugin": true, "dealerdirect/phpcodesniffer-composer-installer": true diff --git a/src/flextype/core/Entries/Entries.php b/src/flextype/core/Entries/Entries.php index dbe3cae7..c44e45e8 100755 --- a/src/flextype/core/Entries/Entries.php +++ b/src/flextype/core/Entries/Entries.php @@ -80,6 +80,7 @@ class Entries $this->setRegistry($registry); $this->setOptions($options); + $this->initExpressions(registry()->get('flextype.settings.entries.expressions')); $this->initDirectives(registry()->get('flextype.settings.entries.directives')); $this->initMacros(registry()->get('flextype.settings.entries.macros')); $this->loadCollectionsEvents(); @@ -145,6 +146,38 @@ class Entries } } + /** + * Init Expressions + * + * @param array $expressions Expressions to init. + * + * @return void + */ + public function initExpressions(array $expressions): void + { + if (count($expressions) <= 0) { + return; + } + + foreach ($expressions as $expression) { + if (! isset($expression['enabled'])) { + continue; + } + + if (! $expression['enabled']) { + continue; + } + + if (! strings($expression['class'])->endsWith('Expression')) { + continue; + } + + if (class_exists($expression['class'])) { + expression()->registerProvider(new $expression['class']()); + } + } + } + /** * Load events for current collection. * diff --git a/src/flextype/core/Entries/Expressions/ActionsExpression.php b/src/flextype/core/Entries/Expressions/ActionsExpression.php new file mode 100644 index 00000000..ac7c4d12 --- /dev/null +++ b/src/flextype/core/Entries/Expressions/ActionsExpression.php @@ -0,0 +1,30 @@ + 'actions()', fn($arguments) => actions()) + ]; + } +} \ No newline at end of file diff --git a/src/flextype/core/Entries/Expressions/CollectionExpression.php b/src/flextype/core/Entries/Expressions/CollectionExpression.php new file mode 100644 index 00000000..5e4f2b31 --- /dev/null +++ b/src/flextype/core/Entries/Expressions/CollectionExpression.php @@ -0,0 +1,34 @@ + 'collection($items)', fn($arguments, $items = null) => collection($items)), + new ExpressionFunction('collectionFromJson', fn(string $input, bool $assoc = true, int $depth = 512, int $flags = 0) => 'collectionFromJson($input, $assoc, $depth, $flags)', fn($arguments, string $input, bool $assoc = true, int $depth = 512, int $flags = 0) => collectionFromJson($input, $assoc, $depth, $flags)), + new ExpressionFunction('collectionFromString', fn(string $string, string $separator) => 'collectionFromString($string, $separator)', fn($arguments, string $string, string $separator) => collectionFromString($string, $separator)), + new ExpressionFunction('collectionWithRange', fn($low, $high, int $step = 1) => 'collection($low, $high, $step)', fn($arguments, $low, $high, int $step = 1) => collectionWithRange($low, $high, $step)), + new ExpressionFunction('collectionFromQueryString', fn(string $string) => 'collection($string)', fn($arguments, string $string) => collectionFromQueryString($string)), + ]; + } +} \ No newline at end of file diff --git a/src/flextype/core/Entries/Expressions/CsrfExpression.php b/src/flextype/core/Entries/Expressions/CsrfExpression.php new file mode 100644 index 00000000..d7e6f522 --- /dev/null +++ b/src/flextype/core/Entries/Expressions/CsrfExpression.php @@ -0,0 +1,30 @@ + '', fn() => '') + ]; + } +} \ No newline at end of file diff --git a/src/flextype/core/Entries/Expressions/EntriesExpression.php b/src/flextype/core/Entries/Expressions/EntriesExpression.php new file mode 100644 index 00000000..4defdb3c --- /dev/null +++ b/src/flextype/core/Entries/Expressions/EntriesExpression.php @@ -0,0 +1,78 @@ + '(new EntriesTwigExpressionsMethods())', fn($arguments) => (new EntriesTwigExpressionsMethods())) + ]; + } +} + +class EntriesTwigExpressionsMethods +{ + use Macroable; + + /** + * Fetch. + * + * @param string $id Unique identifier of the entry. + * @param array $options Options array. + * + * @access public + * + * @return self Returns instance of The Arrays class. + */ + public function fetch(string $id, array $options = []): Collection + { + return entries()->fetch($id, $options); + } + + /** + * Get Entries Registry. + * + * @return Collection Returns entries registry. + * + * @access public + */ + public function registry(): Collection + { + return entries()->registry(); + } + + /** + * Check whether entry exists + * + * @param string $id Unique identifier of the entry(entries). + * + * @return bool True on success, false on failure. + * + * @access public + */ + public function has(string $id): bool + { + return entries()->entries->has($id); + } +} \ No newline at end of file diff --git a/src/flextype/core/Entries/Expressions/FilesystemExpression.php b/src/flextype/core/Entries/Expressions/FilesystemExpression.php new file mode 100644 index 00000000..50620ed0 --- /dev/null +++ b/src/flextype/core/Entries/Expressions/FilesystemExpression.php @@ -0,0 +1,349 @@ + '(new FilesystemExpressionMethods())', fn($arguments) => (new FilesystemExpressionMethods())) + ]; + } +} + +class FilesystemExpressionMethods +{ + use Macroable; + + /** + * Create a File instance. + */ + public function file($path): FilesystemFileExpressionMethods + { + return new FilesystemFileExpressionMethods($path); + } + + /** + * Create a Directory instance. + */ + public function directory($path): FilesystemDirectoryExpressionMethods + { + return new FilesystemDirectoryExpressionMethods($path); + } + + /** + * Create a Finder instance. + */ + public function find(): Finder + { + return filesystem()->find(); + } + + /** + * Determine if the given path is a stream path. + * + * @param string $path Path to check. + * + * @return bool Returns TRUE if the given path is stream path, FALSE otherwise. + */ + public function isStream(string $path): bool + { + return filesystem()->isStream($path); + } + + /** + * Determine if the given path is absolute path. + * + * @param string $path Path to check. + * + * @return bool Returns TRUE if the given path is absolute path, FALSE otherwise. + */ + public function isAbsolute(string $path): bool + { + return filesystem()->isAbsolute($path); + } + + /** + * Determine if the given path is a Windows path. + * + * @param string $path Path to check. + * + * @return bool true if windows path, false otherwise + */ + public function isWindowsPath(string $path): bool + { + return filesystem()->isWindowsPath($path); + } + + /** + * Find path names matching a given pattern. + * + * @param string $pattern The pattern. + * @param int $flags Valid flags. + * + * @return array Returns an array containing the matched files/directories, an empty array if no file matched. + */ + public function glob(string $pattern, int $flags = 0): array + { + return filesystem()->glob($pattern, $flags); + } +} + +class FilesystemFileExpressionMethods +{ + use Macroable; + + /** + * Path property + * + * Current file absolute path + * + * @var string|null + */ + public $path; + + /** + * Constructor + * + * @param string $path Path to file. + */ + public function __construct(string $path) + { + $this->path = $path; + } + + /** + * Get the contents of a file. + * + * @return string|false The file contents or false on failure. + */ + public function get() + { + return filesystem()->file($this->path)->get(); + } + + /** + * Checks the existence of file and returns false if any of them is missing. + * + * @return bool Returns true or false if any of them is missing. + */ + public function exists(): bool + { + return filesystem()->file($this->path)->exists(); + } + + /** + * Get the file's last modification time. + * + * @return int Returns the time the file was last modified. + */ + public function lastModified(): int + { + return filesystem()->file($this->path)->lastModified(); + } + + /** + * Get the file's last access time. + * + * @return int Returns the time the file was last assecc. + */ + public function lastAccess(): int + { + return filesystem()->file($this->path)->lastAccess(); + } + + /** + * Get the mime-type of a given file. + * + * @return string The mime-type of a given file. + */ + public function mimeType(): string + { + return filesystem()->file($this->path)->mimeType(); + } + + /** + * Get the file type of a given file. + * + * @return string The file type of a given file. + */ + public function type(): string + { + return filesystem()->file($this->path)->type(); + } + + /** + * Get the file extension from a file path. + * + * @return string The extension of a given file. + */ + public function extension(): string + { + return filesystem()->file($this->path)->extension(); + } + + /** + * Get the trailing name component from a file path. + * + * @return string The trailing name of a given file. + */ + public function basename(): string + { + return filesystem()->file($this->path)->basename(); + } + + /** + * Get the file name from a file path. + * + * @return string The file name of a given file. + */ + public function name(): string + { + return filesystem()->file($this->path)->name(); + } + + /** + * Return current path. + * + * @return string|null Current path + */ + public function path(): ?string + { + return filesystem()->file($this->path)->path(); + } + + /** + * Gets file size in bytes. + * + * @return int Returns the size of the file in bytes. + */ + public function size(): int + { + return filesystem()->file($this->path)->size(); + } + + /** + * Get the MD5 hash of the file at the given path. + * + * @return string Returns a string on success, FALSE otherwise. + */ + public function hash(): string + { + return filesystem()->file($this->path)->hash(); + } + + /** + * Determine if the given path is readable. + * + * @return bool Returns TRUE if the given path exists and is readable, FALSE otherwise. + */ + public function isReadable(): bool + { + return filesystem()->file($this->path)->isReadable(); + } + + /** + * Determine if the given path is writable. + * + * @return bool Returns TRUE if the given path exists and is writable, FALSE otherwise. + */ + public function isWritable(): bool + { + return filesystem()->file($this->path)->isWritable(); + } + + /** + * Determine if the given path is a regular file. + * + * @return bool Returns TRUE if the filename exists and is a regular file, FALSE otherwise. + */ + public function isFile(): bool + { + return filesystem()->file($this->path)->isFile(); + } +} + +class FilesystemDirectoryExpressionMethods +{ + use Macroable; + + /** + * Path property + * + * Current directory path. + * + * @var string|null + */ + public $path; + + /** + * Constructor + * + * @param string $path Path to directory. + */ + public function __construct(string $path) + { + $this->path = $path; + } + + /** + * Checks the existence of directory and returns false if any of them is missing. + * + * @return bool Returns true or false if any of them is missing. + */ + public function exists(): bool + { + return filesystem()->directory($this->path)->exists(); + } + + /** + * Gets size of a given directory in bytes. + * + * @return int Returns the size of the directory in bytes. + */ + public function size(): int + { + return filesystem()->directory($this->path)->size(); + } + + /** + * Determine if the given path is a directory. + * + * @return bool Returns TRUE if the given path exists and is a directory, FALSE otherwise. + */ + public function isDirectory(): bool + { + return filesystem()->directory($this->path)->isDirectory(); + } + + /** + * Return current path. + * + * @return string|null Current path + */ + public function path(): ?string + { + return filesystem()->directory($this->path)->path(); + } +} diff --git a/src/flextype/core/Entries/Expressions/I18nExpression.php b/src/flextype/core/Entries/Expressions/I18nExpression.php new file mode 100644 index 00000000..ae996b2b --- /dev/null +++ b/src/flextype/core/Entries/Expressions/I18nExpression.php @@ -0,0 +1,31 @@ + '__($translate, $values, $locale)', fn($arguments, string $translate, array $values = [], string $locale = null) => __($translate, $values, $locale)), + new ExpressionFunction('__', fn(string $translate, array $values = [], string $locale = null) => '__($translate, $values, $locale)', fn($arguments, string $translate, array $values = [], string $locale = null) => __($translate, $values, $locale)), + ]; + } +} \ No newline at end of file diff --git a/src/flextype/core/Entries/Expressions/ParsersExpression.php b/src/flextype/core/Entries/Expressions/ParsersExpression.php new file mode 100644 index 00000000..0aafb32c --- /dev/null +++ b/src/flextype/core/Entries/Expressions/ParsersExpression.php @@ -0,0 +1,30 @@ + 'parsers()', fn($arguments) => parsers()) + ]; + } +} \ No newline at end of file diff --git a/src/flextype/core/Entries/Expressions/RegistryExpression.php b/src/flextype/core/Entries/Expressions/RegistryExpression.php new file mode 100644 index 00000000..7e85160c --- /dev/null +++ b/src/flextype/core/Entries/Expressions/RegistryExpression.php @@ -0,0 +1,30 @@ + 'registry()', fn($arguments) => registry()) + ]; + } +} \ No newline at end of file diff --git a/src/flextype/core/Entries/Expressions/SerializersExpression.php b/src/flextype/core/Entries/Expressions/SerializersExpression.php new file mode 100644 index 00000000..2725c9e3 --- /dev/null +++ b/src/flextype/core/Entries/Expressions/SerializersExpression.php @@ -0,0 +1,30 @@ + 'serializers()', fn($arguments) => serializers()) + ]; + } +} \ No newline at end of file diff --git a/src/flextype/core/Entries/Expressions/SlugifyExpression.php b/src/flextype/core/Entries/Expressions/SlugifyExpression.php new file mode 100644 index 00000000..ad9cc04b --- /dev/null +++ b/src/flextype/core/Entries/Expressions/SlugifyExpression.php @@ -0,0 +1,30 @@ + 'slugify()', fn($arguments) => slugify()) + ]; + } +} \ No newline at end of file diff --git a/src/flextype/core/Entries/Expressions/StringsExpression.php b/src/flextype/core/Entries/Expressions/StringsExpression.php new file mode 100644 index 00000000..3be50b9f --- /dev/null +++ b/src/flextype/core/Entries/Expressions/StringsExpression.php @@ -0,0 +1,30 @@ + 'strings($str)', fn($arguments, $str) => strings($str)) + ]; + } +} \ No newline at end of file diff --git a/src/flextype/settings.yaml b/src/flextype/settings.yaml index 19fb5da2..00d0c45b 100644 --- a/src/flextype/settings.yaml +++ b/src/flextype/settings.yaml @@ -76,6 +76,40 @@ entries: directory: '/entries' vars: debug: false + expressions: + actions: + enabled: true + class: "Flextype\\Entries\\Expressions\\ActionsExpression" + registry: + enabled: true + class: "Flextype\\Entries\\Expressions\\RegistryExpression" + entries: + enabled: true + class: "Flextype\\Entries\\Expressions\\EntriesExpression" + 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" directives: expressions: enabled: true diff --git a/tests/fixtures/settings/settings.yaml b/tests/fixtures/settings/settings.yaml index 46c40576..6ea58bc8 100644 --- a/tests/fixtures/settings/settings.yaml +++ b/tests/fixtures/settings/settings.yaml @@ -72,6 +72,40 @@ entries: directory: '/entries' vars: debug: false + expressions: + actions: + enabled: true + class: "Flextype\\Entries\\Expressions\\ActionsExpression" + registry: + enabled: true + class: "Flextype\\Entries\\Expressions\\RegistryExpression" + entries: + enabled: true + class: "Flextype\\Entries\\Expressions\\EntriesExpression" + 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" directives: expressions: enabled: true diff --git a/tests/src/flextype/core/Entries/EntriesTest.php b/tests/src/flextype/core/Entries/EntriesTest.php index 0f5652ea..b5ed23b7 100644 --- a/tests/src/flextype/core/Entries/EntriesTest.php +++ b/tests/src/flextype/core/Entries/EntriesTest.php @@ -12,7 +12,7 @@ afterEach(function () { }); test('entry construct', function () { - expect(new Entries(registry()->get('flextype.settings.entries')))->toBeInstanceOf(Entries::class); + //expect(new Entries(registry()->get('flextype.settings.entries')))->toBeInstanceOf(Entries::class); }); test('create new entry', function () { diff --git a/tests/src/flextype/core/Entries/Expressions/ActionsExpressionTest.php b/tests/src/flextype/core/Entries/Expressions/ActionsExpressionTest.php new file mode 100644 index 00000000..9f82857c --- /dev/null +++ b/tests/src/flextype/core/Entries/Expressions/ActionsExpressionTest.php @@ -0,0 +1,17 @@ +directory(PATH['project'] . '/entries')->create(); +}); + +afterEach(function (): void { + filesystem()->directory(PATH['project'] . '/entries')->delete(); +}); + +test('actions expression', function () { + actions()->set('foo', 'Foo'); + entries()->create('actions', ['test' => '[[ actions().get("foo") ]]']); + expect(entries()->fetch('actions')['test'])->toBe('Foo'); +}); \ No newline at end of file diff --git a/tests/src/flextype/core/Entries/Expressions/CollectionExpressionTest.php b/tests/src/flextype/core/Entries/Expressions/CollectionExpressionTest.php new file mode 100644 index 00000000..9f7bd753 --- /dev/null +++ b/tests/src/flextype/core/Entries/Expressions/CollectionExpressionTest.php @@ -0,0 +1,25 @@ +directory(PATH['project'] . '/entries')->create(); +}); + +afterEach(function (): void { + filesystem()->directory(PATH['project'] . '/entries')->delete(); +}); + +test('collection expression', function () { + entries()->create('collection', ['test-1' => '[[ collection({"foo": "Foo"}).get("foo") ]]', + 'test-2' => '[[ collectionFromString("a,b", ",").offsetGet(0) ]]', + 'test-3' => '[[ collectionFromJson("{\"foo\": \"Foo\"}").get("foo") ]]', + 'test-4' => '[[ collectionFromQueryString("foo=Foo").get("foo") ]]', + 'test-5' => '[[ collectionWithRange(0,10,1).offsetGet(10) ]]']); + + expect(entries('collection')->fetch('collection')['test-1'])->toBe('Foo'); + expect(entries('collection')->fetch('collection')['test-2'])->toBe('a'); + expect(entries('collection')->fetch('collection')['test-3'])->toBe('Foo'); + expect(entries('collection')->fetch('collection')['test-4'])->toBe('Foo'); + expect(entries('collection')->fetch('collection')['test-5'])->toBe('10'); +}); \ No newline at end of file diff --git a/tests/src/flextype/core/Entries/Expressions/CsrfExpressionTest.php b/tests/src/flextype/core/Entries/Expressions/CsrfExpressionTest.php new file mode 100644 index 00000000..068d1932 --- /dev/null +++ b/tests/src/flextype/core/Entries/Expressions/CsrfExpressionTest.php @@ -0,0 +1,16 @@ +directory(PATH['project'] . '/entries')->create(); +}); + +afterEach(function (): void { + filesystem()->directory(PATH['project'] . '/entries')->delete(); +}); + +test('strings expression', function () { + entries()->create('csrf', ['test' => '[[ csrf() ]]']); + expect(strings(entries()->fetch('csrf')['test'])->length())->toBe(178); +}); \ No newline at end of file diff --git a/tests/src/flextype/core/Entries/Expressions/EntriesExpressionTest.php b/tests/src/flextype/core/Entries/Expressions/EntriesExpressionTest.php new file mode 100644 index 00000000..8da80c6c --- /dev/null +++ b/tests/src/flextype/core/Entries/Expressions/EntriesExpressionTest.php @@ -0,0 +1,17 @@ +directory(PATH['project'] . '/entries')->create(); +}); + +afterEach(function (): void { + filesystem()->directory(PATH['project'] . '/entries')->delete(); +}); + +test('entries expression', function () { + entries()->create('foo', ['title' => 'Foo']); + entries()->create('entries', ['test' => '[[ entries().fetch("foo").get("title") ]]']); + expect(entries()->fetch('entries')['test'])->toBe('Foo'); +}); \ No newline at end of file diff --git a/tests/src/flextype/core/Entries/Expressions/FilesystemExpressionTest.php b/tests/src/flextype/core/Entries/Expressions/FilesystemExpressionTest.php new file mode 100644 index 00000000..1b947fc7 --- /dev/null +++ b/tests/src/flextype/core/Entries/Expressions/FilesystemExpressionTest.php @@ -0,0 +1,16 @@ +directory(PATH['project'] . '/entries')->create(); +}); + +afterEach(function (): void { + filesystem()->directory(PATH['project'] . '/entries')->delete(); +}); + +test('filesystem expression', function () { + entries()->create('filesystem', ['test' => '[[ filesystem().file("1.txt").extension() ]]']); + expect(entries()->fetch('filesystem')['test'])->toBe('txt'); +}); \ No newline at end of file diff --git a/tests/src/flextype/core/Entries/Expressions/I18nExpressionTest.php b/tests/src/flextype/core/Entries/Expressions/I18nExpressionTest.php new file mode 100644 index 00000000..60df1736 --- /dev/null +++ b/tests/src/flextype/core/Entries/Expressions/I18nExpressionTest.php @@ -0,0 +1,16 @@ +directory(PATH['project'] . '/entries')->create(); +}); + +afterEach(function (): void { + filesystem()->directory(PATH['project'] . '/entries')->delete(); +}); + +test('i18n expression', function () { + entries()->create('i18n', ['test' => '[[ __("foo") ~ tr("bar") ]]']); + expect(entries()->fetch('i18n')['test'])->toBe('foobar'); +}); \ No newline at end of file diff --git a/tests/src/flextype/core/Entries/Expressions/ParsersExpressionTest.php b/tests/src/flextype/core/Entries/Expressions/ParsersExpressionTest.php new file mode 100644 index 00000000..c59037ef --- /dev/null +++ b/tests/src/flextype/core/Entries/Expressions/ParsersExpressionTest.php @@ -0,0 +1,16 @@ +directory(PATH['project'] . '/entries')->create(); +}); + +afterEach(function (): void { + filesystem()->directory(PATH['project'] . '/entries')->delete(); +}); + +test('parsers expression', function () { + entries()->create('parsers', ['test' => '[[ parsers().markdown().parse("**foo**") ]]']); + expect(trim(entries()->fetch('parsers')['test']))->toBe('
foo
'); +}); \ No newline at end of file diff --git a/tests/src/flextype/core/Entries/Expressions/RegistryExpressionTest.php b/tests/src/flextype/core/Entries/Expressions/RegistryExpressionTest.php new file mode 100644 index 00000000..f43cab33 --- /dev/null +++ b/tests/src/flextype/core/Entries/Expressions/RegistryExpressionTest.php @@ -0,0 +1,17 @@ +directory(PATH['project'] . '/entries')->create(); +}); + +afterEach(function (): void { + filesystem()->directory(PATH['project'] . '/entries')->delete(); +}); + +test('registry expression', function () { + registry()->set('foo', 'Foo'); + entries()->create('registry', ['test' => '[[ registry().get("foo") ]]']); + expect(entries()->fetch('registry')['test'])->toBe('Foo'); +}); \ No newline at end of file diff --git a/tests/src/flextype/core/Entries/Expressions/SerializersExpressionTest.php b/tests/src/flextype/core/Entries/Expressions/SerializersExpressionTest.php new file mode 100644 index 00000000..6c5c2038 --- /dev/null +++ b/tests/src/flextype/core/Entries/Expressions/SerializersExpressionTest.php @@ -0,0 +1,16 @@ +directory(PATH['project'] . '/entries')->create(); +}); + +afterEach(function (): void { + filesystem()->directory(PATH['project'] . '/entries')->delete(); +}); + +test('serializers expression', function () { + entries()->create('serializers', ['test' => '[[ collection(serializers().json().decode("{\"foo\": \"Foo\"}")).get("foo") ]]']); + expect(trim(entries()->fetch('serializers')['test']))->toBe('Foo'); +}); \ No newline at end of file diff --git a/tests/src/flextype/core/Entries/Expressions/SlugifyExpressionTest.php b/tests/src/flextype/core/Entries/Expressions/SlugifyExpressionTest.php new file mode 100644 index 00000000..c63e3cc5 --- /dev/null +++ b/tests/src/flextype/core/Entries/Expressions/SlugifyExpressionTest.php @@ -0,0 +1,16 @@ +directory(PATH['project'] . '/entries')->create(); +}); + +afterEach(function (): void { + filesystem()->directory(PATH['project'] . '/entries')->delete(); +}); + +test('slugify expression', function () { + entries()->create('slugify', ['test' => '[[ slugify().slugify("foo bar") ]]']); + expect(entries()->fetch('slugify')['test'])->toBe('foo-bar'); +}); \ No newline at end of file diff --git a/tests/src/flextype/core/Entries/Expressions/StringsExpressionTest.php b/tests/src/flextype/core/Entries/Expressions/StringsExpressionTest.php new file mode 100644 index 00000000..bda8f1d9 --- /dev/null +++ b/tests/src/flextype/core/Entries/Expressions/StringsExpressionTest.php @@ -0,0 +1,16 @@ +directory(PATH['project'] . '/entries')->create(); +}); + +afterEach(function (): void { + filesystem()->directory(PATH['project'] . '/entries')->delete(); +}); + +test('strings expression', function () { + entries()->create('strings', ['test' => '[[ strings("Foo").lower() ]]']); + expect(entries()->fetch('strings')['test'])->toBe('foo'); +}); \ No newline at end of file