Skip to content

Commit

Permalink
Merge pull request #501 from BitBagCommerce/feature/OP-321
Browse files Browse the repository at this point in the history
OP-321: Update block functionality
  • Loading branch information
jkindly authored Jul 1, 2024
2 parents 9344235 + 721d9e7 commit 4ac9ba8
Show file tree
Hide file tree
Showing 74 changed files with 669 additions and 1,079 deletions.
6 changes: 3 additions & 3 deletions features/admin/adding_block.feature
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Feature: Adding blocks
Scenario: Adding block
When I go to the create block page
And I fill the code with "store_description"
And I fill the content with "<p>We have the best candies on the internet!</p>"
And I fill the name with "Store Description"
And I add it
Then I should be notified that the block has been created

Expand All @@ -21,8 +21,8 @@ Feature: Adding blocks
Given there are existing collections named "Blog" and "Homepage"
When I go to the create block page
And I fill the code with "intro"
And I fill the name with "Intro"
And I add "Blog" and "Homepage" collections to it
And I fill the content with "Hello world!"
And I add it
Then I should be notified that the block has been created

Expand All @@ -43,7 +43,7 @@ Feature: Adding blocks
@ui
Scenario: Trying to add block with too long data
When I go to the create block page
And I fill "Code, Name, Content" fields with 251 characters
And I fill "Code, Name" fields with 251 characters
And I try to add it
Then I should be notified that "Code, Name" fields are too long

5 changes: 3 additions & 2 deletions features/admin/managing_blocks.feature
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@ Feature: Managing cms blocks

@ui @javascript
Scenario: Updating block
Given there is a block with "store_phone_number" code and "123456789" content
Given there is a block with "store_phone_number" code
When I go to the update "store_phone_number" block page
And I fill the content with "987654321"
And I fill the name with "Store phone number" if the name field is empty
And I update it
Then I should be notified that the block has been successfully updated

@ui
Scenario: Disabling block
Given there is an existing block with "bitbag_quote" code
When I go to the update "bitbag_quote" block page
And I fill the name with "BitBag quote" if the name field is empty
And I disable it
And I update it
Then I should be notified that the block has been successfully updated
Expand Down
3 changes: 1 addition & 2 deletions features/api/viewing_blocks.feature
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Feature: Getting data from cms blocks
Background:
Given the store operates on a single channel in "United States"
And there is a block in the store
And there is a block with "block-1" code and "Hi there!" content
And there is a block with "block-1" code

@api
Scenario: Browsing blocks
Expand All @@ -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

14 changes: 0 additions & 14 deletions features/shop/displaying_homepage_block.feature

This file was deleted.

24 changes: 0 additions & 24 deletions spec/Entity/BlockSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,6 @@ public function it_toggles(): void
$this->isEnabled()->shouldReturn(false);
}

public function it_associates_products(ProductInterface $firstProduct, ProductInterface $secondProduct): void
{
$this->addProduct($firstProduct);
$this->hasProduct($firstProduct)->shouldReturn(true);

$this->hasProduct($secondProduct)->shouldReturn(false);

$this->removeProduct($firstProduct);

$this->hasProduct($firstProduct)->shouldReturn(false);
}

public function it_associates_collections(CollectionInterface $firstCollection, CollectionInterface $secondCollection): void
{
$this->addCollection($firstCollection);
Expand All @@ -80,16 +68,4 @@ public function it_associates_channels(ChannelInterface $firstChannel, ChannelIn

$this->hasChannel($firstChannel)->shouldReturn(false);
}

public function it_associates_taxons(TaxonInterface $firstTaxon, TaxonInterface $secondTaxon): void
{
$this->addTaxon($firstTaxon);
$this->hasTaxon($firstTaxon)->shouldReturn(true);

$this->hasTaxon($secondTaxon)->shouldReturn(false);

$this->removeTaxon($firstTaxon);

$this->hasTaxon($secondTaxon)->shouldReturn(false);
}
}
47 changes: 0 additions & 47 deletions spec/Entity/BlockTranslationSpec.php

This file was deleted.

38 changes: 11 additions & 27 deletions spec/Importer/BlockImporterSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,22 @@
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,
ResourceResolverInterface $blockResourceResolver,
ImporterCollectionsResolverInterface $importerCollectionsResolver,
ImporterChannelsResolverInterface $importerChannelsResolver,
ImporterProductsResolverInterface $importerProductsResolver,
ValidatorInterface $validator,
BlockRepositoryInterface $blockRepository
ImporterChannelsResolverInterface $importerChannelsResolver,
ValidatorInterface $validator,
BlockRepositoryInterface $blockRepository
) {
$this->beConstructedWith(
$blockResourceResolver,
$localeContext,
$importerCollectionsResolver,
$importerChannelsResolver,
$importerProductsResolver,
$validator,
$blockRepository
);
Expand All @@ -50,32 +45,21 @@ public function it_is_initializable()
}

public function it_imports_block(
ResourceResolverInterface $blockResourceResolver,
LocaleContextInterface $localeContext,
ResourceResolverInterface $blockResourceResolver,
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'];
ImporterChannelsResolverInterface $importerChannelsResolver,
ValidatorInterface $validator,
BlockRepositoryInterface $blockRepository,
BlockInterface $block
) {
$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();
$importerProductsResolver->resolve($block, null)->shouldBeCalled();

$validator->validate($block, null, ['bitbag'])->willReturn(new ConstraintViolationList());

Expand Down
4 changes: 0 additions & 4 deletions src/Controller/BlockController.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ public function previewAction(Request $request): Response

/** @var BlockInterface $block */
$block = $form->getData();
$defaultLocale = $this->getParameter('locale');

$block->setFallbackLocale($request->get('_locale', $defaultLocale));
$block->setCurrentLocale($request->get('_locale', $defaultLocale));

if (!$configuration->isHtmlRequest()) {
Assert::true(null !== $this->viewHandler);
Expand Down
73 changes: 13 additions & 60 deletions src/Entity/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,28 @@
namespace BitBag\SyliusCmsPlugin\Entity;

use Sylius\Component\Resource\Model\ToggleableTrait;
use Sylius\Component\Resource\Model\TranslatableTrait;
use Sylius\Component\Resource\Model\TranslationInterface;

class Block implements BlockInterface
{
use ToggleableTrait;
use CollectibleTrait;
use ProductsAwareTrait;
use TaxonAwareTrait;
use ChannelsAwareTrait;
use TranslatableTrait {
__construct as protected initializeTranslationsCollection;
}
use BlockContentAwareTrait;
use LocaleAwareTrait;

public function __construct()
{
$this->initializeTranslationsCollection();
$this->initializeCollectionsCollection();
$this->initializeProductsCollection();
$this->initializeTaxonCollection();
$this->initializeChannelsCollection();
$this->initializeContentsCollection();
$this->initializeLocalesCollection();
}

/** @var int|null */
protected $id;
protected ?int $id;

protected ?string $code = null;

/** @var string|null */
protected $code;
protected ?string $name;

public function getId(): ?int
{
Expand All @@ -57,59 +51,18 @@ public function setCode(?string $code): void

public function getName(): ?string
{
/** @var BlockTranslationInterface $blockTranslationInterface */
$blockTranslationInterface = $this->getBlockTranslation();

return $blockTranslationInterface->getName();
return $this->name;
}

public function setName(?string $name): void
{
/** @var BlockTranslationInterface $blockTranslationInterface */
$blockTranslationInterface = $this->getBlockTranslation();
$blockTranslationInterface->setName($name);
$this->name = $name;
}

public function getContent(): ?string
{
/** @var BlockTranslationInterface $blockTranslationInterface */
$blockTranslationInterface = $this->getBlockTranslation();

return $blockTranslationInterface->getContent();
}

public function setContent(?string $content): void
{
/** @var BlockTranslationInterface $blockTranslationInterface */
$blockTranslationInterface = $this->getBlockTranslation();
$blockTranslationInterface->setContent($content);
}

public function getLink(): ?string
{
/** @var BlockTranslationInterface $blockTranslationInterface */
$blockTranslationInterface = $this->getBlockTranslation();

return $blockTranslationInterface->getLink();
}

public function setLink(?string $link): void
{
/** @var BlockTranslationInterface $blockTranslationInterface */
$blockTranslationInterface = $this->getBlockTranslation();
$blockTranslationInterface->setLink($link);
}

/**
* @return BlockTranslationInterface|TranslationInterface
*/
protected function getBlockTranslation(): TranslationInterface
{
return $this->getTranslation();
}

protected function createTranslation(): BlockTranslationInterface
{
return new BlockTranslation();
// TODO: empty for now for testing purposes, to be implemented in the future tasks
// related to the epic: https://bitbag.atlassian.net/browse/OP-312
return '';
}
}
Loading

0 comments on commit 4ac9ba8

Please sign in to comment.