mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 09:02:12 +00:00
[Metadata] [Core] Implemented part of Behat scenarios for metadata
This commit is contained in:
parent
9e8a857392
commit
33f9d96677
12 changed files with 283 additions and 20 deletions
|
|
@ -144,6 +144,18 @@ default:
|
|||
filters:
|
||||
tags: "@localization"
|
||||
|
||||
metadata:
|
||||
contexts:
|
||||
- Behat\MinkExtension\Context\MinkContext
|
||||
- Sylius\Bundle\CoreBundle\Behat\HookContext
|
||||
- Sylius\Bundle\CoreBundle\Behat\CoreContext
|
||||
- Sylius\Bundle\ResourceBundle\Behat\FixtureContext
|
||||
- Sylius\Bundle\WebBundle\Behat\WebContext
|
||||
- Sylius\Bundle\ProductBundle\Behat\ProductContext
|
||||
- Sylius\Bundle\CoreBundle\Behat\MetadataContext
|
||||
filters:
|
||||
tags: "@metadata"
|
||||
|
||||
oauth:
|
||||
contexts:
|
||||
- Behat\MinkExtension\Context\MinkContext
|
||||
|
|
|
|||
240
src/Sylius/Bundle/CoreBundle/Behat/MetadataContext.php
Normal file
240
src/Sylius/Bundle/CoreBundle/Behat/MetadataContext.php
Normal file
|
|
@ -0,0 +1,240 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\CoreBundle\Behat;
|
||||
|
||||
use Behat\Behat\Tester\Exception\PendingException;
|
||||
use Behat\Gherkin\Node\TableNode;
|
||||
use Behat\Mink\Element\ElementInterface;
|
||||
use Behat\Mink\Element\NodeElement;
|
||||
use Sylius\Bundle\ResourceBundle\Behat\DefaultContext;
|
||||
|
||||
/**
|
||||
* @author Kamil Kokot <kamil.kokot@lakion.com>
|
||||
*/
|
||||
class MetadataContext extends DefaultContext
|
||||
{
|
||||
/**
|
||||
* @When I am customizing metadata
|
||||
* @When I am customizing metadata with identifier "([^"]+)"
|
||||
*/
|
||||
public function iAmCustomizingMetadata($identifier = 'FooBar')
|
||||
{
|
||||
$this->getSession()->visit($this->generateUrl('sylius_backend_metadata_customize', ['id' => $identifier]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should see metadata customization form
|
||||
*/
|
||||
public function iShouldSeeMetadataCustomizationForm()
|
||||
{
|
||||
$this->assertThereIsFormWithFields(
|
||||
$this->getSession()->getPage(),
|
||||
['Title', 'Description', 'Keywords', 'Twitter Card']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should see the following metadata:
|
||||
*/
|
||||
public function iShouldSeeTheFollowingMetadata(TableNode $metadata)
|
||||
{
|
||||
/** @var NodeElement $table */
|
||||
$table = $this->getSession()->getPage()->find('css', '#content > table');
|
||||
|
||||
/** @var NodeElement $row */
|
||||
$row = $table->findAll('css', 'tr')[1];
|
||||
|
||||
/** @var NodeElement[] $columns */
|
||||
$columns = $row->findAll('css', 'td');
|
||||
|
||||
$contentIndex = $this->getColumnIndex($table, 'Content');
|
||||
|
||||
/** @var NodeElement $list */
|
||||
$list = $columns[$contentIndex];
|
||||
foreach ($metadata->getRowsHash() as $key => $value) {
|
||||
$currentElement = $list;
|
||||
$parts = explode('.', $key);
|
||||
|
||||
foreach ($parts as $part) {
|
||||
$currentElement = $currentElement->find('xpath', sprintf('/ul/li[starts-with(normalize-space(.), "%s:")]', $part));
|
||||
}
|
||||
|
||||
$exploded = explode(':', $currentElement->getText());
|
||||
$text = trim(end($exploded));
|
||||
|
||||
$expectedValue = $value;
|
||||
if ('<empty>' === $expectedValue) {
|
||||
$expectedValue = 'empty';
|
||||
} elseif (false !== strpos($expectedValue, ',')) {
|
||||
$expectedValue = str_replace([', ', ','], [' ', ' '], $expectedValue);
|
||||
}
|
||||
|
||||
if ($text !== $expectedValue) {
|
||||
throw new \Exception(sprintf(
|
||||
'Expected "%s", got "%s" (item: "%s", original value: "%s")',
|
||||
$expectedValue,
|
||||
$text,
|
||||
$key,
|
||||
$value
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should be customizing default metadata
|
||||
*/
|
||||
public function iShouldBeCustomizingDefaultMetadata()
|
||||
{
|
||||
$this->assertItIsMetadataCustomizationPage(
|
||||
$this->getSession()->getPage(),
|
||||
'/DefaultPage/'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should be customizing products metadata
|
||||
*/
|
||||
public function iShouldBeCustomizingProductsMetadata()
|
||||
{
|
||||
$this->assertItIsMetadataCustomizationPage(
|
||||
$this->getSession()->getPage(),
|
||||
'/Product(?!\-)/'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should be customizing specific product metadata
|
||||
*/
|
||||
public function iShouldBeCustomizingSpecificProductMetadata()
|
||||
{
|
||||
$this->assertItIsMetadataCustomizationPage(
|
||||
$this->getSession()->getPage(),
|
||||
'/Product-\d+/'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should be customizing specific product variant metadata
|
||||
*/
|
||||
public function iShouldBeCustomizingSpecificProductVariantMetadata()
|
||||
{
|
||||
$this->assertItIsMetadataCustomizationPage(
|
||||
$this->getSession()->getPage(),
|
||||
'/ProductVariant-\d+/'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should see Twitter's application card form
|
||||
*/
|
||||
public function iShouldSeeTwitterApplicationCardForm()
|
||||
{
|
||||
$this->assertSession()->fieldExists('Iphone application name');
|
||||
$this->assertSession()->fieldExists('Ipad application url');
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should not see Twitter's application card form
|
||||
*/
|
||||
public function iShouldNotSeeTwitterApplicationCardForm()
|
||||
{
|
||||
$this->assertSession()->fieldNotExists('Iphone application name');
|
||||
$this->assertSession()->fieldNotExists('Ipad application url');
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /I deselect "([^"]+)"/
|
||||
*/
|
||||
public function iDeselectSelectField($fieldName)
|
||||
{
|
||||
$this->getSession()->getPage()->selectFieldOption($fieldName, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ElementInterface $element
|
||||
* @param string $regexp
|
||||
*
|
||||
* @throws \Exception If assertion failed
|
||||
*/
|
||||
private function assertItIsMetadataCustomizationPage(ElementInterface $element, $regexp)
|
||||
{
|
||||
if ($this->isItMetadataCustomizationPage($element, $regexp)) {
|
||||
return;
|
||||
}
|
||||
|
||||
throw new \Exception(sprintf("It is not metadata customziation page (regexp: %s)", $regexp));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ElementInterface $element
|
||||
* @param string $regexp
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isItMetadataCustomizationPage(ElementInterface $element, $regexp)
|
||||
{
|
||||
$header = $element->find('css', '.page-header h1');
|
||||
|
||||
if (false === strpos($header->getText(), "Customizing metadata")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!preg_match($regexp, $header->getText())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ElementInterface $element
|
||||
* @param array $fields
|
||||
*
|
||||
* @throws \Exception If assertion failed
|
||||
*/
|
||||
private function assertThereIsFormWithFields(ElementInterface $element, array $fields)
|
||||
{
|
||||
if (null !== $this->getFormWithFields($element, $fields)) {
|
||||
return;
|
||||
}
|
||||
|
||||
throw new \Exception(sprintf("Could not found table with fields: %s", join(', ', $fields)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ElementInterface $element
|
||||
* @param string[] $fields
|
||||
*
|
||||
* @return ElementInterface|null
|
||||
*/
|
||||
private function getFormWithFields(ElementInterface $element, array $fields)
|
||||
{
|
||||
/** @var NodeElement[] $forms */
|
||||
$forms = $element->findAll('css', 'form');
|
||||
|
||||
foreach ($forms as $form) {
|
||||
$found = true;
|
||||
foreach ($fields as $field) {
|
||||
if (null === $form->findField($field)) {
|
||||
$found = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($found) {
|
||||
return $form;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -46,10 +46,11 @@ abstract class DefaultContext extends RawMinkContext implements Context, KernelA
|
|||
* @var array
|
||||
*/
|
||||
protected $actions = array(
|
||||
'viewing' => 'show',
|
||||
'creation' => 'create',
|
||||
'editing' => 'update',
|
||||
'building' => 'build',
|
||||
'viewing' => 'show',
|
||||
'creation' => 'create',
|
||||
'editing' => 'update',
|
||||
'building' => 'build',
|
||||
'customization' => 'customize',
|
||||
);
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -565,7 +565,14 @@ sylius:
|
|||
customize: Customize metadata
|
||||
manage: Manage metadata
|
||||
content: Content
|
||||
index_metadata: Metadata
|
||||
index_metadata: Metadatas
|
||||
default_page:
|
||||
group_customize: Customize default metadata
|
||||
product:
|
||||
single_customize: Customize metadata
|
||||
group_customize: Customize products metadata
|
||||
product_variant:
|
||||
single_customize: Customize metadata
|
||||
move_down: Move down
|
||||
move_up: Move up
|
||||
na: N/A
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
{% block content %}
|
||||
<div class="page-header">
|
||||
<h1><i class="glyphicon glyphicon-pencil"></i> {{ 'sylius.metadata.customize_header'|trans|raw }}</h1>
|
||||
<h1><i class="glyphicon glyphicon-pencil"></i> {{ 'sylius.metadata.customize_header'|trans|raw }} {{ metadata.id }}</h1>
|
||||
</div>
|
||||
|
||||
{{ form_errors(form) }}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
<div class="page-header">
|
||||
<div class="actions-menu">
|
||||
<a href="{{ path('sylius_backend_metadata_customize', { 'id': 'DefaultPage' }) }}" class="btn btn-default">
|
||||
<i class="glyphicon glyphicon-file"></i><span>{{ 'sylius.metadata.customize'|trans }}</span>
|
||||
<i class="glyphicon glyphicon-file"></i><span>{{ 'sylius.metadata.default_page.group_customize'|trans }}</span>
|
||||
</a>
|
||||
</div>
|
||||
<h1><i class="glyphicon glyphicon-flag"></i> {{ 'sylius.metadata.index_header'|trans|raw }}</h1>
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
<div class="actions-menu">
|
||||
{{ buttons.create(path('sylius_backend_product_create'), 'sylius.product.create'|trans) }}
|
||||
<a href="{{ path('sylius_backend_metadata_customize', { 'id': constant('Sylius\\Component\\Core\\Model\\ProductInterface::METADATA_CLASS_IDENTIFIER') }) }}" class="btn btn-default">
|
||||
<i class="glyphicon glyphicon-file"></i><span>{{ 'sylius.metadata.customize'|trans }}</span>
|
||||
<i class="glyphicon glyphicon-file"></i><span>{{ 'sylius.metadata.product.group_customize'|trans }}</span>
|
||||
</a>
|
||||
{{ buttons.manage(path('sylius_backend_product_option_index'), 'sylius.product_option.manage'|trans) }}
|
||||
{{ buttons.manage(path('sylius_backend_product_attribute_index'), 'sylius.product_attribute.manage'|trans) }}
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@
|
|||
</td>
|
||||
<td class="center-text">
|
||||
<a href="{{ path('sylius_backend_metadata_customize', { 'id': product.metadataIdentifier }) }}" class="btn btn-default">
|
||||
<i class="glyphicon glyphicon-file"></i><span>{{ 'sylius.metadata.customize'|trans }}</span>
|
||||
<i class="glyphicon glyphicon-file"></i><span>{{ 'sylius.metadata.product.single_customize'|trans }}</span>
|
||||
</a>
|
||||
{% if product.deleted %}
|
||||
{{ buttons.patch(path('sylius_backend_product_delete_restore', {'id': product.id}), 'sylius.restore'|trans, null, 'btn btn-primary') }}
|
||||
|
|
|
|||
|
|
@ -23,12 +23,15 @@
|
|||
{{ buttons.enable(path('sylius_backend_product_enable', {'id': product.id})) }}
|
||||
{% endif %}
|
||||
{% if not product.deleted %}
|
||||
{{ buttons.edit(path('sylius_backend_product_update', {'id': product.id})) }}
|
||||
{{ buttons.delete(path('sylius_backend_product_delete', {'id': product.id}), null, false, true) }}
|
||||
<a href="{{ path(product) }}" class="btn btn-info">
|
||||
<i class="glyphicon glyphicon-shopping-cart"></i>
|
||||
{{ 'sylius.product.show_in_store'|trans }}
|
||||
</a>
|
||||
<a href="{{ path('sylius_backend_metadata_customize', { 'id': product.metadataIdentifier }) }}" class="btn btn-default">
|
||||
<i class="glyphicon glyphicon-file"></i><span>{{ 'sylius.metadata.product.single_customize'|trans }}</span>
|
||||
</a>
|
||||
{{ buttons.edit(path('sylius_backend_product_update', {'id': product.id})) }}
|
||||
{{ buttons.delete(path('sylius_backend_product_delete', {'id': product.id}), null, false, true) }}
|
||||
<a href="{{ path(product) }}" class="btn btn-info">
|
||||
<i class="glyphicon glyphicon-shopping-cart"></i>
|
||||
{{ 'sylius.product.show_in_store'|trans }}
|
||||
</a>
|
||||
{% else %}
|
||||
{{ buttons.patch(path('sylius_backend_product_delete_restore', {'id': product.id}), 'sylius.restore'|trans, null, 'btn btn-primary') }}
|
||||
{% endif %}
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@
|
|||
<div class="pull-right">
|
||||
{% if not variant.deleted %}
|
||||
<a href="{{ path('sylius_backend_metadata_customize', { 'id': variant.metadataIdentifier }) }}" class="btn btn-default">
|
||||
<i class="glyphicon glyphicon-file"></i><span>{{ 'sylius.metadata.customize'|trans }}</span>
|
||||
<i class="glyphicon glyphicon-file"></i><span>{{ 'sylius.metadata.product_variant.single_customize'|trans }}</span>
|
||||
</a>
|
||||
{{ buttons.edit(path('sylius_backend_product_variant_update', {'productId': product.id, 'id': variant.id})) }}
|
||||
{{ buttons.delete(path('sylius_backend_product_variant_delete', {'productId': product.id, 'id': variant.id})) }}
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ class ProductHierarchyProviderSpec extends ObjectBehavior
|
|||
'Product-42',
|
||||
'Archetype-42',
|
||||
'Product',
|
||||
'Default',
|
||||
'DefaultPage',
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -71,7 +71,7 @@ class ProductHierarchyProviderSpec extends ObjectBehavior
|
|||
$this->getHierarchyByMetadataSubject($product)->shouldReturn([
|
||||
'Product-42',
|
||||
'Product',
|
||||
'Default',
|
||||
'DefaultPage',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ class ProductVariantHierarchyProviderSpec extends ObjectBehavior
|
|||
'Product-42',
|
||||
'Archetype-42',
|
||||
'Product',
|
||||
'Default',
|
||||
'DefaultPage',
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -84,7 +84,7 @@ class ProductVariantHierarchyProviderSpec extends ObjectBehavior
|
|||
'ProductVariant-42',
|
||||
'Product-42',
|
||||
'Product',
|
||||
'Default',
|
||||
'DefaultPage',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue