mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 17:10:53 +00:00
Review fixes
This commit is contained in:
parent
49a0ab4680
commit
1159f2ce43
9 changed files with 64 additions and 14 deletions
34
app/migrations/Version20160122143514.php
Normal file
34
app/migrations/Version20160122143514.php
Normal 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');
|
||||
}
|
||||
}
|
||||
|
|
@ -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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class ProvinceType extends AbstractResourceType
|
|||
'label' => 'sylius.form.province.name',
|
||||
))
|
||||
->add('abbreviation', 'text', array(
|
||||
'label' => 'sylius.form.province.abbreviation',
|
||||
'label' => false,
|
||||
))
|
||||
;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -72,8 +72,6 @@ class BuildAddressFormSubscriberSpec extends ObjectBehavior
|
|||
$formFactory->createNamed('provinceCode', 'sylius_province_code_choice', 'province', Argument::withKey('country'))
|
||||
->willReturn($provinceForm);
|
||||
|
||||
|
||||
|
||||
$this->preSetData($event);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -50,7 +50,11 @@ class ProvinceNamingProvider implements ProvinceNamingProviderInterface
|
|||
{
|
||||
$province = $this->getProvince($provinceCode);
|
||||
|
||||
return $province->getAbbreviation();
|
||||
if (null !== $provinceAbbreviation = $province->getAbbreviation()) {
|
||||
return $provinceAbbreviation;
|
||||
}
|
||||
|
||||
return $provinceCode;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue