Skip to content

Commit

Permalink
OP-515: Spec fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jkindly committed Sep 10, 2024
1 parent 660e8cd commit c388771
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 107 deletions.
19 changes: 7 additions & 12 deletions spec/Renderer/ContentElement/HeadingContentElementRendererSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,16 @@
use PhpSpec\ObjectBehavior;
use Sylius\CmsPlugin\Entity\ContentConfigurationInterface;
use Sylius\CmsPlugin\Form\Type\ContentElements\HeadingContentElementType;
use Sylius\CmsPlugin\Renderer\ContentElement\ContentElementRendererInterface;
use Sylius\CmsPlugin\Renderer\ContentElement\AbstractContentElement;
use Sylius\CmsPlugin\Renderer\ContentElement\HeadingContentElementRenderer;
use Twig\Environment;

final class HeadingContentElementRendererSpec extends ObjectBehavior
{
public function let(Environment $twig): void
{
$this->beConstructedWith($twig);
}

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

public function it_implements_content_element_renderer_interface(): void
{
$this->shouldImplement(ContentElementRendererInterface::class);
$this->shouldBeAnInstanceOf(AbstractContentElement::class);
}

public function it_supports_heading_content_element_type(ContentConfigurationInterface $contentConfiguration): void
Expand All @@ -42,13 +33,17 @@ public function it_does_not_support_other_content_element_types(ContentConfigura

public function it_renders_heading_content_element(Environment $twig, ContentConfigurationInterface $contentConfiguration): void
{
$template = 'custom_template';
$this->setTemplate($template);
$this->setTwigEnvironment($twig);

$contentConfiguration->getConfiguration()->willReturn([
'heading_type' => 'h1',
'heading' => 'Sample Heading',
]);

$twig->render('@SyliusCmsPlugin/Shop/ContentElement/index.html.twig', [
'content_element' => '@SyliusCmsPlugin/Shop/ContentElement/_heading.html.twig',
'content_element' => $template,
'heading_type' => 'h1',
'heading_content' => 'Sample Heading',
])->willReturn('rendered template');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Sylius\CmsPlugin\Entity\ContentConfigurationInterface;
use Sylius\CmsPlugin\Entity\MediaInterface;
use Sylius\CmsPlugin\Form\Type\ContentElements\MultipleMediaContentElementType;
use Sylius\CmsPlugin\Renderer\ContentElement\ContentElementRendererInterface;
use Sylius\CmsPlugin\Renderer\ContentElement\AbstractContentElement;
use Sylius\CmsPlugin\Renderer\ContentElement\MultipleMediaContentElementRenderer;
use Sylius\CmsPlugin\Repository\MediaRepositoryInterface;
use Sylius\CmsPlugin\Twig\Runtime\RenderMediaRuntimeInterface;
Expand All @@ -17,21 +17,16 @@
final class MultipleMediaContentElementRendererSpec extends ObjectBehavior
{
public function let(
Environment $twig,
RenderMediaRuntimeInterface $renderMediaRuntime,
MediaRepositoryInterface $mediaRepository,
): void {
$this->beConstructedWith($twig, $renderMediaRuntime, $mediaRepository);
$this->beConstructedWith($renderMediaRuntime, $mediaRepository);
}

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

public function it_implements_content_element_renderer_interface(): void
{
$this->shouldImplement(ContentElementRendererInterface::class);
$this->shouldBeAnInstanceOf(AbstractContentElement::class);
}

public function it_supports_multiple_media_content_element_type(ContentConfigurationInterface $contentConfiguration): void
Expand All @@ -54,6 +49,10 @@ public function it_renders_multiple_media_content_element(
MediaInterface $media1,
MediaInterface $media2,
): void {
$template = 'custom_template';
$this->setTemplate($template);
$this->setTwigEnvironment($twig);

$contentConfiguration->getConfiguration()->willReturn([
'multiple_media' => ['code1', 'code2'],
]);
Expand All @@ -67,7 +66,7 @@ public function it_renders_multiple_media_content_element(
$renderMediaRuntime->renderMedia('code2')->willReturn('rendered media 2');

$twig->render('@SyliusCmsPlugin/Shop/ContentElement/index.html.twig', [
'content_element' => '@SyliusCmsPlugin/Shop/ContentElement/_multiple_media.html.twig',
'content_element' => $template,
'media' => [
[
'renderedContent' => 'rendered media 1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,23 @@
use Sylius\CmsPlugin\Entity\CollectionInterface;
use Sylius\CmsPlugin\Entity\ContentConfigurationInterface;
use Sylius\CmsPlugin\Form\Type\ContentElements\PagesCollectionContentElementType;
use Sylius\CmsPlugin\Renderer\ContentElement\AbstractContentElement;
use Sylius\CmsPlugin\Renderer\ContentElement\ContentElementRendererInterface;
use Sylius\CmsPlugin\Renderer\ContentElement\PagesCollectionContentElementRenderer;
use Sylius\CmsPlugin\Repository\CollectionRepositoryInterface;
use Twig\Environment;

final class PagesCollectionContentElementRendererSpec extends ObjectBehavior
{
public function let(Environment $twig, CollectionRepositoryInterface $collectionRepository): void
public function let(CollectionRepositoryInterface $collectionRepository): void
{
$this->beConstructedWith($twig, $collectionRepository);
$this->beConstructedWith($collectionRepository);
}

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

public function it_implements_content_element_renderer_interface(): void
{
$this->shouldImplement(ContentElementRendererInterface::class);
$this->shouldBeAnInstanceOf(AbstractContentElement::class);
}

public function it_supports_pages_collection_content_element_type(ContentConfigurationInterface $contentConfiguration): void
Expand All @@ -49,6 +46,10 @@ public function it_renders_pages_collection_content_element(
ContentConfigurationInterface $contentConfiguration,
CollectionInterface $collection,
): void {
$template = 'custom_template';
$this->setTemplate($template);
$this->setTwigEnvironment($twig);

$contentConfiguration->getConfiguration()->willReturn([
'pages_collection' => 'collection_code',
]);
Expand All @@ -59,7 +60,7 @@ public function it_renders_pages_collection_content_element(
$collection->getPages()->willReturn($pagesCollection);

$twig->render('@SyliusCmsPlugin/Shop/ContentElement/index.html.twig', [
'content_element' => '@SyliusCmsPlugin/Shop/ContentElement/_pages_collection.html.twig',
'content_element' => $template,
'collection' => $pagesCollection,
])->willReturn('rendered_output');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use PhpSpec\ObjectBehavior;
use Sylius\CmsPlugin\Entity\ContentConfigurationInterface;
use Sylius\CmsPlugin\Form\Type\ContentElements\ProductsCarouselByTaxonContentElementType;
use Sylius\CmsPlugin\Renderer\ContentElement\ContentElementRendererInterface;
use Sylius\CmsPlugin\Renderer\ContentElement\AbstractContentElement;
use Sylius\CmsPlugin\Renderer\ContentElement\ProductsCarouselByTaxonContentElementRenderer;
use Sylius\Component\Core\Model\Product;
use Sylius\Component\Core\Model\TaxonInterface;
Expand All @@ -17,19 +17,15 @@

final class ProductsCarouselByTaxonContentElementRendererSpec extends ObjectBehavior
{
public function let(Environment $twig, ProductRepositoryInterface $productRepository, TaxonRepositoryInterface $taxonRepository): void
public function let(ProductRepositoryInterface $productRepository, TaxonRepositoryInterface $taxonRepository): void
{
$this->beConstructedWith($twig, $productRepository, $taxonRepository);
$this->beConstructedWith($productRepository, $taxonRepository);
}

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

public function it_implements_content_element_renderer_interface(): void
{
$this->shouldImplement(ContentElementRendererInterface::class);
$this->shouldBeAnInstanceOf(AbstractContentElement::class);
}

public function it_supports_products_carousel_by_taxon_content_element_type(ContentConfigurationInterface $contentConfiguration): void
Expand All @@ -53,6 +49,10 @@ public function it_renders_products_carousel_by_taxon_content_element(
Product $product1,
Product $product2,
): void {
$template = 'custom_template';
$this->setTemplate($template);
$this->setTwigEnvironment($twig);

$contentConfiguration->getConfiguration()->willReturn([
'products_carousel_by_taxon' => 'taxon_code',
]);
Expand All @@ -61,7 +61,7 @@ public function it_renders_products_carousel_by_taxon_content_element(
$productRepository->findByTaxon($taxon)->willReturn([$product1, $product2]);

$twig->render('@SyliusCmsPlugin/Shop/ContentElement/index.html.twig', [
'content_element' => '@SyliusCmsPlugin/Shop/ContentElement/_products_carousel.html.twig',
'content_element' => $template,
'products' => [$product1, $product2],
])->willReturn('rendered template');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,23 @@
use PhpSpec\ObjectBehavior;
use Sylius\CmsPlugin\Entity\ContentConfigurationInterface;
use Sylius\CmsPlugin\Form\Type\ContentElements\ProductsCarouselContentElementType;
use Sylius\CmsPlugin\Renderer\ContentElement\ContentElementRendererInterface;
use Sylius\CmsPlugin\Renderer\ContentElement\AbstractContentElement;
use Sylius\CmsPlugin\Renderer\ContentElement\ProductsCarouselContentElementRenderer;
use Sylius\Component\Core\Model\Product;
use Sylius\Component\Core\Repository\ProductRepositoryInterface;
use Twig\Environment;

final class ProductsCarouselContentElementRendererSpec extends ObjectBehavior
{
public function let(Environment $twig, ProductRepositoryInterface $productRepository): void
public function let(ProductRepositoryInterface $productRepository): void
{
$this->beConstructedWith($twig, $productRepository);
$this->beConstructedWith($productRepository);
}

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

public function it_implements_content_element_renderer_interface(): void
{
$this->shouldImplement(ContentElementRendererInterface::class);
$this->shouldBeAnInstanceOf(AbstractContentElement::class);
}

public function it_supports_products_carousel_content_element_type(ContentConfigurationInterface $contentConfiguration): void
Expand All @@ -49,14 +45,18 @@ public function it_renders_products_carousel_content_element(
Product $product1,
Product $product2,
): void {
$template = 'custom_template';
$this->setTemplate($template);
$this->setTwigEnvironment($twig);

$contentConfiguration->getConfiguration()->willReturn([
'products_carousel' => ['products' => ['code1', 'code2']],
]);

$productRepository->findBy(['code' => ['code1', 'code2']])->willReturn([$product1, $product2]);

$twig->render('@SyliusCmsPlugin/Shop/ContentElement/index.html.twig', [
'content_element' => '@SyliusCmsPlugin/Shop/ContentElement/_products_carousel.html.twig',
'content_element' => $template,
'products' => [$product1, $product2],
])->willReturn('rendered template');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use PhpSpec\ObjectBehavior;
use Sylius\CmsPlugin\Entity\ContentConfigurationInterface;
use Sylius\CmsPlugin\Form\Type\ContentElements\ProductsGridByTaxonContentElementType;
use Sylius\CmsPlugin\Renderer\ContentElement\ContentElementRendererInterface;
use Sylius\CmsPlugin\Renderer\ContentElement\AbstractContentElement;
use Sylius\CmsPlugin\Renderer\ContentElement\ProductsGridByTaxonContentElementRenderer;
use Sylius\Component\Core\Model\Product;
use Sylius\Component\Core\Model\TaxonInterface;
Expand All @@ -17,19 +17,15 @@

final class ProductsGridByTaxonContentElementRendererSpec extends ObjectBehavior
{
public function let(Environment $twig, ProductRepositoryInterface $productRepository, TaxonRepositoryInterface $taxonRepository): void
public function let(ProductRepositoryInterface $productRepository, TaxonRepositoryInterface $taxonRepository): void
{
$this->beConstructedWith($twig, $productRepository, $taxonRepository);
$this->beConstructedWith($productRepository, $taxonRepository);
}

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

public function it_implements_content_element_renderer_interface(): void
{
$this->shouldImplement(ContentElementRendererInterface::class);
$this->shouldBeAnInstanceOf(AbstractContentElement::class);
}

public function it_supports_products_grid_by_taxon_content_element_type(ContentConfigurationInterface $contentConfiguration): void
Expand All @@ -53,6 +49,10 @@ public function it_renders_products_grid_by_taxon_content_element(
Product $product1,
Product $product2,
): void {
$template = 'custom_template';
$this->setTemplate($template);
$this->setTwigEnvironment($twig);

$contentConfiguration->getConfiguration()->willReturn([
'products_grid_by_taxon' => 'taxon_code',
]);
Expand All @@ -61,7 +61,7 @@ public function it_renders_products_grid_by_taxon_content_element(
$productRepository->findByTaxon($taxon)->willReturn([$product1, $product2]);

$twig->render('@SyliusCmsPlugin/Shop/ContentElement/index.html.twig', [
'content_element' => '@SyliusCmsPlugin/Shop/ContentElement/_products_grid.html.twig',
'content_element' => $template,
'products' => [$product1, $product2],
])->willReturn('rendered template');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,23 @@
use PhpSpec\ObjectBehavior;
use Sylius\CmsPlugin\Entity\ContentConfigurationInterface;
use Sylius\CmsPlugin\Form\Type\ContentElements\ProductsGridContentElementType;
use Sylius\CmsPlugin\Renderer\ContentElement\ContentElementRendererInterface;
use Sylius\CmsPlugin\Renderer\ContentElement\AbstractContentElement;
use Sylius\CmsPlugin\Renderer\ContentElement\ProductsGridContentElementRenderer;
use Sylius\Component\Core\Model\Product;
use Sylius\Component\Core\Repository\ProductRepositoryInterface;
use Twig\Environment;

final class ProductsGridContentElementRendererSpec extends ObjectBehavior
{
public function let(Environment $twig, ProductRepositoryInterface $productRepository): void
public function let(ProductRepositoryInterface $productRepository): void
{
$this->beConstructedWith($twig, $productRepository);
$this->beConstructedWith($productRepository);
}

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

public function it_implements_content_element_renderer_interface(): void
{
$this->shouldImplement(ContentElementRendererInterface::class);
$this->shouldBeAnInstanceOf(AbstractContentElement::class);
}

public function it_supports_products_grid_content_element_type(ContentConfigurationInterface $contentConfiguration): void
Expand All @@ -49,14 +45,18 @@ public function it_renders_products_grid_content_element(
Product $product1,
Product $product2,
): void {
$template = 'custom_template';
$this->setTemplate($template);
$this->setTwigEnvironment($twig);

$contentConfiguration->getConfiguration()->willReturn([
'products_grid' => ['products' => ['code1', 'code2']],
]);

$productRepository->findBy(['code' => ['code1', 'code2']])->willReturn([$product1, $product2]);

$twig->render('@SyliusCmsPlugin/Shop/ContentElement/index.html.twig', [
'content_element' => '@SyliusCmsPlugin/Shop/ContentElement/_products_grid.html.twig',
'content_element' => $template,
'products' => [$product1, $product2],
])->willReturn('rendered template');

Expand Down
Loading

0 comments on commit c388771

Please sign in to comment.