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();
@@ -45,7 +50,12 @@ class ControllerWorkZoneTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$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,8 +65,6 @@ class ControllerWorkZoneTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->assertEquals(302, $response->getStatusCode());
$em = self::$DI['app']['EM'];
/* @var $em \Doctrine\ORM\EntityManager */
$query = $em->createQuery(
@@ -75,8 +83,40 @@ class ControllerWorkZoneTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$em->remove(array_shift($storyWZ));
$em->flush();
}
public function testAttachExistingStory()
{
$story = self::$DI['record_story_1'];
$route = sprintf("/prod/WorkZone/attachStories/");
$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")
@@ -175,4 +215,5 @@ class ControllerWorkZoneTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$route = sprintf("/prod/WorkZone/detachStory/%s/%s/", $story->get_sbas_id(), 'unknow');
//story not yet Attched
}
}