Skip to content

Commit

Permalink
OP-344: Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jkindly committed Aug 12, 2024
1 parent 5b6f5c7 commit 8e7686c
Show file tree
Hide file tree
Showing 11 changed files with 166 additions and 1,030 deletions.
12 changes: 3 additions & 9 deletions features/shop/displaying_media.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ Feature: Displaying media

@ui
Scenario: Displaying media
And there is an existing "image" media with "homepage_pdf" code
When I go to the homepage
And I want to see a media with code "homepage_pdf"

@ui
Scenario: Displaying media no standard template
And there is an existing "image" media with "media_with_parameters" code
When I go to the homepage
And I want to see a media with code "media_with_parameters"
And there is an existing "image" media with "blog_banner" code
When I go to the "blog" page
And I want to see a media with code "blog_banner"
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?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\Renderer\ContentElement;

use BitBag\SyliusCmsPlugin\Entity\CollectionInterface;
use BitBag\SyliusCmsPlugin\Entity\ContentConfigurationInterface;
use BitBag\SyliusCmsPlugin\Entity\PageInterface;
use BitBag\SyliusCmsPlugin\Form\Type\ContentElements\PagesCollectionContentElementType;
use BitBag\SyliusCmsPlugin\Renderer\ContentElement\ContentElementRendererInterface;
use BitBag\SyliusCmsPlugin\Renderer\ContentElement\PagesCollectionContentElementRenderer;
use BitBag\SyliusCmsPlugin\Repository\CollectionRepositoryInterface;
use Doctrine\Common\Collections\ArrayCollection;
use PhpSpec\ObjectBehavior;
use Twig\Environment;

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

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

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

public function it_supports_pages_collection_content_element_type(ContentConfigurationInterface $contentConfiguration): void
{
$contentConfiguration->getType()->willReturn(PagesCollectionContentElementType::TYPE);
$this->supports($contentConfiguration)->shouldReturn(true);
}

public function it_does_not_support_other_content_element_types(ContentConfigurationInterface $contentConfiguration): void
{
$contentConfiguration->getType()->willReturn('other_type');
$this->supports($contentConfiguration)->shouldReturn(false);
}

public function it_renders_pages_collection_content_element(
Environment $twig,
CollectionRepositoryInterface $collectionRepository,
ContentConfigurationInterface $contentConfiguration,
CollectionInterface $collection,
): void
{
$contentConfiguration->getConfiguration()->willReturn([
'pages_collection' => 'collection_code'
]);

$collectionRepository->findOneBy(['code' => 'collection_code'])->willReturn($collection);

$pagesCollection = new ArrayCollection(['page1', 'page2']);
$collection->getPages()->willReturn($pagesCollection);

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

$this->render($contentConfiguration)->shouldReturn('rendered_output');
}
}
62 changes: 62 additions & 0 deletions spec/Renderer/ContentElement/SpacerContentElementRendererSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?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\Renderer\ContentElement;

use BitBag\SyliusCmsPlugin\Entity\ContentConfigurationInterface;
use BitBag\SyliusCmsPlugin\Form\Type\ContentElements\SpacerContentElementType;
use BitBag\SyliusCmsPlugin\Renderer\ContentElement\ContentElementRendererInterface;
use BitBag\SyliusCmsPlugin\Renderer\ContentElement\SpacerContentElementRenderer;
use PhpSpec\ObjectBehavior;
use Twig\Environment;

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

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

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

public function it_supports_spacer_content_element_type(ContentConfigurationInterface $contentConfiguration): void
{
$contentConfiguration->getType()->willReturn(SpacerContentElementType::TYPE);
$this->supports($contentConfiguration)->shouldReturn(true);
}

public function it_does_not_support_other_content_element_types(ContentConfigurationInterface $contentConfiguration): void
{
$contentConfiguration->getType()->willReturn('other_type');
$this->supports($contentConfiguration)->shouldReturn(false);
}

public function it_renders_spacer_content_element(Environment $twig, ContentConfigurationInterface $contentConfiguration): void
{
$contentConfiguration->getConfiguration()->willReturn([
'spacer' => '40',
]);

$twig->render('@BitBagSyliusCmsPlugin/Shop/ContentElement/index.html.twig', [
'content_element' => '@BitBagSyliusCmsPlugin/Shop/ContentElement/_spacer.html.twig',
'spacer_height' => '40',
])->willReturn('rendered template');

$this->render($contentConfiguration)->shouldReturn('rendered template');
}
}
2 changes: 2 additions & 0 deletions spec/Twig/Runtime/RenderBlockRuntimeSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public function it_renders_block_with_default_template(

$templatingEngine->render('@BitBagSyliusCmsPlugin/Shop/Block/show.html.twig', [
'content' => 'rendered content',
'context' => null,
])->willReturn('rendered block');

$this->renderBlock('code')->shouldReturn('rendered block');
Expand All @@ -99,6 +100,7 @@ public function it_renders_block_with_custom_template(

$templatingEngine->render('custom_template.html.twig', [
'content' => 'rendered content',
'context' => null,
])->willReturn('rendered block');

$this->renderBlock('code', 'custom_template.html.twig')->shouldReturn('rendered block');
Expand Down
161 changes: 0 additions & 161 deletions tests/Functional/Fixture/BlockFixtureTest.php

This file was deleted.

Loading

0 comments on commit 8e7686c

Please sign in to comment.