From cd4e1d2d66097f06a8a91f1bc4460926fd2d92c6 Mon Sep 17 00:00:00 2001 From: Nikita Hovratov Date: Thu, 1 Aug 2024 23:14:44 +0200 Subject: [PATCH] [!!!][TASK] Introduce AssetPathViewHelper The new AssetPathViewHelper can be used inside Content Blocks templates to get the EXT path of the current block. This can be used in combination with f:asset and f:uri.resource VH from Core. ViewHelpers removed: - cb:asset.css - cb:asset.script - cb:uri.resource --- .../accordion/Source/EditorPreview.html | 2 +- .../accordion/Source/Frontend.html | 4 +- .../card_group/Source/EditorPreview.html | 2 +- .../card_group/Source/Frontend.html | 2 +- .../cta/Source/EditorPreview.html | 2 +- .../ContentElements/cta/Source/Frontend.html | 2 +- .../icon_group/Source/EditorPreview.html | 2 +- .../icon_group/Source/Frontend.html | 2 +- .../imageslider/Source/EditorPreview.html | 2 +- .../imageslider/Source/Frontend.html | 6 +- .../ContentElements/tabs/Source/Frontend.html | 4 +- Classes/ViewHelpers/Asset/CssViewHelper.php | 141 ------------------ .../ViewHelpers/Asset/ScriptViewHelper.php | 139 ----------------- ...ViewHelper.php => AssetPathViewHelper.php} | 29 ++-- Documentation/Templating/Index.rst | 36 +---- .../Source/EditorPreview.html | 2 +- .../content-element-a/Source/Frontend.html | 4 +- .../Source/EditorPreview.html | 2 +- .../content-element-b/Source/Frontend.html | 4 +- .../simple-with-basics/Source/Frontend.html | 4 +- .../simple/Source/Frontend.html | 8 +- .../simple2/Source/Frontend.html | 4 +- .../ViewHelpers/Asset/CssViewHelperTest.php | 61 -------- .../Asset/ScriptViewHelperTest.php | 61 -------- ...erTest.php => AssetPathViewHelperTest.php} | 10 +- 25 files changed, 50 insertions(+), 485 deletions(-) delete mode 100644 Classes/ViewHelpers/Asset/CssViewHelper.php delete mode 100644 Classes/ViewHelpers/Asset/ScriptViewHelper.php rename Classes/ViewHelpers/{Uri/ResourceViewHelper.php => AssetPathViewHelper.php} (59%) delete mode 100644 Tests/Functional/ViewHelpers/Asset/CssViewHelperTest.php delete mode 100644 Tests/Functional/ViewHelpers/Asset/ScriptViewHelperTest.php rename Tests/Functional/ViewHelpers/{Uri/ResourceViewHelperTest.php => AssetPathViewHelperTest.php} (79%) diff --git a/Build/content-blocks-examples/ContentBlocks/ContentElements/accordion/Source/EditorPreview.html b/Build/content-blocks-examples/ContentBlocks/ContentElements/accordion/Source/EditorPreview.html index 5d3e8cce..9a1e8670 100644 --- a/Build/content-blocks-examples/ContentBlocks/ContentElements/accordion/Source/EditorPreview.html +++ b/Build/content-blocks-examples/ContentBlocks/ContentElements/accordion/Source/EditorPreview.html @@ -5,7 +5,7 @@ data-namespace-typo3-fluid="true" > - +
diff --git a/Build/content-blocks-examples/ContentBlocks/ContentElements/accordion/Source/Frontend.html b/Build/content-blocks-examples/ContentBlocks/ContentElements/accordion/Source/Frontend.html index f3388aff..07d99f43 100644 --- a/Build/content-blocks-examples/ContentBlocks/ContentElements/accordion/Source/Frontend.html +++ b/Build/content-blocks-examples/ContentBlocks/ContentElements/accordion/Source/Frontend.html @@ -4,8 +4,8 @@ data-namespace-typo3-fluid="true" > - - + +
diff --git a/Build/content-blocks-examples/ContentBlocks/ContentElements/card_group/Source/EditorPreview.html b/Build/content-blocks-examples/ContentBlocks/ContentElements/card_group/Source/EditorPreview.html index 77b81007..6395732c 100644 --- a/Build/content-blocks-examples/ContentBlocks/ContentElements/card_group/Source/EditorPreview.html +++ b/Build/content-blocks-examples/ContentBlocks/ContentElements/card_group/Source/EditorPreview.html @@ -5,7 +5,7 @@ data-namespace-typo3-fluid="true" > - +
diff --git a/Build/content-blocks-examples/ContentBlocks/ContentElements/card_group/Source/Frontend.html b/Build/content-blocks-examples/ContentBlocks/ContentElements/card_group/Source/Frontend.html index 18c13f75..822a8283 100644 --- a/Build/content-blocks-examples/ContentBlocks/ContentElements/card_group/Source/Frontend.html +++ b/Build/content-blocks-examples/ContentBlocks/ContentElements/card_group/Source/Frontend.html @@ -4,7 +4,7 @@ data-namespace-typo3-fluid="true" > - +
diff --git a/Build/content-blocks-examples/ContentBlocks/ContentElements/cta/Source/EditorPreview.html b/Build/content-blocks-examples/ContentBlocks/ContentElements/cta/Source/EditorPreview.html index 838ecd4d..f976aa25 100644 --- a/Build/content-blocks-examples/ContentBlocks/ContentElements/cta/Source/EditorPreview.html +++ b/Build/content-blocks-examples/ContentBlocks/ContentElements/cta/Source/EditorPreview.html @@ -4,7 +4,7 @@ data-namespace-typo3-fluid="true" > - +

{data.header}

diff --git a/Build/content-blocks-examples/ContentBlocks/ContentElements/cta/Source/Frontend.html b/Build/content-blocks-examples/ContentBlocks/ContentElements/cta/Source/Frontend.html index 23406278..8d610e3e 100644 --- a/Build/content-blocks-examples/ContentBlocks/ContentElements/cta/Source/Frontend.html +++ b/Build/content-blocks-examples/ContentBlocks/ContentElements/cta/Source/Frontend.html @@ -4,7 +4,7 @@ data-namespace-typo3-fluid="true" > - +
diff --git a/Build/content-blocks-examples/ContentBlocks/ContentElements/icon_group/Source/EditorPreview.html b/Build/content-blocks-examples/ContentBlocks/ContentElements/icon_group/Source/EditorPreview.html index b9dcef1a..2043f76f 100644 --- a/Build/content-blocks-examples/ContentBlocks/ContentElements/icon_group/Source/EditorPreview.html +++ b/Build/content-blocks-examples/ContentBlocks/ContentElements/icon_group/Source/EditorPreview.html @@ -4,7 +4,7 @@ data-namespace-typo3-fluid="true" > - +
diff --git a/Build/content-blocks-examples/ContentBlocks/ContentElements/icon_group/Source/Frontend.html b/Build/content-blocks-examples/ContentBlocks/ContentElements/icon_group/Source/Frontend.html index c12edfdf..21a260aa 100644 --- a/Build/content-blocks-examples/ContentBlocks/ContentElements/icon_group/Source/Frontend.html +++ b/Build/content-blocks-examples/ContentBlocks/ContentElements/icon_group/Source/Frontend.html @@ -4,7 +4,7 @@ data-namespace-typo3-fluid="true" > - +
diff --git a/Build/content-blocks-examples/ContentBlocks/ContentElements/imageslider/Source/EditorPreview.html b/Build/content-blocks-examples/ContentBlocks/ContentElements/imageslider/Source/EditorPreview.html index 237e68c5..bd308b93 100644 --- a/Build/content-blocks-examples/ContentBlocks/ContentElements/imageslider/Source/EditorPreview.html +++ b/Build/content-blocks-examples/ContentBlocks/ContentElements/imageslider/Source/EditorPreview.html @@ -4,7 +4,7 @@ data-namespace-typo3-fluid="true" > - +
diff --git a/Build/content-blocks-examples/ContentBlocks/ContentElements/imageslider/Source/Frontend.html b/Build/content-blocks-examples/ContentBlocks/ContentElements/imageslider/Source/Frontend.html index 83510bf2..9f562011 100644 --- a/Build/content-blocks-examples/ContentBlocks/ContentElements/imageslider/Source/Frontend.html +++ b/Build/content-blocks-examples/ContentBlocks/ContentElements/imageslider/Source/Frontend.html @@ -4,9 +4,9 @@ data-namespace-typo3-fluid="true" > - - - + + +
diff --git a/Build/content-blocks-examples/ContentBlocks/ContentElements/tabs/Source/Frontend.html b/Build/content-blocks-examples/ContentBlocks/ContentElements/tabs/Source/Frontend.html index 48d0a15b..f1da2119 100644 --- a/Build/content-blocks-examples/ContentBlocks/ContentElements/tabs/Source/Frontend.html +++ b/Build/content-blocks-examples/ContentBlocks/ContentElements/tabs/Source/Frontend.html @@ -4,8 +4,8 @@ data-namespace-typo3-fluid="true" > - - + +
diff --git a/Classes/ViewHelpers/Asset/CssViewHelper.php b/Classes/ViewHelpers/Asset/CssViewHelper.php deleted file mode 100644 index 8f114d33..00000000 --- a/Classes/ViewHelpers/Asset/CssViewHelper.php +++ /dev/null @@ -1,141 +0,0 @@ - - * - */ -final class CssViewHelper extends AbstractTagBasedViewHelper -{ - /** - * This VH does not produce direct output, thus does not need to be wrapped in an escaping node - * - * @var bool - */ - protected $escapeOutput = false; - - /** - * Rendered children string is passed as CSS code, - * there is no point in HTML encoding anything from that. - * - * @var bool - */ - protected $escapeChildren = true; - - protected AssetCollector $assetCollector; - protected ContentBlockRegistry $contentBlockRegistry; - - public function injectAssetCollector(AssetCollector $assetCollector): void - { - $this->assetCollector = $assetCollector; - } - - public function injectContentBlockRegistry(ContentBlockRegistry $contentBlockRegistry): void - { - $this->contentBlockRegistry = $contentBlockRegistry; - } - - public function initialize(): void - { - // Add a tag builder, that does not html encode values, because rendering with encoding happens in AssetRenderer - $this->setTagBuilder( - new class () extends TagBuilder { - public function addAttribute($attributeName, $attributeValue, $escapeSpecialCharacters = false): void - { - parent::addAttribute($attributeName, $attributeValue, false); - } - } - ); - parent::initialize(); - } - - public function initializeArguments(): void - { - parent::initializeArguments(); - $this->registerUniversalTagAttributes(); - $this->registerTagAttribute('file', 'string', 'Define which file should be delivered from within the "Assets" directory.', true); - $this->registerTagAttribute('name', 'string', 'Define the name (vendor/package) of the content block.'); - $this->registerTagAttribute('as', 'string', 'Define the type of content being loaded (For rel="preload" or rel="prefetch" only).'); - $this->registerTagAttribute('crossorigin', 'string', 'Define how to handle crossorigin requests.'); - $this->registerTagAttribute('disabled', 'bool', 'Define whether or not the described stylesheet should be loaded and applied to the document.'); - $this->registerTagAttribute('hreflang', 'string', 'Define the language of the resource (Only to be used if \'href\' is set).'); - $this->registerTagAttribute('importance', 'string', 'Define the relative fetch priority of the resource.'); - $this->registerTagAttribute('integrity', 'string', 'Define base64-encoded cryptographic hash of the resource that allows browsers to verify what they fetch.'); - $this->registerTagAttribute('media', 'string', 'Define which media type the resources applies to.'); - $this->registerTagAttribute('referrerpolicy', 'string', 'Define which referrer is sent when fetching the resource.'); - $this->registerTagAttribute('rel', 'string', 'Define the relationship of the target object to the link object.'); - $this->registerTagAttribute('sizes', 'string', 'Define the icon size of the resource.'); - $this->registerTagAttribute('type', 'string', 'Define the MIME type (usually \'text/css\').'); - $this->registerTagAttribute('nonce', 'string', 'Define a cryptographic nonce (number used once) used to whitelist inline styles in a style-src Content-Security-Policy.'); - $this->registerArgument('useNonce', 'bool', 'Whether to use the global nonce value', false, false); - $this->registerArgument( - 'identifier', - 'string', - 'Use this identifier within templates to only inject your CSS once, even though it is added multiple times.', - true - ); - $this->registerArgument( - 'priority', - 'boolean', - 'Define whether the CSS should be included before other CSS. CSS will always be output in the tag.', - false, - false - ); - } - - public function render(): string - { - $identifier = (string)$this->arguments['identifier']; - $attributes = $this->tag->getAttributes(); - - // boolean attributes shall output attr="attr" if set - if ($attributes['disabled'] ?? false) { - $attributes['disabled'] = 'disabled'; - } - - $name = $attributes['name'] ?? $this->templateVariableContainer->get('data._name'); - $file = $attributes['file']; - unset( - $attributes['name'], - $attributes['file'], - ); - $contentBlock = $this->contentBlockRegistry->getContentBlock($name); - $extPath = ContentBlockPathUtility::getHostExtPublicContentBlockPath($contentBlock->getHostExtension(), $name); - $href = $extPath . '/' . $file; - $options = [ - 'priority' => $this->arguments['priority'], - 'useNonce' => $this->arguments['useNonce'], - ]; - $this->assetCollector->addStyleSheet($identifier, $href, $attributes, $options); - return ''; - } -} diff --git a/Classes/ViewHelpers/Asset/ScriptViewHelper.php b/Classes/ViewHelpers/Asset/ScriptViewHelper.php deleted file mode 100644 index 90602622..00000000 --- a/Classes/ViewHelpers/Asset/ScriptViewHelper.php +++ /dev/null @@ -1,139 +0,0 @@ - - * - */ -final class ScriptViewHelper extends AbstractTagBasedViewHelper -{ - /** - * This VH does not produce direct output, thus does not need to be wrapped in an escaping node - * - * @var bool - */ - protected $escapeOutput = false; - - /** - * Rendered children string is passed as JavaScript code, - * there is no point in HTML encoding anything from that. - * - * @var bool - */ - protected $escapeChildren = false; - - protected AssetCollector $assetCollector; - protected ContentBlockRegistry $contentBlockRegistry; - - public function injectAssetCollector(AssetCollector $assetCollector): void - { - $this->assetCollector = $assetCollector; - } - - public function injectContentBlockRegistry(ContentBlockRegistry $contentBlockRegistry): void - { - $this->contentBlockRegistry = $contentBlockRegistry; - } - - public function initialize(): void - { - // Add a tag builder, that does not html encode values, because rendering with encoding happens in AssetRenderer - $this->setTagBuilder( - new class () extends TagBuilder { - public function addAttribute($attributeName, $attributeValue, $escapeSpecialCharacters = false): void - { - parent::addAttribute($attributeName, $attributeValue, false); - } - } - ); - parent::initialize(); - } - - public function initializeArguments(): void - { - parent::initializeArguments(); - $this->registerUniversalTagAttributes(); - $this->registerTagAttribute('file', 'string', 'Define which file should be delivered from within the "Assets" directory.', true); - $this->registerTagAttribute('name', 'string', 'Define the name (vendor/dir) of the content block.'); - $this->registerTagAttribute('async', 'bool', 'Define that the script will be fetched in parallel to parsing and evaluation.'); - $this->registerTagAttribute('crossorigin', 'string', 'Define how to handle crossorigin requests.'); - $this->registerTagAttribute('defer', 'bool', 'Define that the script is meant to be executed after the document has been parsed.'); - $this->registerTagAttribute('integrity', 'string', 'Define base64-encoded cryptographic hash of the resource that allows browsers to verify what they fetch.'); - $this->registerTagAttribute('nomodule', 'bool', 'Define that the script should not be executed in browsers that support ES2015 modules.'); - $this->registerTagAttribute('nonce', 'string', 'Define a cryptographic nonce (number used once) used to whitelist inline styles in a style-src Content-Security-Policy.'); - $this->registerTagAttribute('referrerpolicy', 'string', 'Define which referrer is sent when fetching the resource.'); - $this->registerTagAttribute('type', 'string', 'Define the MIME type (usually \'text/javascript\').'); - $this->registerArgument('useNonce', 'bool', 'Whether to use the global nonce value', false, false); - $this->registerArgument( - 'identifier', - 'string', - 'Use this identifier within templates to only inject your JS once, even though it is added multiple times.', - true - ); - $this->registerArgument( - 'priority', - 'boolean', - 'Define whether the JavaScript should be put in the tag above-the-fold or somewhere in the body part.', - false, - false - ); - } - - public function render(): string - { - $identifier = (string)$this->arguments['identifier']; - $attributes = $this->tag->getAttributes(); - - // boolean attributes shall output attr="attr" if set - foreach (['async', 'defer', 'nomodule'] as $_attr) { - if ($attributes[$_attr] ?? false) { - $attributes[$_attr] = $_attr; - } - } - - $name = $attributes['name'] ?? $this->templateVariableContainer->get('data._name'); - $file = $attributes['file']; - unset( - $attributes['name'], - $attributes['file'] - ); - $contentBlock = $this->contentBlockRegistry->getContentBlock($name); - $extPath = ContentBlockPathUtility::getHostExtPublicContentBlockPath($contentBlock->getHostExtension(), $name); - $src = $extPath . '/' . $file; - $options = [ - 'priority' => $this->arguments['priority'], - 'useNonce' => $this->arguments['useNonce'], - ]; - $this->assetCollector->addJavaScript($identifier, $src, $attributes, $options); - return ''; - } -} diff --git a/Classes/ViewHelpers/Uri/ResourceViewHelper.php b/Classes/ViewHelpers/AssetPathViewHelper.php similarity index 59% rename from Classes/ViewHelpers/Uri/ResourceViewHelper.php rename to Classes/ViewHelpers/AssetPathViewHelper.php index e4e4e424..0cd6163c 100644 --- a/Classes/ViewHelpers/Uri/ResourceViewHelper.php +++ b/Classes/ViewHelpers/AssetPathViewHelper.php @@ -15,49 +15,40 @@ * The TYPO3 project - inspiring people to share! */ -namespace TYPO3\CMS\ContentBlocks\ViewHelpers\Uri; +namespace TYPO3\CMS\ContentBlocks\ViewHelpers; use TYPO3\CMS\ContentBlocks\Registry\ContentBlockRegistry; use TYPO3\CMS\ContentBlocks\Utility\ContentBlockPathUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; -use TYPO3\CMS\Core\Utility\PathUtility; use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic; use TYPO3Fluid\Fluid\Exception; -class ResourceViewHelper extends AbstractViewHelper +class AssetPathViewHelper extends AbstractViewHelper { use CompileWithRenderStatic; public function initializeArguments(): void { - $this->registerArgument('path', 'string', 'The file path of the resource (relative to Assets directory of the Content Block).', true); $this->registerArgument('name', 'string', 'Target Content Block name. If not set, the current Content Block will be used'); - $this->registerArgument('absolute', 'bool', 'If set, an absolute URI is rendered', false, false); } - /** - * Render the URI to the resource. The filename is used from child content. - */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string - { + public static function renderStatic( + array $arguments, + \Closure $renderChildrenClosure, + RenderingContextInterface $renderingContext + ): string { $name = (string)($arguments['name'] ?? $renderingContext->getVariableProvider()->get('data._name')); - $filePath = $arguments['path']; if ($name === '') { throw new Exception(__CLASS__ . ' seemingly called outside Content Blocks context.', 1701198923); } $contentBlockRegistry = GeneralUtility::makeInstance(ContentBlockRegistry::class); $contentBlock = $contentBlockRegistry->getContentBlock($name); - $absoluteAssetPath = ContentBlockPathUtility::getHostAbsolutePublicContentBlockPath( + $assetExtPath = ContentBlockPathUtility::getHostExtPublicContentBlockPath( $contentBlock->getHostExtension(), - $contentBlock->getName() + $name ); - $absoluteFilePath = $absoluteAssetPath . '/' . $filePath; - $uri = PathUtility::getAbsoluteWebPath($absoluteFilePath); - if ($arguments['absolute']) { - $uri = GeneralUtility::locationHeaderUrl($uri); - } - return $uri; + return $assetExtPath; } } diff --git a/Documentation/Templating/Index.rst b/Documentation/Templating/Index.rst index a48d4d1b..2960f98e 100644 --- a/Documentation/Templating/Index.rst +++ b/Documentation/Templating/Index.rst @@ -100,17 +100,17 @@ template in **Source/EditorPreview.html**. Asset ViewHelpers ================= -Content Blocks provides new asset ViewHelpers to access assets from within the -current Content Block in the template. These ViewHelpers look for the given file -in the `Assets` directory. +Content Blocks provides a new AssetPathViewHelper to access assets from within +the current Content Block in the template. These ViewHelpers look for the given +file in the `Assets` directory. .. code-block:: html - + - + The information of the current Content Block is stored in :html:`{data}`. This means if you use an asset ViewHelper in a partial, you have to provide @@ -120,31 +120,7 @@ means if you use an asset ViewHelper in a partial, you have to provide .. code-block:: html - - - -Resource URI ViewHelper -======================= - -The ViewHelper can be used to generate a URI relative to the Assets folder. - -.. code-block:: html - - - -To generate an absolute URI, activate the :html:`absolute` parameter. - -.. code-block:: html - - - -As described above in the asset ViewHelper, the :html:`{data}` variable is -required to resolve the Content Block automatically. You can also set -:html:`name` by hand: - -.. code-block:: html - - + Translation ViewHelper ====================== diff --git a/Tests/Fixtures/Extensions/test_content_blocks_a/ContentBlocks/ContentElements/content-element-a/Source/EditorPreview.html b/Tests/Fixtures/Extensions/test_content_blocks_a/ContentBlocks/ContentElements/content-element-a/Source/EditorPreview.html index 284d3952..bf096db0 100644 --- a/Tests/Fixtures/Extensions/test_content_blocks_a/ContentBlocks/ContentElements/content-element-a/Source/EditorPreview.html +++ b/Tests/Fixtures/Extensions/test_content_blocks_a/ContentBlocks/ContentElements/content-element-a/Source/EditorPreview.html @@ -4,4 +4,4 @@ data-namespace-typo3-fluid="true" > - + diff --git a/Tests/Fixtures/Extensions/test_content_blocks_a/ContentBlocks/ContentElements/content-element-a/Source/Frontend.html b/Tests/Fixtures/Extensions/test_content_blocks_a/ContentBlocks/ContentElements/content-element-a/Source/Frontend.html index db78ee68..3d4711ae 100644 --- a/Tests/Fixtures/Extensions/test_content_blocks_a/ContentBlocks/ContentElements/content-element-a/Source/Frontend.html +++ b/Tests/Fixtures/Extensions/test_content_blocks_a/ContentBlocks/ContentElements/content-element-a/Source/Frontend.html @@ -4,5 +4,5 @@ data-namespace-typo3-fluid="true" > - - + + diff --git a/Tests/Fixtures/Extensions/test_content_blocks_b/ContentBlocks/ContentElements/content-element-b/Source/EditorPreview.html b/Tests/Fixtures/Extensions/test_content_blocks_b/ContentBlocks/ContentElements/content-element-b/Source/EditorPreview.html index 284d3952..bf096db0 100644 --- a/Tests/Fixtures/Extensions/test_content_blocks_b/ContentBlocks/ContentElements/content-element-b/Source/EditorPreview.html +++ b/Tests/Fixtures/Extensions/test_content_blocks_b/ContentBlocks/ContentElements/content-element-b/Source/EditorPreview.html @@ -4,4 +4,4 @@ data-namespace-typo3-fluid="true" > - + diff --git a/Tests/Fixtures/Extensions/test_content_blocks_b/ContentBlocks/ContentElements/content-element-b/Source/Frontend.html b/Tests/Fixtures/Extensions/test_content_blocks_b/ContentBlocks/ContentElements/content-element-b/Source/Frontend.html index 8c117802..5f7120d6 100644 --- a/Tests/Fixtures/Extensions/test_content_blocks_b/ContentBlocks/ContentElements/content-element-b/Source/Frontend.html +++ b/Tests/Fixtures/Extensions/test_content_blocks_b/ContentBlocks/ContentElements/content-element-b/Source/Frontend.html @@ -4,8 +4,8 @@ data-namespace-typo3-fluid="true" > - - + + diff --git a/Tests/Fixtures/Extensions/test_content_blocks_c/ContentBlocks/ContentElements/simple-with-basics/Source/Frontend.html b/Tests/Fixtures/Extensions/test_content_blocks_c/ContentBlocks/ContentElements/simple-with-basics/Source/Frontend.html index 822094ce..a9e3a16d 100644 --- a/Tests/Fixtures/Extensions/test_content_blocks_c/ContentBlocks/ContentElements/simple-with-basics/Source/Frontend.html +++ b/Tests/Fixtures/Extensions/test_content_blocks_c/ContentBlocks/ContentElements/simple-with-basics/Source/Frontend.html @@ -4,8 +4,8 @@ data-namespace-typo3-fluid="true" > - - + +

{data.header}

{data.bodytext}

diff --git a/Tests/Fixtures/Extensions/test_content_blocks_c/ContentBlocks/ContentElements/simple/Source/Frontend.html b/Tests/Fixtures/Extensions/test_content_blocks_c/ContentBlocks/ContentElements/simple/Source/Frontend.html index 81914dba..45aba544 100644 --- a/Tests/Fixtures/Extensions/test_content_blocks_c/ContentBlocks/ContentElements/simple/Source/Frontend.html +++ b/Tests/Fixtures/Extensions/test_content_blocks_c/ContentBlocks/ContentElements/simple/Source/Frontend.html @@ -4,8 +4,8 @@ data-namespace-typo3-fluid="true" > - - + +

{data.header}

{data.bodytext}

@@ -18,5 +18,5 @@

{data.header}

creationDate:{data.creationDate}

updateDate:{data.updateDate}

- - + + diff --git a/Tests/Fixtures/Extensions/test_content_blocks_c/ContentBlocks/ContentElements/simple2/Source/Frontend.html b/Tests/Fixtures/Extensions/test_content_blocks_c/ContentBlocks/ContentElements/simple2/Source/Frontend.html index 822094ce..d3b8852e 100644 --- a/Tests/Fixtures/Extensions/test_content_blocks_c/ContentBlocks/ContentElements/simple2/Source/Frontend.html +++ b/Tests/Fixtures/Extensions/test_content_blocks_c/ContentBlocks/ContentElements/simple2/Source/Frontend.html @@ -4,8 +4,8 @@ data-namespace-typo3-fluid="true" > - - + +

{data.header}

{data.bodytext}

diff --git a/Tests/Functional/ViewHelpers/Asset/CssViewHelperTest.php b/Tests/Functional/ViewHelpers/Asset/CssViewHelperTest.php deleted file mode 100644 index 5d682c75..00000000 --- a/Tests/Functional/ViewHelpers/Asset/CssViewHelperTest.php +++ /dev/null @@ -1,61 +0,0 @@ -get(RenderingContextFactory::class)->create(); - $context->getTemplatePaths()->setTemplateSource(''); - - (new TemplateView($context))->render(); - - $collectedStyleSheets = $this->get(AssetCollector::class)->getStyleSheets(); - self::assertSame('EXT:test_content_blocks_b/Resources/Public/ContentBlocks/typo3tests/content-element-b/Frontend.css', $collectedStyleSheets['test']['source']); - self::assertSame([], $collectedStyleSheets['test']['attributes']); - } - - #[Test] - public function booleanAttributesAreProperlyConverted(): void - { - $context = $this->get(RenderingContextFactory::class)->create(); - $context->getTemplatePaths()->setTemplateSource(''); - - (new TemplateView($context))->render(); - - $collectedStyleSheets = $this->get(AssetCollector::class)->getStyleSheets(); - self::assertSame('EXT:test_content_blocks_a/Resources/Public/ContentBlocks/typo3tests/content-element-a/my.css', $collectedStyleSheets['test']['source']); - self::assertSame(['disabled' => 'disabled'], $collectedStyleSheets['test']['attributes']); - } -} diff --git a/Tests/Functional/ViewHelpers/Asset/ScriptViewHelperTest.php b/Tests/Functional/ViewHelpers/Asset/ScriptViewHelperTest.php deleted file mode 100644 index 6e084b10..00000000 --- a/Tests/Functional/ViewHelpers/Asset/ScriptViewHelperTest.php +++ /dev/null @@ -1,61 +0,0 @@ -get(RenderingContextFactory::class)->create(); - $context->getTemplatePaths()->setTemplateSource(''); - - (new TemplateView($context))->render(); - - $collectedJavaScripts = $this->get(AssetCollector::class)->getJavaScripts(); - self::assertSame('EXT:test_content_blocks_b/Resources/Public/ContentBlocks/typo3tests/content-element-b/Frontend.js', $collectedJavaScripts['test']['source']); - self::assertSame([], $collectedJavaScripts['test']['attributes']); - } - - #[Test] - public function booleanAttributesAreProperlyConverted(): void - { - $context = $this->get(RenderingContextFactory::class)->create(); - $context->getTemplatePaths()->setTemplateSource(''); - - (new TemplateView($context))->render(); - - $collectedJavaScripts = $this->get(AssetCollector::class)->getJavaScripts(); - self::assertSame('EXT:test_content_blocks_a/Resources/Public/ContentBlocks/typo3tests/content-element-a/my.js', $collectedJavaScripts['test']['source']); - self::assertSame(['async' => 'async', 'defer' => 'defer', 'nomodule' => 'nomodule'], $collectedJavaScripts['test']['attributes']); - } -} diff --git a/Tests/Functional/ViewHelpers/Uri/ResourceViewHelperTest.php b/Tests/Functional/ViewHelpers/AssetPathViewHelperTest.php similarity index 79% rename from Tests/Functional/ViewHelpers/Uri/ResourceViewHelperTest.php rename to Tests/Functional/ViewHelpers/AssetPathViewHelperTest.php index c649c025..9828841f 100644 --- a/Tests/Functional/ViewHelpers/Uri/ResourceViewHelperTest.php +++ b/Tests/Functional/ViewHelpers/AssetPathViewHelperTest.php @@ -15,7 +15,7 @@ * The TYPO3 project - inspiring people to share! */ -namespace TYPO3\CMS\ContentBlocks\Tests\Functional\ViewHelpers\Uri; +namespace TYPO3\CMS\ContentBlocks\Tests\Functional\ViewHelpers; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; @@ -24,7 +24,7 @@ use TYPO3Fluid\Fluid\Exception; use TYPO3Fluid\Fluid\View\TemplateView; -final class ResourceViewHelperTest extends FunctionalTestCase +final class AssetPathViewHelperTest extends FunctionalTestCase { protected bool $initializeDatabase = false; @@ -39,15 +39,15 @@ public function renderingFailsWithNoContentBlockName() $this->expectException(Exception::class); $this->expectExceptionCode(1701198923); $context = $this->get(RenderingContextFactory::class)->create(); - $context->getTemplatePaths()->setTemplateSource(''); + $context->getTemplatePaths()->setTemplateSource('{cb:assetPath()}'); (new TemplateView($context))->render(); } public static function renderDataProvider(): \Generator { yield 'render returns URI' => [ - '', - 'typo3conf/ext/test_content_blocks_b/Resources/Public/ContentBlocks/typo3tests/content-element-b/Extension.svg', + '{cb:assetPath(name: "typo3tests/content-element-b")}/Extension.svg', + 'EXT:test_content_blocks_b/Resources/Public/ContentBlocks/typo3tests/content-element-b/Extension.svg', ]; }