Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OP-464: Block and page import adjustments #517

Merged
merged 4 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/block.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
code,type,name_en_US,content_en_US,sections,channels,products,image_en_US,slug_en_US
test4,image,Test,test,"blog, general",US_WEB,"010ba66b-adee-3d6e-9d63-67c44d686db1, 01d35db9-247d-3834-b300-20483d5e34e8",https://bitbag.shop/assets/web/images/header-logo.png,https://bitbag.shop/assets/web/images/header-logo.png
code,name,enabled,collections,locales,channels,products,products_in_taxons,taxons
test4,Block name,1,"blog,general",,FASHION_WEB,"000F_office_grey_jeans, 007M_black_elegance_jeans","caps, t_shirts",t_shirts
4 changes: 2 additions & 2 deletions doc/page.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
code,sections,channels,products,slug_en_US,name_en_US,image_en_US,meta_keywords_en_US,meta_description_en_US,content_en_US,breadcrumb_en_US,name_when_linked_en_US,description_when_linked_en_US
aboutUS,,US_WEB,,about_us,About US,,About US,About US,"",,,
code,name,enabled,collections,channels,slug_en_US,meta_title_en_US,meta_keywords_en_US,meta_description_en_US,slug_de_DE,meta_title_de_DE,meta_keywords_de_DE,meta_description_de_DE
aboutUS,About US,1,,FASHION_WEB,about_us,Meta title en US,About US,About US,about_us,Meta title en DE,About US,About US
53 changes: 53 additions & 0 deletions spec/Assigner/LocalesAssignerSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/

declare(strict_types=1);

namespace spec\BitBag\SyliusCmsPlugin\Assigner;

use BitBag\SyliusCmsPlugin\Assigner\LocalesAssigner;
use BitBag\SyliusCmsPlugin\Assigner\LocalesAssignerInterface;
use BitBag\SyliusCmsPlugin\Entity\LocaleAwareInterface;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Locale\Model\LocaleInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;

final class LocalesAssignerSpec extends ObjectBehavior
{
public function let(RepositoryInterface $localeRepository)
{
$this->beConstructedWith($localeRepository);
}

public function it_is_initializable()
{
$this->shouldHaveType(LocalesAssigner::class);
}

public function it_implements_locales_assigner_interface()
{
$this->shouldImplement(LocalesAssignerInterface::class);
}

public function it_assigns_locales_to_locale_aware_entity(
RepositoryInterface $localeRepository,
LocaleAwareInterface $localesAware,
LocaleInterface $locale1,
LocaleInterface $locale2
) {
$locale1->getCode()->willReturn('en_US');
$locale2->getCode()->willReturn('fr_FR');

$localeRepository->findAll()->willReturn([$locale1, $locale2]);

$localesAware->addLocale($locale1)->shouldBeCalled();
$localesAware->addLocale($locale2)->shouldBeCalled();

$this->assign($localesAware, ['en_US', 'fr_FR']);
}
}
54 changes: 54 additions & 0 deletions spec/Assigner/ProductsInTaxonsAssignerSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/

declare(strict_types=1);

namespace spec\BitBag\SyliusCmsPlugin\Assigner;

use BitBag\SyliusCmsPlugin\Assigner\ProductsInTaxonsAssigner;
use BitBag\SyliusCmsPlugin\Assigner\ProductsInTaxonsAssignerInterface;
use BitBag\SyliusCmsPlugin\Entity\ProductsInTaxonsAwareInterface;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Core\Model\TaxonInterface;
use Sylius\Component\Taxonomy\Repository\TaxonRepositoryInterface;

final class ProductsInTaxonsAssignerSpec extends ObjectBehavior
{
public function let(TaxonRepositoryInterface $taxonRepository)
{
$this->beConstructedWith($taxonRepository);
}

public function it_is_initializable()
{
$this->shouldHaveType(ProductsInTaxonsAssigner::class);
}

public function it_implements_products_in_taxons_assigner_interface()
{
$this->shouldImplement(ProductsInTaxonsAssignerInterface::class);
}

public function it_assigns_taxons_to_products_in_taxons_aware_entity(
TaxonRepositoryInterface $taxonRepository,
ProductsInTaxonsAwareInterface $productsInTaxonsAware,
TaxonInterface $taxon1,
TaxonInterface $taxon2
) {
$taxon1->getCode()->willReturn('taxon_code_1');
$taxon2->getCode()->willReturn('taxon_code_2');

$taxonRepository->findOneBy(['code' => 'taxon_code_1'])->willReturn($taxon1);
$taxonRepository->findOneBy(['code' => 'taxon_code_2'])->willReturn($taxon2);

$productsInTaxonsAware->addProductsInTaxon($taxon1)->shouldBeCalled();
$productsInTaxonsAware->addProductsInTaxon($taxon2)->shouldBeCalled();

$this->assign($productsInTaxonsAware, ['taxon_code_1', 'taxon_code_2']);
}
}
53 changes: 39 additions & 14 deletions spec/Importer/BlockImporterSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@
namespace spec\BitBag\SyliusCmsPlugin\Importer;

use BitBag\SyliusCmsPlugin\Entity\BlockInterface;
use BitBag\SyliusCmsPlugin\Importer\BlockImporter;
use BitBag\SyliusCmsPlugin\Importer\BlockImporterInterface;
use BitBag\SyliusCmsPlugin\Repository\BlockRepositoryInterface;
use BitBag\SyliusCmsPlugin\Resolver\ImporterChannelsResolverInterface;
use BitBag\SyliusCmsPlugin\Resolver\ImporterLocalesResolverInterface;
use BitBag\SyliusCmsPlugin\Resolver\ImporterProductsInTaxonsResolverInterface;
use BitBag\SyliusCmsPlugin\Resolver\ImporterProductsResolverInterface;
use BitBag\SyliusCmsPlugin\Resolver\ImporterCollectionsResolverInterface;
use BitBag\SyliusCmsPlugin\Resolver\ImporterTaxonsResolverInterface;
use BitBag\SyliusCmsPlugin\Resolver\ResourceResolverInterface;
use PhpSpec\ObjectBehavior;
use Symfony\Component\Validator\ConstraintViolationList;
Expand All @@ -23,43 +28,63 @@
final class BlockImporterSpec extends ObjectBehavior
{
public function let(
ResourceResolverInterface $blockResourceResolver,
ResourceResolverInterface $blockResourceResolver,
ImporterCollectionsResolverInterface $importerCollectionsResolver,
ImporterChannelsResolverInterface $importerChannelsResolver,
ValidatorInterface $validator,
BlockRepositoryInterface $blockRepository
) {
ImporterChannelsResolverInterface $importerChannelsResolver,
ImporterLocalesResolverInterface $importerLocalesResolver,
ImporterProductsResolverInterface $importerProductsResolver,
ImporterTaxonsResolverInterface $importerTaxonsResolver,
ImporterProductsInTaxonsResolverInterface $importerProductsInTaxonsResolver,
ValidatorInterface $validator,
BlockRepositoryInterface $blockRepository
)
{
$this->beConstructedWith(
$blockResourceResolver,
$importerCollectionsResolver,
$importerChannelsResolver,
$importerLocalesResolver,
$importerProductsResolver,
$importerTaxonsResolver,
$importerProductsInTaxonsResolver,
$validator,
$blockRepository
);
}

public function it_is_initializable()
{
$this->shouldHaveType(\BitBag\SyliusCmsPlugin\Importer\BlockImporter::class);
$this->shouldImplement(\BitBag\SyliusCmsPlugin\Importer\BlockImporterInterface::class);
$this->shouldHaveType(BlockImporter::class);
$this->shouldImplement(BlockImporterInterface::class);
}

public function it_imports_block(
ResourceResolverInterface $blockResourceResolver,
ResourceResolverInterface $blockResourceResolver,
ImporterCollectionsResolverInterface $importerCollectionsResolver,
ImporterChannelsResolverInterface $importerChannelsResolver,
ValidatorInterface $validator,
BlockRepositoryInterface $blockRepository,
BlockInterface $block
) {
$row = ['name_pl' => 'name', 'code' => 'block_code'];
ImporterChannelsResolverInterface $importerChannelsResolver,
ImporterLocalesResolverInterface $importerLocalesResolver,
ImporterProductsResolverInterface $importerProductsResolver,
ImporterTaxonsResolverInterface $importerTaxonsResolver,
ImporterProductsInTaxonsResolverInterface $importerProductsInTaxonsResolver,
ValidatorInterface $validator,
BlockRepositoryInterface $blockRepository,
BlockInterface $block
)
{
$row = ['name' => 'block_name', 'code' => 'block_code', 'enabled' => '1'];

$blockResourceResolver->getResource('block_code')->willReturn($block);

$block->setCode('block_code')->shouldBeCalled();
$block->setName('block_name')->shouldBeCalled();
$block->setEnabled(true)->shouldBeCalled();

$importerCollectionsResolver->resolve($block, null)->shouldBeCalled();
$importerChannelsResolver->resolve($block, null)->shouldBeCalled();
$importerLocalesResolver->resolve($block, null)->shouldBeCalled();
$importerProductsResolver->resolve($block, null)->shouldBeCalled();
$importerTaxonsResolver->resolve($block, null)->shouldBeCalled();
$importerProductsInTaxonsResolver->resolve($block, null)->shouldBeCalled();

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

Expand Down
19 changes: 8 additions & 11 deletions spec/Importer/PageImporterSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,32 +62,29 @@ public function it_imports_page_no_url(
{
$row = [
'code' => 'page_code',
'name' => 'page_name',
'enabled' => '1',
'slug_pl' => 'slug',
'name_pl' => 'name',
'image_pl' => null,
'imagecode_pl' => 'imagecode',
'metakeywords_pl' => 'metakeywords',
'metadescription_pl' => 'metadescription',
'content_pl' => 'content',
'breadcrumb_pl' => 'breadcrumb',
'namewhenlinked_pl' => 'namewhenlinked',
'descriptionwhenlinked_pl' => 'descriptionwhenlinked',
'meta_title_pl' => 'metatitle',
'meta_keywords_pl' => 'metakeywords',
'meta_description_pl' => 'metadescription',
'collections' => 'collections',
'channels' => 'channels',
'products' => 'products',
];

$pageResourceResolver->getResource('page_code')->willReturn($page);

$localeContext->getLocaleCode()->willReturn('en_US');

$page->setCode('page_code')->shouldBeCalled();
$page->setName('page_name')->shouldBeCalled();
$page->setEnabled(true)->shouldBeCalled();
$page->setFallbackLocale('en_US')->shouldBeCalled();

$page->setCurrentLocale('pl')->shouldBeCalled();

$page->setSlug('slug')->shouldBeCalled();
$page->setName('name')->shouldBeCalled();
$page->setTitle('metatitle')->shouldBeCalled();
$page->setMetaKeywords('metakeywords')->shouldBeCalled();
$page->setMetaDescription('metadescription')->shouldBeCalled();

Expand Down
48 changes: 48 additions & 0 deletions spec/Resolver/ImporterLocalesResolverSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/

declare(strict_types=1);

namespace spec\BitBag\SyliusCmsPlugin\Resolver;

use BitBag\SyliusCmsPlugin\Assigner\LocalesAssignerInterface;
use BitBag\SyliusCmsPlugin\Entity\LocaleAwareInterface;
use BitBag\SyliusCmsPlugin\Resolver\ImporterLocalesResolver;
use PhpSpec\ObjectBehavior;

final class ImporterLocalesResolverSpec extends ObjectBehavior
{
public function let(LocalesAssignerInterface $localesAssigner)
{
$this->beConstructedWith($localesAssigner);
}

public function it_is_initializable()
{
$this->shouldHaveType(ImporterLocalesResolver::class);
}

public function it_resolves_locales_for_locale_aware_entity(
LocalesAssignerInterface $localesAssigner,
LocaleAwareInterface $localesAware
) {
$localesRow = 'en_US, fr_FR';
$localesAssigner->assign($localesAware, ['en_US', 'fr_FR'])->shouldBeCalled();

$this->resolve($localesAware, $localesRow);
}

public function it_does_not_assign_locales_when_locales_row_is_empty(
LocalesAssignerInterface $localesAssigner,
LocaleAwareInterface $localesAware
) {
$localesAssigner->assign($localesAware, [])->shouldNotBeCalled();

$this->resolve($localesAware, '');
}
}
48 changes: 48 additions & 0 deletions spec/Resolver/ImporterProductsInTaxonsResolverSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/

declare(strict_types=1);

namespace spec\BitBag\SyliusCmsPlugin\Resolver;

use BitBag\SyliusCmsPlugin\Assigner\ProductsInTaxonsAssignerInterface;
use BitBag\SyliusCmsPlugin\Entity\ProductsInTaxonsAwareInterface;
use BitBag\SyliusCmsPlugin\Resolver\ImporterProductsInTaxonsResolver;
use PhpSpec\ObjectBehavior;

final class ImporterProductsInTaxonsResolverSpec extends ObjectBehavior
{
public function let(ProductsInTaxonsAssignerInterface $productsInTaxonsAssigner)
{
$this->beConstructedWith($productsInTaxonsAssigner);
}

public function it_is_initializable()
{
$this->shouldHaveType(ImporterProductsInTaxonsResolver::class);
}

public function it_resolves_taxons_for_products_in_taxons_aware_entity(
ProductsInTaxonsAssignerInterface $productsInTaxonsAssigner,
ProductsInTaxonsAwareInterface $productsInTaxonsAware
) {
$taxonsRow = 'taxon_code_1, taxon_code_2';
$productsInTaxonsAssigner->assign($productsInTaxonsAware, ['taxon_code_1', 'taxon_code_2'])->shouldBeCalled();

$this->resolve($productsInTaxonsAware, $taxonsRow);
}

public function it_does_not_assign_taxons_when_taxons_row_is_null(
ProductsInTaxonsAssignerInterface $productsInTaxonsAssigner,
ProductsInTaxonsAwareInterface $productsInTaxonsAware
) {
$productsInTaxonsAssigner->assign($productsInTaxonsAware, [])->shouldNotBeCalled();

$this->resolve($productsInTaxonsAware, null);
}
}
Loading
Loading