From 1a9a4c263fb8d73c24ed7f82abaae782c33d53a6 Mon Sep 17 00:00:00 2001 From: romain Date: Wed, 10 Oct 2012 09:53:44 +0200 Subject: [PATCH] Fix workzone tests --- .../Phrasea/Controller/Prod/WorkZoneTest.php | 75 ++++++++++++++----- 1 file changed, 58 insertions(+), 17 deletions(-) diff --git a/tests/Alchemy/Phrasea/Controller/Prod/WorkZoneTest.php b/tests/Alchemy/Phrasea/Controller/Prod/WorkZoneTest.php index db52874a5b..e428ef467f 100644 --- a/tests/Alchemy/Phrasea/Controller/Prod/WorkZoneTest.php +++ b/tests/Alchemy/Phrasea/Controller/Prod/WorkZoneTest.php @@ -4,6 +4,7 @@ require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract. class ControllerWorkZoneTest extends \PhraseanetWebTestCaseAuthenticatedAbstract { + protected $client; public function testRootGet() @@ -19,9 +20,8 @@ class ControllerWorkZoneTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $this->assertEquals(200, $response->getStatusCode()); } - public function testAttachStoryToWZ() + public function testAttachStoryToWZBadRequest() { - $story = self::$DI['record_story_1']; /* @var $story \Record_Adapter */ $route = sprintf("/prod/WorkZone/attachStories/"); @@ -30,7 +30,12 @@ class ControllerWorkZoneTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $this->assertEquals(400, $response->getStatusCode()); $this->assertFalse($response->isOk()); + } + public function testAttachStoryToWZ() + { + $story = self::$DI['record_story_1']; + $route = sprintf("/prod/WorkZone/attachStories/"); self::$DI['client']->request('POST', $route, array('stories' => array($story->get_serialize_key()))); $response = self::$DI['client']->getResponse(); @@ -39,13 +44,18 @@ class ControllerWorkZoneTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $em = self::$DI['app']['EM']; /* @var $em \Doctrine\ORM\EntityManager */ $query = $em->createQuery( - 'SELECT COUNT(w.id) FROM \Entities\StoryWZ w' + 'SELECT COUNT(w.id) FROM \Entities\StoryWZ w' ); $count = $query->getSingleScalarResult(); $this->assertEquals(1, $count); + } + public function testAttachMultipleStoriesToWZ() + { + $story = self::$DI['record_story_1']; + $route = sprintf("/prod/WorkZone/attachStories/"); $story2 = self::$DI['record_story_2']; $stories = array($story->get_serialize_key(), $story2->get_serialize_key()); @@ -55,12 +65,10 @@ class ControllerWorkZoneTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $this->assertEquals(302, $response->getStatusCode()); - - $em = self::$DI['app']['EM']; /* @var $em \Doctrine\ORM\EntityManager */ $query = $em->createQuery( - 'SELECT COUNT(w.id) FROM \Entities\StoryWZ w' + 'SELECT COUNT(w.id) FROM \Entities\StoryWZ w' ); $count = $query->getSingleScalarResult(); @@ -68,28 +76,60 @@ class ControllerWorkZoneTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $this->assertEquals(2, $count); $query = $em->createQuery( - 'SELECT w FROM \Entities\StoryWZ w' + 'SELECT w FROM \Entities\StoryWZ w' ); $storyWZ = $query->getResult(); $em->remove(array_shift($storyWZ)); $em->flush(); + } + public function testAttachExistingStory() + { + $story = self::$DI['record_story_1']; + $route = sprintf("/prod/WorkZone/attachStories/"); - //attach JSON - self::$DI['client']->request('POST', $route, array('stories' => array($story->get_serialize_key())), array(), array( - "HTTP_ACCEPT" => "application/json") - ); + $StoryWZ = new \Entities\StoryWZ(); + $StoryWZ->setUser(self::$DI['app']['phraseanet.user']); + $StoryWZ->setRecord($story); + + self::$DI['app']['EM']->persist($StoryWZ); + self::$DI['app']['EM']->flush(); + + self::$DI['client']->request('POST', $route, array('stories' => array($story->get_serialize_key()))); + $response = self::$DI['client']->getResponse(); + + $this->assertEquals(302, $response->getStatusCode()); + + $em = self::$DI['app']['EM']; + /* @var $em \Doctrine\ORM\EntityManager */ + $query = $em->createQuery( + 'SELECT COUNT(w.id) FROM \Entities\StoryWZ w' + ); + + $count = $query->getSingleScalarResult(); + + $this->assertEquals(1, $count); + } + + public function testAttachStoryToWZJson() + { + $story = self::$DI['record_story_1']; + $route = sprintf("/prod/WorkZone/attachStories/"); + //attach JSON + self::$DI['client']->request('POST', $route, array('stories' => array($story->get_serialize_key())), array(), array( + "HTTP_ACCEPT" => "application/json") + ); $response = self::$DI['client']->getResponse(); $this->assertEquals(200, $response->getStatusCode()); - //test already attached - self::$DI['client']->request('POST', $route, array('stories' => array($story->get_serialize_key())), array(), array( - "HTTP_ACCEPT" => "application/json") - ); + //test already attached + self::$DI['client']->request('POST', $route, array('stories' => array($story->get_serialize_key())), array(), array( + "HTTP_ACCEPT" => "application/json") + ); $response = self::$DI['client']->getResponse(); @@ -114,7 +154,7 @@ class ControllerWorkZoneTest extends \PhraseanetWebTestCaseAuthenticatedAbstract self::$DI['client']->request('POST', $attachRoute, array('stories' => array($story->get_serialize_key()))); $query = self::$DI['app']['EM']->createQuery( - 'SELECT COUNT(w.id) FROM \Entities\StoryWZ w' + 'SELECT COUNT(w.id) FROM \Entities\StoryWZ w' ); $count = $query->getSingleScalarResult(); @@ -128,7 +168,7 @@ class ControllerWorkZoneTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $this->assertEquals(302, $response->getStatusCode()); $query = self::$DI['app']['EM']->createQuery( - 'SELECT COUNT(w.id) FROM \Entities\StoryWZ w' + 'SELECT COUNT(w.id) FROM \Entities\StoryWZ w' ); $count = $query->getSingleScalarResult(); @@ -175,4 +215,5 @@ class ControllerWorkZoneTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $route = sprintf("/prod/WorkZone/detachStory/%s/%s/", $story->get_sbas_id(), 'unknow'); //story not yet Attched } + }