From d7186fd397af457a2ecd105ed43b42edaf8a8e83 Mon Sep 17 00:00:00 2001 From: fellipevasconcelos Date: Tue, 11 Feb 2014 22:32:24 -0200 Subject: [PATCH] Adiciona impressora --- Controller/PrinterController.php | 437 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Entity/Printer.php | 200 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Entity/PrinterCounter.php | 189 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Entity/PrinterCounterRepository.php | 15 +++++++++++++++ Entity/PrinterRepository.php | 15 +++++++++++++++ Form/PrinterType.php | 42 ++++++++++++++++++++++++++++++++++++++++++ Resources/public/images/circuitos.png | Bin 0 -> 4734 bytes Resources/public/images/entidades.png | Bin 0 -> 4596 bytes Resources/public/images/help.png | Bin 0 -> 1542 bytes Resources/public/images/home.png | Bin 0 -> 4357 bytes Resources/public/images/ico1.png | Bin 0 -> 4795 bytes Resources/public/images/ico2.png | Bin 0 -> 4230 bytes Resources/public/images/relatorios.png | Bin 0 -> 4562 bytes Resources/public/images/table.png | Bin 0 -> 886 bytes Resources/views/Printer/edit.html.twig | 47 +++++++++++++++++++++++++++++++++++++++++++++++ Resources/views/Printer/index.html.twig | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ Resources/views/Printer/new.html.twig | 32 ++++++++++++++++++++++++++++++++ Resources/views/Printer/reports.html.twig | 35 +++++++++++++++++++++++++++++++++++ Resources/views/Printer/show.html.twig | 46 ++++++++++++++++++++++++++++++++++++++++++++++ Resources/views/layout.html.twig | 8 +++++++- Tests/Controller/PrinterControllerTest.php | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 21 files changed, 1170 insertions(+), 1 deletion(-) create mode 100755 Controller/PrinterController.php create mode 100755 Entity/Printer.php create mode 100755 Entity/PrinterCounter.php create mode 100755 Entity/PrinterCounterRepository.php create mode 100755 Entity/PrinterRepository.php create mode 100644 Form/PrinterType.php create mode 100644 Resources/public/images/circuitos.png create mode 100644 Resources/public/images/entidades.png create mode 100644 Resources/public/images/help.png create mode 100644 Resources/public/images/home.png create mode 100644 Resources/public/images/ico1.png create mode 100644 Resources/public/images/ico2.png create mode 100644 Resources/public/images/relatorios.png create mode 100644 Resources/public/images/table.png create mode 100755 Resources/views/Printer/edit.html.twig create mode 100755 Resources/views/Printer/index.html.twig create mode 100755 Resources/views/Printer/new.html.twig create mode 100644 Resources/views/Printer/reports.html.twig create mode 100755 Resources/views/Printer/show.html.twig create mode 100644 Tests/Controller/PrinterControllerTest.php diff --git a/Controller/PrinterController.php b/Controller/PrinterController.php new file mode 100755 index 0000000..d51018e --- /dev/null +++ b/Controller/PrinterController.php @@ -0,0 +1,437 @@ +getDoctrine()->getManager(); + + $entities = $em->getRepository('CocarBundle:Printer')->findAll(); + + return array( + 'entities' => $entities, + ); + } + /** + * Creates a new Printer entity. + * + * @Route("/", name="printer_create") + * @Method("POST") + * @Template("CocarBundle:Printer:new.html.twig") + */ + public function createAction(Request $request) + { + $entity = new Printer(); + $form = $this->createCreateForm($entity); + $form->handleRequest($request); + + if ($form->isValid()) + { + $em = $this->getDoctrine()->getManager(); + $em->persist($entity); + $em->flush(); + + return $this->redirect($this->generateUrl('printer_show', array('id' => $entity->getId()))); + } + + return array( + 'entity' => $entity, + 'form' => $form->createView(), + ); + } + + /** + * Creates a form to create a Printer entity. + * + * @param Printer $entity The entity + * + * @return \Symfony\Component\Form\Form The form + */ + private function createCreateForm(Printer $entity) + { + $form = $this->createForm(new PrinterType(), $entity, array( + 'action' => $this->generateUrl('printer_create'), + 'method' => 'POST', + )); + + $form->add('submit', 'submit', array('label' => 'Create')); + + return $form; + } + + /** + * Displays a form to create a new Printer entity. + * + * @Route("/new", name="printer_new") + * @Method("GET") + * @Template() + */ + public function newAction() + { + $entity = new Printer(); + $form = $this->createCreateForm($entity); + + return array( + 'entity' => $entity, + 'form' => $form->createView(), + ); + } + + /** + * Finds and displays a Printer entity. + * + * @Route("/{id}", name="printer_show") + * @Method("GET") + * @Template() + */ + public function showAction($id) + { + $em = $this->getDoctrine()->getManager(); + + $entity = $em->getRepository('CocarBundle:Printer')->find($id); + + if (!$entity) { + throw $this->createNotFoundException('Unable to find Printer entity.'); + } + + $deleteForm = $this->createDeleteForm($id); + + return array( + 'entity' => $entity, + 'delete_form' => $deleteForm->createView(), + ); + } + + /** + * Displays a form to edit an existing Printer entity. + * + * @Route("/{id}/edit", name="printer_edit") + * @Method("GET") + * @Template() + */ + public function editAction($id) + { + $em = $this->getDoctrine()->getManager(); + + $entity = $em->getRepository('CocarBundle:Printer')->find($id); + + if (!$entity) { + throw $this->createNotFoundException('Unable to find Printer entity.'); + } + + $editForm = $this->createEditForm($entity); + $deleteForm = $this->createDeleteForm($id); + + return array( + 'entity' => $entity, + 'edit_form' => $editForm->createView(), + 'delete_form' => $deleteForm->createView(), + ); + } + + /** + * Creates a form to edit a Printer entity. + * + * @param Printer $entity The entity + * + * @return \Symfony\Component\Form\Form The form + */ + private function createEditForm(Printer $entity) + { + $form = $this->createForm(new PrinterType(), $entity, array( + 'action' => $this->generateUrl('printer_update', array('id' => $entity->getId())), + 'method' => 'PUT', + )); + + $form->add('submit', 'submit', array('label' => 'Update')); + + return $form; + } + /** + * Edits an existing Printer entity. + * + * @Route("/{id}", name="printer_update") + * @Method("PUT") + * @Template("CocarBundle:Printer:edit.html.twig") + */ + public function updateAction(Request $request, $id) + { + $em = $this->getDoctrine()->getManager(); + + $entity = $em->getRepository('CocarBundle:Printer')->find($id); + + if (!$entity) { + throw $this->createNotFoundException('Unable to find Printer entity.'); + } + + $deleteForm = $this->createDeleteForm($id); + $editForm = $this->createEditForm($entity); + $editForm->handleRequest($request); + + if ($editForm->isValid()) { + $em->flush(); + + return $this->redirect($this->generateUrl('printer_edit', array('id' => $id))); + } + + return array( + 'entity' => $entity, + 'edit_form' => $editForm->createView(), + 'delete_form' => $deleteForm->createView(), + ); + } + /** + * Deletes a Printer entity. + * + * @Route("/{id}", name="printer_delete") + * @Method("DELETE") + */ + public function deleteAction(Request $request, $id) + { + $form = $this->createDeleteForm($id); + $form->handleRequest($request); + + if ($form->isValid()) { + $em = $this->getDoctrine()->getManager(); + $entity = $em->getRepository('CocarBundle:Printer')->find($id); + + if (!$entity) { + throw $this->createNotFoundException('Unable to find Printer entity.'); + } + + $em->remove($entity); + $em->flush(); + } + + return $this->redirect($this->generateUrl('printer')); + } + + /** + * Creates a form to delete a Printer entity by id. + * + * @param mixed $id The entity id + * + * @return \Symfony\Component\Form\Form The form + */ + private function createDeleteForm($id) + { + return $this->createFormBuilder() + ->setAction($this->generateUrl('printer_delete', array('id' => $id))) + ->setMethod('DELETE') + ->getForm() + ; + } + + /** + * @Route("/reports/{id}", name="cocar_printer_reports") + * @Template() + */ + public function reportsAction($id, Request $request) + { + $em = $this->getDoctrine()->getManager(); + + if($request->request->get('form')) + { + $start = new \DateTime($request->request->get('form')['startDate']); + $start = $start->format('U'); + + $end = new \DateTime($request->request->get('form')['endDate']); + $end = $end->format('U'); + } + + $start = isset($start) ? $start : (time() - ((60*60*24)*30)); + $end = isset($end) ? $end : time(); + + $printerCounter = $em->createQuery( + "SELECT pc.id, pc.prints, pc.blackInk, pc.coloredInk FROM CocarBundle:PrinterCounter pc + WHERE (pc.date >= :start AND pc.date <= :end) AND (pc.printer = :id) + ORDER BY pc.id ASC" + ) + ->setParameter('start', $start) + ->setParameter('end', $end) + ->setParameter('id', $id) + ->getResult(); + + $pCounter = array(); + + foreach ($printerCounter as $counter) + { + if($counter === reset($printerCounter)) + { + $pCounter['prints'] = $counter['prints']; + } + + if ($counter === end($printerCounter)) + { + $pCounter['prints'] = $counter['prints'] - $pCounter['prints']; + $pCounter['blackInk'] = $counter['blackInk']; + $pCounter['coloredInk'] = $counter['coloredInk']; + } + } + + $printer = $em->getRepository('CocarBundle:Printer')->find($id); + + + return array( + "printer" => $printer, + "printerCounter" => $pCounter, + "form" => $this->createCalendarForm($id, new \DateTime(date("Y-m-d", $start)), new \DateTime(date("Y-m-d", $end)))->createView(), + "start" => $start, + "end" => $end + ); + } + + /** + * Creates a form to reports + * + * @param mixed $id The entity id + * + * @return \Symfony\Component\Form\Form The form + */ + private function createCalendarForm($id, $start, $end) + { + return $this->createFormBuilder() + ->add('startDate', 'date', array('widget' => 'single_text', 'data' => $start)) + ->add('endDate', 'date', array('widget' => 'single_text', 'data' => $end)) + ->add('printer', 'hidden', array( + 'data' => $id + )) + ->getForm(); + } + + /** + * @Route("/totalizer/info", name="cocar_totalizer_info") + * @Template() + */ + public function totalizerAction() + { + $em = $this->getDoctrine()->getManager(); + + $printers = $em->getRepository('CocarBundle:Printer')->findAll(); + + foreach($printers as $printer) + { + try + { + $community = $printer->getCommunitySnmpPrinter(); + $host = $printer->getHost(); + + $com = "snmpwalk -O qv -v 1 -c $community $host 1.3.6.1.2.1.43.10.2.1.4.1.1"; + + if($outPut = shell_exec($com)) + { + $this->updateCounter($printer, $outPut); + $this->createOrUpdateGraph($printer, $outPut); + } + } + catch(Exception $e) + { + return new Response($e->getMessage()); + } + } + return new Response(); + } + + /** + * Update table by id + */ + private function updateCounter($printer, $prints) + { + try + { + $em = $this->getDoctrine()->getManager(); + + $counter = new PrinterCounter; + + $counter->setPrinter($printer); + $counter->setPrints($prints); + $counter->setDate(time()); + + $em->persist($counter); + $em->flush(); + } + catch(\Exception $e) + { + return false; + } + return true; + } + + /** + * Update graphic counter by id + */ + private function createOrUpdateGraph($printer, $prints) + { + try + { + $this->dir = $this->get('kernel')->getRootDir() . "/../web/rrd/graficos/"; + + $arqRrd = $this->dir . "printer_" . $printer->getId() . '.rrd'; + + if (!file_exists($arqRrd)) + $this->createRrd($arqRrd); + $this->updateRrd($arqRrd, $prints); + + } + catch(\Exception $e) + { + return false; + } + return true; + } + + public function createRrd($arqRrd) + { + $create = "rrdtool create $arqRrd --step 60 " . + "DS:ds0:COUNTER:120:0:125000000 " . + "DS:ds1:COUNTER:120:0:125000000 " . + "RRA:AVERAGE:0.5:1:4320 " . + "RRA:AVERAGE:0.5:5:2016 " . + "RRA:AVERAGE:0.5:20:2232 " . + "RRA:AVERAGE:0.5:90:2976 " . + "RRA:AVERAGE:0.5:360:1460 " . + "RRA:AVERAGE:0.5:1440:730 " . + "RRA:MAX:0.5:1:4320 " . + "RRA:MAX:0.5:5:2016 " . + "RRA:MAX:0.5:20:2232 " . + "RRA:MAX:0.5:90:2976 " . + "RRA:MAX:0.5:360:1460 " . + "RRA:MAX:0.5:1440:730"; + echo $create;die; + shell_exec($create); + } + + public function updateRrd($arqRrd, $prints, $date = null) + { + $date = empty($date) ? date('U') : $date; + shell_exec("rrdtool update $arqRrd $date:$prints:0"); + } +} diff --git a/Entity/Printer.php b/Entity/Printer.php new file mode 100755 index 0000000..40a68c6 --- /dev/null +++ b/Entity/Printer.php @@ -0,0 +1,200 @@ +printerCounter = new ArrayCollection(); + } + + /** + * Get id + * + * @return integer + */ + public function getId() + { + return $this->id; + } + + /** + * Set name + * + * @param string $name + * @return Printer + */ + public function setName($name) + { + $this->name = $name; + + return $this; + } + + /** + * Get name + * + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Set description + * + * @param string $description + * @return Printer + */ + public function setDescription($description) + { + $this->description = $description; + + return $this; + } + + /** + * Get description + * + * @return string + */ + public function getDescription() + { + return $this->description; + } + + /** + * Set communitySnmpPrinter + * + * @param string $communitySnmpPrinter + * @return Printer + */ + public function setCommunitySnmpPrinter($communitySnmpPrinter) + { + $this->communitySnmpPrinter = $communitySnmpPrinter; + + return $this; + } + + /** + * Get communitySnmpPrinter + * + * @return string + */ + public function getCommunitySnmpPrinter() + { + return $this->communitySnmpPrinter; + } + + /** + * Set host + * + * @param string $host + * @return Printer + */ + public function setHost($host) + { + $this->host = $host; + + return $this; + } + + /** + * Get host + * + * @return string + */ + public function getHost() + { + return $this->host; + } + + /** + * Add printerCounter + * + * @param \Cocar\CocarBundle\Entity\PrinterCounter $printerCounter + * @return Entity + */ + public function addPrinterCounter(\Swpb\Bundle\CocarBundle\Entity\PrinterCounter $printerCounter) + { + $this->printerCounter[] = $printerCounter; + + return $this; + } + + /** + * Remove printerCounter + * + * @param \Cocar\CocarBundle\Entity\PrinterCounter $printerCounter + */ + public function removePrinterCounter(\Swpb\Bundle\CocarBundle\Entity\PrinterCounter $printerCounter) + { + $this->printerCounter->removeElement($printerCounter); + } + + /** + * Get printerCounter + * + * @return \Doctrine\Common\Collections\Collection + */ + public function getPrinterCounter() + { + return $this->printerCounter; + } +} diff --git a/Entity/PrinterCounter.php b/Entity/PrinterCounter.php new file mode 100755 index 0000000..724dda4 --- /dev/null +++ b/Entity/PrinterCounter.php @@ -0,0 +1,189 @@ +printer = 0; + $this->coloredInk = 0; + $this->blackInk = 0; + } + + /** + * Get id + * + * @return integer + */ + public function getId() + { + return $this->id; + } + + /** + * Set blackInk + * + * @param integer $blackInk + * @return PrinterCounter + */ + public function setBlackInk($blackInk) + { + $this->blackInk = $blackInk; + + return $this; + } + + /** + * Get blackInk + * + * @return integer + */ + public function getBlackInk() + { + return $this->blackInk; + } + + /** + * Set coloredInk + * + * @param integer $coloredInk + * @return PrinterCounter + */ + public function setColoredInk($coloredInk) + { + $this->coloredInk = $coloredInk; + + return $this; + } + + /** + * Get coloredInk + * + * @return integer + */ + public function getColoredInk() + { + return $this->coloredInk; + } + + /** + * Set prints + * + * @param integer $prints + * @return PrinterCounter + */ + public function setPrints($prints) + { + $this->prints = $prints; + + return $this; + } + + /** + * Get prints + * + * @return integer + */ + public function getPrints() + { + return $this->prints; + } + + /** + * Set date + * + * @param integer $date + * @return PrinterCounter + */ + public function setDate($date) + { + $this->date = $date; + + return $this; + } + + /** + * Get date + * + * @return integer + */ + public function getDate() + { + return $this->date; + } + + /** + * Set printer + * + * @param \Cocar\CocarBundle\Entity\Printer $printer + * @return Circuits + */ + public function setPrinter(\Swpb\Bundle\CocarBundle\Entity\Printer $printer = null) + { + $this->printer = $printer; + + return $this; + } + + /** + * Get printer + * + * @return \Cocar\CocarBundle\Entity\Printer + */ + public function getPrinter() + { + return $this->printer; + } +} diff --git a/Entity/PrinterCounterRepository.php b/Entity/PrinterCounterRepository.php new file mode 100755 index 0000000..e702e88 --- /dev/null +++ b/Entity/PrinterCounterRepository.php @@ -0,0 +1,15 @@ +add('name') + ->add('description') + ->add('communitySnmpPrinter') + ->add('host') + ; + } + + /** + * @param OptionsResolverInterface $resolver + */ + public function setDefaultOptions(OptionsResolverInterface $resolver) + { + $resolver->setDefaults(array( + 'data_class' => 'Swpb\Bundle\CocarBundle\Entity\Printer' + )); + } + + /** + * @return string + */ + public function getName() + { + return 'swpb_bundle_cocarbundle_printer'; + } +} diff --git a/Resources/public/images/circuitos.png b/Resources/public/images/circuitos.png new file mode 100644 index 0000000..f6f52da Binary files /dev/null and b/Resources/public/images/circuitos.png differ diff --git a/Resources/public/images/entidades.png b/Resources/public/images/entidades.png new file mode 100644 index 0000000..cf6a282 Binary files /dev/null and b/Resources/public/images/entidades.png differ diff --git a/Resources/public/images/help.png b/Resources/public/images/help.png new file mode 100644 index 0000000..e1a4d92 Binary files /dev/null and b/Resources/public/images/help.png differ diff --git a/Resources/public/images/home.png b/Resources/public/images/home.png new file mode 100644 index 0000000..e494996 Binary files /dev/null and b/Resources/public/images/home.png differ diff --git a/Resources/public/images/ico1.png b/Resources/public/images/ico1.png new file mode 100644 index 0000000..9721ea8 Binary files /dev/null and b/Resources/public/images/ico1.png differ diff --git a/Resources/public/images/ico2.png b/Resources/public/images/ico2.png new file mode 100644 index 0000000..6413d7d Binary files /dev/null and b/Resources/public/images/ico2.png differ diff --git a/Resources/public/images/relatorios.png b/Resources/public/images/relatorios.png new file mode 100644 index 0000000..58759b8 Binary files /dev/null and b/Resources/public/images/relatorios.png differ diff --git a/Resources/public/images/table.png b/Resources/public/images/table.png new file mode 100644 index 0000000..1c19cb4 Binary files /dev/null and b/Resources/public/images/table.png differ diff --git a/Resources/views/Printer/edit.html.twig b/Resources/views/Printer/edit.html.twig new file mode 100755 index 0000000..6e3bcb5 --- /dev/null +++ b/Resources/views/Printer/edit.html.twig @@ -0,0 +1,47 @@ +{% extends 'CocarBundle::layout.html.twig' %} + +{% block main -%} +

{{ entity.description }}

+
+
+ +
+ {{ form_errors(edit_form) }} + {{ form_widget(edit_form._token) }} +
+ + {{ form_widget(edit_form.name) }} +
+
+ + {{ form_widget(edit_form.description) }} +
+
+ + {{ form_widget(edit_form.communitySnmpPrinter) }} +
+
+ + {{ form_widget(edit_form.host) }} +
+
+ +
+
+
+
+ +{% endblock %} diff --git a/Resources/views/Printer/index.html.twig b/Resources/views/Printer/index.html.twig new file mode 100755 index 0000000..51177b1 --- /dev/null +++ b/Resources/views/Printer/index.html.twig @@ -0,0 +1,50 @@ +{% extends 'CocarBundle::layout.html.twig' %} + +{% block main -%} +

Impressoras cadastradas

+ + + + + + + + + + + + + + {% for entity in entities %} + + + + + + + + + {% endfor %} + +
IdNameDescriptionCommunityHostActions
{{ entity.id }}{{ entity.name }}{{ entity.description }}{{ entity.communitySnmpPrinter }}{{ entity.host }} + +
+ + + {% endblock %} diff --git a/Resources/views/Printer/new.html.twig b/Resources/views/Printer/new.html.twig new file mode 100755 index 0000000..a425a50 --- /dev/null +++ b/Resources/views/Printer/new.html.twig @@ -0,0 +1,32 @@ +{% extends 'CocarBundle::layout.html.twig' %} + +{% block main -%} +

Cadastro de Impressoras

+
+
+
+ {{ form_errors(form) }} + {{ form_widget(form._token) }} +
+ + {{ form_widget(form.name) }} +
+
+ + {{ form_widget(form.description) }} +
+
+ + {{ form_widget(form.communitySnmpPrinter) }} +
+
+ + {{ form_widget(form.host) }} +
+
+ +
+
+
+
+{% endblock %} diff --git a/Resources/views/Printer/reports.html.twig b/Resources/views/Printer/reports.html.twig new file mode 100644 index 0000000..d5a1261 --- /dev/null +++ b/Resources/views/Printer/reports.html.twig @@ -0,0 +1,35 @@ +{% extends 'CocarBundle::layout.html.twig' %} + +{% block main -%} +

{{ printer.name }}

+

{{ start|date("d/m/Y") }} a {{ end|date("d/m/Y") }}

+
+ +
+ + + + + + + + + + + {% for p in printerCounter %} + + {% endfor %} + + + +
Total de impressõesNível de tinta PretaNível de tinta Colorida
{{ p }}
+{% endblock %} diff --git a/Resources/views/Printer/show.html.twig b/Resources/views/Printer/show.html.twig new file mode 100755 index 0000000..4e49a6a --- /dev/null +++ b/Resources/views/Printer/show.html.twig @@ -0,0 +1,46 @@ +{% extends 'CocarBundle::layout.html.twig' %} + +{% block main -%} +

Impressora

+ + + + + + + + + + + + + + + + + + + + +
IdNameDescriptionCommunityHost
{{ entity.id }}{{ entity.name }}{{ entity.description }}{{ entity.communitySnmpPrinter }}{{ entity.host }}
+ + +{% endblock %} diff --git a/Resources/views/layout.html.twig b/Resources/views/layout.html.twig index fb8ec35..337bc6e 100755 --- a/Resources/views/layout.html.twig +++ b/Resources/views/layout.html.twig @@ -19,6 +19,12 @@
  • + + + Impressoras + +
  • +
  • Circuitos @@ -82,7 +88,7 @@ | - {% image '@CocarBundle/Resources/public/images/home.gif' %} + {% image '@CocarBundle/Resources/public/images/home.png' %} {% endimage %} | diff --git a/Tests/Controller/PrinterControllerTest.php b/Tests/Controller/PrinterControllerTest.php new file mode 100644 index 0000000..f29dbab --- /dev/null +++ b/Tests/Controller/PrinterControllerTest.php @@ -0,0 +1,55 @@ +request('GET', '/printer/'); + $this->assertEquals(200, $client->getResponse()->getStatusCode(), "Unexpected HTTP status code for GET /printer/"); + $crawler = $client->click($crawler->selectLink('Create a new entry')->link()); + + // Fill in the form and submit it + $form = $crawler->selectButton('Create')->form(array( + 'swpb_bundle_cocarbundle_printertype[field_name]' => 'Test', + // ... other fields to fill + )); + + $client->submit($form); + $crawler = $client->followRedirect(); + + // Check data in the show view + $this->assertGreaterThan(0, $crawler->filter('td:contains("Test")')->count(), 'Missing element td:contains("Test")'); + + // Edit the entity + $crawler = $client->click($crawler->selectLink('Edit')->link()); + + $form = $crawler->selectButton('Edit')->form(array( + 'swpb_bundle_cocarbundle_printertype[field_name]' => 'Foo', + // ... other fields to fill + )); + + $client->submit($form); + $crawler = $client->followRedirect(); + + // Check the element contains an attribute with value equals "Foo" + $this->assertGreaterThan(0, $crawler->filter('[value="Foo"]')->count(), 'Missing element [value="Foo"]'); + + // Delete the entity + $client->submit($crawler->selectButton('Delete')->form()); + $crawler = $client->followRedirect(); + + // Check the entity has been delete on the list + $this->assertNotRegExp('/Foo/', $client->getResponse()->getContent()); + } + + */ +} -- libgit2 0.21.2