From eca7bd44a5ebe33e375e9d519a01ef5da375e864 Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Sun, 26 Jun 2016 16:11:43 +0200 Subject: [PATCH] Add tests for the dependend objects Ticket #28 --- .../Tests/Controller/EventControllerTest.php | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Hackspace/Bundle/CalciferBundle/Tests/Controller/EventControllerTest.php b/src/Hackspace/Bundle/CalciferBundle/Tests/Controller/EventControllerTest.php index 70fa287..7ed7447 100644 --- a/src/Hackspace/Bundle/CalciferBundle/Tests/Controller/EventControllerTest.php +++ b/src/Hackspace/Bundle/CalciferBundle/Tests/Controller/EventControllerTest.php @@ -2,6 +2,7 @@ namespace Hackspace\Bundle\CalciferBundle\Tests\Controller; +use Doctrine\ORM\Decorator\EntityManagerDecorator; use Doctrine\ORM\EntityRepository; use Hackspace\Bundle\CalciferBundle\Entity\Event; use Liip\FunctionalTestBundle\Test\WebTestCase; @@ -61,13 +62,25 @@ class EventControllerTest extends WebTestCase $this->assertGreaterThan(0,strlen($slug)); + /** @var EntityManagerDecorator $em */ $em = $this->getContainer()->get('doctrine')->getManager(); /** @var EntityRepository $repo */ $repo = $em->getRepository('CalciferBundle:Event'); + $qb = $em->createQueryBuilder(); + $qb->select(array('e')) + ->from('CalciferBundle:Event', 'e') + ->innerJoin('e.tags','t') + ->innerJoin('e.location','l') + ->where('e.slug>= :slug') + ->setParameter('slug', $slug); + $entities = $qb->getQuery()->execute(); + + $this->assertCount(1,$entities); + /** @var Event $entity */ - $entity = $repo->findOneBy(['slug' => $slug]); + $entity = $entities[0]; $this->assertInstanceOf('Hackspace\Bundle\CalciferBundle\Entity\Event', $entity); @@ -77,5 +90,14 @@ class EventControllerTest extends WebTestCase $this->assertTrue($form["url"]->getValue() == $entity->url, "URL equal"); $this->assertTrue($form["description"]->getValue() == $entity->description, "Description equal"); + $tags = explode(",",$form["tags"]->getValue()); + foreach($entity->tags as $tag) { + $this->assertTrue(in_array($tag->name,$tags)); + } + + $this->assertTrue($form["location"]->getValue() == $entity->location->name); + $this->assertTrue($form["location_lat"]->getValue() == $entity->location->lat); + $this->assertTrue($form["location_lon"]->getValue() == $entity->location->lon); + } }