From f245fe6aaa894c2ed771b24493060f45fa5999c3 Mon Sep 17 00:00:00 2001 From: jkindly Date: Tue, 3 Sep 2024 12:27:57 +0200 Subject: [PATCH] OP-290: tests --- spec/Assigner/ChannelsAssignerSpec.php | 3 +- spec/Assigner/CollectionsAssignerSpec.php | 3 +- spec/Assigner/LocalesAssignerSpec.php | 2 +- spec/Assigner/ProductsAssignerSpec.php | 3 +- .../Assigner/ProductsInTaxonsAssignerSpec.php | 3 +- spec/Assigner/TaxonsAssignerSpec.php | 3 +- src/DependencyInjection/Configuration.php | 4 +- src/Resources/config/api_resources/Block.xml | 8 +- src/Resources/config/serialization/Block.xml | 11 ++- .../config/serialization/Collection.xml | 1 + src/Resources/config/serialization/Media.xml | 8 +- .../DataFixtures/ORM/Api/BlockTest/block.yml | 11 ++- .../ORM/Api/CollectionTest/collection.yml | 3 + .../DataFixtures/ORM/Api/MediaTest/media.yml | 2 +- .../DataFixtures/ORM/Api/PageTest/page.yml | 2 +- .../BlockTest/test_it_get_block_by_id.json | 11 ++- .../Api/BlockTest/test_it_get_blocks.json | 54 ++----------- .../test_it_get_collection_by_id.json | 6 +- .../Api/MediaTest/test_it_get_media.json | 78 +------------------ .../MediaTest/test_it_get_media_by_id.json | 7 +- .../Api/PageTest/test_it_get_page_by_id.json | 2 +- .../Api/PageTest/test_it_get_pages.json | 39 +--------- 22 files changed, 67 insertions(+), 197 deletions(-) diff --git a/spec/Assigner/ChannelsAssignerSpec.php b/spec/Assigner/ChannelsAssignerSpec.php index c11119c2f..5fc38fc80 100644 --- a/spec/Assigner/ChannelsAssignerSpec.php +++ b/spec/Assigner/ChannelsAssignerSpec.php @@ -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(); diff --git a/spec/Assigner/CollectionsAssignerSpec.php b/spec/Assigner/CollectionsAssignerSpec.php index 53b3a7bee..0e95b878e 100644 --- a/spec/Assigner/CollectionsAssignerSpec.php +++ b/spec/Assigner/CollectionsAssignerSpec.php @@ -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(); diff --git a/spec/Assigner/LocalesAssignerSpec.php b/spec/Assigner/LocalesAssignerSpec.php index 4f4f7d1b1..7e2da73fb 100644 --- a/spec/Assigner/LocalesAssignerSpec.php +++ b/spec/Assigner/LocalesAssignerSpec.php @@ -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(); diff --git a/spec/Assigner/ProductsAssignerSpec.php b/spec/Assigner/ProductsAssignerSpec.php index 25394a93e..e79e07ee3 100644 --- a/spec/Assigner/ProductsAssignerSpec.php +++ b/spec/Assigner/ProductsAssignerSpec.php @@ -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(); diff --git a/spec/Assigner/ProductsInTaxonsAssignerSpec.php b/spec/Assigner/ProductsInTaxonsAssignerSpec.php index 581c2aea7..4b98ad9ce 100644 --- a/spec/Assigner/ProductsInTaxonsAssignerSpec.php +++ b/spec/Assigner/ProductsInTaxonsAssignerSpec.php @@ -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(); diff --git a/spec/Assigner/TaxonsAssignerSpec.php b/spec/Assigner/TaxonsAssignerSpec.php index 8992b1aec..b8933ff98 100644 --- a/spec/Assigner/TaxonsAssignerSpec.php +++ b/spec/Assigner/TaxonsAssignerSpec.php @@ -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(); diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 8a373efd2..9f30f0f0d 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -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() @@ -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() diff --git a/src/Resources/config/api_resources/Block.xml b/src/Resources/config/api_resources/Block.xml index 7ccf8e59f..d1bec15bc 100644 --- a/src/Resources/config/api_resources/Block.xml +++ b/src/Resources/config/api_resources/Block.xml @@ -41,10 +41,14 @@ + + + - - + + + diff --git a/src/Resources/config/serialization/Block.xml b/src/Resources/config/serialization/Block.xml index 725457432..ad39aa163 100644 --- a/src/Resources/config/serialization/Block.xml +++ b/src/Resources/config/serialization/Block.xml @@ -12,16 +12,23 @@ sylius_cms:block:read:index sylius_cms:block:read:show - + sylius_cms:block:read:index sylius_cms:block:read:show - + + sylius_cms:block:read:index sylius_cms:block:read:show sylius_cms:block:read:show + + sylius_cms:block:read:show + + + sylius_cms:block:read:show + sylius_cms:block:read:show diff --git a/src/Resources/config/serialization/Collection.xml b/src/Resources/config/serialization/Collection.xml index f41c0c7de..90182810b 100644 --- a/src/Resources/config/serialization/Collection.xml +++ b/src/Resources/config/serialization/Collection.xml @@ -13,6 +13,7 @@ sylius_cms:collection:read:show + sylius_cms:collection:read:index sylius_cms:collection:read:show diff --git a/src/Resources/config/serialization/Media.xml b/src/Resources/config/serialization/Media.xml index 97d14203d..24f4c722b 100644 --- a/src/Resources/config/serialization/Media.xml +++ b/src/Resources/config/serialization/Media.xml @@ -20,14 +20,14 @@ sylius_cms:media:read:index sylius_cms:media:read:show - + + sylius_cms:media:read:index sylius_cms:media:read:show - + sylius_cms:media:read:show - - sylius_cms:media:read:index + sylius_cms:media:read:show diff --git a/tests/Functional/DataFixtures/ORM/Api/BlockTest/block.yml b/tests/Functional/DataFixtures/ORM/Api/BlockTest/block.yml index a0f540e01..822e4510c 100644 --- a/tests/Functional/DataFixtures/ORM/Api/BlockTest/block.yml +++ b/tests/Functional/DataFixtures/ORM/Api/BlockTest/block.yml @@ -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' diff --git a/tests/Functional/DataFixtures/ORM/Api/CollectionTest/collection.yml b/tests/Functional/DataFixtures/ORM/Api/CollectionTest/collection.yml index 809961d83..30e109511 100644 --- a/tests/Functional/DataFixtures/ORM/Api/CollectionTest/collection.yml +++ b/tests/Functional/DataFixtures/ORM/Api/CollectionTest/collection.yml @@ -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' diff --git a/tests/Functional/DataFixtures/ORM/Api/MediaTest/media.yml b/tests/Functional/DataFixtures/ORM/Api/MediaTest/media.yml index 05ea75ac8..7dd0bd8df 100644 --- a/tests/Functional/DataFixtures/ORM/Api/MediaTest/media.yml +++ b/tests/Functional/DataFixtures/ORM/Api/MediaTest/media.yml @@ -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: diff --git a/tests/Functional/DataFixtures/ORM/Api/PageTest/page.yml b/tests/Functional/DataFixtures/ORM/Api/PageTest/page.yml index 444a7b836..1e4919a85 100644 --- a/tests/Functional/DataFixtures/ORM/Api/PageTest/page.yml +++ b/tests/Functional/DataFixtures/ORM/Api/PageTest/page.yml @@ -109,7 +109,7 @@ Sylius\CmsPlugin\Entity\Page: - '@page2_translation' page3: code: 'page3-code' - enabled: false + enabled: true collections: - '@collection3' channels: diff --git a/tests/Functional/Responses/Expected/Api/BlockTest/test_it_get_block_by_id.json b/tests/Functional/Responses/Expected/Api/BlockTest/test_it_get_block_by_id.json index dbc9c1802..33c79870c 100644 --- a/tests/Functional/Responses/Expected/Api/BlockTest/test_it_get_block_by_id.json +++ b/tests/Functional/Responses/Expected/Api/BlockTest/test_it_get_block_by_id.json @@ -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": [], diff --git a/tests/Functional/Responses/Expected/Api/BlockTest/test_it_get_blocks.json b/tests/Functional/Responses/Expected/Api/BlockTest/test_it_get_blocks.json index c163c76eb..d434f94f6 100644 --- a/tests/Functional/Responses/Expected/Api/BlockTest/test_it_get_blocks.json +++ b/tests/Functional/Responses/Expected/Api/BlockTest/test_it_get_blocks.json @@ -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 diff --git a/tests/Functional/Responses/Expected/Api/CollectionTest/test_it_get_collection_by_id.json b/tests/Functional/Responses/Expected/Api/CollectionTest/test_it_get_collection_by_id.json index 314c8ffc6..8652ee2b8 100644 --- a/tests/Functional/Responses/Expected/Api/CollectionTest/test_it_get_collection_by_id.json +++ b/tests/Functional/Responses/Expected/Api/CollectionTest/test_it_get_collection_by_id.json @@ -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": [] } diff --git a/tests/Functional/Responses/Expected/Api/MediaTest/test_it_get_media.json b/tests/Functional/Responses/Expected/Api/MediaTest/test_it_get_media.json index fd285cf70..541780b75 100644 --- a/tests/Functional/Responses/Expected/Api/MediaTest/test_it_get_media.json +++ b/tests/Functional/Responses/Expected/Api/MediaTest/test_it_get_media.json @@ -10,31 +10,7 @@ "type": "image", "code": "media1-code", "name": "media1-name", - "path": "/path/to/media1", - "mimeType": null, - "width": null, - "height": null, - "saveWithOriginalName": false, - "enabled": true, - "collections": [ - { - "@id": "/api/v2/shop/cms-plugin/collections/@integer@", - "@type": "Collection", - "id": "@integer@", - "code": "collection1-code" - } - ], - "channels": [ - "/api/v2/shop/channels/code" - ], - "translations": { - "en_US": { - "@type": "MediaTranslation", - "content": "translation_content_en_US", - "alt": null, - "link": "translation_link_en_US" - } - } + "enabled": true }, { "@id": "/api/v2/shop/cms-plugin/media/@integer@", @@ -43,31 +19,7 @@ "type": "image", "code": "media2-code", "name": "media2-name", - "path": "/path/to/media2", - "mimeType": null, - "width": null, - "height": null, - "saveWithOriginalName": false, - "enabled": true, - "collections": [ - { - "@id": "/api/v2/shop/cms-plugin/collections/@integer@", - "@type": "Collection", - "id": "@integer@", - "code": "collection2-code" - } - ], - "channels": [ - "/api/v2/shop/channels/code" - ], - "translations": { - "en_US": { - "@type": "MediaTranslation", - "content": "translation_content_en_US", - "alt": null, - "link": "translation_link_en_US" - } - } + "enabled": true }, { "@id": "/api/v2/shop/cms-plugin/media/@integer@", @@ -76,31 +28,7 @@ "type": "image", "code": "media3-code", "name": "media3-name", - "path": "/path/to/media3", - "mimeType": null, - "width": null, - "height": null, - "saveWithOriginalName": false, - "enabled": false, - "collections": [ - { - "@id": "/api/v2/shop/cms-plugin/collections/@integer@", - "@type": "Collection", - "id": "@integer@", - "code": "collection3-code" - } - ], - "channels": [ - "/api/v2/shop/channels/code" - ], - "translations": { - "en_US": { - "@type": "MediaTranslation", - "content": "translation_content_en_US", - "alt": null, - "link": "translation_link_en_US" - } - } + "enabled": true } ], "hydra:totalItems": 3 diff --git a/tests/Functional/Responses/Expected/Api/MediaTest/test_it_get_media_by_id.json b/tests/Functional/Responses/Expected/Api/MediaTest/test_it_get_media_by_id.json index 24ad5c7d0..1a9134592 100644 --- a/tests/Functional/Responses/Expected/Api/MediaTest/test_it_get_media_by_id.json +++ b/tests/Functional/Responses/Expected/Api/MediaTest/test_it_get_media_by_id.json @@ -13,12 +13,7 @@ "saveWithOriginalName": false, "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" diff --git a/tests/Functional/Responses/Expected/Api/PageTest/test_it_get_page_by_id.json b/tests/Functional/Responses/Expected/Api/PageTest/test_it_get_page_by_id.json index 2c367e69b..5e08fe1ed 100644 --- a/tests/Functional/Responses/Expected/Api/PageTest/test_it_get_page_by_id.json +++ b/tests/Functional/Responses/Expected/Api/PageTest/test_it_get_page_by_id.json @@ -6,10 +6,10 @@ "code": "page1-code", "name": null, "publishAt": null, + "contentElements": [], "translations": { "en_US": { "@type": "PageTranslation", - "id": "@integer@", "slug": "translation1_slug_en_US", "metaKeywords": "html,application", "metaDescription": null, diff --git a/tests/Functional/Responses/Expected/Api/PageTest/test_it_get_pages.json b/tests/Functional/Responses/Expected/Api/PageTest/test_it_get_pages.json index a0809ef35..cdadae79c 100644 --- a/tests/Functional/Responses/Expected/Api/PageTest/test_it_get_pages.json +++ b/tests/Functional/Responses/Expected/Api/PageTest/test_it_get_pages.json @@ -8,54 +8,21 @@ "@type": "Page", "id": "@integer@", "code": "page1-code", - "name": null, - "publishAt": null, - "translations": { - "en_US": { - "@type": "PageTranslation", - "id": "@integer@", - "slug": "translation1_slug_en_US", - "metaKeywords": "html,application", - "metaDescription": null, - "title": "Amazing article1" - } - } + "name": null }, { "@id": "/api/v2/shop/cms-plugin/pages/@integer@", "@type": "Page", "id": "@integer@", "code": "page2-code", - "name": null, - "publishAt": null, - "translations": { - "en_US": { - "@type": "PageTranslation", - "id": "@integer@", - "slug": "translation2_slug_en_US", - "metaKeywords": "html,application", - "metaDescription": null, - "title": "Amazing article2" - } - } + "name": null }, { "@id": "/api/v2/shop/cms-plugin/pages/@integer@", "@type": "Page", "id": "@integer@", "code": "page3-code", - "name": null, - "publishAt": null, - "translations": { - "en_US": { - "@type": "PageTranslation", - "id": "@integer@", - "slug": "translation3_slug_en_US", - "metaKeywords": "html,application", - "metaDescription": null, - "title": "Amazing article3" - } - } + "name": null } ], "hydra:totalItems": 3