Commit 8dcc72ca6e9c08bf9b7d311c582adc758056a578
1 parent
c7372559d5
Exists in
feature/karellys
aplicar asser
Showing
8 changed files
with
381 additions
and
0 deletions
Show diff stats
app/Resources/views/aldea/edit.html.twig
| ... | ... | @@ -0,0 +1,21 @@ |
| 1 | +{% extends 'base.html.twig' %} | |
| 2 | + | |
| 3 | +{% block body %} | |
| 4 | + <h1>Aldea 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('aldea_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/aldea/index.html.twig
| ... | ... | @@ -0,0 +1,45 @@ |
| 1 | +{% extends 'base.html.twig' %} | |
| 2 | + | |
| 3 | +{% block body %} | |
| 4 | + <h1>Aldeas list</h1> | |
| 5 | + | |
| 6 | + <table> | |
| 7 | + <thead> | |
| 8 | + <tr> | |
| 9 | + <th>Id</th> | |
| 10 | + <th>Descripcion</th> | |
| 11 | + <th>Codigosucre</th> | |
| 12 | + <th>Codigoaldea</th> | |
| 13 | + <th>Estatus</th> | |
| 14 | + <th>Actions</th> | |
| 15 | + </tr> | |
| 16 | + </thead> | |
| 17 | + <tbody> | |
| 18 | + {% for aldea in aldeas %} | |
| 19 | + <tr> | |
| 20 | + <td><a href="{{ path('aldea_show', { 'id': aldea.id }) }}">{{ aldea.id }}</a></td> | |
| 21 | + <td>{{ aldea.descripcion }}</td> | |
| 22 | + <td>{{ aldea.codigoSucre }}</td> | |
| 23 | + <td>{{ aldea.codigoAldea }}</td> | |
| 24 | + <td>{% if aldea.estatus %}Yes{% else %}No{% endif %}</td> | |
| 25 | + <td> | |
| 26 | + <ul> | |
| 27 | + <li> | |
| 28 | + <a href="{{ path('aldea_show', { 'id': aldea.id }) }}">show</a> | |
| 29 | + </li> | |
| 30 | + <li> | |
| 31 | + <a href="{{ path('aldea_edit', { 'id': aldea.id }) }}">edit</a> | |
| 32 | + </li> | |
| 33 | + </ul> | |
| 34 | + </td> | |
| 35 | + </tr> | |
| 36 | + {% endfor %} | |
| 37 | + </tbody> | |
| 38 | + </table> | |
| 39 | + | |
| 40 | + <ul> | |
| 41 | + <li> | |
| 42 | + <a href="{{ path('aldea_new') }}">Create a new aldea</a> | |
| 43 | + </li> | |
| 44 | + </ul> | |
| 45 | +{% endblock %} | ... | ... |
app/Resources/views/aldea/new.html.twig
| ... | ... | @@ -0,0 +1,16 @@ |
| 1 | +{% extends 'base.html.twig' %} | |
| 2 | + | |
| 3 | +{% block body %} | |
| 4 | + <h1>Aldea 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('aldea_index') }}">Back to the list</a> | |
| 14 | + </li> | |
| 15 | + </ul> | |
| 16 | +{% endblock %} | ... | ... |
app/Resources/views/aldea/show.html.twig
| ... | ... | @@ -0,0 +1,44 @@ |
| 1 | +{% extends 'base.html.twig' %} | |
| 2 | + | |
| 3 | +{% block body %} | |
| 4 | + <h1>Aldea</h1> | |
| 5 | + | |
| 6 | + <table> | |
| 7 | + <tbody> | |
| 8 | + <tr> | |
| 9 | + <th>Id</th> | |
| 10 | + <td>{{ aldea.id }}</td> | |
| 11 | + </tr> | |
| 12 | + <tr> | |
| 13 | + <th>Descripcion</th> | |
| 14 | + <td>{{ aldea.descripcion }}</td> | |
| 15 | + </tr> | |
| 16 | + <tr> | |
| 17 | + <th>Codigosucre</th> | |
| 18 | + <td>{{ aldea.codigoSucre }}</td> | |
| 19 | + </tr> | |
| 20 | + <tr> | |
| 21 | + <th>Codigoaldea</th> | |
| 22 | + <td>{{ aldea.codigoAldea }}</td> | |
| 23 | + </tr> | |
| 24 | + <tr> | |
| 25 | + <th>Estatus</th> | |
| 26 | + <td>{% if aldea.estatus %}Yes{% else %}No{% endif %}</td> | |
| 27 | + </tr> | |
| 28 | + </tbody> | |
| 29 | + </table> | |
| 30 | + | |
| 31 | + <ul> | |
| 32 | + <li> | |
| 33 | + <a href="{{ path('aldea_index') }}">Back to the list</a> | |
| 34 | + </li> | |
| 35 | + <li> | |
| 36 | + <a href="{{ path('aldea_edit', { 'id': aldea.id }) }}">Edit</a> | |
| 37 | + </li> | |
| 38 | + <li> | |
| 39 | + {{ form_start(delete_form) }} | |
| 40 | + <input type="submit" value="Delete"> | |
| 41 | + {{ form_end(delete_form) }} | |
| 42 | + </li> | |
| 43 | + </ul> | |
| 44 | +{% endblock %} | ... | ... |
src/UBV/PracticaBundle/Controller/aldeaController.php
| ... | ... | @@ -0,0 +1,137 @@ |
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace UBV\PracticaBundle\Controller; | |
| 4 | + | |
| 5 | +use UBV\PracticaBundle\Entity\aldea; | |
| 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 | +/** | |
| 12 | + * Aldea controller. | |
| 13 | + * | |
| 14 | + * @Route("aldea") | |
| 15 | + */ | |
| 16 | +class aldeaController extends Controller | |
| 17 | +{ | |
| 18 | + /** | |
| 19 | + * Lists all aldea entities. | |
| 20 | + * | |
| 21 | + * @Route("/", name="aldea_index") | |
| 22 | + * @Method("GET") | |
| 23 | + */ | |
| 24 | + public function indexAction() | |
| 25 | + { | |
| 26 | + $em = $this->getDoctrine()->getManager(); | |
| 27 | + | |
| 28 | + $aldeas = $em->getRepository('UBVPracticaBundle:aldea')->findAll(); | |
| 29 | + | |
| 30 | + return $this->render('aldea/index.html.twig', array( | |
| 31 | + 'aldeas' => $aldeas, | |
| 32 | + )); | |
| 33 | + } | |
| 34 | + | |
| 35 | + /** | |
| 36 | + * Creates a new aldea entity. | |
| 37 | + * | |
| 38 | + * @Route("/new", name="aldea_new") | |
| 39 | + * @Method({"GET", "POST"}) | |
| 40 | + */ | |
| 41 | + public function newAction(Request $request) | |
| 42 | + { | |
| 43 | + $aldea = new Aldea(); | |
| 44 | + $form = $this->createForm('UBV\PracticaBundle\Form\aldeaType', $aldea); | |
| 45 | + $form->handleRequest($request); | |
| 46 | + | |
| 47 | + if ($form->isSubmitted() && $form->isValid()) { | |
| 48 | + $em = $this->getDoctrine()->getManager(); | |
| 49 | + $em->persist($aldea); | |
| 50 | + $em->flush(); | |
| 51 | + | |
| 52 | + return $this->redirectToRoute('aldea_index', array('id' => $aldea->getId())); | |
| 53 | + } | |
| 54 | + | |
| 55 | + return $this->render('aldea/new.html.twig', array( | |
| 56 | + 'aldea' => $aldea, | |
| 57 | + 'form' => $form->createView(), | |
| 58 | + )); | |
| 59 | + } | |
| 60 | + | |
| 61 | + /** | |
| 62 | + * Finds and displays a aldea entity. | |
| 63 | + * | |
| 64 | + * @Route("/{id}", name="aldea_show") | |
| 65 | + * @Method("GET") | |
| 66 | + */ | |
| 67 | + public function showAction(aldea $aldea) | |
| 68 | + { | |
| 69 | + $deleteForm = $this->createDeleteForm($aldea); | |
| 70 | + | |
| 71 | + return $this->render('aldea/show.html.twig', array( | |
| 72 | + 'aldea' => $aldea, | |
| 73 | + 'delete_form' => $deleteForm->createView(), | |
| 74 | + )); | |
| 75 | + } | |
| 76 | + | |
| 77 | + /** | |
| 78 | + * Displays a form to edit an existing aldea entity. | |
| 79 | + * | |
| 80 | + * @Route("/{id}/edit", name="aldea_edit") | |
| 81 | + * @Method({"GET", "POST"}) | |
| 82 | + */ | |
| 83 | + public function editAction(Request $request, aldea $aldea) | |
| 84 | + { | |
| 85 | + $deleteForm = $this->createDeleteForm($aldea); | |
| 86 | + $editForm = $this->createForm('UBV\PracticaBundle\Form\aldeaType', $aldea); | |
| 87 | + $editForm->handleRequest($request); | |
| 88 | + | |
| 89 | + if ($editForm->isSubmitted() && $editForm->isValid()) { | |
| 90 | + $this->getDoctrine()->getManager()->flush(); | |
| 91 | + | |
| 92 | + return $this->redirectToRoute('aldea_edit', array('id' => $aldea->getId())); | |
| 93 | + } | |
| 94 | + | |
| 95 | + return $this->render('aldea/edit.html.twig', array( | |
| 96 | + 'aldea' => $aldea, | |
| 97 | + 'edit_form' => $editForm->createView(), | |
| 98 | + 'delete_form' => $deleteForm->createView(), | |
| 99 | + )); | |
| 100 | + } | |
| 101 | + | |
| 102 | + /** | |
| 103 | + * Deletes a aldea entity. | |
| 104 | + * | |
| 105 | + * @Route("/{id}", name="aldea_delete") | |
| 106 | + * @Method("DELETE") | |
| 107 | + */ | |
| 108 | + public function deleteAction(Request $request, aldea $aldea) | |
| 109 | + { | |
| 110 | + $form = $this->createDeleteForm($aldea); | |
| 111 | + $form->handleRequest($request); | |
| 112 | + | |
| 113 | + if ($form->isSubmitted() && $form->isValid()) { | |
| 114 | + $em = $this->getDoctrine()->getManager(); | |
| 115 | + $em->remove($aldea); | |
| 116 | + $em->flush(); | |
| 117 | + } | |
| 118 | + | |
| 119 | + return $this->redirectToRoute('aldea_index'); | |
| 120 | + } | |
| 121 | + | |
| 122 | + /** | |
| 123 | + * Creates a form to delete a aldea entity. | |
| 124 | + * | |
| 125 | + * @param aldea $aldea The aldea entity | |
| 126 | + * | |
| 127 | + * @return \Symfony\Component\Form\Form The form | |
| 128 | + */ | |
| 129 | + private function createDeleteForm(aldea $aldea) | |
| 130 | + { | |
| 131 | + return $this->createFormBuilder() | |
| 132 | + ->setAction($this->generateUrl('aldea_delete', array('id' => $aldea->getId()))) | |
| 133 | + ->setMethod('DELETE') | |
| 134 | + ->getForm() | |
| 135 | + ; | |
| 136 | + } | |
| 137 | +} | ... | ... |
src/UBV/PracticaBundle/Entity/aldea.php
| ... | ... | @@ -3,6 +3,7 @@ |
| 3 | 3 | namespace UBV\PracticaBundle\Entity; |
| 4 | 4 | |
| 5 | 5 | use Doctrine\ORM\Mapping as ORM; |
| 6 | +use Symfony\Component\Validator\Constraints as Assert; | |
| 6 | 7 | |
| 7 | 8 | /** |
| 8 | 9 | * aldea |
| ... | ... | @@ -22,6 +23,13 @@ class aldea |
| 22 | 23 | private $id; |
| 23 | 24 | |
| 24 | 25 | /** |
| 26 | + *@Assert\NotBlank( message= "Por favor introduzca la Descripciรณn de la Aldea") | |
| 27 | + *@Assert\NotNull(message= "Por favor introduzca la Descripciรณn de la Aldea", groups={"Default"}) | |
| 28 | + *@Assert\Length( | |
| 29 | + * min = 5, | |
| 30 | + * max = 100, | |
| 31 | + * minMessage = "Por favor introduzca un Nombre de la Aldea mรกs especรญfico. Mรญnimo {{ limit }} caracteres", | |
| 32 | + * maxMessage = "Por favor introduzca un Nombre de la Aldea mรกs breve. Mรกximo {{ limit }} caracteres", | |
| 25 | 33 | * @var string |
| 26 | 34 | * |
| 27 | 35 | * @ORM\Column(name="descripcion", type="string", length=255) |
| ... | ... | @@ -29,6 +37,13 @@ class aldea |
| 29 | 37 | private $descripcion; |
| 30 | 38 | |
| 31 | 39 | /** |
| 40 | + *@Assert\NotBlank( message= "Por favor introduzca el codigo de la Aldea") | |
| 41 | + *@Assert\NotNull(message= "Por favor introduzca el codigo de la Aldea", groups={"Default"}) | |
| 42 | + *@Assert\Length( | |
| 43 | + * min = 5, | |
| 44 | + * max = 30, | |
| 45 | + * minMessage = "Por favor introduzca el codigo de la Aldea mรกs especรญfico. Mรญnimo {{ limit }} caracteres", | |
| 46 | + * maxMessage = "Por favor introduzca el codigo de la Aldea mรกs breve. Mรกximo {{ limit }} caracteres", | |
| 32 | 47 | * @var int |
| 33 | 48 | * |
| 34 | 49 | * @ORM\Column(name="codigo_sucre", type="integer") | ... | ... |
src/UBV/PracticaBundle/Form/aldeaType.php
| ... | ... | @@ -0,0 +1,48 @@ |
| 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 aldeaType extends AbstractType | |
| 10 | +{ | |
| 11 | + /** | |
| 12 | + * {@inheritdoc} | |
| 13 | + */ | |
| 14 | + public function buildForm(FormBuilderInterface $builder, array $options) | |
| 15 | + { | |
| 16 | + $builder | |
| 17 | + ->add('descripcion','text', array( 'label' | |
| 18 | + => 'Descripciรณn de la aldea', 'attr' | |
| 19 | + => array('class' | |
| 20 | + => 'form-control','placeholder'=>'Descripcion de la aldea'), 'label_attr' | |
| 21 | + => array('class' => 'control-label'), )) | |
| 22 | + ->add('codigoSucre','integer', array( 'label' | |
| 23 | + => 'codigo Sucre', 'attr' | |
| 24 | + => array('class' | |
| 25 | + => 'form-control','placeholder'=>'codigo sucre'), 'label_attr' | |
| 26 | + => array('class' => 'control-label'), )) | |
| 27 | + ->add('codigoAldea') | |
| 28 | + ->add('estatus'); | |
| 29 | + }/** | |
| 30 | + * {@inheritdoc} | |
| 31 | + */ | |
| 32 | + public function configureOptions(OptionsResolver $resolver) | |
| 33 | + { | |
| 34 | + $resolver->setDefaults(array( | |
| 35 | + 'data_class' => 'UBV\PracticaBundle\Entity\aldea' | |
| 36 | + )); | |
| 37 | + } | |
| 38 | + | |
| 39 | + /** | |
| 40 | + * {@inheritdoc} | |
| 41 | + */ | |
| 42 | + public function getBlockPrefix() | |
| 43 | + { | |
| 44 | + return 'ubv_practicabundle_aldea'; | |
| 45 | + } | |
| 46 | + | |
| 47 | + | |
| 48 | +} | ... | ... |
src/UBV/PracticaBundle/Tests/Controller/aldeaControllerTest.php
| ... | ... | @@ -0,0 +1,55 @@ |
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace UBV\PracticaBundle\Tests\Controller; | |
| 4 | + | |
| 5 | +use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | |
| 6 | + | |
| 7 | +class aldeaControllerTest 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', '/aldea/'); | |
| 17 | + $this->assertEquals(200, $client->getResponse()->getStatusCode(), "Unexpected HTTP status code for GET /aldea/"); | |
| 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_aldea[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_aldea[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 | +} | ... | ... |