mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 13:24:25 +00:00
add new / create address + tests
This commit is contained in:
parent
545e155334
commit
ff5bda12b6
@ -37,6 +37,92 @@ use Symfony\Component\HttpFoundation\Request;
|
|||||||
*/
|
*/
|
||||||
class PersonAddressController extends Controller
|
class PersonAddressController extends Controller
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public function listAction($person_id)
|
||||||
|
{
|
||||||
|
$person = $this->getDoctrine()->getManager()
|
||||||
|
->getRepository('ChillPersonBundle:Person')
|
||||||
|
->find($person_id);
|
||||||
|
|
||||||
|
if ($person === NULL) {
|
||||||
|
throw $this->createNotFoundException("Person with id $person_id not"
|
||||||
|
. " found ");
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person,
|
||||||
|
"You are not allowed to edit this person.");
|
||||||
|
|
||||||
|
return $this->render('ChillPersonBundle:Address:list.html.twig', array(
|
||||||
|
'person' => $person
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function newAction($person_id)
|
||||||
|
{
|
||||||
|
$person = $this->getDoctrine()->getManager()
|
||||||
|
->getRepository('ChillPersonBundle:Person')
|
||||||
|
->find($person_id);
|
||||||
|
|
||||||
|
if ($person === NULL) {
|
||||||
|
throw $this->createNotFoundException("Person with id $person_id not"
|
||||||
|
. " found ");
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->denyAccessUnlessGranted('CHILL_PERSON_UPDATE', $person,
|
||||||
|
"You are not allowed to edit this person.");
|
||||||
|
|
||||||
|
$address = new Address();
|
||||||
|
|
||||||
|
$form = $this->createCreateForm($person, $address);
|
||||||
|
|
||||||
|
return $this->render('ChillPersonBundle:Address:new.html.twig', array(
|
||||||
|
'person' => $person,
|
||||||
|
'form' => $form->createView()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createAction($person_id, Request $request)
|
||||||
|
{
|
||||||
|
$person = $this->getDoctrine()->getManager()
|
||||||
|
->getRepository('ChillPersonBundle:Person')
|
||||||
|
->find($person_id);
|
||||||
|
|
||||||
|
if ($person === NULL) {
|
||||||
|
throw $this->createNotFoundException("Person with id $person_id not"
|
||||||
|
. " found ");
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->denyAccessUnlessGranted('CHILL_PERSON_UPDATE', $person,
|
||||||
|
"You are not allowed to edit this person.");
|
||||||
|
|
||||||
|
$address = new Address();
|
||||||
|
|
||||||
|
$form = $this->createCreateForm($person, $address);
|
||||||
|
|
||||||
|
$form->handleRequest($request);
|
||||||
|
|
||||||
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
|
$address = $form->getData();
|
||||||
|
$person->addAddress($address);
|
||||||
|
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
$em->flush();
|
||||||
|
|
||||||
|
$this->addFlash('success',
|
||||||
|
$this->get('translator')->trans('The new address was created successfully')
|
||||||
|
);
|
||||||
|
|
||||||
|
return $this->redirectToRoute('chill_person_address_list', array(
|
||||||
|
'person_id' => $person->getId()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->render('ChillPersonBundle:Address:new.html.twig', array(
|
||||||
|
'person' => $person,
|
||||||
|
'form' => $form->createView()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
public function editAction($person_id, $address_id)
|
public function editAction($person_id, $address_id)
|
||||||
{
|
{
|
||||||
$person = $this->getDoctrine()->getManager()
|
$person = $this->getDoctrine()->getManager()
|
||||||
@ -91,7 +177,7 @@ class PersonAddressController extends Controller
|
|||||||
$this->addFlash('success', $this->get('translator')->trans(
|
$this->addFlash('success', $this->get('translator')->trans(
|
||||||
"The address has been successfully updated"));
|
"The address has been successfully updated"));
|
||||||
|
|
||||||
return $this->redirectToRoute('chill_person_view', array(
|
return $this->redirectToRoute('chill_person_address_list', array(
|
||||||
'person_id' => $person->getId()
|
'person_id' => $person->getId()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -126,6 +212,28 @@ class PersonAddressController extends Controller
|
|||||||
return $form;
|
return $form;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param Person $person
|
||||||
|
* @param Address $address
|
||||||
|
* @return \Symfony\Component\Form\Form
|
||||||
|
*/
|
||||||
|
protected function createCreateForm(Person $person, Address $address)
|
||||||
|
{
|
||||||
|
$form = $this->createForm(AddressType::class, $address, array(
|
||||||
|
'method' => 'POST',
|
||||||
|
'action' => $this->generateUrl('chill_person_address_create', array(
|
||||||
|
'person_id' => $person->getId()
|
||||||
|
))
|
||||||
|
));
|
||||||
|
|
||||||
|
$form->add('submit', 'submit', array(
|
||||||
|
'label' => 'Submit'
|
||||||
|
));
|
||||||
|
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param Person $person
|
* @param Person $person
|
||||||
|
@ -619,8 +619,10 @@ class Person implements HasCenterInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* By default, the addresses are ordered by date, descending (the most
|
||||||
|
* recent first)
|
||||||
*
|
*
|
||||||
* @return \Chill\MainBundle\Entity\Address[]@return Address[]
|
* @return \Chill\MainBundle\Entity\Address[]
|
||||||
*/
|
*/
|
||||||
public function getAddresses()
|
public function getAddresses()
|
||||||
{
|
{
|
||||||
@ -633,21 +635,14 @@ class Person implements HasCenterInterface {
|
|||||||
$date = new \DateTime('now');
|
$date = new \DateTime('now');
|
||||||
}
|
}
|
||||||
|
|
||||||
$lastAddress = null;
|
$addresses = $this->getAddresses();
|
||||||
|
|
||||||
foreach ($this->getAddresses() as $address) {
|
if ($addresses == null) {
|
||||||
if ($address->getValidFrom() < $date) {
|
|
||||||
if ($lastAddress === NULL) {
|
return null;
|
||||||
$lastAddress = $address;
|
|
||||||
} else {
|
|
||||||
if ($lastAddress->getValidFrom() < $address->getValidFrom()) {
|
|
||||||
$lastAddress = $address;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $lastAddress;
|
return $addresses->first();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -74,6 +74,7 @@ Chill\PersonBundle\Entity\Person:
|
|||||||
referencedColumnName: id
|
referencedColumnName: id
|
||||||
addresses:
|
addresses:
|
||||||
targetEntity: Chill\MainBundle\Entity\Address
|
targetEntity: Chill\MainBundle\Entity\Address
|
||||||
|
orderBy: { 'validFrom': 'DESC' }
|
||||||
joinTable:
|
joinTable:
|
||||||
name: chill_person_persons_to_addresses
|
name: chill_person_persons_to_addresses
|
||||||
cascade: [persist, remove, merge, detach]
|
cascade: [persist, remove, merge, detach]
|
||||||
|
@ -70,6 +70,19 @@ chill_person_accompanying_period_open:
|
|||||||
path: /{_locale}/person/{person_id}/accompanying-period/open
|
path: /{_locale}/person/{person_id}/accompanying-period/open
|
||||||
defaults: { _controller: ChillPersonBundle:AccompanyingPeriod:open }
|
defaults: { _controller: ChillPersonBundle:AccompanyingPeriod:open }
|
||||||
|
|
||||||
|
chill_person_address_list:
|
||||||
|
path: /{_locale}/person/{person_id}/address/list
|
||||||
|
defaults: { _controller: ChillPersonBundle:PersonAddress:list }
|
||||||
|
|
||||||
|
chill_person_address_create:
|
||||||
|
path: /{_locale}/person/{person_id}/address/create
|
||||||
|
defaults: { _controller: ChillPersonBundle:PersonAddress:create }
|
||||||
|
methods: [POST]
|
||||||
|
|
||||||
|
chill_person_address_new:
|
||||||
|
path: /{_locale}/person/{person_id}/address/new
|
||||||
|
defaults: { _controller: ChillPersonBundle:PersonAddress:new }
|
||||||
|
|
||||||
chill_person_address_edit:
|
chill_person_address_edit:
|
||||||
path: /{_locale}/person/{person_id}/address/{address_id}/edit
|
path: /{_locale}/person/{person_id}/address/{address_id}/edit
|
||||||
defaults: { _controller: ChillPersonBundle:PersonAddress:edit }
|
defaults: { _controller: ChillPersonBundle:PersonAddress:edit }
|
||||||
|
@ -76,6 +76,12 @@ Since %date%: Depuis le %date%
|
|||||||
No address given: Pas d'adresse renseignée
|
No address given: Pas d'adresse renseignée
|
||||||
The address has been successfully updated: L'adresse a été mise à jour avec succès
|
The address has been successfully updated: L'adresse a été mise à jour avec succès
|
||||||
Update address for %name%: Mettre à jour une adresse pour %name%
|
Update address for %name%: Mettre à jour une adresse pour %name%
|
||||||
|
Addresses'history for %name%: Historique des adresses de %name%
|
||||||
|
Addresses'history: Historique des adresses
|
||||||
|
New address for %name% : Nouvelle adresse pour %name%
|
||||||
|
The new address was created successfully: La nouvelle adresse a été créée
|
||||||
|
Add an address: Ajouter une adresse
|
||||||
|
Back to the person details: Retour aux détails de la personne
|
||||||
|
|
||||||
#timeline
|
#timeline
|
||||||
'An accompanying period is opened for %person% on %date%': Une période d'accompagnement a été ouverte le %date% pour %person%
|
'An accompanying period is opened for %person% on %date%': Une période d'accompagnement a été ouverte le %date% pour %person%
|
||||||
|
@ -18,10 +18,12 @@
|
|||||||
|
|
||||||
{% set activeRouteKey = '' %}
|
{% set activeRouteKey = '' %}
|
||||||
|
|
||||||
{% block title %}{{ 'Update address for %name%'|trans({ '%name%': person.firstName|capitalize ~ ' ' ~ person.lastName } )|capitalize }}{% endblock %}
|
{% block title 'Update address for %name%'|trans({ '%name%': person.firstName ~ ' ' ~ person.lastName } ) %}
|
||||||
|
|
||||||
{% block personcontent %}
|
{% block personcontent %}
|
||||||
|
|
||||||
|
<h1>{{ 'Update address for %name%'|trans({ '%name%': person.firstName ~ ' ' ~ person.lastName } ) }}</h1>
|
||||||
|
|
||||||
{{ form_start(form) }}
|
{{ form_start(form) }}
|
||||||
|
|
||||||
{{ form_row(form.streetAddress1) }}
|
{{ form_row(form.streetAddress1) }}
|
||||||
@ -29,7 +31,16 @@
|
|||||||
{{ form_row(form.postCode) }}
|
{{ form_row(form.postCode) }}
|
||||||
{{ form_row(form.validFrom) }}
|
{{ form_row(form.validFrom) }}
|
||||||
|
|
||||||
{{ form_row(form.submit, { 'attr' : { 'class': 'sc-button bt-edit' } } ) }}
|
<ul class="record_actions">
|
||||||
|
<li>
|
||||||
|
<a href="{{ path('chill_person_address_list', { 'person_id' : person.id } ) }}" class="sc-button btn-cancel">
|
||||||
|
{{ 'Back to the list'|trans }}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
{{ form_row(form.submit, { 'attr' : { 'class': 'sc-button bt-edit' } } ) }}
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
{{ form_end(form) }}
|
{{ form_end(form) }}
|
||||||
|
|
||||||
|
84
Resources/views/Address/list.html.twig
Normal file
84
Resources/views/Address/list.html.twig
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
{#
|
||||||
|
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#}
|
||||||
|
{% extends "ChillPersonBundle::layout.html.twig" %}
|
||||||
|
|
||||||
|
{% import 'ChillMainBundle:Address:macro.html.twig' as address_macros %}
|
||||||
|
|
||||||
|
{% set activeRouteKey = '' %}
|
||||||
|
|
||||||
|
{% block title %}{{ 'Addresses\'history for %name%'|trans({ '%name%': person.firstName ~ ' ' ~ person.lastName } ) }}{% endblock %}
|
||||||
|
|
||||||
|
{% block personcontent %}
|
||||||
|
|
||||||
|
<h1>{{ 'Addresses\'history for %name%'|trans({ '%name%': person.firstName ~ ' ' ~ person.lastName } ) }}</h1>
|
||||||
|
|
||||||
|
<table class="records_list">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>{{ 'Valid from'|trans }}</th>
|
||||||
|
<th>{{ 'Address'|trans }}</th>
|
||||||
|
<th> </th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% if person.addresses|length == 0 %}
|
||||||
|
<tr>
|
||||||
|
<td colspan="3">
|
||||||
|
<span class="chill-no-data-statement">{{ 'No address given'|trans }}</span>
|
||||||
|
<a href="{{ path('chill_person_address_new', { 'person_id' : person.id } ) }}">
|
||||||
|
{{ 'Add an address'|trans }}
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% else %}
|
||||||
|
{% for address in person.addresses %}
|
||||||
|
<tr>
|
||||||
|
<td><strong>{{ 'Since %date%'|trans( { '%date%' : address.validFrom|localizeddate('long', 'none') } ) }}</strong></td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
{{ address_macros._render(address, { 'with_valid_from' : false } ) }}
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
<ul class="record_actions">
|
||||||
|
<li>
|
||||||
|
<a href="{{ path('chill_person_address_edit', { 'person_id': person.id, 'address_id' : address.id } ) }}" class="sc-button bt-edit">
|
||||||
|
{{ 'Edit'|trans }}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<ul class="record_actions">
|
||||||
|
<li>
|
||||||
|
<a href="{{ path('chill_person_view', { 'person_id' : person.id } ) }}" class="sc-button btn-cancel">
|
||||||
|
{{ 'Back to the person details'|trans }}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="{{ path('chill_person_address_new', { 'person_id' : person.id } ) }}" class="sc-button btn-create">
|
||||||
|
{{ 'Add an address'|trans }}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
{% endblock personcontent %}
|
47
Resources/views/Address/new.html.twig
Normal file
47
Resources/views/Address/new.html.twig
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
{#
|
||||||
|
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#}
|
||||||
|
{% extends "ChillPersonBundle::layout.html.twig" %}
|
||||||
|
|
||||||
|
{% set activeRouteKey = '' %}
|
||||||
|
|
||||||
|
{% block title %}{{ 'New address for %name%'|trans({ '%name%': person.firstName|capitalize ~ ' ' ~ person.lastName } )|capitalize }}{% endblock %}
|
||||||
|
|
||||||
|
{% block personcontent %}
|
||||||
|
|
||||||
|
<h1>{{ 'New address for %name%'|trans({ '%name%': person.firstName ~ ' ' ~ person.lastName } ) }}</h1>
|
||||||
|
|
||||||
|
{{ form_start(form) }}
|
||||||
|
|
||||||
|
{{ form_row(form.streetAddress1) }}
|
||||||
|
{{ form_row(form.streetAddress2) }}
|
||||||
|
{{ form_row(form.postCode) }}
|
||||||
|
{{ form_row(form.validFrom) }}
|
||||||
|
|
||||||
|
<ul class="record_actions">
|
||||||
|
<li>
|
||||||
|
<a href="{{ path('chill_person_address_list', { 'person_id' : person.id } ) }}" class="sc-button btn-cancel">
|
||||||
|
{{ 'Back to the list'|trans }}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
{{ form_row(form.submit, { 'attr' : { 'class': 'sc-button bt-create' } } ) }}
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
{{ form_end(form) }}
|
||||||
|
|
||||||
|
{% endblock personcontent %}
|
@ -175,9 +175,15 @@ This view should receive those arguments:
|
|||||||
{{ address._render(person.lastAddress) }}
|
{{ address._render(person.lastAddress) }}
|
||||||
<a href="{{ path('chill_person_address_edit', { 'person_id': person.id, 'address_id' : person.lastAddress.id } ) }}">
|
<a href="{{ path('chill_person_address_edit', { 'person_id': person.id, 'address_id' : person.lastAddress.id } ) }}">
|
||||||
{{ 'Edit'|trans }}
|
{{ 'Edit'|trans }}
|
||||||
|
</a><br/>
|
||||||
|
<a href="{{ path('chill_person_address_list', { 'person_id': person.id } ) }}">
|
||||||
|
{{ 'Addresses\'history'|trans }}
|
||||||
</a>
|
</a>
|
||||||
{%- else -%}
|
{%- else -%}
|
||||||
<span class="chill-no-data-statement">{{ 'No address given'|trans }}</span>
|
<span class="chill-no-data-statement">{{ 'No address given'|trans }}</span>
|
||||||
|
<a href="{{ path('chill_person_address_new', { 'person_id' : person.id } ) }}" class="">
|
||||||
|
{{ 'Add an address'|trans }}
|
||||||
|
</a>
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
</dd>
|
</dd>
|
||||||
</dl>
|
</dl>
|
||||||
|
189
Tests/Controller/PersonAddressControllerTest.php
Normal file
189
Tests/Controller/PersonAddressControllerTest.php
Normal file
@ -0,0 +1,189 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Champs-Libres <info@champs-libres.coop>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Chill\PersonBundle\Tests\Controller;
|
||||||
|
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||||
|
use Chill\PersonBundle\Entity\Person;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||||
|
*/
|
||||||
|
class PersonAddressControllerTest extends WebTestCase
|
||||||
|
{
|
||||||
|
/** @var \Doctrine\ORM\EntityManagerInterface The entity manager */
|
||||||
|
protected $em;
|
||||||
|
|
||||||
|
/** @var Person The person on which the test is executed */
|
||||||
|
protected static $person;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @var \Chill\MainBundle\Entity\PostalCode
|
||||||
|
*/
|
||||||
|
protected $postalCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @var \Symfony\Component\BrowserKit\Client
|
||||||
|
*/
|
||||||
|
protected $client;
|
||||||
|
|
||||||
|
public static function setUpBeforeClass()
|
||||||
|
{
|
||||||
|
static::bootKernel();
|
||||||
|
|
||||||
|
$em = static::$kernel->getContainer()
|
||||||
|
->get('doctrine.orm.entity_manager');
|
||||||
|
|
||||||
|
$center = $em->getRepository('ChillMainBundle:Center')
|
||||||
|
->findOneBy(array('name' => 'Center A'));
|
||||||
|
|
||||||
|
self::$person = (new Person())
|
||||||
|
->setLastName("Tested person")
|
||||||
|
->setFirstName("Test")
|
||||||
|
->setCenter($center)
|
||||||
|
->setGender(Person::MALE_GENDER);
|
||||||
|
|
||||||
|
$em->persist(self::$person);
|
||||||
|
$em->flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepare client and create a random person
|
||||||
|
*/
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
static::bootKernel();
|
||||||
|
|
||||||
|
$this->em = static::$kernel->getContainer()
|
||||||
|
->get('doctrine.orm.entity_manager');
|
||||||
|
|
||||||
|
$this->postalCode = $this->em->getRepository('ChillMainBundle:PostalCode')
|
||||||
|
->findOneBy(array('code' => 1000));
|
||||||
|
|
||||||
|
$this->client = static::createClient(array(), array(
|
||||||
|
'PHP_AUTH_USER' => 'center a_social',
|
||||||
|
'PHP_AUTH_PW' => 'password',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function tearDownAfter()
|
||||||
|
{
|
||||||
|
$this->refreshPerson();
|
||||||
|
$this->em->remove(self::$person);
|
||||||
|
$this->em->flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reload the person from the db
|
||||||
|
*/
|
||||||
|
protected function refreshPerson()
|
||||||
|
{
|
||||||
|
self::$person = $this->em->getRepository('ChillPersonBundle:Person')
|
||||||
|
->find(self::$person->getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testEmptyList()
|
||||||
|
{
|
||||||
|
$crawler = $this->client->request('GET', '/fr/person/'.
|
||||||
|
self::$person->getId().'/address/list');
|
||||||
|
|
||||||
|
$this->assertTrue($this->client->getResponse()->isSuccessful());
|
||||||
|
|
||||||
|
$this->assertEquals(1, $crawler->filter('td:contains("Pas d\'adresse renseignée")')
|
||||||
|
->count(),
|
||||||
|
"assert that a message say 'no address given'");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testEmptyList
|
||||||
|
*/
|
||||||
|
public function testCreateAddress()
|
||||||
|
{
|
||||||
|
$crawler = $this->client->request('GET', '/fr/person/'.
|
||||||
|
self::$person->getId().'/address/new');
|
||||||
|
|
||||||
|
$this->assertTrue($this->client->getResponse()->isSuccessful());
|
||||||
|
|
||||||
|
$form = $crawler->selectButton('Envoi')->form(array(
|
||||||
|
'address[streetAddress1]' => 'Rue de la Paix, 50',
|
||||||
|
'address[streetAddress2]' => $this->postalCode->getId(),
|
||||||
|
'address[validFrom]' => '15-01-2016'
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->client->submit($form);
|
||||||
|
|
||||||
|
$crawler = $this->client->followRedirect();
|
||||||
|
|
||||||
|
$this->assertRegexp('|/fr/person/[0-9]{1,}/address/list|',
|
||||||
|
$this->client->getHistory()->current()->getUri(),
|
||||||
|
"assert that the current page is on |/fr/person/[0-9]{1,}/address/list|");
|
||||||
|
$this->assertEquals(1, $crawler
|
||||||
|
->filter('div.flash_message.success')
|
||||||
|
->count(),
|
||||||
|
"Asserting that the response page contains a success flash message");
|
||||||
|
$this->assertEquals(1, $crawler
|
||||||
|
->filter('td:contains("Rue de la Paix, 50")')
|
||||||
|
->count(),
|
||||||
|
"Asserting that the page contains the new address");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testCreateAddress
|
||||||
|
*/
|
||||||
|
public function testUpdateAddress()
|
||||||
|
{
|
||||||
|
$this->refreshPerson();
|
||||||
|
$address = self::$person->getLastAddress();
|
||||||
|
|
||||||
|
$crawler = $this->client->request('GET', '/fr/person/'.self::$person->getId()
|
||||||
|
.'/address/'.$address->getId().'/edit');
|
||||||
|
|
||||||
|
$this->assertTrue($this->client->getResponse()->isSuccessful());
|
||||||
|
|
||||||
|
$form = $crawler->selectButton('Envoi')->form(array(
|
||||||
|
'address[streetAddress1]' => 'Rue du Trou Normand, 15',
|
||||||
|
'address[validFrom]' => '15-01-2015'
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->client->submit($form);
|
||||||
|
|
||||||
|
$crawler = $this->client->followRedirect();
|
||||||
|
|
||||||
|
$this->assertRegexp('|/fr/person/[0-9]{1,}/address/list|',
|
||||||
|
$this->client->getHistory()->current()->getUri(),
|
||||||
|
"assert that the current page is on |/fr/person/[0-9]{1,}/address/list|");
|
||||||
|
$this->assertGreaterThan(0, $crawler
|
||||||
|
->filter('div.flash_message.success')
|
||||||
|
->count(),
|
||||||
|
"Asserting that the response page contains a success flash message");
|
||||||
|
$this->assertEquals(1, $crawler
|
||||||
|
->filter('td:contains("Rue du Trou Normand")')
|
||||||
|
->count(),
|
||||||
|
"Asserting that the page contains the new address");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user