Skip to content

Commit

Permalink
OP-321: Tests adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
jkindly committed Jun 25, 2024
1 parent ae0f031 commit 12602a0
Show file tree
Hide file tree
Showing 12 changed files with 9 additions and 538 deletions.
1 change: 0 additions & 1 deletion features/api/viewing_blocks.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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

47 changes: 0 additions & 47 deletions spec/Entity/BlockTranslationSpec.php

This file was deleted.

13 changes: 1 addition & 12 deletions spec/Importer/BlockImporterSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@
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;

final class BlockImporterSpec extends ObjectBehavior
{
public function let(
ResourceResolverInterface $blockResourceResolver,
LocaleContextInterface $localeContext,
ImporterCollectionsResolverInterface $importerCollectionsResolver,
ImporterChannelsResolverInterface $importerChannelsResolver,
ImporterProductsResolverInterface $importerProductsResolver,
Expand All @@ -34,7 +32,6 @@ public function let(
) {
$this->beConstructedWith(
$blockResourceResolver,
$localeContext,
$importerCollectionsResolver,
$importerChannelsResolver,
$importerProductsResolver,
Expand All @@ -51,26 +48,18 @@ public function it_is_initializable()

public function it_imports_block(
ResourceResolverInterface $blockResourceResolver,
LocaleContextInterface $localeContext,
ImporterCollectionsResolverInterface $importerCollectionsResolver,
ImporterChannelsResolverInterface $importerChannelsResolver,
ImporterProductsResolverInterface $importerProductsResolver,
ValidatorInterface $validator,
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();
Expand Down
65 changes: 0 additions & 65 deletions tests/Application/config/packages/bitbag_sylius_cms_plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,90 +40,25 @@ sylius_fixtures:
homepage_products_info:
channels:
- "FASHION_WEB"
translations:
en_US:
content: |
<div class="ui info message">
<i class="em em-arrow_down"></i> Click one of the below products to see what you can do with the blocks in your product view! <i class="em em-arrow_down"></i>
</div>
collection_info_block:
channels:
- "FASHION_WEB"
collections:
- "products"
translations:
en_US:
content: |
<div class="ignored info ui message">
The block you can see on the left is just a block associated with a collection named <code>Products</code>
</div>
<p>With this feature, you can render any block you want on the product page, like size table, delivery information, or even promotion banner.</p>
<p>It's done with a simple controller render:</p>
<pre>{{ render(path('bitbag_sylius_cms_plugin_shop_block_index_by_collection_code', {'collectionCode' : 'products', 'template' : '@BitBagSyliusCmsPlugin/Shop/Block/index.html.twig'})) }}</pre>
product_info_block:
channels:
- "FASHION_WEB"
products: 5
translations:
en_US:
content: |
<div class="ignored info ui message">On the other hand, the block on the right is a block associated with specific products.</div>
<p>This approach can be helpful with displaying some content dedicated to specific products, like size table or product story</p>
<p>The way you render it is similar to the one from above example:</p>
<pre>{{ render(path('bitbag_sylius_cms_plugin_shop_block_index_by_product_code', {'productCode' : product.code, 'template' : '@BitBagSyliusCmsPlugin/Shop/Block/index.html.twig'})) }}</pre>
homepage_intro:
channels:
- "FASHION_WEB"
translations:
en_US:
content: |
<h3>Blocks</h3>
<p>
The left block is rendered with the usage of the particular controller like this:
</p>
<pre>
render(path('bitbag_sylius_cms_plugin_shop_block_render', {'code' : 'homepage_header_image'}))
</pre>
<p>
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.
</p>
<p>
The other three blocks, including this one you are reading right now, are using Twig helper method.
</p>
<pre>
bitbag_cms_render_block('homepage_intro')
bitbag_cms_render_block('homepage_banner_image_1')
bitbag_cms_render_block('homepage_banner_image_2')
</pre>
lorem_ipsum:
channels:
- "FASHION_WEB"
collections:
- "homepage"
translations:
en_US:
content: |
<p>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</p>
<ul>
<li>Morbi in sem quis dui placerat ornare. Pellentesque odio nisi, euismod in, pharetra a, ultricies in, diam. Sed arcu. Cras consequat.</li>
<li>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.</li>
<li>Phasellus ultrices nulla quis nibh. Quisque a lectus. Donec consectetuer ligula vulputate sem tristique cursus. Nam nulla quam, gravida non, commodo a, sodales sit amet, nisi.</li>
<li>Pellentesque fermentum dolor. Aliquam quam lectus, facilisis auctor, ultrices ut, elementum vulputate, nunc.</li>
</ul>
<p>Pellentesque habitant morbi tristique sene</p>
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:
Expand Down
12 changes: 2 additions & 10 deletions tests/Behat/Context/Setup/BlockContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand All @@ -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;
Expand Down
31 changes: 0 additions & 31 deletions tests/Functional/DataFixtures/ORM/Api/BlockTest/block.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Loading

0 comments on commit 12602a0

Please sign in to comment.