diff --git a/features/api/viewing_blocks.feature b/features/api/viewing_blocks.feature index de2888844..c2453c011 100644 --- a/features/api/viewing_blocks.feature +++ b/features/api/viewing_blocks.feature @@ -19,5 +19,4 @@ Feature: Getting data from cms blocks Scenario: Displaying block Given I view block with code "block-1" Then I should see block name - And I should see block content diff --git a/spec/Entity/BlockTranslationSpec.php b/spec/Entity/BlockTranslationSpec.php deleted file mode 100755 index 2bc57c894..000000000 --- a/spec/Entity/BlockTranslationSpec.php +++ /dev/null @@ -1,47 +0,0 @@ -shouldHaveType(ResourceInterface::class); - } - - public function it_is_a_resource(): void - { - $this->shouldHaveType(ResourceInterface::class); - } - - public function it_implements_block_translation_interface(): void - { - $this->shouldHaveType(BlockTranslationInterface::class); - $this->shouldHaveType(TranslationInterface::class); - } - - public function it_allows_access_via_properties(): void - { - $this->setName('Escobar favorite quote'); - $this->getName()->shouldReturn('Escobar favorite quote'); - - $this->setLink('https://en.wikipedia.org/wiki/Pablo_Escobar'); - $this->getLink()->shouldReturn('https://en.wikipedia.org/wiki/Pablo_Escobar'); - - $this->setContent('Plata o plomo'); - $this->getContent()->shouldReturn('Plata o plomo'); - } -} diff --git a/spec/Importer/BlockImporterSpec.php b/spec/Importer/BlockImporterSpec.php index c7a5cd00b..a4181fade 100644 --- a/spec/Importer/BlockImporterSpec.php +++ b/spec/Importer/BlockImporterSpec.php @@ -17,7 +17,6 @@ use BitBag\SyliusCmsPlugin\Resolver\ImporterCollectionsResolverInterface; use BitBag\SyliusCmsPlugin\Resolver\ResourceResolverInterface; use PhpSpec\ObjectBehavior; -use Sylius\Component\Locale\Context\LocaleContextInterface; use Symfony\Component\Validator\ConstraintViolationList; use Symfony\Component\Validator\Validator\ValidatorInterface; @@ -25,7 +24,6 @@ final class BlockImporterSpec extends ObjectBehavior { public function let( ResourceResolverInterface $blockResourceResolver, - LocaleContextInterface $localeContext, ImporterCollectionsResolverInterface $importerCollectionsResolver, ImporterChannelsResolverInterface $importerChannelsResolver, ImporterProductsResolverInterface $importerProductsResolver, @@ -34,7 +32,6 @@ public function let( ) { $this->beConstructedWith( $blockResourceResolver, - $localeContext, $importerCollectionsResolver, $importerChannelsResolver, $importerProductsResolver, @@ -51,7 +48,6 @@ public function it_is_initializable() public function it_imports_block( ResourceResolverInterface $blockResourceResolver, - LocaleContextInterface $localeContext, ImporterCollectionsResolverInterface $importerCollectionsResolver, ImporterChannelsResolverInterface $importerChannelsResolver, ImporterProductsResolverInterface $importerProductsResolver, @@ -59,18 +55,11 @@ public function it_imports_block( BlockRepositoryInterface $blockRepository, BlockInterface $block ) { - $row = ['name_pl' => 'name', 'content_pl' => 'content', 'link_pl' => 'link', 'code' => 'block_code']; + $row = ['name_pl' => 'name', 'code' => 'block_code']; $blockResourceResolver->getResource('block_code')->willReturn($block); - $localeContext->getLocaleCode()->willReturn('en_US'); - $block->setCode('block_code')->shouldBeCalled(); - $block->setFallbackLocale('en_US')->shouldBeCalled(); - $block->setCurrentLocale('pl')->shouldBeCalled(); - $block->setName('name')->shouldBeCalled(); - $block->setLink('link')->shouldBeCalled(); - $block->setContent('content')->shouldBeCalled(); $importerCollectionsResolver->resolve($block, null)->shouldBeCalled(); $importerChannelsResolver->resolve($block, null)->shouldBeCalled(); diff --git a/tests/Application/config/packages/bitbag_sylius_cms_plugin.yaml b/tests/Application/config/packages/bitbag_sylius_cms_plugin.yaml index e3f397167..423efca8b 100644 --- a/tests/Application/config/packages/bitbag_sylius_cms_plugin.yaml +++ b/tests/Application/config/packages/bitbag_sylius_cms_plugin.yaml @@ -40,90 +40,25 @@ sylius_fixtures: homepage_products_info: channels: - "FASHION_WEB" - translations: - en_US: - content: | -
- Click one of the below products to see what you can do with the blocks in your product view! -
collection_info_block: channels: - "FASHION_WEB" collections: - "products" - translations: - en_US: - content: | -
- The block you can see on the left is just a block associated with a collection named Products -
-

With this feature, you can render any block you want on the product page, like size table, delivery information, or even promotion banner.

-

It's done with a simple controller render:

-
{{ render(path('bitbag_sylius_cms_plugin_shop_block_index_by_collection_code', {'collectionCode' : 'products', 'template' : '@BitBagSyliusCmsPlugin/Shop/Block/index.html.twig'})) }}
product_info_block: channels: - "FASHION_WEB" - products: 5 - translations: - en_US: - content: | -
On the other hand, the block on the right is a block associated with specific products.
-

This approach can be helpful with displaying some content dedicated to specific products, like size table or product story

-

The way you render it is similar to the one from above example:

-
{{ render(path('bitbag_sylius_cms_plugin_shop_block_index_by_product_code', {'productCode' : product.code, 'template' : '@BitBagSyliusCmsPlugin/Shop/Block/index.html.twig'})) }}
homepage_intro: channels: - "FASHION_WEB" - translations: - en_US: - content: | -

Blocks

-

- The left block is rendered with the usage of the particular controller like this: -

-
-                                            render(path('bitbag_sylius_cms_plugin_shop_block_render', {'code' : 'homepage_header_image'}))
-                                            
-

- It also can take template as a parameter, but it's optional. In this case, it works the same as below Twig functions. Sometimes you might want the block to render in a different template, that's where the controller is useful. -

-

- The other three blocks, including this one you are reading right now, are using Twig helper method. -

- -
-                                            bitbag_cms_render_block('homepage_intro')
-                                            bitbag_cms_render_block('homepage_banner_image_1')
-                                            bitbag_cms_render_block('homepage_banner_image_2')
-                                            
lorem_ipsum: channels: - "FASHION_WEB" collections: - "homepage" - translations: - en_US: - content: | -

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus

- -

Pellentesque habitant morbi tristique sene

taxons_and_products_block: channels: - "FASHION_WEB" - productCodes: - - "666F_boyfriend_jeans_with_rips" - - "727F_patched_cropped_jeans" - - "111F_patched_jeans_with_fancy_badges" - taxons: - - "womens_jeans" - translations: - en_US: - name: "Womens jeans" media: options: custom: diff --git a/tests/Behat/Context/Setup/BlockContext.php b/tests/Behat/Context/Setup/BlockContext.php index 0d25adb70..f351f9bd8 100755 --- a/tests/Behat/Context/Setup/BlockContext.php +++ b/tests/Behat/Context/Setup/BlockContext.php @@ -52,23 +52,20 @@ public function thereIsABlockWithCode(string $code): void /** * @Given there is a block with :code code and :content content */ - public function thereIsABlockWithCodeAndContent(string $code, string $content): void + public function thereIsABlockWithCodeAndContent(string $code): void { - $block = $this->createBlock($code, $content); + $block = $this->createBlock($code); $this->saveBlock($block); } private function createBlock( ?string $code = null, - ?string $content = null, ChannelInterface $channel = null, ): BlockInterface { /** @var BlockInterface $block */ $block = $this->blockFactory->createNew(); - $block->setCurrentLocale('en_US'); - if (null === $channel && $this->sharedStorage->has('channel')) { $channel = $this->sharedStorage->get('channel'); } @@ -77,12 +74,7 @@ private function createBlock( $code = $this->randomStringGenerator->generate(); } - if (null === $content) { - $content = $this->randomStringGenerator->generate(); - } - $block->setCode($code); - $block->setContent($content); $block->addChannel($channel); return $block; diff --git a/tests/Functional/DataFixtures/ORM/Api/BlockTest/block.yml b/tests/Functional/DataFixtures/ORM/Api/BlockTest/block.yml index 67e66abd9..1ea8738e4 100644 --- a/tests/Functional/DataFixtures/ORM/Api/BlockTest/block.yml +++ b/tests/Functional/DataFixtures/ORM/Api/BlockTest/block.yml @@ -71,59 +71,28 @@ Sylius\Component\Core\Model\ProductVariant: product_variant1: product: '@product1' code: "code1" - -BitBag\SyliusCmsPlugin\Entity\BlockTranslation: - block1_translation: - name: 'translation_name_en_US' - locale: 'en_US' - content: 'translation_content_en_US' - link: 'translation_link_en_US' - block2_translation: - name: 'translation_name_en_US' - locale: 'en_US' - content: 'translation_content_en_US' - link: 'translation_link_en_US' - block3_translation: - name: 'translation_name_en_US' - locale: 'en_US' - content: 'translation_content_en_US' - link: 'translation_link_en_US' BitBag\SyliusCmsPlugin\Entity\Block: block1: code: 'block1-code' enabled: true - products: - - '@product1' collections: - '@collection1' channels: - '@channel' - translations: - - '@block1_translation' - taxons: - - '@taxon' block2: code: 'block2-code' enabled: true - products: - - '@product2' collections: - '@collection2' channels: - '@channel' - translations: - - '@block2_translation' block3: code: 'block3-code' enabled: false - products: - - '@product3' collections: - '@collection3' channels: - '@channel' - translations: - - '@block3_translation' BitBag\SyliusCmsPlugin\Entity\Collection: collection1: code: 'collection1-code' diff --git a/tests/Functional/Fixture/BlockFixtureTest.php b/tests/Functional/Fixture/BlockFixtureTest.php index 6916a941d..17e936ad9 100644 --- a/tests/Functional/Fixture/BlockFixtureTest.php +++ b/tests/Functional/Fixture/BlockFixtureTest.php @@ -105,118 +105,6 @@ public function custom_number_is_optional_but_must_be_integer(): void ], 'custom.*.number'); } - /** - * @test - */ - public function custom_last_four_products_is_optional_but_must_be_boolean(): void - { - $this->assertConfigurationIsValid([ - [ - 'custom' => [ - 'homepage_banner' => [ - 'last_four_products' => true, - ], - ], - ], - ], 'custom.*.last_four_products'); - - $this->assertPartialConfigurationIsInvalid([ - [ - 'custom' => [ - 'homepage_banner' => [ - 'last_four_products' => 'boolean', - ], - ], - ], - ], 'custom.*.last_four_products'); - } - - /** - * @test - */ - public function custom_products_is_optional_but_must_be_integer(): void - { - $this->assertConfigurationIsValid([ - [ - 'custom' => [ - 'homepage_banner' => [ - 'products' => 5, - ], - ], - ], - ], 'custom.*.products'); - - $this->assertPartialConfigurationIsInvalid([ - [ - 'custom' => [ - 'homepage_banner' => [ - 'enabled' => 'integer', - ], - ], - ], - ], 'custom.*.products'); - } - - /** - * @test - */ - public function custom_product_codes_is_optional_but_must_be_array(): void - { - $this->assertConfigurationIsValid([ - [ - 'custom' => [ - 'homepage_banner' => [ - 'productCodes' => [], - ], - ], - ], - ], 'custom.*.productCodes'); - - $this->assertPartialConfigurationIsInvalid([ - [ - 'custom' => [ - 'homepage_banner' => [ - 'enabled' => 'integer', - ], - ], - ], - ], 'custom.*.productCodes'); - } - - /** - * @test - */ - public function custom_translations_is_optional_but_must_be_array(): void - { - $this->assertConfigurationIsValid([ - [ - 'custom' => [ - 'homepage_banner' => [ - 'translations' => [], - ], - ], - ], - ], 'custom.*.translations'); - - $this->assertPartialConfigurationIsInvalid([ - [ - 'custom' => [ - 'custom_1' => [ - 'translations' => '', - ], - ], - ], - ], 'custom.*.translations'); - - $this->assertConfigurationIsValid([ - [ - 'custom' => [ - 'custom_1' => [], - ], - ], - ], 'custom.*.translations'); - } - /** * @test */ @@ -263,142 +151,6 @@ public function custom_collections_is_optional_but_must_be_scalar_array(): void ], 'custom.*.collections'); } - /** - * @test - */ - public function custom_may_contain_name(): void - { - $this->assertConfigurationIsValid([ - [ - 'custom' => [ - 'homepage_banner' => [ - 'translations' => [ - 'en_US' => [ - 'name' => 'block', - ], - ], - ], - ], - ], - ], 'custom.*.translations.*.name'); - - $this->assertConfigurationIsValid([ - [ - 'custom' => [ - 'homepage_banner' => [ - 'translations' => [ - 'en_US' => [ - 'name' => '', - ], - ], - ], - ], - ], - ], 'custom.*.translations.*.name'); - } - - /** - * @test - */ - public function custom_may_contain_content(): void - { - $this->assertConfigurationIsValid([ - [ - 'custom' => [ - 'homepage_banner' => [ - 'translations' => [ - 'en_US' => [ - 'content' => 'block', - ], - ], - ], - ], - ], - ], 'custom.*.translations.*.content'); - - $this->assertConfigurationIsValid([ - [ - 'custom' => [ - 'homepage_banner' => [ - 'translations' => [ - 'en_US' => [ - 'content' => '', - ], - ], - ], - ], - ], - ], 'custom.*.translations.*.content'); - } - - /** - * @test - */ - public function custom_may_contain_link(): void - { - $this->assertConfigurationIsValid([ - [ - 'custom' => [ - 'homepage_banner' => [ - 'translations' => [ - 'en_US' => [ - 'link' => 'block', - ], - ], - ], - ], - ], - ], 'custom.*.translations.*.link'); - - $this->assertConfigurationIsValid([ - [ - 'custom' => [ - 'homepage_banner' => [ - 'translations' => [ - 'en_US' => [ - 'link' => '', - ], - ], - ], - ], - ], - ], 'custom.*.translations.*.link'); - } - - /** - * @test - */ - public function custom_may_contain_image_path(): void - { - $this->assertConfigurationIsValid([ - [ - 'custom' => [ - 'homepage_banner' => [ - 'translations' => [ - 'en_US' => [ - 'image_path' => '/path/to/img', - ], - ], - ], - ], - ], - ], 'custom.*.translations.*.image_path'); - - $this->assertConfigurationIsValid([ - [ - 'custom' => [ - 'homepage_banner' => [ - 'translations' => [ - 'en_US' => [ - 'image_path' => '', - ], - ], - ], - ], - ], - ], 'custom.*.translations.*.image_path'); - } - protected function getConfiguration(): BlockFixture { /** @var FixtureFactoryInterface $blockFixtureFactory */ diff --git a/tests/Functional/Responses/Expected/Api/BlockTest/test_it_get_block_by_id.json b/tests/Functional/Responses/Expected/Api/BlockTest/test_it_get_block_by_id.json index d4442784c..18560fbd8 100644 --- a/tests/Functional/Responses/Expected/Api/BlockTest/test_it_get_block_by_id.json +++ b/tests/Functional/Responses/Expected/Api/BlockTest/test_it_get_block_by_id.json @@ -13,24 +13,8 @@ "code": "collection1-code" } ], - "products": [ - "/api/v2/shop/products/MUG_SW" - ], "channels": [ "/api/v2/shop/channels/code" ], - "translations": { - "en_US": { - "@type": "BlockTranslation", - "name": "translation_name_en_US", - "content": "translation_content_en_US", - "link": "translation_link_en_US" - } - }, - "taxons": [ - { - "@id": "/api/v2/shop/taxons/menu_category", - "@type": "Taxon" - } - ] + "contents": [] } diff --git a/tests/Functional/Responses/Expected/Api/BlockTest/test_it_get_blocks.json b/tests/Functional/Responses/Expected/Api/BlockTest/test_it_get_blocks.json index 9a8d02cfb..7fa2cd847 100644 --- a/tests/Functional/Responses/Expected/Api/BlockTest/test_it_get_blocks.json +++ b/tests/Functional/Responses/Expected/Api/BlockTest/test_it_get_blocks.json @@ -17,26 +17,10 @@ "code": "collection1-code" } ], - "products": [ - "/api/v2/shop/products/MUG_SW" - ], "channels": [ "/api/v2/shop/channels/code" ], - "translations": { - "en_US": { - "@type": "BlockTranslation", - "name": "translation_name_en_US", - "content": "translation_content_en_US", - "link": "translation_link_en_US" - } - }, - "taxons": [ - { - "@id": "/api/v2/shop/taxons/menu_category", - "@type": "Taxon" - } - ] + "contents": [] }, { "@id": "/api/v2/shop/cms-plugin/blocks/@integer@", @@ -52,21 +36,10 @@ "code": "collection2-code" } ], - "products": [ - "/api/v2/shop/products/MUG_SW2" - ], "channels": [ "/api/v2/shop/channels/code" ], - "translations": { - "en_US": { - "@type": "BlockTranslation", - "name": "translation_name_en_US", - "content": "translation_content_en_US", - "link": "translation_link_en_US" - } - }, - "taxons": [] + "contents": [] }, { "@id": "/api/v2/shop/cms-plugin/blocks/@integer@", @@ -82,21 +55,10 @@ "code": "collection3-code" } ], - "products": [ - "/api/v2/shop/products/MUG_SW3" - ], "channels": [ "/api/v2/shop/channels/code" ], - "translations": { - "en_US": { - "@type": "BlockTranslation", - "name": "translation_name_en_US", - "content": "translation_content_en_US", - "link": "translation_link_en_US" - } - }, - "taxons": [] + "contents": [] } ], "hydra:totalItems": 3 diff --git a/tests/Integration/DataFixtures/ORM/BlockRepositoryTest/test_it_finds_block_by_collection_code.yml b/tests/Integration/DataFixtures/ORM/BlockRepositoryTest/test_it_finds_block_by_collection_code.yml index 61f111d7f..8e4fb1b0c 100644 --- a/tests/Integration/DataFixtures/ORM/BlockRepositoryTest/test_it_finds_block_by_collection_code.yml +++ b/tests/Integration/DataFixtures/ORM/BlockRepositoryTest/test_it_finds_block_by_collection_code.yml @@ -17,22 +17,6 @@ Sylius\Component\Core\Model\Channel: default_locale: '@locale' tax_calculation_strategy: 'order_items_based' base_currency: '@dollar' -BitBag\SyliusCmsPlugin\Entity\BlockTranslation: - block1_translation: - name: 'translation_name_en_US' - locale: 'en_US' - content: 'translation_content_en_US' - link: 'translation_link_en_US' - block2_translation: - name: 'translation_name_en_US' - locale: 'en_US' - content: 'translation_content_en_US' - link: 'translation_link_en_US' - block3_translation: - name: 'translation_name_en_US' - locale: 'en_US' - content: 'translation_content_en_US' - link: 'translation_link_en_US' BitBag\SyliusCmsPlugin\Entity\Block: block1: code: 'block1-code' @@ -41,8 +25,6 @@ BitBag\SyliusCmsPlugin\Entity\Block: - '@collection1' channels: - '@channel' - translations: - - '@block1_translation' block2: code: 'block2-code' enabled: true @@ -50,8 +32,6 @@ BitBag\SyliusCmsPlugin\Entity\Block: - '@collection2' channels: - '@channel' - translations: - - '@block2_translation' block3: code: 'block3-code' enabled: false @@ -59,8 +39,6 @@ BitBag\SyliusCmsPlugin\Entity\Block: - '@collection3' channels: - '@channel' - translations: - - '@block3_translation' BitBag\SyliusCmsPlugin\Entity\Collection: collection1: code: 'collection1-code' diff --git a/tests/Integration/DataFixtures/ORM/BlockRepositoryTest/test_it_finds_block_by_product_code.yml b/tests/Integration/DataFixtures/ORM/BlockRepositoryTest/test_it_finds_block_by_product_code.yml index b59eb71e9..1ea8738e4 100644 --- a/tests/Integration/DataFixtures/ORM/BlockRepositoryTest/test_it_finds_block_by_product_code.yml +++ b/tests/Integration/DataFixtures/ORM/BlockRepositoryTest/test_it_finds_block_by_product_code.yml @@ -71,57 +71,28 @@ Sylius\Component\Core\Model\ProductVariant: product_variant1: product: '@product1' code: "code1" - -BitBag\SyliusCmsPlugin\Entity\BlockTranslation: - block1_translation: - name: 'translation_name_en_US' - locale: 'en_US' - content: 'translation_content_en_US' - link: 'translation_link_en_US' - block2_translation: - name: 'translation_name_en_US' - locale: 'en_US' - content: 'translation_content_en_US' - link: 'translation_link_en_US' - block3_translation: - name: 'translation_name_en_US' - locale: 'en_US' - content: 'translation_content_en_US' - link: 'translation_link_en_US' BitBag\SyliusCmsPlugin\Entity\Block: block1: code: 'block1-code' enabled: true - products: - - '@product1' collections: - '@collection1' channels: - '@channel' - translations: - - '@block1_translation' block2: code: 'block2-code' enabled: true - products: - - '@product2' collections: - '@collection2' channels: - '@channel' - translations: - - '@block2_translation' block3: code: 'block3-code' enabled: false - products: - - '@product3' collections: - '@collection3' channels: - '@channel' - translations: - - '@block3_translation' BitBag\SyliusCmsPlugin\Entity\Collection: collection1: code: 'collection1-code' diff --git a/tests/Integration/Repository/BlockRepositoryTest.php b/tests/Integration/Repository/BlockRepositoryTest.php index f9bd8084a..a76f67933 100644 --- a/tests/Integration/Repository/BlockRepositoryTest.php +++ b/tests/Integration/Repository/BlockRepositoryTest.php @@ -41,21 +41,8 @@ public function test_it_finds_enabled_block_by_collection_code(): void $blockRepository = $this->getRepository(); - $block_array1 = $blockRepository->findByCollectionCode('collection1-code', 'en_US', 'code'); - $block_array3 = $blockRepository->findByCollectionCode('collection3-code', 'en_US', 'code'); - - self::assertNotEmpty($block_array1); - self::assertEmpty($block_array3); - } - - public function test_it_finds_enabled_block_by_product_code(): void - { - $this->loadFixturesFromFile('BlockRepositoryTest/test_it_finds_block_by_product_code.yml'); - - $blockRepository = $this->getRepository(); - - $block_array1 = $blockRepository->findByProductCode('MUG_SW', 'en_US', 'code'); - $block_array3 = $blockRepository->findByProductCode('MUG_SW3', 'en_US', 'code'); + $block_array1 = $blockRepository->findByCollectionCode('collection1-code', 'code'); + $block_array3 = $blockRepository->findByCollectionCode('collection3-code', 'code'); self::assertNotEmpty($block_array1); self::assertEmpty($block_array3);