From 6e75a40de0dd917f372e2b1bafdad3176e0d83a4 Mon Sep 17 00:00:00 2001 From: jkindly Date: Fri, 2 Aug 2024 13:06:26 +0200 Subject: [PATCH 1/4] OP-464: Page import adjustments --- doc/page.csv | 4 ++-- src/Importer/PageImporter.php | 12 ++++------ src/Importer/PageImporterInterface.php | 24 ++++++-------------- src/Resolver/ImporterCollectionsResolver.php | 2 +- 4 files changed, 14 insertions(+), 28 deletions(-) diff --git a/doc/page.csv b/doc/page.csv index 47d208dd7..4518d95bf 100644 --- a/doc/page.csv +++ b/doc/page.csv @@ -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 diff --git a/src/Importer/PageImporter.php b/src/Importer/PageImporter.php index aaf83a31a..48531cdf4 100644 --- a/src/Importer/PageImporter.php +++ b/src/Importer/PageImporter.php @@ -43,11 +43,13 @@ public function import(array $row): void $page->setCode($code); $page->setFallbackLocale($this->localeContext->getLocaleCode()); + $page->setName($this->getColumnValue(self::NAME_COLUMN, $row)); + $page->setEnabled((bool) $this->getColumnValue(self::ENABLED_COLUMN, $row)); foreach ($this->getAvailableLocales($this->getTranslatableColumns(), array_keys($row)) as $locale) { $page->setCurrentLocale($locale); $page->setSlug($this->getTranslatableColumnValue(self::SLUG_COLUMN, $locale, $row)); - $page->setName($this->getTranslatableColumnValue(self::NAME_COLUMN, $locale, $row)); + $page->setTitle($this->getTranslatableColumnValue(self::META_TITLE_COLUMN, $locale, $row)); $page->setMetaKeywords($this->getTranslatableColumnValue(self::META_KEYWORDS_COLUMN, $locale, $row)); $page->setMetaDescription($this->getTranslatableColumnValue(self::META_DESCRIPTION_COLUMN, $locale, $row)); } @@ -70,15 +72,9 @@ private function getTranslatableColumns(): array { return [ self::SLUG_COLUMN, - self::NAME_COLUMN, - self::IMAGE_COLUMN, - self::IMAGE_CODE_COLUMN, + self::META_TITLE_COLUMN, self::META_KEYWORDS_COLUMN, self::META_DESCRIPTION_COLUMN, - self::CONTENT_COLUMN, - self::BREADCRUMB_COLUMN, - self::NAME_WHEN_LINKED_COLUMN, - self::DESCRIPTION_WHEN_LINKED_COLUMN, ]; } } diff --git a/src/Importer/PageImporterInterface.php b/src/Importer/PageImporterInterface.php index b8da6d41c..ec3da1320 100644 --- a/src/Importer/PageImporterInterface.php +++ b/src/Importer/PageImporterInterface.php @@ -14,29 +14,19 @@ interface PageImporterInterface extends ImporterInterface { public const CODE_COLUMN = 'code'; - public const COLLECTIONS_COLUMN = 'collections'; + public const NAME_COLUMN = 'name'; + + public const ENABLED_COLUMN = 'enabled'; public const CHANNELS_COLUMN = 'channels'; - public const PRODUCTS_COLUMN = 'products'; + public const COLLECTIONS_COLUMN = 'collections'; public const SLUG_COLUMN = 'slug__locale__'; - public const NAME_COLUMN = 'name__locale__'; - - public const IMAGE_COLUMN = 'image__locale__'; - - public const IMAGE_CODE_COLUMN = 'imagecode__locale__'; - - public const META_KEYWORDS_COLUMN = 'metakeywords__locale__'; - - public const META_DESCRIPTION_COLUMN = 'metadescription__locale__'; - - public const CONTENT_COLUMN = 'content__locale__'; - - public const BREADCRUMB_COLUMN = 'breadcrumb__locale__'; + public const META_TITLE_COLUMN = 'meta_title__locale__'; - public const NAME_WHEN_LINKED_COLUMN = 'namewhenlinked__locale__'; + public const META_KEYWORDS_COLUMN = 'meta_keywords__locale__'; - public const DESCRIPTION_WHEN_LINKED_COLUMN = 'descriptionwhenlinked__locale__'; + public const META_DESCRIPTION_COLUMN = 'meta_description__locale__'; } diff --git a/src/Resolver/ImporterCollectionsResolver.php b/src/Resolver/ImporterCollectionsResolver.php index d803ecebc..938555826 100644 --- a/src/Resolver/ImporterCollectionsResolver.php +++ b/src/Resolver/ImporterCollectionsResolver.php @@ -21,7 +21,7 @@ public function __construct(private CollectionsAssignerInterface $collectionsAss public function resolve(CollectibleInterface $collectionable, ?string $collectionsRow): void { - if (null === $collectionsRow) { + if (empty($collectionsRow)) { return; } From 5da87f22d2eb9f7fe60a90300bbe0482dcf18867 Mon Sep 17 00:00:00 2001 From: jkindly Date: Mon, 5 Aug 2024 12:40:47 +0200 Subject: [PATCH 2/4] OP-464: Block import adjustments --- doc/block.csv | 4 +-- src/Assigner/LocalesAssigner.php | 34 ++++++++++++++++++ src/Assigner/LocalesAssignerInterface.php | 18 ++++++++++ src/Assigner/ProductsInTaxonsAssigner.php | 34 ++++++++++++++++++ .../ProductsInTaxonsAssignerInterface.php | 18 ++++++++++ src/Command/ImportFromCsvCommand.php | 8 ++++- src/Importer/BlockImporter.php | 14 ++++++++ src/Importer/BlockImporterInterface.php | 12 ++++--- src/Resolver/ImporterLocalesResolver.php | 35 +++++++++++++++++++ .../ImporterLocalesResolverInterface.php | 18 ++++++++++ .../ImporterProductsInTaxonsResolver.php | 35 +++++++++++++++++++ ...orterProductsInTaxonsResolverInterface.php | 18 ++++++++++ src/Resolver/ImporterTaxonsResolver.php | 35 +++++++++++++++++++ .../ImporterTaxonsResolverInterface.php | 18 ++++++++++ src/Resources/config/services/assigner.xml | 8 +++++ src/Resources/config/services/importer.xml | 4 +++ src/Resources/config/services/resolver.xml | 12 +++++++ 17 files changed, 318 insertions(+), 7 deletions(-) create mode 100644 src/Assigner/LocalesAssigner.php create mode 100644 src/Assigner/LocalesAssignerInterface.php create mode 100644 src/Assigner/ProductsInTaxonsAssigner.php create mode 100644 src/Assigner/ProductsInTaxonsAssignerInterface.php create mode 100644 src/Resolver/ImporterLocalesResolver.php create mode 100644 src/Resolver/ImporterLocalesResolverInterface.php create mode 100644 src/Resolver/ImporterProductsInTaxonsResolver.php create mode 100644 src/Resolver/ImporterProductsInTaxonsResolverInterface.php create mode 100644 src/Resolver/ImporterTaxonsResolver.php create mode 100644 src/Resolver/ImporterTaxonsResolverInterface.php diff --git a/doc/block.csv b/doc/block.csv index 0e592d202..227dc60b7 100644 --- a/doc/block.csv +++ b/doc/block.csv @@ -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 diff --git a/src/Assigner/LocalesAssigner.php b/src/Assigner/LocalesAssigner.php new file mode 100644 index 000000000..f90519143 --- /dev/null +++ b/src/Assigner/LocalesAssigner.php @@ -0,0 +1,34 @@ +localeRepository->findAll(); + + /** @var LocaleInterface $locale */ + foreach ($locales as $locale) { + if (in_array($locale->getCode(), $localesCodes, true)) { + $localesAware->addLocale($locale); + } + } + } +} diff --git a/src/Assigner/LocalesAssignerInterface.php b/src/Assigner/LocalesAssignerInterface.php new file mode 100644 index 000000000..a189e7776 --- /dev/null +++ b/src/Assigner/LocalesAssignerInterface.php @@ -0,0 +1,18 @@ +taxonRepository->findOneBy(['code' => $taxonCode]); + + Assert::notNull($taxon, sprintf('Taxon with %s code not found.', $taxonCode)); + $productsInTaxonsAware->addProductsInTaxon($taxon); + } + } +} diff --git a/src/Assigner/ProductsInTaxonsAssignerInterface.php b/src/Assigner/ProductsInTaxonsAssignerInterface.php new file mode 100644 index 000000000..569fc3833 --- /dev/null +++ b/src/Assigner/ProductsInTaxonsAssignerInterface.php @@ -0,0 +1,18 @@ +getArgument('resource'); $file = $input->getArgument('file'); + $io->title('Importing resources...'); + $this->importProcessor->process($resourceName, $file); - return 0; + $io->success('Resources imported successfully.'); + + return Command::SUCCESS; } } diff --git a/src/Importer/BlockImporter.php b/src/Importer/BlockImporter.php index 5261460fb..e41ed67d0 100644 --- a/src/Importer/BlockImporter.php +++ b/src/Importer/BlockImporter.php @@ -14,6 +14,10 @@ use BitBag\SyliusCmsPlugin\Repository\BlockRepositoryInterface; use BitBag\SyliusCmsPlugin\Resolver\ImporterChannelsResolverInterface; use BitBag\SyliusCmsPlugin\Resolver\ImporterCollectionsResolverInterface; +use BitBag\SyliusCmsPlugin\Resolver\ImporterLocalesResolverInterface; +use BitBag\SyliusCmsPlugin\Resolver\ImporterProductsInTaxonsResolverInterface; +use BitBag\SyliusCmsPlugin\Resolver\ImporterProductsResolverInterface; +use BitBag\SyliusCmsPlugin\Resolver\ImporterTaxonsResolverInterface; use BitBag\SyliusCmsPlugin\Resolver\ResourceResolverInterface; use Symfony\Component\Validator\Validator\ValidatorInterface; use Webmozart\Assert\Assert; @@ -24,6 +28,10 @@ public function __construct( private ResourceResolverInterface $blockResourceResolver, private ImporterCollectionsResolverInterface $importerCollectionsResolver, private ImporterChannelsResolverInterface $importerChannelsResolver, + private ImporterLocalesResolverInterface $importerLocalesResolver, + private ImporterProductsResolverInterface $importerProductsResolver, + private ImporterTaxonsResolverInterface $importerTaxonsResolver, + private ImporterProductsInTaxonsResolverInterface $importerProductsInTaxonsResolver, ValidatorInterface $validator, private BlockRepositoryInterface $blockRepository, ) { @@ -38,9 +46,15 @@ public function import(array $row): void /** @var BlockInterface $block */ $block = $this->blockResourceResolver->getResource($code); $block->setCode($code); + $block->setName($this->getColumnValue(self::NAME_COLUMN, $row)); + $block->setEnabled((bool) $this->getColumnValue(self::ENABLED_COLUMN, $row)); $this->importerCollectionsResolver->resolve($block, $this->getColumnValue(self::COLLECTIONS_COLUMN, $row)); $this->importerChannelsResolver->resolve($block, $this->getColumnValue(self::CHANNELS_COLUMN, $row)); + $this->importerLocalesResolver->resolve($block, $this->getColumnValue(self::LOCALES_COLUMN, $row)); + $this->importerProductsResolver->resolve($block, $this->getColumnValue(self::PRODUCTS_COLUMN, $row)); + $this->importerTaxonsResolver->resolve($block, $this->getColumnValue(self::TAXONS_COLUMN, $row)); + $this->importerProductsInTaxonsResolver->resolve($block, $this->getColumnValue(self::PRODUCTS_IN_TAXONS_COLUMN, $row)); $this->validateResource($block, ['bitbag']); $this->blockRepository->add($block); diff --git a/src/Importer/BlockImporterInterface.php b/src/Importer/BlockImporterInterface.php index 21dccb04d..fce4522af 100644 --- a/src/Importer/BlockImporterInterface.php +++ b/src/Importer/BlockImporterInterface.php @@ -14,15 +14,19 @@ interface BlockImporterInterface extends ImporterInterface { public const CODE_COLUMN = 'code'; + public const NAME_COLUMN = 'name'; + + public const ENABLED_COLUMN = 'enabled'; + public const COLLECTIONS_COLUMN = 'collections'; + public const LOCALES_COLUMN = 'locales'; + public const CHANNELS_COLUMN = 'channels'; public const PRODUCTS_COLUMN = 'products'; - public const NAME_COLUMN = 'name__locale__'; - - public const CONTENT_COLUMN = 'content__locale__'; + public const PRODUCTS_IN_TAXONS_COLUMN = 'products_in_taxons'; - public const LINK_COLUMN = 'link__locale__'; + public const TAXONS_COLUMN = 'taxons'; } diff --git a/src/Resolver/ImporterLocalesResolver.php b/src/Resolver/ImporterLocalesResolver.php new file mode 100644 index 000000000..450832d53 --- /dev/null +++ b/src/Resolver/ImporterLocalesResolver.php @@ -0,0 +1,35 @@ +localesAssigner->assign($localesAware, $channelsCodes); + } +} diff --git a/src/Resolver/ImporterLocalesResolverInterface.php b/src/Resolver/ImporterLocalesResolverInterface.php new file mode 100644 index 000000000..45864042b --- /dev/null +++ b/src/Resolver/ImporterLocalesResolverInterface.php @@ -0,0 +1,18 @@ +productsInTaxonsAssigner->assign($productsInTaxonsAware, $taxonsCodes); + } +} diff --git a/src/Resolver/ImporterProductsInTaxonsResolverInterface.php b/src/Resolver/ImporterProductsInTaxonsResolverInterface.php new file mode 100644 index 000000000..ddb07a222 --- /dev/null +++ b/src/Resolver/ImporterProductsInTaxonsResolverInterface.php @@ -0,0 +1,18 @@ +taxonsAssigner->assign($taxonsAware, $taxonsCodes); + } +} diff --git a/src/Resolver/ImporterTaxonsResolverInterface.php b/src/Resolver/ImporterTaxonsResolverInterface.php new file mode 100644 index 000000000..e828e87c3 --- /dev/null +++ b/src/Resolver/ImporterTaxonsResolverInterface.php @@ -0,0 +1,18 @@ + + + + + + + + + diff --git a/src/Resources/config/services/importer.xml b/src/Resources/config/services/importer.xml index 041b293f1..d5eb2c352 100644 --- a/src/Resources/config/services/importer.xml +++ b/src/Resources/config/services/importer.xml @@ -20,6 +20,10 @@ + + + + diff --git a/src/Resources/config/services/resolver.xml b/src/Resources/config/services/resolver.xml index f95ea26ad..651791039 100644 --- a/src/Resources/config/services/resolver.xml +++ b/src/Resources/config/services/resolver.xml @@ -68,5 +68,17 @@ + + + + + + + + + + + + From a360d8ceea1ad578b8b66caf8f5762f04bcd8644 Mon Sep 17 00:00:00 2001 From: jkindly Date: Mon, 5 Aug 2024 13:33:23 +0200 Subject: [PATCH 3/4] OP-464: PHPSpec --- spec/Importer/BlockImporterSpec.php | 53 +++++++++++++++++++++-------- spec/Importer/PageImporterSpec.php | 19 +++++------ 2 files changed, 47 insertions(+), 25 deletions(-) diff --git a/spec/Importer/BlockImporterSpec.php b/spec/Importer/BlockImporterSpec.php index cf4a53529..49a754908 100644 --- a/spec/Importer/BlockImporterSpec.php +++ b/spec/Importer/BlockImporterSpec.php @@ -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; @@ -23,16 +28,25 @@ 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 ); @@ -40,26 +54,37 @@ public function let( 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()); diff --git a/spec/Importer/PageImporterSpec.php b/spec/Importer/PageImporterSpec.php index 8d9843044..86f500c62 100644 --- a/spec/Importer/PageImporterSpec.php +++ b/spec/Importer/PageImporterSpec.php @@ -62,19 +62,14 @@ 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); @@ -82,12 +77,14 @@ public function it_imports_page_no_url( $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(); From 1c285313579220772a9bd9443d60a01a67f0b36b Mon Sep 17 00:00:00 2001 From: jkindly Date: Tue, 13 Aug 2024 08:40:57 +0200 Subject: [PATCH 4/4] OP-464: Specs --- spec/Assigner/LocalesAssignerSpec.php | 53 ++++++++++++++++++ .../Assigner/ProductsInTaxonsAssignerSpec.php | 54 +++++++++++++++++++ spec/Resolver/ImporterLocalesResolverSpec.php | 48 +++++++++++++++++ .../ImporterProductsInTaxonsResolverSpec.php | 48 +++++++++++++++++ spec/Resolver/ImporterTaxonsResolverSpec.php | 48 +++++++++++++++++ 5 files changed, 251 insertions(+) create mode 100644 spec/Assigner/LocalesAssignerSpec.php create mode 100644 spec/Assigner/ProductsInTaxonsAssignerSpec.php create mode 100644 spec/Resolver/ImporterLocalesResolverSpec.php create mode 100644 spec/Resolver/ImporterProductsInTaxonsResolverSpec.php create mode 100644 spec/Resolver/ImporterTaxonsResolverSpec.php diff --git a/spec/Assigner/LocalesAssignerSpec.php b/spec/Assigner/LocalesAssignerSpec.php new file mode 100644 index 000000000..e757ff87b --- /dev/null +++ b/spec/Assigner/LocalesAssignerSpec.php @@ -0,0 +1,53 @@ +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']); + } +} diff --git a/spec/Assigner/ProductsInTaxonsAssignerSpec.php b/spec/Assigner/ProductsInTaxonsAssignerSpec.php new file mode 100644 index 000000000..6d5454f95 --- /dev/null +++ b/spec/Assigner/ProductsInTaxonsAssignerSpec.php @@ -0,0 +1,54 @@ +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']); + } +} diff --git a/spec/Resolver/ImporterLocalesResolverSpec.php b/spec/Resolver/ImporterLocalesResolverSpec.php new file mode 100644 index 000000000..ed4b4e619 --- /dev/null +++ b/spec/Resolver/ImporterLocalesResolverSpec.php @@ -0,0 +1,48 @@ +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, ''); + } +} diff --git a/spec/Resolver/ImporterProductsInTaxonsResolverSpec.php b/spec/Resolver/ImporterProductsInTaxonsResolverSpec.php new file mode 100644 index 000000000..c1ce51ab4 --- /dev/null +++ b/spec/Resolver/ImporterProductsInTaxonsResolverSpec.php @@ -0,0 +1,48 @@ +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); + } +} diff --git a/spec/Resolver/ImporterTaxonsResolverSpec.php b/spec/Resolver/ImporterTaxonsResolverSpec.php new file mode 100644 index 000000000..16bb30e4b --- /dev/null +++ b/spec/Resolver/ImporterTaxonsResolverSpec.php @@ -0,0 +1,48 @@ +beConstructedWith($taxonsAssigner); + } + + public function it_is_initializable() + { + $this->shouldHaveType(ImporterTaxonsResolver::class); + } + + public function it_resolves_taxons_for_taxon_aware_entity( + TaxonsAssignerInterface $taxonsAssigner, + TaxonAwareInterface $taxonsAware + ) { + $taxonsRow = 'taxon_code_1, taxon_code_2'; + $taxonsAssigner->assign($taxonsAware, ['taxon_code_1', 'taxon_code_2'])->shouldBeCalled(); + + $this->resolve($taxonsAware, $taxonsRow); + } + + public function it_does_not_assign_taxons_when_taxons_row_is_null( + TaxonsAssignerInterface $taxonsAssigner, + TaxonAwareInterface $taxonsAware + ) { + $taxonsAssigner->assign($taxonsAware, [])->shouldNotBeCalled(); + + $this->resolve($taxonsAware, null); + } +}