Fix workzone tests

This commit is contained in:
romain
2012-10-10 09:53:44 +02:00
parent a447df8ad0
commit 1a9a4c263f

View File

@@ -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
}
}