diff --git a/composer.json b/composer.json index 7c83bb2..111e7a1 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ }, "require-dev": { "behat/behat": "^3.6.1", - "behat/mink-selenium2-driver": "^1.4", + "behat/mink-selenium2-driver": "~1.6.0", "bitbag/coding-standard": "^3.0", "dmore/behat-chrome-extension": "^1.3", "dmore/chrome-mink-driver": "^2.7", diff --git a/features/caching_sulu_request.feature b/features/caching_sulu_request.feature new file mode 100644 index 0000000..4cc118d --- /dev/null +++ b/features/caching_sulu_request.feature @@ -0,0 +1,50 @@ +@sulu_cache +Feature: Caching sulu page request + In order to see again some page + As a Visitor + I want to be able to see the page without sending request to sulu + + Background: + Given the store operates on a single channel in "United States" + And Sulu has defined page "blog_page_with_blocks_and_links" in locale "en_US" + And Cache for sulu not exists + + + @ui + Scenario: See the featured pages on homepage + When I visit this channel's homepage + And "United States" has enabled sulu localized requests + Then Sulu cache should not exists + And I visit a sulu page "blog_page_with_blocks_and_links" in locale en_US + And Sulu cache should exists for "United States" with locale en_US + + @ui + Scenario: Manually clear cache when localized urls are disabled + When I visit a sulu page "blog_page_with_blocks_and_links" in locale en_US + Then Sulu cache should exists + And I am logged in as an administrator + And I browse channels + And I should see button "Purge sulu cache" in "United States" + And I click "Clear Cache" button in "United States" + And I should see success "Successfully purged" flash message + And Sulu cache should exists for "United States" with locale en_US + + @ui + Scenario: Manually clear cache when localized urls are enabled + When "United States" has enabled sulu localized requests + And I visit a sulu page "blog_page_with_blocks_and_links" in locale en_US + Then Sulu cache should exists + And I am logged in as an administrator + And I browse channels + And I should see expanded button "Purge sulu cache" in "United States" + And I click expanded "en_US" button in "United States" + And I should see success "Successfully purged" flash message + And Sulu cache should exists for "United States" with locale en_US + + @ui + Scenario: Manually clear cache when localized urls are disabled and cache not exists + When I am logged in as an administrator + And I browse channels + Then I should see button "Purge sulu cache" in "United States" + And I click "Purge sulu cache" button in "United States" + And I should see error "Dir with sulu cache not found" flash message diff --git a/features/render_sulu_page.feature b/features/render_sulu_page.feature new file mode 100644 index 0000000..b617487 --- /dev/null +++ b/features/render_sulu_page.feature @@ -0,0 +1,27 @@ +@render_sulu_page +Feature: Render sulu page + In order to see a sulu page + As a Visitor + I want to be able to see rendered sulu page + + Background: + Given the store operates on a single channel in "United States" + And Sulu has defined page "blog_page_with_properties" in locale "en_US" + And Sulu has defined page "blog_page_with_blocks_and_links" in locale "en_US" + And Page "blog_page_with_blocks_and_links" has block "quote" + And Page "blog_page_with_blocks_and_links" has block "text" + And Page "blog_page_with_blocks_and_links" has block "image" + + @ui + Scenario: Rendering a sulu page with properties + When I visit a sulu page "blog_page_with_properties" in locale en_US + Then I should see a "title" with value "E-commerce trends" + And I should see a "content" with value "CONTENT" + + @ui + Scenario: Rendering a sulu page with properties and blocks + When I visit a sulu page "blog_page_with_blocks_and_links" in locale en_US + Then I should see a "title" with value "E-commerce trends" + And I should see a block "content" with value "2021 was followed by the time of the 2020 pandemic. During these two years, a lot has changed..." + And I should see a block image with url "https://en.wikipedia.org/wiki/Cat#/media/File:Sheba1.JPG" + And I should see a block "quote" with value "Lorem ipsum dolor sit amet, con" diff --git a/features/show_featured_pages_on_homepage.feature b/features/show_featured_pages_on_homepage.feature new file mode 100644 index 0000000..daa2964 --- /dev/null +++ b/features/show_featured_pages_on_homepage.feature @@ -0,0 +1,20 @@ +@sulu_page +Feature: Show featured pages on homepage + In order to see featured pages on homepage + As a Visitor + I want to be able to see featured pages on homepage + + Background: + Given the store operates on a single channel in "United States" + And Sulu has defined featured pages list featured_pages in locale en_US + And One of the featured page is page "Blog Page 1" + And One of the featured page is page "Blog Page 2" + And One of the featured page is page "Blog Page 3" + + @ui + Scenario: See the featured pages on homepage + When I visit this channel's homepage + Then I should see 3 featured pages. + And I should see featured page "Blog Page 1" + And I should see featured page "Blog Page 2" + And I should see featured page "Blog Page 3" diff --git a/src/Entity/SuluChannelConfigurationTrait.php b/src/Entity/SuluChannelConfigurationTrait.php index 2143228..583e729 100644 --- a/src/Entity/SuluChannelConfigurationTrait.php +++ b/src/Entity/SuluChannelConfigurationTrait.php @@ -4,8 +4,18 @@ namespace BitBag\SyliusSuluPlugin\Entity; +use Doctrine\ORM\Mapping as ORM; + +/** + * @ORM\Entity + * + * @ORM\Table(name="sylius_channel") + */ +#[ORM\Entity] +#[ORM\Table(name: 'sylius_channel')] trait SuluChannelConfigurationTrait { + /** @ORM\Column(type="boolean", nullable=false) */ protected bool $suluUseLocalizedUrls = false; public function isSuluUseLocalizedUrls(): bool diff --git a/src/Twig/Extension/SuluPageExtension.php b/src/Twig/Extension/SuluPageExtension.php index 064137c..6d927ee 100644 --- a/src/Twig/Extension/SuluPageExtension.php +++ b/src/Twig/Extension/SuluPageExtension.php @@ -23,6 +23,7 @@ public function getFunctions(): array new TwigFunction('bitbag_render_sulu_blocks', [$this->suluRuntime, 'renderSuluBlocks']), new TwigFunction('bitbag_render_sulu_blocks_with_type', [$this->suluRuntime, 'renderSuluBlocksWithType']), new TwigFunction('bitbag_render_sulu_block_with_type', [$this->suluRuntime, 'renderSuluBlockWithType']), + new TwigFunction('bitbag_page_has_sulu_block', [$this->suluRuntime, 'hasSuluBlock']), ]; } } diff --git a/src/Twig/Runtime/SuluRuntime.php b/src/Twig/Runtime/SuluRuntime.php index c8e7104..f31e6ea 100644 --- a/src/Twig/Runtime/SuluRuntime.php +++ b/src/Twig/Runtime/SuluRuntime.php @@ -59,10 +59,10 @@ public function renderSuluBlocksWithType(array $blocks, string $type, ?string $d public function renderSuluBlockWithType(array $blocks, string $type): string { $blocks = array_filter($blocks, fn (array $block) => $block['type'] === $type); - if (count($blocks) > 1) { $blocks = $blocks[0]; } + $content = ''; foreach ($blocks as $block) { @@ -71,4 +71,21 @@ public function renderSuluBlockWithType(array $blocks, string $type): string return $content; } + + public function hasSuluBlock(array $page, string $type): bool + { + if (!array_key_exists('blocks', $page)) { + return false; + } + + $blocks = $page['blocks']; + + if (count($blocks) === 0) { + return false; + } + + $blocks = array_filter($blocks, fn (array $block) => $block['type'] === $type); + + return count($blocks) !== 0; + } } diff --git a/src/Twig/Runtime/SuluRuntimeInterface.php b/src/Twig/Runtime/SuluRuntimeInterface.php index 643f1ec..f1c7753 100644 --- a/src/Twig/Runtime/SuluRuntimeInterface.php +++ b/src/Twig/Runtime/SuluRuntimeInterface.php @@ -17,4 +17,6 @@ public function renderSuluBlocks(array $blocks): string; public function renderSuluBlocksWithType(array $blocks, string $type): string; public function renderSuluBlockWithType(array $blocks, string $type): string; + + public function hasSuluBlock(array $page, string $type): bool; } diff --git a/templates/Admin/Grid/Action/invalidateSuluCache.html.twig b/templates/Admin/Grid/Action/invalidateSuluCache.html.twig index 2523db1..24be26c 100644 --- a/templates/Admin/Grid/Action/invalidateSuluCache.html.twig +++ b/templates/Admin/Grid/Action/invalidateSuluCache.html.twig @@ -1,5 +1,5 @@ {% if true == data.isSuluUseLocalizedUrls %} -