Commit 3213d75b2f770009e9d285f689ab3afd3139cb59

Authored by Edgar Gonzalez
1 parent 8c45a84511
Exists in feature/pruebas

inicializacion de rama de pruebas

app/Resources/views/persona/edit.html.twig
... ... @@ -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,47 @@
  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>Cedula</th>
  13 + <th>Genero</th>
  14 + <th>Direccion</th>
  15 + <th>Actions</th>
  16 + </tr>
  17 + </thead>
  18 + <tbody>
  19 + {% for persona in personas %}
  20 + <tr>
  21 + <td><a href="{{ path('persona_show', { 'id': persona.id }) }}">{{ persona.id }}</a></td>
  22 + <td>{{ persona.nombre }}</td>
  23 + <td>{{ persona.apellido }}</td>
  24 + <td>{{ persona.cedula }}</td>
  25 + <td>{{ persona.genero }}</td>
  26 + <td>{{ persona.direccion }}</td>
  27 + <td>
  28 + <ul>
  29 + <li>
  30 + <a href="{{ path('persona_show', { 'id': persona.id }) }}">show</a>
  31 + </li>
  32 + <li>
  33 + <a href="{{ path('persona_edit', { 'id': persona.id }) }}">edit</a>
  34 + </li>
  35 + </ul>
  36 + </td>
  37 + </tr>
  38 + {% endfor %}
  39 + </tbody>
  40 + </table>
  41 +
  42 + <ul>
  43 + <li>
  44 + <a href="{{ path('persona_new') }}">Create a new persona</a>
  45 + </li>
  46 + </ul>
  47 +{% endblock %}
... ...
app/Resources/views/persona/new.html.twig
... ... @@ -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,48 @@
  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>Cedula</th>
  22 + <td>{{ persona.cedula }}</td>
  23 + </tr>
  24 + <tr>
  25 + <th>Genero</th>
  26 + <td>{{ persona.genero }}</td>
  27 + </tr>
  28 + <tr>
  29 + <th>Direccion</th>
  30 + <td>{{ persona.direccion }}</td>
  31 + </tr>
  32 + </tbody>
  33 + </table>
  34 +
  35 + <ul>
  36 + <li>
  37 + <a href="{{ path('persona_index') }}">Back to the list</a>
  38 + </li>
  39 + <li>
  40 + <a href="{{ path('persona_edit', { 'id': persona.id }) }}">Edit</a>
  41 + </li>
  42 + <li>
  43 + {{ form_start(delete_form) }}
  44 + <input type="submit" value="Delete">
  45 + {{ form_end(delete_form) }}
  46 + </li>
  47 + </ul>
  48 +{% endblock %}
... ...
src/UBV/PracticaBundle/Controller/personaController.php
... ... @@ -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,190 @@
  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=50)
  28 + */
  29 + private $nombre;
  30 +
  31 + /**
  32 + * @var string
  33 + *
  34 + * @ORM\Column(name="apellido", type="string", length=50)
  35 + */
  36 + private $apellido;
  37 +
  38 + /**
  39 + * @var int
  40 + *
  41 + * @ORM\Column(name="cedula", type="integer", unique=true)
  42 + */
  43 + private $cedula;
  44 +
  45 + /**
  46 + * @var string
  47 + *
  48 + * @ORM\Column(name="genero", type="string", length=20)
  49 + */
  50 + private $genero;
  51 +
  52 + /**
  53 + * @var string
  54 + *
  55 + * @ORM\Column(name="direccion", type="string", length=255)
  56 + */
  57 + private $direccion;
  58 +
  59 +
  60 + /**
  61 + * Get id
  62 + *
  63 + * @return int
  64 + */
  65 + public function getId()
  66 + {
  67 + return $this->id;
  68 + }
  69 +
  70 + /**
  71 + * Set nombre
  72 + *
  73 + * @param string $nombre
  74 + *
  75 + * @return persona
  76 + */
  77 + public function setNombre($nombre)
  78 + {
  79 + $this->nombre = $nombre;
  80 +
  81 + return $this;
  82 + }
  83 +
  84 + /**
  85 + * Get nombre
  86 + *
  87 + * @return string
  88 + */
  89 + public function getNombre()
  90 + {
  91 + return $this->nombre;
  92 + }
  93 +
  94 + /**
  95 + * Set apellido
  96 + *
  97 + * @param string $apellido
  98 + *
  99 + * @return persona
  100 + */
  101 + public function setApellido($apellido)
  102 + {
  103 + $this->apellido = $apellido;
  104 +
  105 + return $this;
  106 + }
  107 +
  108 + /**
  109 + * Get apellido
  110 + *
  111 + * @return string
  112 + */
  113 + public function getApellido()
  114 + {
  115 + return $this->apellido;
  116 + }
  117 +
  118 + /**
  119 + * Set cedula
  120 + *
  121 + * @param integer $cedula
  122 + *
  123 + * @return persona
  124 + */
  125 + public function setCedula($cedula)
  126 + {
  127 + $this->cedula = $cedula;
  128 +
  129 + return $this;
  130 + }
  131 +
  132 + /**
  133 + * Get cedula
  134 + *
  135 + * @return int
  136 + */
  137 + public function getCedula()
  138 + {
  139 + return $this->cedula;
  140 + }
  141 +
  142 + /**
  143 + * Set genero
  144 + *
  145 + * @param string $genero
  146 + *
  147 + * @return persona
  148 + */
  149 + public function setGenero($genero)
  150 + {
  151 + $this->genero = $genero;
  152 +
  153 + return $this;
  154 + }
  155 +
  156 + /**
  157 + * Get genero
  158 + *
  159 + * @return string
  160 + */
  161 + public function getGenero()
  162 + {
  163 + return $this->genero;
  164 + }
  165 +
  166 + /**
  167 + * Set direccion
  168 + *
  169 + * @param string $direccion
  170 + *
  171 + * @return persona
  172 + */
  173 + public function setDireccion($direccion)
  174 + {
  175 + $this->direccion = $direccion;
  176 +
  177 + return $this;
  178 + }
  179 +
  180 + /**
  181 + * Get direccion
  182 + *
  183 + * @return string
  184 + */
  185 + public function getDireccion()
  186 + {
  187 + return $this->direccion;
  188 + }
  189 +}
  190 +
... ...
src/UBV/PracticaBundle/Form/personaType.php
... ... @@ -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('cedula')->add('genero')->add('direccion');
  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 @@
  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 @@
  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 +}
... ...