-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
278 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
features/admin/adding_template.feature → ...res/admin/adding_content_template.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
features/admin/managing_templates.feature → .../admin/managing_content_templates.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace spec\Sylius\CmsPlugin\Provider; | ||
|
||
use PhpSpec\ObjectBehavior; | ||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; | ||
use Sylius\CmsPlugin\Provider\ResourceTemplateProvider; | ||
use Sylius\CmsPlugin\Provider\ResourceTemplateProviderInterface; | ||
|
||
final class ResourceTemplateProviderSpec extends ObjectBehavior | ||
{ | ||
public function let(ParameterBagInterface $parameterBag): void | ||
{ | ||
$parameterBag->get('sylius_cms.templates.pages')->willReturn([ | ||
'@CustomTemplate/Page.html.twig' => '@CustomTemplate/Page.html.twig', | ||
]); | ||
|
||
$parameterBag->get('sylius_cms.templates.blocks')->willReturn([ | ||
'@CustomTemplate/Block.html.twig' => '@CustomTemplate/Block.html.twig', | ||
]); | ||
|
||
$this->beConstructedWith($parameterBag); | ||
} | ||
|
||
public function it_is_initializable(): void | ||
{ | ||
$this->shouldHaveType(ResourceTemplateProvider::class); | ||
} | ||
|
||
public function it_implements_resource_template_provider_interface(): void | ||
{ | ||
$this->shouldImplement(ResourceTemplateProviderInterface::class); | ||
} | ||
|
||
public function it_returns_default_and_custom_page_templates(): void | ||
{ | ||
$this->getPageTemplates()->shouldReturn([ | ||
'sylius.ui.default' => '@SyliusCmsPlugin/Shop/Page/show.html.twig', | ||
'@CustomTemplate/Page.html.twig' => '@CustomTemplate/Page.html.twig', | ||
]); | ||
} | ||
|
||
public function it_returns_default_and_custom_block_templates(): void | ||
{ | ||
$this->getBlockTemplates()->shouldReturn([ | ||
'sylius.ui.default' => '@SyliusCmsPlugin/Shop/Block/show.html.twig', | ||
'@CustomTemplate/Block.html.twig' => '@CustomTemplate/Block.html.twig', | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Sylius\CmsPlugin\Behat\Context\Setup; | ||
|
||
use Behat\Behat\Context\Context; | ||
use Sylius\Behat\Service\SharedStorageInterface; | ||
use Sylius\CmsPlugin\Entity\TemplateInterface; | ||
use Sylius\CmsPlugin\Repository\TemplateRepositoryInterface; | ||
use Sylius\Component\Resource\Factory\FactoryInterface; | ||
use Tests\Sylius\CmsPlugin\Behat\Helpers\ContentElementHelper; | ||
|
||
final class ContentTemplateContext implements Context | ||
{ | ||
public function __construct( | ||
private FactoryInterface $templateFactory, | ||
private SharedStorageInterface $sharedStorage, | ||
private TemplateRepositoryInterface $templateRepository, | ||
) { | ||
} | ||
|
||
/** | ||
* @Given there is a template in the store with :name name | ||
* @Given there is a template in the store with :name name and :type type | ||
*/ | ||
public function thereIsATemplate(string $name, ?string $type = null): void | ||
{ | ||
$template = $this->createTemplate($name, $type); | ||
|
||
$this->saveTemplate($template); | ||
} | ||
|
||
/** | ||
* @Given there are :firstContentElement and :secondContentElement content elements in this template | ||
*/ | ||
public function thereAreContentElementsInThisTemplate(string $firstContentElement, string $secondContentElement): void | ||
{ | ||
/** @var TemplateInterface $template */ | ||
$template = $this->sharedStorage->get('template'); | ||
$template->setContentElements([ | ||
['type' => ContentElementHelper::getContentElementValueByName($firstContentElement)], | ||
['type' => ContentElementHelper::getContentElementValueByName($secondContentElement)], | ||
]); | ||
|
||
$this->saveTemplate($template); | ||
} | ||
|
||
/** | ||
* @Given there is an existing content template named :templateName with :type type that contains :contentElements content elements | ||
*/ | ||
public function thereIsAnExistingTemplateThatContainsContentElements(string $templateName, string $type, string $contentElements): void | ||
{ | ||
$template = $this->createTemplate($templateName, $type); | ||
|
||
$contentElements = explode(', ', $contentElements); | ||
|
||
$contentElementsArray = []; | ||
foreach ($contentElements as $contentElement) { | ||
$contentElementsArray[] = ['type' => ContentElementHelper::getContentElementValueByName($contentElement)]; | ||
} | ||
|
||
$template->setContentElements($contentElementsArray); | ||
|
||
$this->saveTemplate($template); | ||
} | ||
|
||
private function createTemplate(string $name, ?string $type = null): TemplateInterface | ||
{ | ||
/** @var TemplateInterface $template */ | ||
$template = $this->templateFactory->createNew(); | ||
$template->setName($name); | ||
|
||
if (null !== $type) { | ||
$template->setType($type); | ||
} | ||
|
||
return $template; | ||
} | ||
|
||
private function saveTemplate(TemplateInterface $template): void | ||
{ | ||
$this->templateRepository->add($template); | ||
$this->sharedStorage->set('template', $template); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.