Skip to content

Commit

Permalink
OP-461: Behat tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jkindly committed Jul 31, 2024
1 parent e5f0937 commit a92a6ef
Show file tree
Hide file tree
Showing 23 changed files with 867 additions and 47 deletions.
15 changes: 15 additions & 0 deletions features/admin/adding_page.feature
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,18 @@ Feature: Adding new page
Then I should be notified that the page has been created
And I should see newly created "Single media" content element in Content elements section
And I should see newly created "Multiple media" content element in Content elements section

@ui @javascript
Scenario: Adding page with template
Given there is an existing template named "Homepage" with "Page" type that contains "Textarea, Single media" content elements
When I go to the create page page
And I fill the code with "my_page"
And I fill the slug with "my_page"
And I fill the name with "My page"
And I select "Homepage" template
And I click button to use this template
And I confirm that I want to use this template
And I add it
Then I should be notified that the page has been created
And I should see newly created "Textarea" content element in Content elements section
And I should see newly created "Single media" content element in Content elements section
59 changes: 59 additions & 0 deletions features/admin/adding_template.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
@managing_templates
Feature: Adding cms templates
In order to create templates
As an Administrator
I want to be able to add new templates

Background:
Given the store operates on a single channel in "United States"
And I am logged in as an administrator

@ui
Scenario: Creating template
When I go to the create template page
And I fill the name with "Test template"
And I choose "Page" in Type field
And I add it
Then I should be notified that the template has been created

@ui @javascript
Scenario: Creating template with content elements
When I go to the create template page
And I fill the name with "Test template"
And I choose "Page" in Type field
And I click on Add button in Content elements section
And I select "Textarea" content element
And I click on Add button in Content elements section
And I select "Single media" content element
And I add it
Then I should be notified that the template has been created
And I should see newly created "Textarea" content element in Content elements section
And I should see newly created "Single media" content element in Content elements section

@ui
Scenario: Trying to add template with existing name
Given there is a template in the store with "New template" name
When I go to the create template page
And I fill the name with "New template"
And I try to add it
Then I should be notified that there is already existing template with provided name

@ui
Scenario: Adding new template with blank data
When I go to the create template page
And I add it
And I should be notified that "Name" field cannot be blank

@ui
Scenario: Trying to add a template with too short data
When I go to the create template page
And I fill the name with "X"
And I try to add it
Then I should be notified that "Name" field is too short

@ui
Scenario: Trying to add a template with too long data
When I go to the create template page
And I fill "Name" field with 251 characters
And I try to add it
Then I should be notified that "Name" field is too long
35 changes: 35 additions & 0 deletions features/admin/managing_templates.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@managing_templates
Feature: Managing cms templates
In order to manage existing templates
As an Administrator
I want to be able to edit and remove existing templates

Background:
Given the store operates on a single channel in "United States"
And I am logged in as an administrator

@ui
Scenario: Deleting template
Given there is a template in the store with "Test template" name
When I go to the templates page
And I delete this template
Then I should be notified that the template has been deleted
And I should see empty list of templates

@ui
Scenario: Updating template
Given there is a template in the store with "Test template" name
When I go to the update "Test template" template page
And I fill the name with "New template"
And I update it
Then I should be notified that the template has been successfully updated

@ui @javascript
Scenario: Updating template with content elements
Given there is a template in the store with "Test template" name
And there are "Textarea" and "Single media" content elements in this template
When I go to the update "Test template" template page
And I delete "Textarea" content element
And I update it
Then I should be notified that the template has been successfully updated
And I should see only "Single media" content element in Content elements section
92 changes: 92 additions & 0 deletions tests/Behat/Context/Setup/TemplateContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?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 Tests\BitBag\SyliusCmsPlugin\Behat\Context\Setup;

use Behat\Behat\Context\Context;
use BitBag\SyliusCmsPlugin\Entity\TemplateInterface;
use BitBag\SyliusCmsPlugin\Repository\TemplateRepositoryInterface;
use Sylius\Behat\Service\SharedStorageInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;
use Tests\BitBag\SyliusCmsPlugin\Behat\Helpers\ContentElementHelper;

final class TemplateContext 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): 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 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);
}
}
24 changes: 24 additions & 0 deletions tests/Behat/Context/Ui/Admin/PageContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,30 @@ public function iShouldNotSeeContentElementInTheContentElementsSection(string $c
Assert::false($this->resolveCurrentPage()->containsContentElement($contentElement));
}

/**
* @Then I select :templateName template
*/
public function iSelectTemplate(string $templateName): void
{
$this->resolveCurrentPage()->selectTemplate($templateName);
}

/**
* @Then I click button to use this template
*/
public function iClickButtonToUseThisTemplate(): void
{
$this->resolveCurrentPage()->useTemplate();
}

/**
* @Then I confirm that I want to use this template
*/
public function iConfirmThatIWantToUseThisTemplate(): void
{
$this->resolveCurrentPage()->confirmUseTemplate();
}

/**
* @When I add it
* @When I try to add it
Expand Down
Loading

0 comments on commit a92a6ef

Please sign in to comment.