Review fixes

This commit is contained in:
Jan Goralski 2016-01-22 14:28:26 +01:00
parent 49a0ab4680
commit 1159f2ce43
9 changed files with 64 additions and 14 deletions

View file

@ -0,0 +1,34 @@
<?php
namespace Sylius\Migrations;
use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* Auto-generated Migration: Please modify to your needs!
*/
class Version20160122143514 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('ALTER TABLE sylius_province ADD abbreviation VARCHAR(255) DEFAULT NULL');
}
/**
* @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('ALTER TABLE sylius_province DROP abbreviation');
}
}

View file

@ -135,12 +135,12 @@ class AddressingContext extends DefaultContext
/**
* @Given /^there is province "([^"]*)"$/
*/
public function thereIsProvince($name)
public function thereIsProvince($name, $countryCode = null)
{
/* @var $province ProvinceInterface */
$province = $this->getFactory('province')->createNew();
$province->setName($name);
$province->setCode($name);
$province->setCode(sprintf('%s-%s', $countryCode, $name));
$this->getEntityManager()->persist($province);
@ -172,7 +172,7 @@ class AddressingContext extends DefaultContext
if (null !== $provinces) {
$provinces = $provinces instanceof TableNode ? $provinces->getHash() : $provinces;
foreach ($provinces as $provinceName) {
$country->addProvince($this->thereisProvince($provinceName));
$country->addProvince($this->thereisProvince($provinceName, $country->getCode()));
}
}
}

View file

@ -31,7 +31,7 @@ class ProvinceType extends AbstractResourceType
'label' => 'sylius.form.province.name',
))
->add('abbreviation', 'text', array(
'label' => 'sylius.form.province.abbreviation',
'label' => false,
))
;
}

View file

@ -142,7 +142,12 @@
</constraint>
<constraint name="Regex">
<option name="message">sylius.province.code.regex</option>
<option name="pattern">/[A-Z]{2}-[A-Z,a-z]{2,}/</option>
<option name="pattern">/[A-Z]{2}-[^W\d]{2,}/</option>
<option name="groups">sylius</option>
</constraint>
<constraint name="Length">
<option name="min">5</option>
<option name="minMessage">sylius.province.code.min_length</option>
<option name="groups">sylius</option>
</constraint>
</property>

View file

@ -32,7 +32,9 @@ sylius:
unique: Country ISO code must be unique.
province:
code:
min_length: Province code must be at least 5 characters long|Province code must be at least 5 characters long.
not_blank: Please enter province code.
regex: Province code should have the following format XX-XX (e.g. US-FL).
unique: Province code must be unique.
name:
max_length: Province name must not be longer than 255 characters|Province name must not be longer than 255 characters.

View file

@ -72,8 +72,6 @@ class BuildAddressFormSubscriberSpec extends ObjectBehavior
$formFactory->createNamed('provinceCode', 'sylius_province_code_choice', 'province', Argument::withKey('country'))
->willReturn($provinceForm);
$this->preSetData($event);
}

View file

@ -7,12 +7,7 @@
{{ address.street }}<br/>
{{ address.city }}<br/>
{% if address.provinceCode %}
{% set abbreviation = address.provinceCode|sylius_province_abbreviation %}
{% if '' == abbreviation %}
{{ address.provinceCode }}<br/>
{% else %}
{{ abbreviation }}<br/>
{% endif %}
{{ address.provinceCode|sylius_province_abbreviation }}<br/>
{% endif %}
{{ address.countryCode|sylius_country_name|upper }} {{ address.postcode }}
</address>

View file

@ -50,7 +50,11 @@ class ProvinceNamingProvider implements ProvinceNamingProviderInterface
{
$province = $this->getProvince($provinceCode);
return $province->getAbbreviation();
if (null !== $provinceAbbreviation = $province->getAbbreviation()) {
return $provinceAbbreviation;
}
return $provinceCode;
}
/**

View file

@ -69,4 +69,16 @@ class ProvinceNamingProviderSpec extends ObjectBehavior
$this->getAbbreviation('IE-UL')->shouldReturn('ULS');
}
function it_gets_province_code_if_its_abbreviation_is_not_set(
RepositoryInterface $provinceRepository,
ProvinceInterface $province
)
{
$province->getCode()->willReturn('IE-UL');
$province->getAbbreviation()->willReturn(null);
$provinceRepository->findOneBy(array('code' => 'IE-UL'))->willReturn($province);
$this->getAbbreviation('IE-UL')->shouldReturn('IE-UL');
}
}