Commit 204bd6b0f528ad7371cb3aa77a516b0940a9ac14
1 parent
8c45a84511
Exists in
feature/maria
creaion crud persona
Showing
9 changed files
with
488 additions
and
0 deletions
Show diff stats
app/Resources/views/persona/edit.html.twig
| @@ -0,0 +1,21 @@ | @@ -0,0 +1,21 @@ | ||
| 1 | +{% extends 'base.html.twig' %} | ||
| 2 | + | ||
| 3 | +{% block body %} | ||
| 4 | + <h1>Persona edit</h1> | ||
| 5 | + | ||
| 6 | + {{ form_start(edit_form) }} | ||
| 7 | + {{ form_widget(edit_form) }} | ||
| 8 | + <input type="submit" value="Edit" /> | ||
| 9 | + {{ form_end(edit_form) }} | ||
| 10 | + | ||
| 11 | + <ul> | ||
| 12 | + <li> | ||
| 13 | + <a href="{{ path('persona_index') }}">Back to the list</a> | ||
| 14 | + </li> | ||
| 15 | + <li> | ||
| 16 | + {{ form_start(delete_form) }} | ||
| 17 | + <input type="submit" value="Delete"> | ||
| 18 | + {{ form_end(delete_form) }} | ||
| 19 | + </li> | ||
| 20 | + </ul> | ||
| 21 | +{% endblock %} |
app/Resources/views/persona/index.html.twig
| @@ -0,0 +1,43 @@ | @@ -0,0 +1,43 @@ | ||
| 1 | +{% extends 'base.html.twig' %} | ||
| 2 | + | ||
| 3 | +{% block body %} | ||
| 4 | + <h1>Personas list</h1> | ||
| 5 | + | ||
| 6 | + <table> | ||
| 7 | + <thead> | ||
| 8 | + <tr> | ||
| 9 | + <th>Id</th> | ||
| 10 | + <th>Nombre</th> | ||
| 11 | + <th>Apellido</th> | ||
| 12 | + <th>Ceduña</th> | ||
| 13 | + <th>Actions</th> | ||
| 14 | + </tr> | ||
| 15 | + </thead> | ||
| 16 | + <tbody> | ||
| 17 | + {% for persona in personas %} | ||
| 18 | + <tr> | ||
| 19 | + <td><a href="{{ path('persona_show', { 'id': persona.id }) }}">{{ persona.id }}</a></td> | ||
| 20 | + <td>{{ persona.nombre }}</td> | ||
| 21 | + <td>{{ persona.apellido }}</td> | ||
| 22 | + <td>{{ persona.ceduña }}</td> | ||
| 23 | + <td> | ||
| 24 | + <ul> | ||
| 25 | + <li> | ||
| 26 | + <a href="{{ path('persona_show', { 'id': persona.id }) }}">show</a> | ||
| 27 | + </li> | ||
| 28 | + <li> | ||
| 29 | + <a href="{{ path('persona_edit', { 'id': persona.id }) }}">edit</a> | ||
| 30 | + </li> | ||
| 31 | + </ul> | ||
| 32 | + </td> | ||
| 33 | + </tr> | ||
| 34 | + {% endfor %} | ||
| 35 | + </tbody> | ||
| 36 | + </table> | ||
| 37 | + | ||
| 38 | + <ul> | ||
| 39 | + <li> | ||
| 40 | + <a href="{{ path('persona_new') }}">Create a new persona</a> | ||
| 41 | + </li> | ||
| 42 | + </ul> | ||
| 43 | +{% endblock %} |
app/Resources/views/persona/new.html.twig
| @@ -0,0 +1,16 @@ | @@ -0,0 +1,16 @@ | ||
| 1 | +{% extends 'base.html.twig' %} | ||
| 2 | + | ||
| 3 | +{% block body %} | ||
| 4 | + <h1>Persona creation</h1> | ||
| 5 | + | ||
| 6 | + {{ form_start(form) }} | ||
| 7 | + {{ form_widget(form) }} | ||
| 8 | + <input type="submit" value="Create" /> | ||
| 9 | + {{ form_end(form) }} | ||
| 10 | + | ||
| 11 | + <ul> | ||
| 12 | + <li> | ||
| 13 | + <a href="{{ path('persona_index') }}">Back to the list</a> | ||
| 14 | + </li> | ||
| 15 | + </ul> | ||
| 16 | +{% endblock %} |
app/Resources/views/persona/show.html.twig
| @@ -0,0 +1,40 @@ | @@ -0,0 +1,40 @@ | ||
| 1 | +{% extends 'base.html.twig' %} | ||
| 2 | + | ||
| 3 | +{% block body %} | ||
| 4 | + <h1>Persona</h1> | ||
| 5 | + | ||
| 6 | + <table> | ||
| 7 | + <tbody> | ||
| 8 | + <tr> | ||
| 9 | + <th>Id</th> | ||
| 10 | + <td>{{ persona.id }}</td> | ||
| 11 | + </tr> | ||
| 12 | + <tr> | ||
| 13 | + <th>Nombre</th> | ||
| 14 | + <td>{{ persona.nombre }}</td> | ||
| 15 | + </tr> | ||
| 16 | + <tr> | ||
| 17 | + <th>Apellido</th> | ||
| 18 | + <td>{{ persona.apellido }}</td> | ||
| 19 | + </tr> | ||
| 20 | + <tr> | ||
| 21 | + <th>Ceduña</th> | ||
| 22 | + <td>{{ persona.ceduña }}</td> | ||
| 23 | + </tr> | ||
| 24 | + </tbody> | ||
| 25 | + </table> | ||
| 26 | + | ||
| 27 | + <ul> | ||
| 28 | + <li> | ||
| 29 | + <a href="{{ path('persona_index') }}">Back to the list</a> | ||
| 30 | + </li> | ||
| 31 | + <li> | ||
| 32 | + <a href="{{ path('persona_edit', { 'id': persona.id }) }}">Edit</a> | ||
| 33 | + </li> | ||
| 34 | + <li> | ||
| 35 | + {{ form_start(delete_form) }} | ||
| 36 | + <input type="submit" value="Delete"> | ||
| 37 | + {{ form_end(delete_form) }} | ||
| 38 | + </li> | ||
| 39 | + </ul> | ||
| 40 | +{% endblock %} |
src/UBV/PracticaBundle/Controller/personaController.php
| @@ -0,0 +1,136 @@ | @@ -0,0 +1,136 @@ | ||
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace UBV\PracticaBundle\Controller; | ||
| 4 | + | ||
| 5 | +use UBV\PracticaBundle\Entity\persona; | ||
| 6 | +use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||
| 7 | +use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; | ||
| 8 | +use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;use Symfony\Component\HttpFoundation\Request; | ||
| 9 | + | ||
| 10 | +/** | ||
| 11 | + * Persona controller. | ||
| 12 | + * | ||
| 13 | + * @Route("persona") | ||
| 14 | + */ | ||
| 15 | +class personaController extends Controller | ||
| 16 | +{ | ||
| 17 | + /** | ||
| 18 | + * Lists all persona entities. | ||
| 19 | + * | ||
| 20 | + * @Route("/", name="persona_index") | ||
| 21 | + * @Method("GET") | ||
| 22 | + */ | ||
| 23 | + public function indexAction() | ||
| 24 | + { | ||
| 25 | + $em = $this->getDoctrine()->getManager(); | ||
| 26 | + | ||
| 27 | + $personas = $em->getRepository('UBVPracticaBundle:persona')->findAll(); | ||
| 28 | + | ||
| 29 | + return $this->render('persona/index.html.twig', array( | ||
| 30 | + 'personas' => $personas, | ||
| 31 | + )); | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + /** | ||
| 35 | + * Creates a new persona entity. | ||
| 36 | + * | ||
| 37 | + * @Route("/new", name="persona_new") | ||
| 38 | + * @Method({"GET", "POST"}) | ||
| 39 | + */ | ||
| 40 | + public function newAction(Request $request) | ||
| 41 | + { | ||
| 42 | + $persona = new Persona(); | ||
| 43 | + $form = $this->createForm('UBV\PracticaBundle\Form\personaType', $persona); | ||
| 44 | + $form->handleRequest($request); | ||
| 45 | + | ||
| 46 | + if ($form->isSubmitted() && $form->isValid()) { | ||
| 47 | + $em = $this->getDoctrine()->getManager(); | ||
| 48 | + $em->persist($persona); | ||
| 49 | + $em->flush(); | ||
| 50 | + | ||
| 51 | + return $this->redirectToRoute('persona_show', array('id' => $persona->getId())); | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + return $this->render('persona/new.html.twig', array( | ||
| 55 | + 'persona' => $persona, | ||
| 56 | + 'form' => $form->createView(), | ||
| 57 | + )); | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + /** | ||
| 61 | + * Finds and displays a persona entity. | ||
| 62 | + * | ||
| 63 | + * @Route("/{id}", name="persona_show") | ||
| 64 | + * @Method("GET") | ||
| 65 | + */ | ||
| 66 | + public function showAction(persona $persona) | ||
| 67 | + { | ||
| 68 | + $deleteForm = $this->createDeleteForm($persona); | ||
| 69 | + | ||
| 70 | + return $this->render('persona/show.html.twig', array( | ||
| 71 | + 'persona' => $persona, | ||
| 72 | + 'delete_form' => $deleteForm->createView(), | ||
| 73 | + )); | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + /** | ||
| 77 | + * Displays a form to edit an existing persona entity. | ||
| 78 | + * | ||
| 79 | + * @Route("/{id}/edit", name="persona_edit") | ||
| 80 | + * @Method({"GET", "POST"}) | ||
| 81 | + */ | ||
| 82 | + public function editAction(Request $request, persona $persona) | ||
| 83 | + { | ||
| 84 | + $deleteForm = $this->createDeleteForm($persona); | ||
| 85 | + $editForm = $this->createForm('UBV\PracticaBundle\Form\personaType', $persona); | ||
| 86 | + $editForm->handleRequest($request); | ||
| 87 | + | ||
| 88 | + if ($editForm->isSubmitted() && $editForm->isValid()) { | ||
| 89 | + $this->getDoctrine()->getManager()->flush(); | ||
| 90 | + | ||
| 91 | + return $this->redirectToRoute('persona_edit', array('id' => $persona->getId())); | ||
| 92 | + } | ||
| 93 | + | ||
| 94 | + return $this->render('persona/edit.html.twig', array( | ||
| 95 | + 'persona' => $persona, | ||
| 96 | + 'edit_form' => $editForm->createView(), | ||
| 97 | + 'delete_form' => $deleteForm->createView(), | ||
| 98 | + )); | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + /** | ||
| 102 | + * Deletes a persona entity. | ||
| 103 | + * | ||
| 104 | + * @Route("/{id}", name="persona_delete") | ||
| 105 | + * @Method("DELETE") | ||
| 106 | + */ | ||
| 107 | + public function deleteAction(Request $request, persona $persona) | ||
| 108 | + { | ||
| 109 | + $form = $this->createDeleteForm($persona); | ||
| 110 | + $form->handleRequest($request); | ||
| 111 | + | ||
| 112 | + if ($form->isSubmitted() && $form->isValid()) { | ||
| 113 | + $em = $this->getDoctrine()->getManager(); | ||
| 114 | + $em->remove($persona); | ||
| 115 | + $em->flush(); | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | + return $this->redirectToRoute('persona_index'); | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + /** | ||
| 122 | + * Creates a form to delete a persona entity. | ||
| 123 | + * | ||
| 124 | + * @param persona $persona The persona entity | ||
| 125 | + * | ||
| 126 | + * @return \Symfony\Component\Form\Form The form | ||
| 127 | + */ | ||
| 128 | + private function createDeleteForm(persona $persona) | ||
| 129 | + { | ||
| 130 | + return $this->createFormBuilder() | ||
| 131 | + ->setAction($this->generateUrl('persona_delete', array('id' => $persona->getId()))) | ||
| 132 | + ->setMethod('DELETE') | ||
| 133 | + ->getForm() | ||
| 134 | + ; | ||
| 135 | + } | ||
| 136 | +} |
src/UBV/PracticaBundle/Entity/persona.php
| @@ -0,0 +1,128 @@ | @@ -0,0 +1,128 @@ | ||
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace UBV\PracticaBundle\Entity; | ||
| 4 | + | ||
| 5 | +use Doctrine\ORM\Mapping as ORM; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * persona | ||
| 9 | + * | ||
| 10 | + * @ORM\Table(name="persona") | ||
| 11 | + * @ORM\Entity(repositoryClass="UBV\PracticaBundle\Repository\personaRepository") | ||
| 12 | + */ | ||
| 13 | +class persona | ||
| 14 | +{ | ||
| 15 | + /** | ||
| 16 | + * @var int | ||
| 17 | + * | ||
| 18 | + * @ORM\Column(name="id", type="integer") | ||
| 19 | + * @ORM\Id | ||
| 20 | + * @ORM\GeneratedValue(strategy="AUTO") | ||
| 21 | + */ | ||
| 22 | + private $id; | ||
| 23 | + | ||
| 24 | + /** | ||
| 25 | + * @var string | ||
| 26 | + * | ||
| 27 | + * @ORM\Column(name="nombre", type="string", length=255) | ||
| 28 | + */ | ||
| 29 | + private $nombre; | ||
| 30 | + | ||
| 31 | + /** | ||
| 32 | + * @var string | ||
| 33 | + * | ||
| 34 | + * @ORM\Column(name="apellido", type="string", length=255) | ||
| 35 | + */ | ||
| 36 | + private $apellido; | ||
| 37 | + | ||
| 38 | + /** | ||
| 39 | + * @var string | ||
| 40 | + * | ||
| 41 | + * @ORM\Column(name="ceduña", type="string", length=255, unique=true) | ||
| 42 | + */ | ||
| 43 | + private $ceduña; | ||
| 44 | + | ||
| 45 | + | ||
| 46 | + /** | ||
| 47 | + * Get id | ||
| 48 | + * | ||
| 49 | + * @return int | ||
| 50 | + */ | ||
| 51 | + public function getId() | ||
| 52 | + { | ||
| 53 | + return $this->id; | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + /** | ||
| 57 | + * Set nombre | ||
| 58 | + * | ||
| 59 | + * @param string $nombre | ||
| 60 | + * | ||
| 61 | + * @return persona | ||
| 62 | + */ | ||
| 63 | + public function setNombre($nombre) | ||
| 64 | + { | ||
| 65 | + $this->nombre = $nombre; | ||
| 66 | + | ||
| 67 | + return $this; | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + /** | ||
| 71 | + * Get nombre | ||
| 72 | + * | ||
| 73 | + * @return string | ||
| 74 | + */ | ||
| 75 | + public function getNombre() | ||
| 76 | + { | ||
| 77 | + return $this->nombre; | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + /** | ||
| 81 | + * Set apellido | ||
| 82 | + * | ||
| 83 | + * @param string $apellido | ||
| 84 | + * | ||
| 85 | + * @return persona | ||
| 86 | + */ | ||
| 87 | + public function setApellido($apellido) | ||
| 88 | + { | ||
| 89 | + $this->apellido = $apellido; | ||
| 90 | + | ||
| 91 | + return $this; | ||
| 92 | + } | ||
| 93 | + | ||
| 94 | + /** | ||
| 95 | + * Get apellido | ||
| 96 | + * | ||
| 97 | + * @return string | ||
| 98 | + */ | ||
| 99 | + public function getApellido() | ||
| 100 | + { | ||
| 101 | + return $this->apellido; | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + /** | ||
| 105 | + * Set ceduña | ||
| 106 | + * | ||
| 107 | + * @param string $ceduña | ||
| 108 | + * | ||
| 109 | + * @return persona | ||
| 110 | + */ | ||
| 111 | + public function setCeduña($ceduña) | ||
| 112 | + { | ||
| 113 | + $this->ceduña = $ceduña; | ||
| 114 | + | ||
| 115 | + return $this; | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | + /** | ||
| 119 | + * Get ceduña | ||
| 120 | + * | ||
| 121 | + * @return string | ||
| 122 | + */ | ||
| 123 | + public function getCeduña() | ||
| 124 | + { | ||
| 125 | + return $this->ceduña; | ||
| 126 | + } | ||
| 127 | +} | ||
| 128 | + |
src/UBV/PracticaBundle/Form/personaType.php
| @@ -0,0 +1,36 @@ | @@ -0,0 +1,36 @@ | ||
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace UBV\PracticaBundle\Form; | ||
| 4 | + | ||
| 5 | +use Symfony\Component\Form\AbstractType; | ||
| 6 | +use Symfony\Component\Form\FormBuilderInterface; | ||
| 7 | +use Symfony\Component\OptionsResolver\OptionsResolver; | ||
| 8 | + | ||
| 9 | +class personaType extends AbstractType | ||
| 10 | +{ | ||
| 11 | + /** | ||
| 12 | + * {@inheritdoc} | ||
| 13 | + */ | ||
| 14 | + public function buildForm(FormBuilderInterface $builder, array $options) | ||
| 15 | + { | ||
| 16 | + $builder->add('nombre')->add('apellido')->add('ceduña'); | ||
| 17 | + }/** | ||
| 18 | + * {@inheritdoc} | ||
| 19 | + */ | ||
| 20 | + public function configureOptions(OptionsResolver $resolver) | ||
| 21 | + { | ||
| 22 | + $resolver->setDefaults(array( | ||
| 23 | + 'data_class' => 'UBV\PracticaBundle\Entity\persona' | ||
| 24 | + )); | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + /** | ||
| 28 | + * {@inheritdoc} | ||
| 29 | + */ | ||
| 30 | + public function getBlockPrefix() | ||
| 31 | + { | ||
| 32 | + return 'ubv_practicabundle_persona'; | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + | ||
| 36 | +} |
src/UBV/PracticaBundle/Repository/personaRepository.php
| @@ -0,0 +1,13 @@ | @@ -0,0 +1,13 @@ | ||
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace UBV\PracticaBundle\Repository; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * personaRepository | ||
| 7 | + * | ||
| 8 | + * This class was generated by the Doctrine ORM. Add your own custom | ||
| 9 | + * repository methods below. | ||
| 10 | + */ | ||
| 11 | +class personaRepository extends \Doctrine\ORM\EntityRepository | ||
| 12 | +{ | ||
| 13 | +} |
src/UBV/PracticaBundle/Tests/Controller/personaControllerTest.php
| @@ -0,0 +1,55 @@ | @@ -0,0 +1,55 @@ | ||
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace UBV\PracticaBundle\Tests\Controller; | ||
| 4 | + | ||
| 5 | +use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | ||
| 6 | + | ||
| 7 | +class personaControllerTest extends WebTestCase | ||
| 8 | +{ | ||
| 9 | + /* | ||
| 10 | + public function testCompleteScenario() | ||
| 11 | + { | ||
| 12 | + // Create a new client to browse the application | ||
| 13 | + $client = static::createClient(); | ||
| 14 | + | ||
| 15 | + // Create a new entry in the database | ||
| 16 | + $crawler = $client->request('GET', '/persona/'); | ||
| 17 | + $this->assertEquals(200, $client->getResponse()->getStatusCode(), "Unexpected HTTP status code for GET /persona/"); | ||
| 18 | + $crawler = $client->click($crawler->selectLink('Create a new entry')->link()); | ||
| 19 | + | ||
| 20 | + // Fill in the form and submit it | ||
| 21 | + $form = $crawler->selectButton('Create')->form(array( | ||
| 22 | + 'ubv_practicabundle_persona[field_name]' => 'Test', | ||
| 23 | + // ... other fields to fill | ||
| 24 | + )); | ||
| 25 | + | ||
| 26 | + $client->submit($form); | ||
| 27 | + $crawler = $client->followRedirect(); | ||
| 28 | + | ||
| 29 | + // Check data in the show view | ||
| 30 | + $this->assertGreaterThan(0, $crawler->filter('td:contains("Test")')->count(), 'Missing element td:contains("Test")'); | ||
| 31 | + | ||
| 32 | + // Edit the entity | ||
| 33 | + $crawler = $client->click($crawler->selectLink('Edit')->link()); | ||
| 34 | + | ||
| 35 | + $form = $crawler->selectButton('Update')->form(array( | ||
| 36 | + 'ubv_practicabundle_persona[field_name]' => 'Foo', | ||
| 37 | + // ... other fields to fill | ||
| 38 | + )); | ||
| 39 | + | ||
| 40 | + $client->submit($form); | ||
| 41 | + $crawler = $client->followRedirect(); | ||
| 42 | + | ||
| 43 | + // Check the element contains an attribute with value equals "Foo" | ||
| 44 | + $this->assertGreaterThan(0, $crawler->filter('[value="Foo"]')->count(), 'Missing element [value="Foo"]'); | ||
| 45 | + | ||
| 46 | + // Delete the entity | ||
| 47 | + $client->submit($crawler->selectButton('Delete')->form()); | ||
| 48 | + $crawler = $client->followRedirect(); | ||
| 49 | + | ||
| 50 | + // Check the entity has been delete on the list | ||
| 51 | + $this->assertNotRegExp('/Foo/', $client->getResponse()->getContent()); | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + */ | ||
| 55 | +} |