Skip to content

Commit

Permalink
OP-290: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jkindly committed Sep 3, 2024
1 parent 8c8e236 commit f245fe6
Show file tree
Hide file tree
Showing 22 changed files with 67 additions and 197 deletions.
3 changes: 1 addition & 2 deletions spec/Assigner/ChannelsAssignerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public function it_assigns_channels(
ChannelInterface $posChannel,
ChannelsAwareInterface $channelsAware,
): void {
$channelRepository->findOneBy(['code' => 'web'])->willReturn($webChannel);
$channelRepository->findOneBy(['code' => 'pos'])->willReturn($posChannel);
$channelRepository->findBy(['code' => ['web', 'pos']])->willReturn([$webChannel, $posChannel]);

$channelsAware->addChannel($webChannel)->shouldBeCalled();
$channelsAware->addChannel($posChannel)->shouldBeCalled();
Expand Down
3 changes: 1 addition & 2 deletions spec/Assigner/CollectionsAssignerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public function it_assigns_collections(
CollectionInterface $blogCollection,
CollectibleInterface $collectionsAware,
): void {
$collectionRepository->findOneBy(['code' => 'about'])->willReturn($aboutCollection);
$collectionRepository->findOneBy(['code' => 'blog'])->willReturn($blogCollection);
$collectionRepository->findBy(['code' => ['about', 'blog']])->willReturn([$aboutCollection, $blogCollection]);

$collectionsAware->addCollection($aboutCollection)->shouldBeCalled();
$collectionsAware->addCollection($blogCollection)->shouldBeCalled();
Expand Down
2 changes: 1 addition & 1 deletion spec/Assigner/LocalesAssignerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function it_assigns_locales_to_locale_aware_entity(
$locale1->getCode()->willReturn('en_US');
$locale2->getCode()->willReturn('fr_FR');

$localeRepository->findAll()->willReturn([$locale1, $locale2]);
$localeRepository->findBy(['code' => ['en_US', 'fr_FR']])->willReturn([$locale1, $locale2]);

$localesAware->addLocale($locale1)->shouldBeCalled();
$localesAware->addLocale($locale2)->shouldBeCalled();
Expand Down
3 changes: 1 addition & 2 deletions spec/Assigner/ProductsAssignerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public function it_assigns_products(
ProductInterface $tshirtProduct,
ProductsAwareInterface $productsAware,
): void {
$productRepository->findOneBy(['code' => 'mug'])->willReturn($mugProduct);
$productRepository->findOneBy(['code' => 't-shirt'])->willReturn($tshirtProduct);
$productRepository->findBy(['code' => ['mug', 't-shirt']])->willReturn([$mugProduct, $tshirtProduct]);

$productsAware->addProduct($mugProduct)->shouldBeCalled();
$productsAware->addProduct($tshirtProduct)->shouldBeCalled();
Expand Down
3 changes: 1 addition & 2 deletions spec/Assigner/ProductsInTaxonsAssignerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ public function it_assigns_taxons_to_products_in_taxons_aware_entity(
$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);
$taxonRepository->findBy(['code' => ['taxon_code_1', 'taxon_code_2']])->willReturn([$taxon1, $taxon2]);

$productsInTaxonsAware->addProductsInTaxon($taxon1)->shouldBeCalled();
$productsInTaxonsAware->addProductsInTaxon($taxon2)->shouldBeCalled();
Expand Down
3 changes: 1 addition & 2 deletions spec/Assigner/TaxonsAssignerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public function it_assigns_taxons(
TaxonInterface $stickersTaxon,
TaxonAwareInterface $taxonsAware,
): void {
$taxonRepository->findOneBy(['code' => 'mugs'])->willReturn($mugsTaxon);
$taxonRepository->findOneBy(['code' => 'stickers'])->willReturn($stickersTaxon);
$taxonRepository->findBy(['code' => ['mugs', 'stickers']])->willReturn([$mugsTaxon, $stickersTaxon]);

$taxonsAware->addTaxon($mugsTaxon)->shouldBeCalled();
$taxonsAware->addTaxon($stickersTaxon)->shouldBeCalled();
Expand Down
4 changes: 2 additions & 2 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private function addResourcesSection(ArrayNodeDefinition $node): void
->children()
->scalarNode('model')->defaultValue(MediaTranslation::class)->cannotBeEmpty()->end()
->scalarNode('interface')->defaultValue(MediaTranslationInterface::class)->cannotBeEmpty()->end()
->scalarNode('factory')->defaultValue(TranslatableFactory::class)->cannotBeEmpty()->end()
->scalarNode('factory')->defaultValue(Factory::class)->cannotBeEmpty()->end()
->end()
->end()
->end()
Expand Down Expand Up @@ -167,7 +167,7 @@ private function addResourcesSection(ArrayNodeDefinition $node): void
->children()
->scalarNode('model')->defaultValue(PageTranslation::class)->cannotBeEmpty()->end()
->scalarNode('interface')->defaultValue(PageTranslationInterface::class)->cannotBeEmpty()->end()
->scalarNode('factory')->defaultValue(TranslatableFactory::class)->cannotBeEmpty()->end()
->scalarNode('factory')->defaultValue(Factory::class)->cannotBeEmpty()->end()
->end()
->end()
->end()
Expand Down
8 changes: 6 additions & 2 deletions src/Resources/config/api_resources/Block.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,14 @@

<property name="id" identifier="true" writable="false"/>
<property name="code" identifier="false" writable="false"/>
<property name="name" identifier="false" writable="false"/>
<property name="enabled" identifier="false" writable="false"/>
<property name="channels" identifier="false" writable="false"/>
<property name="locales" identifier="false" writable="false"/>
<property name="collections" identifier="false" writable="false"/>
<property name="products" identifier="false" writable="false"/>
<property name="channels" identifier="false" writable="false"/>
<property name="taxonomies" identifier="false" writable="false"/>
<property name="taxons" identifier="false" writable="false"/>
<property name="productsInTaxons" identifier="false" writable="false"/>
<property name="contentElements" identifier="false" writable="false"/>
</resource>
</resources>
11 changes: 9 additions & 2 deletions src/Resources/config/serialization/Block.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,23 @@
<group>sylius_cms:block:read:index</group>
<group>sylius_cms:block:read:show</group>
</attribute>
<attribute name="enabled">
<attribute name="name">
<group>sylius_cms:block:read:index</group>
<group>sylius_cms:block:read:show</group>
</attribute>
<attribute name="collections">
<attribute name="enabled">
<group>sylius_cms:block:read:index</group>
<group>sylius_cms:block:read:show</group>
</attribute>
<attribute name="channels">
<group>sylius_cms:block:read:show</group>
</attribute>
<attribute name="locales">
<group>sylius_cms:block:read:show</group>
</attribute>
<attribute name="collections">
<group>sylius_cms:block:read:show</group>
</attribute>
<attribute name="products">
<group>sylius_cms:block:read:show</group>
</attribute>
Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/serialization/Collection.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<group>sylius_cms:collection:read:show</group>
</attribute>
<attribute name="type">
<group>sylius_cms:collection:read:index</group>
<group>sylius_cms:collection:read:show</group>
</attribute>
<attribute name="pages">
Expand Down
8 changes: 4 additions & 4 deletions src/Resources/config/serialization/Media.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
<group>sylius_cms:media:read:index</group>
<group>sylius_cms:media:read:show</group>
</attribute>
<attribute name="path">
<attribute name="enabled">
<group>sylius_cms:media:read:index</group>
<group>sylius_cms:media:read:show</group>
</attribute>
<attribute name="mimeType">
<attribute name="path">
<group>sylius_cms:media:read:show</group>
</attribute>
<attribute name="enabled">
<group>sylius_cms:media:read:index</group>
<attribute name="mimeType">
<group>sylius_cms:media:read:show</group>
</attribute>
<attribute name="width">
Expand Down
11 changes: 10 additions & 1 deletion tests/Functional/DataFixtures/ORM/Api/BlockTest/block.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,25 +74,34 @@ Sylius\Component\Core\Model\ProductVariant:
Sylius\CmsPlugin\Entity\Block:
block1:
code: 'block1-code'
name: 'block1-name'
enabled: true
collections:
- '@collection1'
channels:
- '@channel'
locales:
- '@locale'
block2:
code: 'block2-code'
name: 'block2-name'
enabled: true
collections:
- '@collection2'
channels:
- '@channel'
locales:
- '@locale'
block3:
code: 'block3-code'
enabled: false
name: 'block3-name'
enabled: true
collections:
- '@collection3'
channels:
- '@channel'
locales:
- '@locale'
Sylius\CmsPlugin\Entity\Collection:
collection1:
code: 'collection1-code'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ Sylius\CmsPlugin\Entity\Collection:
collection1:
code: 'collection1-code'
name: 'collection1-name'
type: 'page'
collection2:
code: 'collection2-code'
name: 'collection2-name'
type: 'block'
collection3:
code: 'collection3-code'
name: 'collection3-name'
type: 'media'
2 changes: 1 addition & 1 deletion tests/Functional/DataFixtures/ORM/Api/MediaTest/media.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ Sylius\CmsPlugin\Entity\Media:
media3:
code: 'media3-code'
name: 'media3-name'
enabled: false
enabled: true
type: 'image'
path: '/path/to/media3'
collections:
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/DataFixtures/ORM/Api/PageTest/page.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ Sylius\CmsPlugin\Entity\Page:
- '@page2_translation'
page3:
code: 'page3-code'
enabled: false
enabled: true
collections:
- '@collection3'
channels:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@
"@type": "Block",
"id": "@integer@",
"code": "block1-code",
"name": "block1-name",
"enabled": true,
"collections": [
{
"@id": "/api/v2/shop/cms-plugin/collections/@integer@",
"@type": "Collection",
"id": "@integer@",
"code": "collection1-code"
}
"/api/v2/shop/cms-plugin/collections/@integer@"
],
"channels": [
"/api/v2/shop/channels/code"
],
"locales": [
"/api/v2/shop/locales/@string@"
],
"contentElements": [],
"products": [],
"taxons": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,66 +8,24 @@
"@type": "Block",
"id": "@integer@",
"code": "block1-code",
"enabled": true,
"collections": [
{
"@id": "/api/v2/shop/cms-plugin/collections/@integer@",
"@type": "Collection",
"id": "@integer@",
"code": "collection1-code"
}
],
"channels": [
"/api/v2/shop/channels/code"
],
"contentElements": [],
"products": [],
"taxons": [],
"productsInTaxons": []
"name": "block1-name",
"enabled": true
},
{
"@id": "/api/v2/shop/cms-plugin/blocks/@integer@",
"@type": "Block",
"id": "@integer@",
"code": "block2-code",
"enabled": true,
"collections": [
{
"@id": "/api/v2/shop/cms-plugin/collections/@integer@",
"@type": "Collection",
"id": "@integer@",
"code": "collection2-code"
}
],
"channels": [
"/api/v2/shop/channels/code"
],
"contentElements": [],
"products": [],
"taxons": [],
"productsInTaxons": []
"name": "block2-name",
"enabled": true
},
{
"@id": "/api/v2/shop/cms-plugin/blocks/@integer@",
"@type": "Block",
"id": "@integer@",
"code": "block3-code",
"enabled": false,
"collections": [
{
"@id": "/api/v2/shop/cms-plugin/collections/@integer@",
"@type": "Collection",
"id": "@integer@",
"code": "collection3-code"
}
],
"channels": [
"/api/v2/shop/channels/code"
],
"contentElements": [],
"products": [],
"taxons": [],
"productsInTaxons": []
"name": "block3-name",
"enabled": true
}
],
"hydra:totalItems": 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
"@id": "/api/v2/shop/cms-plugin/collections/@integer@",
"@type": "Collection",
"id": "@integer@",
"code": "collection1-code"
"code": "collection1-code",
"type": "page",
"pages": [],
"blocks": [],
"media": []
}
Loading

0 comments on commit f245fe6

Please sign in to comment.