Skip to content

Commit

Permalink
fix validation for user subentity forms (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz authored and wachterjohannes committed Aug 2, 2016
1 parent 1f7fe11 commit 9448674
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 15 deletions.
5 changes: 3 additions & 2 deletions Form/Type/CompletionContactType.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Sulu\Bundle\ContactBundle\Entity\Contact;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

Expand All @@ -29,11 +30,11 @@ public function buildForm(FormBuilderInterface $builder, array $options)
$contact = $builder->getData();

if (!$contact->getFirstName()) {
$builder->add('first_name', 'text');
$builder->add('firstName', TextType::class);
}

if (!$contact->getLastName()) {
$builder->add('last_name', 'text');
$builder->add('lastName', TextType::class);
}
}

Expand Down
6 changes: 3 additions & 3 deletions Form/Type/ProfileContactType.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public function buildForm(FormBuilderInterface $builder, array $options)
]
);

$builder->add('first_name', TextType::class);
$builder->add('last_name', TextType::class);
$builder->add('main_email', EmailType::class);
$builder->add('firstName', TextType::class);
$builder->add('lastName', TextType::class);
$builder->add('mainEmail', EmailType::class);
$builder->add('avatar', FileType::class, ['mapped' => false, 'required' => false]);

$builder->add(
Expand Down
4 changes: 2 additions & 2 deletions Form/Type/RegistrationContactType.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class RegistrationContactType extends AbstractType
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('first_name', TextType::class);
$builder->add('last_name', TextType::class);
$builder->add('firstName', TextType::class);
$builder->add('lastName', TextType::class);
}

/**
Expand Down
25 changes: 21 additions & 4 deletions Resources/config/validation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,16 @@
</property>
</class>

<!-- User -->
<class name="Sulu\Bundle\SecurityBundle\Entity\User">
<property name="contact">
<constraint name="Valid" />
</property>
</class>

<!-- Contact -->
<class name="Sulu\Bundle\SecurityBundle\Entity\ContactInterface">
<property name="first_name">
<class name="Sulu\Bundle\ContactBundle\Entity\Contact">
<property name="firstName">
<constraint name="NotBlank">
<option name="groups">
<value>registration</value>
Expand All @@ -58,7 +65,7 @@
</option>
</constraint>
</property>
<property name="last_name">
<property name="lastName">
<constraint name="NotBlank">
<option name="groups">
<value>registration</value>
Expand All @@ -67,10 +74,20 @@
</option>
</constraint>
</property>
<property name="addresses">
<constraint name="Valid" />
</property>
</class>

<!-- ContactAddress -->
<class name="Sulu\Bundle\ContactBundle\Entity\ContactAddress">
<property name="address">
<constraint name="Valid" />
</property>
</class>

<!-- Address -->
<class name="Sulu\Bundle\SecurityBundle\Entity\Address">
<class name="Sulu\Bundle\ContactBundle\Entity\Address">
<property name="country">
<constraint name="NotBlank">
<option name="groups">
Expand Down
8 changes: 4 additions & 4 deletions Tests/Functional/Controller/ProfileControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public function testForm()
$crawler = $client->request('GET', '/profile');
$this->assertHttpStatusCode(200, $client->getResponse());

$this->assertCount(1, $crawler->filter('#profile_contact_first_name'));
$this->assertCount(1, $crawler->filter('#profile_contact_last_name'));
$this->assertCount(1, $crawler->filter('#profile_contact_firstName'));
$this->assertCount(1, $crawler->filter('#profile_contact_lastName'));
$this->assertCount(1, $crawler->filter('#profile_contact_contactAddresses_0_address_street'));
$this->assertCount(1, $crawler->filter('#profile_contact_contactAddresses_0_address_number'));
$this->assertCount(1, $crawler->filter('#profile_contact_contactAddresses_0_address_zip'));
Expand All @@ -78,8 +78,8 @@ public function testForm()
$form = $crawler->selectButton('profile[submit]')->form(
[
'profile[contact][formOfAddress]' => 0,
'profile[contact][first_name]' => 'Hikaru',
'profile[contact][last_name]' => 'Sulu',
'profile[contact][firstName]' => 'Hikaru',
'profile[contact][lastName]' => 'Sulu',
'profile[contact][contactAddresses][0][address][street]' => 'Rathausstraße',
'profile[contact][contactAddresses][0][address][number]' => 16,
'profile[contact][contactAddresses][0][address][zip]' => 12351,
Expand Down

0 comments on commit 9448674

Please sign in to comment.