-
- {{ form_row(form.template) }}
-
-
+
+
+
+ {{ form_widget(form.templates) }}
diff --git a/src/Twig/Runtime/RenderBlockRuntime.php b/src/Twig/Runtime/RenderBlockRuntime.php
index 7f98f275..fc76d405 100644
--- a/src/Twig/Runtime/RenderBlockRuntime.php
+++ b/src/Twig/Runtime/RenderBlockRuntime.php
@@ -39,8 +39,10 @@ public function renderBlock(string $code, ?string $template = null, ProductInter
return '';
}
+ $blockTemplate = $template ?? $block->getTemplate();
+
return $this->templatingEngine->render(
- $template ?? self::DEFAULT_TEMPLATE,
+ $blockTemplate ?? self::DEFAULT_TEMPLATE,
[
'content' => $this->contentElementRendererStrategy->render($block),
'context' => $context,
diff --git a/tests/Behat/Context/Setup/ContentTemplateContext.php b/tests/Behat/Context/Setup/ContentTemplateContext.php
new file mode 100644
index 00000000..a86f23df
--- /dev/null
+++ b/tests/Behat/Context/Setup/ContentTemplateContext.php
@@ -0,0 +1,86 @@
+createTemplate($name, $type);
+
+ $this->saveTemplate($template);
+ }
+
+ /**
+ * @Given there are :firstContentElement and :secondContentElement content elements in this template
+ */
+ public function thereAreContentElementsInThisTemplate(string $firstContentElement, string $secondContentElement): void
+ {
+ /** @var TemplateInterface $template */
+ $template = $this->sharedStorage->get('template');
+ $template->setContentElements([
+ ['type' => ContentElementHelper::getContentElementValueByName($firstContentElement)],
+ ['type' => ContentElementHelper::getContentElementValueByName($secondContentElement)],
+ ]);
+
+ $this->saveTemplate($template);
+ }
+
+ /**
+ * @Given there is an existing content template named :templateName with :type type that contains :contentElements content elements
+ */
+ public function thereIsAnExistingTemplateThatContainsContentElements(string $templateName, string $type, string $contentElements): void
+ {
+ $template = $this->createTemplate($templateName, $type);
+
+ $contentElements = explode(', ', $contentElements);
+
+ $contentElementsArray = [];
+ foreach ($contentElements as $contentElement) {
+ $contentElementsArray[] = ['type' => ContentElementHelper::getContentElementValueByName($contentElement)];
+ }
+
+ $template->setContentElements($contentElementsArray);
+
+ $this->saveTemplate($template);
+ }
+
+ private function createTemplate(string $name, ?string $type = null): TemplateInterface
+ {
+ /** @var TemplateInterface $template */
+ $template = $this->templateFactory->createNew();
+ $template->setName($name);
+
+ if (null !== $type) {
+ $template->setType($type);
+ }
+
+ return $template;
+ }
+
+ private function saveTemplate(TemplateInterface $template): void
+ {
+ $this->templateRepository->add($template);
+ $this->sharedStorage->set('template', $template);
+ }
+}
diff --git a/tests/Behat/Context/Setup/TemplateContext.php b/tests/Behat/Context/Setup/TemplateContext.php
index 7ed942df..fa8883b1 100644
--- a/tests/Behat/Context/Setup/TemplateContext.php
+++ b/tests/Behat/Context/Setup/TemplateContext.php
@@ -5,82 +5,65 @@
namespace Tests\Sylius\CmsPlugin\Behat\Context\Setup;
use Behat\Behat\Context\Context;
-use Sylius\Behat\Service\SharedStorageInterface;
-use Sylius\CmsPlugin\Entity\TemplateInterface;
-use Sylius\CmsPlugin\Repository\TemplateRepositoryInterface;
-use Sylius\Component\Resource\Factory\FactoryInterface;
-use Tests\Sylius\CmsPlugin\Behat\Helpers\ContentElementHelper;
+use Symfony\Component\Filesystem\Filesystem;
+use Symfony\Component\Yaml\Yaml;
final class TemplateContext implements Context
{
- public function __construct(
- private FactoryInterface $templateFactory,
- private SharedStorageInterface $sharedStorage,
- private TemplateRepositoryInterface $templateRepository,
- ) {
+ private Filesystem $filesystem;
+
+ private string $tempConfigFile = '';
+
+ private string $tempTemplateFile = '';
+
+ public function __construct()
+ {
+ $this->filesystem = new Filesystem();
}
/**
- * @Given there is a template in the store with :name name
- * @Given there is a template in the store with :name name and :type type
+ * @Given there is an existing template with :template value
*/
- public function thereIsATemplate(string $name, ?string $type = null): void
+ public function thereIsAnExistingTemplateWithValue($template): void
{
- $template = $this->createTemplate($name, $type);
+ $this->tempConfigFile = __DIR__ . '/../../../Application/config/packages/sylius_cms_test.yaml';
+ $config = [
+ 'sylius_cms' => [
+ 'templates' => [
+ 'pages' => [$template],
+ ],
+ ],
+ ];
+
+ $this->filesystem->dumpFile($this->tempConfigFile, Yaml::dump($config));
- $this->saveTemplate($template);
+ $this->tempTemplateFile = $this->getTemplateFilePath($template);
+ $dummyTemplateContent = "
This is a test template for: $template
";
+
+ $this->filesystem->dumpFile($this->tempTemplateFile, $dummyTemplateContent);
}
/**
- * @Given there are :firstContentElement and :secondContentElement content elements in this template
+ * Get the real template file path from the given template name.
*/
- public function thereAreContentElementsInThisTemplate(string $firstContentElement, string $secondContentElement): void
+ private function getTemplateFilePath($template): string
{
- /** @var TemplateInterface $template */
- $template = $this->sharedStorage->get('template');
- $template->setContentElements([
- ['type' => ContentElementHelper::getContentElementValueByName($firstContentElement)],
- ['type' => ContentElementHelper::getContentElementValueByName($secondContentElement)],
- ]);
+ $templatePath = str_replace('@SyliusCmsPlugin', 'Application/templates/bundles/SyliusCmsPlugin', $template);
- $this->saveTemplate($template);
+ return __DIR__ . '/../../../' . $templatePath;
}
/**
- * @Given there is an existing template named :templateName with :type type that contains :contentElements content elements
+ * @AfterScenario
*/
- public function thereIsAnExistingTemplateThatContainsContentElements(string $templateName, string $type, string $contentElements): void
+ public function cleanup(): void
{
- $template = $this->createTemplate($templateName, $type);
-
- $contentElements = explode(', ', $contentElements);
-
- $contentElementsArray = [];
- foreach ($contentElements as $contentElement) {
- $contentElementsArray[] = ['type' => ContentElementHelper::getContentElementValueByName($contentElement)];
+ if ($this->tempConfigFile && file_exists($this->tempConfigFile)) {
+ $this->filesystem->remove($this->tempConfigFile);
}
- $template->setContentElements($contentElementsArray);
-
- $this->saveTemplate($template);
- }
-
- private function createTemplate(string $name, ?string $type = null): TemplateInterface
- {
- /** @var TemplateInterface $template */
- $template = $this->templateFactory->createNew();
- $template->setName($name);
-
- if (null !== $type) {
- $template->setType($type);
+ if ($this->tempTemplateFile && file_exists($this->tempTemplateFile)) {
+ $this->filesystem->remove($this->tempTemplateFile);
}
-
- return $template;
- }
-
- private function saveTemplate(TemplateInterface $template): void
- {
- $this->templateRepository->add($template);
- $this->sharedStorage->set('template', $template);
}
}
diff --git a/tests/Behat/Context/Ui/Admin/BlockContext.php b/tests/Behat/Context/Ui/Admin/BlockContext.php
index 92224332..ddeebbcd 100755
--- a/tests/Behat/Context/Ui/Admin/BlockContext.php
+++ b/tests/Behat/Context/Ui/Admin/BlockContext.php
@@ -401,11 +401,11 @@ public function iShouldSeeEmptyListOfBlocks(): void
}
/**
- * @Then I select :templateName template
+ * @Then I select :templateName content template
*/
- public function iSelectTemplate(string $templateName): void
+ public function iSelectContentTemplate(string $templateName): void
{
- $this->resolveCurrentPage()->selectTemplate($templateName);
+ $this->resolveCurrentPage()->selectContentTemplate($templateName);
}
/**
diff --git a/tests/Behat/Context/Ui/Admin/TemplateContext.php b/tests/Behat/Context/Ui/Admin/ContentTemplateContext.php
similarity index 99%
rename from tests/Behat/Context/Ui/Admin/TemplateContext.php
rename to tests/Behat/Context/Ui/Admin/ContentTemplateContext.php
index 78939072..eb48faba 100644
--- a/tests/Behat/Context/Ui/Admin/TemplateContext.php
+++ b/tests/Behat/Context/Ui/Admin/ContentTemplateContext.php
@@ -17,7 +17,7 @@
use Tests\Sylius\CmsPlugin\Behat\Service\RandomStringGeneratorInterface;
use Webmozart\Assert\Assert;
-final class TemplateContext implements Context
+final class ContentTemplateContext implements Context
{
public function __construct(
private SharedStorageInterface $sharedStorage,
diff --git a/tests/Behat/Context/Ui/Admin/PageContext.php b/tests/Behat/Context/Ui/Admin/PageContext.php
index bf984a82..db966a1c 100755
--- a/tests/Behat/Context/Ui/Admin/PageContext.php
+++ b/tests/Behat/Context/Ui/Admin/PageContext.php
@@ -32,7 +32,7 @@ public function __construct(
}
/**
- * @When I go to the pages page
+ * @When I go to the cms pages page
*/
public function iGoToTheCmsPagesPage(): void
{
@@ -99,6 +99,14 @@ public function iFillTheNameWith(string $name): void
$this->resolveCurrentPage()->fillName($name);
}
+ /**
+ * @When I select :code channel
+ */
+ public function iSelectChannel(string $code): void
+ {
+ $this->resolveCurrentPage()->selectChannel($code);
+ }
+
/**
* @When I fill the slug with :slug
*/
@@ -292,11 +300,11 @@ public function iShouldNotSeeContentElementInTheContentElementsSection(string $c
}
/**
- * @Then I select :templateName template
+ * @Then I select :templateName content template
*/
- public function iSelectTemplate(string $templateName): void
+ public function iSelectContentTemplate(string $templateName): void
{
- $this->resolveCurrentPage()->selectTemplate($templateName);
+ $this->resolveCurrentPage()->selectContentTemplate($templateName);
}
/**
@@ -307,6 +315,14 @@ public function iConfirmThatIWantToUseThisTemplate(): void
$this->resolveCurrentPage()->confirmUseTemplate();
}
+ /**
+ * @Then I select :templateName template
+ */
+ public function iSelectTemplate(string $templateName): void
+ {
+ $this->resolveCurrentPage()->selectTemplate($templateName);
+ }
+
/**
* @When I add it
* @When I try to add it
diff --git a/tests/Behat/Context/Ui/Shop/PageContext.php b/tests/Behat/Context/Ui/Shop/PageContext.php
index fa1898da..d8eabe35 100755
--- a/tests/Behat/Context/Ui/Shop/PageContext.php
+++ b/tests/Behat/Context/Ui/Shop/PageContext.php
@@ -108,4 +108,12 @@ public function iShouldSeePageTitle(string $title): void
{
Assert::true($this->showPage->hasTitle($title));
}
+
+ /**
+ * @Then The rendered page should contain custom layout code
+ */
+ public function theRenderedPageShouldContainCustomLayoutCode()
+ {
+ Assert::true($this->showPage->hasCustomLayoutCode());
+ }
}
diff --git a/tests/Behat/Page/Admin/Block/CreatePage.php b/tests/Behat/Page/Admin/Block/CreatePage.php
index 5098fdcf..a3409322 100755
--- a/tests/Behat/Page/Admin/Block/CreatePage.php
+++ b/tests/Behat/Page/Admin/Block/CreatePage.php
@@ -265,18 +265,18 @@ public function addTaxonsListContentElementWithTaxons(array $taxons): void
}
}
- public function selectTemplate(string $templateName): void
+ public function selectContentTemplate(string $templateName): void
{
- $dropdown = $this->getElement('template_select_dropdown');
+ $dropdown = $this->getElement('content_template_select_dropdown');
$dropdown->click();
$dropdown->waitFor(5, function () use ($templateName): bool {
- return $this->hasElement('template_select_dropdown_item', [
+ return $this->hasElement('content_template_select_dropdown_item', [
'%item%' => $templateName,
]);
});
- $item = $this->getElement('template_select_dropdown_item', [
+ $item = $this->getElement('content_template_select_dropdown_item', [
'%item%' => $templateName,
]);
@@ -300,8 +300,8 @@ protected function getDefinedElements(): array
'association_dropdown_collection' => '.field > label:contains("Collections") ~ .sylius-autocomplete',
'association_dropdown_collection_item' => '.field > label:contains("Collections") ~ .sylius-autocomplete > div.menu > div.item:contains("%item%")',
'content_elements_add_button' => '#sylius_cms_block_contentElements a[data-form-collection="add"]',
- 'template_select_dropdown' => 'h5:contains("Use page template") ~ .column .field > .sylius-autocomplete',
- 'template_select_dropdown_item' => 'h5:contains("Use page template") ~ .column .field > .sylius-autocomplete > div.menu > div.item:contains("%item%")',
+ 'content_template_select_dropdown' => 'h5:contains("Content elements template") ~ .column .field > .sylius-autocomplete',
+ 'content_template_select_dropdown_item' => 'h5:contains("Content elements template") ~ .column .field > .sylius-autocomplete > div.menu > div.item:contains("%item%")',
],
);
}
diff --git a/tests/Behat/Page/Admin/Block/CreatePageInterface.php b/tests/Behat/Page/Admin/Block/CreatePageInterface.php
index 59644f53..ad5ed7db 100755
--- a/tests/Behat/Page/Admin/Block/CreatePageInterface.php
+++ b/tests/Behat/Page/Admin/Block/CreatePageInterface.php
@@ -47,7 +47,7 @@ public function addTaxonsListContentElementWithTaxons(array $taxons): void;
public function disable(): void;
- public function selectTemplate(string $templateName): void;
+ public function selectContentTemplate(string $templateName): void;
public function confirmUseTemplate(): void;
}
diff --git a/tests/Behat/Page/Admin/Page/CreatePage.php b/tests/Behat/Page/Admin/Page/CreatePage.php
index 83f983cd..bf2ddaa6 100755
--- a/tests/Behat/Page/Admin/Page/CreatePage.php
+++ b/tests/Behat/Page/Admin/Page/CreatePage.php
@@ -274,18 +274,18 @@ public function addTaxonsListContentElementWithTaxons(array $taxons): void
}
}
- public function selectTemplate(string $templateName): void
+ public function selectContentTemplate(string $templateName): void
{
- $dropdown = $this->getElement('template_select_dropdown');
+ $dropdown = $this->getElement('content_template_select_dropdown');
$dropdown->click();
$dropdown->waitFor(5, function () use ($templateName): bool {
- return $this->hasElement('template_select_dropdown_item', [
+ return $this->hasElement('content_template_select_dropdown_item', [
'%item%' => $templateName,
]);
});
- $item = $this->getElement('template_select_dropdown_item', [
+ $item = $this->getElement('content_template_select_dropdown_item', [
'%item%' => $templateName,
]);
@@ -300,6 +300,16 @@ public function confirmUseTemplate(): void
});
}
+ public function selectTemplate(string $templateName): void
+ {
+ $this->getDocument()->selectFieldOption('Template', $templateName);
+ }
+
+ public function selectChannel(string $code): void
+ {
+ $this->getDocument()->checkField($code);
+ }
+
protected function getDefinedElements(): array
{
return array_merge(
@@ -310,8 +320,8 @@ protected function getDefinedElements(): array
'association_dropdown_collection' => '.field > label:contains("Collections") ~ .sylius-autocomplete',
'association_dropdown_collection_item' => '.field > label:contains("Collections") ~ .sylius-autocomplete > div.menu > div.item:contains("%item%")',
'content_elements_add_button' => '#sylius_cms_page_contentElements a[data-form-collection="add"]',
- 'template_select_dropdown' => 'h5:contains("Use page template") ~ .column .field > .sylius-autocomplete',
- 'template_select_dropdown_item' => 'h5:contains("Use page template") ~ .column .field > .sylius-autocomplete > div.menu > div.item:contains("%item%")',
+ 'content_template_select_dropdown' => 'h5:contains("Content elements template") ~ .column .field > .sylius-autocomplete',
+ 'content_template_select_dropdown_item' => 'h5:contains("Content elements template") ~ .column .field > .sylius-autocomplete > div.menu > div.item:contains("%item%")',
],
);
}
diff --git a/tests/Behat/Page/Admin/Page/CreatePageInterface.php b/tests/Behat/Page/Admin/Page/CreatePageInterface.php
index 3b533859..912d14ca 100755
--- a/tests/Behat/Page/Admin/Page/CreatePageInterface.php
+++ b/tests/Behat/Page/Admin/Page/CreatePageInterface.php
@@ -51,7 +51,11 @@ public function addProductsGridByTaxonContentElementWithTaxon(string $taxon): vo
public function addTaxonsListContentElementWithTaxons(array $taxons): void;
- public function selectTemplate(string $templateName): void;
+ public function selectContentTemplate(string $templateName): void;
public function confirmUseTemplate(): void;
+
+ public function selectTemplate(string $templateName): void;
+
+ public function selectChannel(string $code): void;
}
diff --git a/tests/Behat/Page/Shop/Page/ShowPage.php b/tests/Behat/Page/Shop/Page/ShowPage.php
index d3a1ae9b..c3d44a3c 100755
--- a/tests/Behat/Page/Shop/Page/ShowPage.php
+++ b/tests/Behat/Page/Shop/Page/ShowPage.php
@@ -67,6 +67,11 @@ public function hasTitle(string $title): bool
return $this->getSession()->evaluateScript('return document.title') === $title;
}
+ public function hasCustomLayoutCode(): bool
+ {
+ return $this->hasElement('custom-layout');
+ }
+
protected function getDefinedElements(): array
{
return array_merge(parent::getDefinedElements(), [
@@ -76,6 +81,7 @@ protected function getDefinedElements(): array
'collections' => '.cms-page-collections',
'link' => '.cms-page-link',
'page-image' => '.page-image',
+ 'custom-layout' => '.custom-layout',
]);
}
}
diff --git a/tests/Behat/Page/Shop/Page/ShowPageInterface.php b/tests/Behat/Page/Shop/Page/ShowPageInterface.php
index 8da55940..00f69870 100755
--- a/tests/Behat/Page/Shop/Page/ShowPageInterface.php
+++ b/tests/Behat/Page/Shop/Page/ShowPageInterface.php
@@ -21,4 +21,6 @@ public function hasPageLink(string $linkName): bool;
public function hasPageImage(): bool;
public function hasTitle(string $title): bool;
+
+ public function hasCustomLayoutCode(): bool;
}
diff --git a/tests/Behat/Resources/services/contexts/setup.xml b/tests/Behat/Resources/services/contexts/setup.xml
index 57ffbf82..fda5d43e 100644
--- a/tests/Behat/Resources/services/contexts/setup.xml
+++ b/tests/Behat/Resources/services/contexts/setup.xml
@@ -37,10 +37,12 @@
-
+
+
+
diff --git a/tests/Behat/Resources/services/contexts/ui.xml b/tests/Behat/Resources/services/contexts/ui.xml
index bde9105c..c575c9fe 100644
--- a/tests/Behat/Resources/services/contexts/ui.xml
+++ b/tests/Behat/Resources/services/contexts/ui.xml
@@ -60,7 +60,7 @@
-
+
diff --git a/tests/Behat/Resources/suites.yml b/tests/Behat/Resources/suites.yml
index 8acb5a3f..865ba783 100644
--- a/tests/Behat/Resources/suites.yml
+++ b/tests/Behat/Resources/suites.yml
@@ -3,7 +3,7 @@ imports:
- suites/ui/managing_pages.yml
- suites/ui/managing_collections.yml
- suites/ui/managing_media.yml
- - suites/ui/managing_templates.yml
+ - suites/ui/managing_content_templates.yml
- suites/ui/shop_blocks.yml
- suites/ui/shop_media.yml
- suites/ui/shop_pages.yml
diff --git a/tests/Behat/Resources/suites/ui/managing_blocks.yml b/tests/Behat/Resources/suites/ui/managing_blocks.yml
index 2b8060ab..ad82c741 100755
--- a/tests/Behat/Resources/suites/ui/managing_blocks.yml
+++ b/tests/Behat/Resources/suites/ui/managing_blocks.yml
@@ -11,7 +11,7 @@ default:
- sylius_cms.behat.context.setup.block
- sylius_cms.behat.context.setup.collection
- sylius_cms.behat.context.setup.media
- - sylius_cms.behat.context.setup.template
+ - sylius_cms.behat.context.setup.content_template
- sylius_cms.behat.context.ui.admin.block
filters:
diff --git a/tests/Behat/Resources/suites/ui/managing_templates.yml b/tests/Behat/Resources/suites/ui/managing_content_templates.yml
similarity index 50%
rename from tests/Behat/Resources/suites/ui/managing_templates.yml
rename to tests/Behat/Resources/suites/ui/managing_content_templates.yml
index 9072486e..5538d7b8 100755
--- a/tests/Behat/Resources/suites/ui/managing_templates.yml
+++ b/tests/Behat/Resources/suites/ui/managing_content_templates.yml
@@ -1,11 +1,11 @@
default:
suites:
- ui_managing_templates:
+ ui_managing_content_templates:
contexts:
- sylius.behat.context.hook.doctrine_orm
- sylius.behat.context.setup.channel
- sylius.behat.context.setup.admin_security
- - sylius_cms.behat.context.setup.template
- - sylius_cms.behat.context.ui.admin.template
+ - sylius_cms.behat.context.setup.content_template
+ - sylius_cms.behat.context.ui.admin.content_template
filters:
- tags: "@managing_templates&&@ui"
+ tags: "@managing_content_templates&&@ui"
diff --git a/tests/Behat/Resources/suites/ui/managing_pages.yml b/tests/Behat/Resources/suites/ui/managing_pages.yml
index 349071ad..2c4bd190 100755
--- a/tests/Behat/Resources/suites/ui/managing_pages.yml
+++ b/tests/Behat/Resources/suites/ui/managing_pages.yml
@@ -11,8 +11,10 @@ default:
- sylius_cms.behat.context.setup.media
- sylius_cms.behat.context.setup.page
- sylius_cms.behat.context.setup.collection
+ - sylius_cms.behat.context.setup.content_template
- sylius_cms.behat.context.setup.template
- sylius_cms.behat.context.ui.admin.page
+ - sylius_cms.behat.context.ui.shop.page
filters:
tags: "@managing_pages&&@ui"
diff --git a/tests/Functional/DataFixtures/ORM/Api/PageTest/page.yml b/tests/Functional/DataFixtures/ORM/Api/PageTest/page.yml
index 1e4919a8..7501b1e7 100644
--- a/tests/Functional/DataFixtures/ORM/Api/PageTest/page.yml
+++ b/tests/Functional/DataFixtures/ORM/Api/PageTest/page.yml
@@ -78,16 +78,22 @@ Sylius\CmsPlugin\Entity\PageTranslation:
slug: 'translation1_slug_en_US'
metaKeywords: 'html,application'
title: 'Amazing article1'
+ teaserTitle: "Amazing article1"
+ teaserContent: "This is a teaser content"
page2_translation:
locale: 'en_US'
slug: 'translation2_slug_en_US'
metaKeywords: 'html,application'
title: 'Amazing article2'
+ teaserTitle: "Amazing article2"
+ teaserContent: "This is a teaser content"
page3_translation:
locale: 'en_US'
slug: 'translation3_slug_en_US'
metaKeywords: 'html,application'
title: 'Amazing article3'
+ teaserTitle: "Amazing article3"
+ teaserContent: "This is a teaser content"
Sylius\CmsPlugin\Entity\Page:
page1:
code: 'page1-code'
diff --git a/tests/Functional/Responses/Expected/Api/PageTest/test_it_get_page_by_id.json b/tests/Functional/Responses/Expected/Api/PageTest/test_it_get_page_by_id.json
index 5e08fe1e..b9fed7ff 100644
--- a/tests/Functional/Responses/Expected/Api/PageTest/test_it_get_page_by_id.json
+++ b/tests/Functional/Responses/Expected/Api/PageTest/test_it_get_page_by_id.json
@@ -13,7 +13,10 @@
"slug": "translation1_slug_en_US",
"metaKeywords": "html,application",
"metaDescription": null,
- "title": "Amazing article1"
+ "title": "Amazing article1",
+ "teaserTitle": "Amazing article1",
+ "teaserContent": "This is a teaser content",
+ "teaserImage": null
}
}
}