[Taxon][Behat] Editing taxon's slug without generation

This commit is contained in:
Mateusz Zalewski 2016-11-07 16:04:25 +01:00
parent 5f09c09b45
commit b3d58009a6
No known key found for this signature in database
GPG key ID: CFC1E4176165876B
12 changed files with 94 additions and 7 deletions

View file

@ -0,0 +1,38 @@
<?php
namespace Sylius\Migrations;
use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* Auto-generated Migration: Please modify to your needs!
*/
class Version20161107154554 extends AbstractMigration
{
/**
* @param Schema $schema
*/
public function up(Schema $schema)
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('DROP INDEX permalink_uidx ON sylius_taxon_translation');
$this->addSql('ALTER TABLE sylius_taxon_translation DROP permalink');
$this->addSql('CREATE UNIQUE INDEX slug_uidx ON sylius_taxon_translation (locale, slug)');
}
/**
* @param Schema $schema
*/
public function down(Schema $schema)
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('DROP INDEX slug_uidx ON sylius_taxon_translation');
$this->addSql('ALTER TABLE sylius_taxon_translation ADD permalink VARCHAR(255) NOT NULL COLLATE utf8_unicode_ci');
$this->addSql('CREATE UNIQUE INDEX permalink_uidx ON sylius_taxon_translation (locale, permalink)');
}
}

View file

@ -16,7 +16,7 @@ Feature: Editing taxon's slug
And I add it
Then this taxon slug should be "medieval-weapons"
@ui @javascript @todo
@ui
Scenario: Creating a root taxon with a custom slug
Given I want to create a new taxon
When I specify its code as "MEDIEVAL_WEAPONS"
@ -34,7 +34,7 @@ Feature: Editing taxon's slug
And I add it
Then this taxon slug should be "medieval-weapons/siege-engines"
@ui @javascript @todo
@ui
Scenario: Creating a taxon with a custom slug for parent
Given the store has "Medieval weapons" taxonomy
And I want to create a new taxon for "Medieval weapons"

View file

@ -20,6 +20,7 @@ use Sylius\Component\Core\Model\TaxonInterface;
use Sylius\Component\Core\Uploader\ImageUploaderInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;
use Sylius\Component\Taxonomy\Generator\TaxonSlugGeneratorInterface;
use Symfony\Component\HttpFoundation\File\UploadedFile;
/**
@ -52,6 +53,11 @@ final class TaxonomyContext implements Context
*/
private $imageUploader;
/**
* @var TaxonSlugGeneratorInterface
*/
private $taxonSlugGenerator;
/**
* @var array
*/
@ -63,6 +69,7 @@ final class TaxonomyContext implements Context
* @param FactoryInterface $taxonImageFactory
* @param ObjectManager $objectManager
* @param ImageUploaderInterface $imageUploader
* @param TaxonSlugGeneratorInterface $taxonSlugGenerator
* @param array $minkParameters
*/
public function __construct(
@ -71,6 +78,7 @@ final class TaxonomyContext implements Context
FactoryInterface $taxonImageFactory,
ObjectManager $objectManager,
ImageUploaderInterface $imageUploader,
TaxonSlugGeneratorInterface $taxonSlugGenerator,
array $minkParameters
) {
$this->taxonRepository = $taxonRepository;
@ -78,6 +86,7 @@ final class TaxonomyContext implements Context
$this->taxonImageFactory = $taxonImageFactory;
$this->objectManager = $objectManager;
$this->imageUploader = $imageUploader;
$this->taxonSlugGenerator = $taxonSlugGenerator;
$this->minkParameters = $minkParameters;
}
@ -133,6 +142,7 @@ final class TaxonomyContext implements Context
$taxon = $this->taxonFactory->createNew();
$taxon->setName($name);
$taxon->setCode(StringInflector::nameToCode($name));
$taxon->setSlug($this->taxonSlugGenerator->generate($name));
return $taxon;
}

View file

@ -123,6 +123,21 @@ final class ManagingTaxonsContext implements Context
$this->updatePage->nameIt($name, $language);
}
/**
* @When I set its slug to :slug
*/
public function iSetItsSlugTo($slug)
{
/** @var CreatePageInterface|UpdatePageInterface $currentPage */
$currentPage = $this->currentPageResolver->getCurrentPageWithForm([
$this->createPage,
$this->createForParentPage,
$this->updatePage,
]);
$currentPage->specifySlug($slug);
}
/**
* @When I change its description to :description in :language
*/

View file

@ -108,6 +108,14 @@ class CreatePage extends BaseCreatePage implements CreatePageInterface
$this->getDocument()->fillField(sprintf('sylius_taxon_translations_%s_name', $languageCode), $name);
}
/**
* {@inheritdoc}
*/
public function specifySlug($slug)
{
$this->getDocument()->fillField('Slug', $slug);
}
/**
* {@inheritdoc}
*/

View file

@ -70,6 +70,11 @@ interface CreatePageInterface extends BaseCreatePageInterface
*/
public function specifyCode($code);
/**
* @param string $slug
*/
public function specifySlug($slug);
/**
* @param string $path
* @param string $code

View file

@ -49,6 +49,14 @@ class UpdatePage extends BaseUpdatePage implements UpdatePageInterface
$this->getDocument()->fillField(sprintf('sylius_taxon_translations_%s_name', $languageCode), $name);
}
/**
* {@inheritdoc}
*/
public function specifySlug($slug)
{
$this->getDocument()->fillField('Slug', $slug);
}
/**
* {@inheritdoc}
*/

View file

@ -42,6 +42,11 @@ interface UpdatePageInterface extends BaseUpdatePageInterface
*/
public function nameIt($name, $languageCode);
/**
* @param string $slug
*/
public function specifySlug($slug);
/**
* @return bool
*/

View file

@ -218,6 +218,7 @@
<argument type="service" id="__symfony__.sylius.factory.taxon_image" />
<argument type="service" id="__symfony__.doctrine.orm.entity_manager" />
<argument type="service" id="__symfony__.sylius.image_uploader" />
<argument type="service" id="__symfony__.sylius.generator.taxon_slug" />
<argument>%__behat__.mink.parameters%</argument>
<tag name="fob.context_service" />
</service>

View file

@ -17,6 +17,7 @@
</div>
<div class="content{% if 0 == loop.index0 %} active{% endif %}">
{{ form_row(translationForm.name) }}
{{ form_row(translationForm.slug) }}
{{ form_row(translationForm.description) }}
</div>
{% endfor %}

View file

@ -29,7 +29,6 @@ class TaxonTranslationType extends AbstractResourceType
'label' => 'sylius.form.taxon.name',
])
->add('slug', 'text', [
'required' => false,
'label' => 'sylius.form.taxon.slug',
])
->add('description', 'textarea', [

View file

@ -12,7 +12,6 @@
-->
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:gedmo="http://gediminasm.org/schemas/orm/doctrine-extensions-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
@ -22,9 +21,7 @@
<generator strategy="AUTO" />
</id>
<field name="name" column="name" type="string" />
<field name="slug" column="slug" type="string" unique="false">
<gedmo:slug fields="name" unique="false" />
</field>
<field name="slug" column="slug" type="string" unique="false" />
<field name="description" column="description" type="text" nullable="true" />
<unique-constraints>
<unique-constraint columns="locale,slug" name="slug_uidx" />