From 9a7c326d6c50ac5cddf564fe75f0c2a55227389d Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Mon, 19 Dec 2011 19:07:53 +0100 Subject: [PATCH 01/10] added request --- lib/Alchemy/Phrasea/Controller/Prod/Basket.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Basket.php b/lib/Alchemy/Phrasea/Controller/Prod/Basket.php index d0620af44d..99c643aba4 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Basket.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Basket.php @@ -68,7 +68,7 @@ class Basket implements ControllerProviderInterface } }); - $controllers->post('/{basket_id}/delete/', function(Application $app, $basket_id) use ($basket_controller) + $controllers->post('/{basket_id}/delete/', function(Application $app, Request $request, $basket_id) use ($basket_controller) { $basket = $basket_controller->getUserBasket($app['Core'], $basket_id); @@ -97,13 +97,13 @@ class Basket implements ControllerProviderInterface - $controllers->post('/{basket_id}/update/', function(Application $app, $basket_id) use ($basket_controller) + $controllers->post('/{basket_id}/update/', function(Application $app, Request $request, $basket_id) use ($basket_controller) { $basket = $basket_controller->getUserBasket($app['Core'], $basket_id); $basket->setName($request->get('name')); $basket->setDescription($request->get('description')); - + $em = $app['Core']->getEntityManager(); $em->merge($basket); @@ -144,7 +144,7 @@ class Basket implements ControllerProviderInterface }); - $controllers->post('/{basket_id}/archive/', function(Application $app, $basket_id) use ($basket_controller) + $controllers->post('/{basket_id}/archive/', function(Application $app, Request $request, $basket_id) use ($basket_controller) { $basket = $basket_controller->getUserBasket($app['Core'], $basket_id); @@ -173,11 +173,9 @@ class Basket implements ControllerProviderInterface } }); - $controllers->post('/{basket_id}/addElements/', function(Application $app, $basket_id) use ($basket_controller) + $controllers->post('/{basket_id}/addElements/', function(Application $app, Request $request, $basket_id) use ($basket_controller) { - $request = $app['request']; - $basket = $basket_controller->getUserBasket($app['Core'], $basket_id); $user = $app['Core']->getAuthenticatedUser(); From d4367e09447ffa7d91e044fc128adf1a8a29f68f Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Mon, 19 Dec 2011 19:08:20 +0100 Subject: [PATCH 02/10] test --- .../{Basket => }/AbstractUser.php | 2 +- lib/conf.d/PhraseaFixture/Basket/Root.php | 11 +- lib/unitTest/basketTest.php | 253 ++++++++++++++++-- lib/vendor/symfony | 2 +- 4 files changed, 233 insertions(+), 35 deletions(-) rename lib/conf.d/PhraseaFixture/{Basket => }/AbstractUser.php (93%) diff --git a/lib/conf.d/PhraseaFixture/Basket/AbstractUser.php b/lib/conf.d/PhraseaFixture/AbstractUser.php similarity index 93% rename from lib/conf.d/PhraseaFixture/Basket/AbstractUser.php rename to lib/conf.d/PhraseaFixture/AbstractUser.php index 64fa80a3bb..d0b4ee9453 100644 --- a/lib/conf.d/PhraseaFixture/Basket/AbstractUser.php +++ b/lib/conf.d/PhraseaFixture/AbstractUser.php @@ -16,7 +16,7 @@ * @link www.phraseanet.com */ -namespace PhraseaFixture\Basket; +namespace PhraseaFixture; class AbstractUser { diff --git a/lib/conf.d/PhraseaFixture/Basket/Root.php b/lib/conf.d/PhraseaFixture/Basket/Root.php index e065f3ea55..67c3c5eef3 100644 --- a/lib/conf.d/PhraseaFixture/Basket/Root.php +++ b/lib/conf.d/PhraseaFixture/Basket/Root.php @@ -21,10 +21,13 @@ use Doctrine\Common\DataFixtures\FixtureInterface; * @license http://opensource.org/licenses/gpl-3.0 GPLv3 * @link www.phraseanet.com */ -class Root extends AbstractUser implements FixtureInterface +class Root extends \PhraseaFixture\AbstractUser implements FixtureInterface { - - public $basketId; + /** + * + * @var \Entities\Basket + */ + public $basket; public function load($manager) { @@ -34,7 +37,7 @@ class Root extends AbstractUser implements FixtureInterface $basket->setOwner($this->user); $manager->persist($basket); $manager->flush(); - $this->basketId = $basket->getId(); + $this->basket = $basket; } } \ No newline at end of file diff --git a/lib/unitTest/basketTest.php b/lib/unitTest/basketTest.php index 2b1bec474f..f6b5884a01 100644 --- a/lib/unitTest/basketTest.php +++ b/lib/unitTest/basketTest.php @@ -35,11 +35,6 @@ class basketTest extends PhraseanetWebTestCaseAuthenticatedAbstract $this->loader = new Loader(); } - public static function setUpBeforeClass() - { - parent::setUpBeforeClass(); - } - public function createApplication() { return require __DIR__ . '/../Alchemy/Phrasea/Application/Prod.php'; @@ -48,57 +43,257 @@ class basketTest extends PhraseanetWebTestCaseAuthenticatedAbstract public function testRootPost() { $route = '/baskets/'; - + $this->client->request('POST', $route, array('name' => 'panier', 'desc' => 'mon beau panier')); - + $response = $this->client->getResponse(); - + $query = self::$core->getEntityManager()->createQuery( 'SELECT COUNT(b.id) FROM \Entities\Basket b' ); - + $count = $query->getSingleScalarResult(); $this->assertEquals(1, $count); - + $this->assertEquals(302, $response->getStatusCode()); } public function testCreateGet() { $route = '/baskets/create/'; - + $crawler = $this->client->request('GET', $route); - + $response = $this->client->getResponse(); - + $this->assertEquals(200, $response->getStatusCode()); - + $this->assertEquals($crawler->filter("form[action='/prod/baskets/']")->count(), 1); $this->assertEquals($crawler->filter("form[action='/prod/baskets/'] input[name='name']")->count(), 1); $this->assertEquals($crawler->filter("form[action='/prod/baskets/'] textarea[name='description']")->count(), 1); - - -// $form = $crawler->selectButton(_('boutton::valider'))->form(); -// $crawler = $this->client->submit($form, array('name' => 'Hey you!', 'description' => 'Hey there!')); - } - + public function testBasketGet() { - $basketFixture = new MyFixture\Root(self::$user); - - $this->loader->addFixture($basketFixture); - - $this->insertFixtureInDatabase($this->loader); - - $route = sprintf('/baskets/%s/', $basketFixture->basketId); - + $basket = $this->insertOneBasket(); + + $route = sprintf('/baskets/%s/', $basket->getId()); + $crawler = $this->client->request('GET', $route); + + $response = $this->client->getResponse(); + + $this->assertEquals(200, $response->getStatusCode()); + } + + public function testBasketDeletePost() + { + $basket = $this->insertOneBasket(); + + $route = sprintf('/baskets/%s/delete/', $basket->getId()); + + $crawler = $this->client->request('POST', $route); + + $response = $this->client->getResponse(); + + $query = self::$core->getEntityManager()->createQuery( + 'SELECT COUNT(b.id) FROM \Entities\Basket b' + ); + + $count = $query->getSingleScalarResult(); + + $this->assertEquals(0, $count); + + $this->assertEquals(302, $response->getStatusCode()); + } + + public function testBasketDeletePostJSON() + { + $basket = $this->insertOneBasket(); + + $route = sprintf('/baskets/%s/delete/', $basket->getId()); + + $crawler = $this->client->request('POST', $route, array(), array(), array("HTTP_ACCEPT" => "application/json")); + + $this->client->getRequest()->setRequestFormat('json'); + + $response = $this->client->getResponse(); + + $query = self::$core->getEntityManager()->createQuery( + 'SELECT COUNT(b.id) FROM \Entities\Basket b' + ); + + $count = $query->getSingleScalarResult(); + + $this->assertEquals(0, $count); + + $this->assertEquals(200, $response->getStatusCode()); + } + + public function testBasketUpdatePost() + { + $basket = $this->insertOneBasket(); + + $route = sprintf('/baskets/%s/update/', $basket->getId()); + + $crawler = $this->client->request('POST', $route, array('name' => 'new_name', 'description' => 'new_desc')); + + $response = $this->client->getResponse(); + + $em = self::$core->getEntityManager(); + /* @var $em \Doctrine\ORM\EntityManager */ + $basket = $em->getRepository('Entities\Basket')->find($basket->getId()); + + $this->assertEquals('new_name', $basket->getName()); + $this->assertEquals('new_desc', $basket->getDescription()); + + $this->assertEquals(302, $response->getStatusCode()); + } + + public function testBasketUpdatePostJSON() + { + $basket = $this->insertOneBasket(); + + $route = sprintf('/baskets/%s/update/', $basket->getId()); + + $crawler = $this->client->request('POST', $route, array('name' => 'new_name', 'description' => 'new_desc'), array(), array("HTTP_ACCEPT" => "application/json")); + + $response = $this->client->getResponse(); + + $em = self::$core->getEntityManager(); + /* @var $em \Doctrine\ORM\EntityManager */ + $basket = $em->getRepository('Entities\Basket')->find($basket->getId()); + + $this->assertEquals('new_name', $basket->getName()); + $this->assertEquals('new_desc', $basket->getDescription()); + + $this->assertEquals(200, $response->getStatusCode()); + } + + public function testBasketUpdateGet() + { + $basket = $this->insertOneBasket(); + + $route = sprintf('/baskets/%s/update/', $basket->getId()); + + $crawler = $this->client->request('GET', $route, array('name' => 'new_name', 'description' => 'new_desc')); + + $response = $this->client->getResponse(); + + $this->assertEquals(200, $response->getStatusCode()); + + $this->assertEquals($crawler->filter("form[action='/prod/baskets/" . $basket->getId() . "/update/']")->count(), 1); + + $node = $crawler + ->filter('input[name=name]'); + + $this->assertEquals($basket->getName(), $node->attr('value')); + + $node = $crawler + ->filter('textarea[name=description]'); + + $this->assertEquals($basket->getDescription(), $node->text()); + } + + public function testBasketArchivedPost() + { + $basket = $this->insertOneBasket(); + + $route = sprintf('/baskets/%s/archive/', $basket->getId()); + + $crawler = $this->client->request('POST', $route, array('archive' => '1')); + + $response = $this->client->getResponse(); + + $em = self::$core->getEntityManager(); + /* @var $em \Doctrine\ORM\EntityManager */ + $basket = $em->getRepository('Entities\Basket')->find($basket->getId()); + + $this->assertTrue($basket->getArchived()); + + $crawler = $this->client->request('POST', $route, array('archive' => '0')); + + $response = $this->client->getResponse(); + + $em = self::$core->getEntityManager(); + /* @var $em \Doctrine\ORM\EntityManager */ + $basket = $em->getRepository('Entities\Basket')->find($basket->getId()); + + $this->assertFalse($basket->getArchived()); + + $this->assertEquals(302, $response->getStatusCode()); + } + + public function testBasketArchivedPostJSON() + { + $basket = $this->insertOneBasket(); + + $route = sprintf('/baskets/%s/archive/', $basket->getId()); + + $crawler = $this->client->request('POST', $route, array('archive' => '1'), array(), array("HTTP_ACCEPT" => "application/json")); + + $response = $this->client->getResponse(); + + $em = self::$core->getEntityManager(); + /* @var $em \Doctrine\ORM\EntityManager */ + $basket = $em->getRepository('Entities\Basket')->find($basket->getId()); + + $this->assertTrue($basket->getArchived()); + + $crawler = $this->client->request('POST', $route, array('archive' => '0'), array(), array("HTTP_ACCEPT" => "application/json")); + + $response = $this->client->getResponse(); + + $em = self::$core->getEntityManager(); + /* @var $em \Doctrine\ORM\EntityManager */ + $basket = $em->getRepository('Entities\Basket')->find($basket->getId()); + + $this->assertFalse($basket->getArchived()); + + $this->assertEquals(200, $response->getStatusCode()); + } + + public function testAddElementPost() + { + $basket = $this->insertOneBasket(); + + $route = sprintf('/baskets/%s/addElements/', $basket->getId()); + + $records = array(self::$record_1->get_serialize_key(), self::$record_2->get_serialize_key()); + $lst = implode(';', $records); + + $crawler = $this->client->request('POST', $route, array('lst' => $lst), array(), array("HTTP_ACCEPT" => "application/json")); + $response = $this->client->getResponse(); - $this->assertEquals(200, $response->getStatusCode()); + $this->assertEquals(302, $response->getStatusCode()); + $basket->getElements(); } + + /** + * + * @return \Entities\Basket + */ + protected function insertOneBasket() + { + $basketFixture = new MyFixture\Root(self::$user); + + $this->loader->addFixture($basketFixture); + + $this->insertFixtureInDatabase($this->loader); + + $query = self::$core->getEntityManager()->createQuery( + 'SELECT COUNT(b.id) FROM \Entities\Basket b' + ); + + $count = $query->getSingleScalarResult(); + + $this->assertEquals(1, $count); + + return $basketFixture->basket; + } + } \ No newline at end of file diff --git a/lib/vendor/symfony b/lib/vendor/symfony index 4316595dbb..6924e63587 160000 --- a/lib/vendor/symfony +++ b/lib/vendor/symfony @@ -1 +1 @@ -Subproject commit 4316595dbb7be9dcf2156d090d52f23f11b1ea90 +Subproject commit 6924e63587466c865ca8dc746ff3fcf5cd1a1dcf From 157ce3a586f44c831e520fcfb893c4528807caf2 Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Tue, 20 Dec 2011 13:29:12 +0100 Subject: [PATCH 03/10] rename fixtures --- .../{AbstractUser.php => AbstractWZ.php} | 32 +++++++++++++++---- .../Basket/{Root.php => LoadOneBasket.php} | 17 ++++++++-- 2 files changed, 40 insertions(+), 9 deletions(-) rename lib/conf.d/PhraseaFixture/{AbstractUser.php => AbstractWZ.php} (51%) rename lib/conf.d/PhraseaFixture/Basket/{Root.php => LoadOneBasket.php} (74%) diff --git a/lib/conf.d/PhraseaFixture/AbstractUser.php b/lib/conf.d/PhraseaFixture/AbstractWZ.php similarity index 51% rename from lib/conf.d/PhraseaFixture/AbstractUser.php rename to lib/conf.d/PhraseaFixture/AbstractWZ.php index d0b4ee9453..bdd5c09863 100644 --- a/lib/conf.d/PhraseaFixture/AbstractUser.php +++ b/lib/conf.d/PhraseaFixture/AbstractWZ.php @@ -9,22 +9,42 @@ * file that was distributed with this source code. */ +namespace PhraseaFixture; + +use Doctrine\Common\DataFixtures\AbstractFixture; + /** * * @package * @license http://opensource.org/licenses/gpl-3.0 GPLv3 * @link www.phraseanet.com */ - -namespace PhraseaFixture; - -class AbstractUser +abstract class AbstractWZ extends AbstractFixture { protected $user; - public function __construct(\User_Adapter $user) + protected $record; + + + public function getUser() + { + return $this->user; + } + + public function setUser(\User_Adapter $user) { $this->user = $user; } - + + + public function getRecord() + { + return $this->record; + } + + public function setRecord(\record_adapter $record) + { + $this->record = $record; + } + } \ No newline at end of file diff --git a/lib/conf.d/PhraseaFixture/Basket/Root.php b/lib/conf.d/PhraseaFixture/Basket/LoadOneBasket.php similarity index 74% rename from lib/conf.d/PhraseaFixture/Basket/Root.php rename to lib/conf.d/PhraseaFixture/Basket/LoadOneBasket.php index 67c3c5eef3..6f6ebb91af 100644 --- a/lib/conf.d/PhraseaFixture/Basket/Root.php +++ b/lib/conf.d/PhraseaFixture/Basket/LoadOneBasket.php @@ -11,7 +11,6 @@ namespace PhraseaFixture\Basket; - use Doctrine\ORM\EntityManager; use Doctrine\Common\DataFixtures\FixtureInterface; @@ -21,23 +20,35 @@ use Doctrine\Common\DataFixtures\FixtureInterface; * @license http://opensource.org/licenses/gpl-3.0 GPLv3 * @link www.phraseanet.com */ -class Root extends \PhraseaFixture\AbstractUser implements FixtureInterface +class LoadOneBasket extends \PhraseaFixture\AbstractWZ implements FixtureInterface { + /** * * @var \Entities\Basket */ public $basket; - + public function load($manager) { $basket = new \Entities\Basket(); + $basket->setName('test'); $basket->setDescription('description'); + + if (null === $this->user) + { + throw new \LogicException('Fill a user to store a new basket'); + } + $basket->setOwner($this->user); + $manager->persist($basket); $manager->flush(); + $this->basket = $basket; + + $this->addReference('one-basket', $basket); } } \ No newline at end of file From bade38c5e8e04a3e1f5c7cbc69fa34b19e544bae Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Tue, 20 Dec 2011 13:32:16 +0100 Subject: [PATCH 04/10] add new fxtures --- .../PhraseaFixture/Story/LoadOneStory.php | 57 ++++++++++++++++ .../LoadOneParticipant.php | 54 +++++++++++++++ .../LoadParticipantWithSession.php | 66 +++++++++++++++++++ .../LoadOneValidationSession.php | 61 +++++++++++++++++ 4 files changed, 238 insertions(+) create mode 100644 lib/conf.d/PhraseaFixture/Story/LoadOneStory.php create mode 100644 lib/conf.d/PhraseaFixture/ValidationParticipant/LoadOneParticipant.php create mode 100644 lib/conf.d/PhraseaFixture/ValidationParticipant/LoadParticipantWithSession.php create mode 100644 lib/conf.d/PhraseaFixture/ValidationSession/LoadOneValidationSession.php diff --git a/lib/conf.d/PhraseaFixture/Story/LoadOneStory.php b/lib/conf.d/PhraseaFixture/Story/LoadOneStory.php new file mode 100644 index 0000000000..c24f7956fe --- /dev/null +++ b/lib/conf.d/PhraseaFixture/Story/LoadOneStory.php @@ -0,0 +1,57 @@ +record) + { + throw new \LogicException('Fill a record to store a new story'); + } + + if (null === $this->user) + { + throw new \LogicException('Fill a user to store a new story'); + } + + $story->setRecord($this->record); + $story->setUser($this->user); + + $manager->persist($story); + $manager->flush(); + + $this->story = $story; + + $this->addReference('one-story', $story); + } + +} \ No newline at end of file diff --git a/lib/conf.d/PhraseaFixture/ValidationParticipant/LoadOneParticipant.php b/lib/conf.d/PhraseaFixture/ValidationParticipant/LoadOneParticipant.php new file mode 100644 index 0000000000..b9c9f6af18 --- /dev/null +++ b/lib/conf.d/PhraseaFixture/ValidationParticipant/LoadOneParticipant.php @@ -0,0 +1,54 @@ +user) + { + throw new \LogicException('Fill a user to store a new validation Session'); + } + $validationParticipant->setParticipant($this->user); + + $validationParticipant->setSession( + $this->getReference('one-validation-session') + ); + + $manager->persist($validationParticipant); + $manager->flush(); + + $this->validationParticipant = $validationParticipant; + + $this->addReference('one-validation-participant', $validationParticipant); + } + +} \ No newline at end of file diff --git a/lib/conf.d/PhraseaFixture/ValidationParticipant/LoadParticipantWithSession.php b/lib/conf.d/PhraseaFixture/ValidationParticipant/LoadParticipantWithSession.php new file mode 100644 index 0000000000..13a11a0078 --- /dev/null +++ b/lib/conf.d/PhraseaFixture/ValidationParticipant/LoadParticipantWithSession.php @@ -0,0 +1,66 @@ +user) + { + throw new \LogicException('Fill a user to store a new validation Session'); + } + $validationParticipant->setParticipant($this->user); + + if (null === $this->session) + { + throw new \LogicException('Attach a session to the current participant'); + } + $validationParticipant->setSession($this->session); + + $manager->persist($validationParticipant); + $manager->flush(); + + $this->validationParticipant = $validationParticipant; + } + + public function setSession(\Entities\ValidationSession $session) + { + $this->session = $session; + } + + +} \ No newline at end of file diff --git a/lib/conf.d/PhraseaFixture/ValidationSession/LoadOneValidationSession.php b/lib/conf.d/PhraseaFixture/ValidationSession/LoadOneValidationSession.php new file mode 100644 index 0000000000..5bfdc21d44 --- /dev/null +++ b/lib/conf.d/PhraseaFixture/ValidationSession/LoadOneValidationSession.php @@ -0,0 +1,61 @@ +setBasket( + $this->getReference('one-basket') // load the one-basket stored reference + ); + + $validationSession->setDescription('Une description au hasard'); + $validationSession->setName('Un nom de validation'); + + $expires = new \DateTime(); + $expires->modify('+1 week'); + $validationSession->setExpires($expires); + + if (null === $this->user) + { + throw new \LogicException('Fill a user to store a new validation Session'); + } + $validationSession->setInitiator($this->user); + + $manager->persist($validationSession); + $manager->flush(); + + $this->validationSession = $validationSession; + + $this->addReference('one-validation-session', $validationSession); + } + +} \ No newline at end of file From 2942472b619b60e76256c75d7b9d94bf5c6430a3 Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Tue, 20 Dec 2011 13:32:52 +0100 Subject: [PATCH 05/10] add workzone tests --- lib/unitTest/WorkZoneTest.php | 96 +++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 lib/unitTest/WorkZoneTest.php diff --git a/lib/unitTest/WorkZoneTest.php b/lib/unitTest/WorkZoneTest.php new file mode 100644 index 0000000000..d267d38e11 --- /dev/null +++ b/lib/unitTest/WorkZoneTest.php @@ -0,0 +1,96 @@ +client = $this->createClient(); + } + + public function createApplication() + { + return require __DIR__ . '/../Alchemy/Phrasea/Application/Prod.php'; + } + + public function testRootGet() + { + + $this->loadOneWZ(); + + $route = "/WorkZone/"; + + $this->client->request('GET', $route); + + $response = $this->client->getResponse(); + + $this->assertEquals(200, $response->getStatusCode()); + } + + protected function loadOneWZ() + { + try + { + $currentUser = self::$user; + $altUser = self::$user_alt1; + //add one basket + $basket = new PhraseaFixture\Basket\LoadOneBasket(); + $basket->setUser($currentUser); + //add one story + $story = new PhraseaFixture\Story\LoadOneStory(); + $story->setUser($currentUser); + $story->setRecord(self::$record_1); + //add a validation session initiated by alt user + $validationSession = new PhraseaFixture\ValidationSession\LoadOneValidationSession(); + $validationSession->setUser($altUser); + + $loader = new Loader(); + $loader->addFixture($basket); + $loader->addFixture($story); + $loader->addFixture($validationSession); + + $this->insertFixtureInDatabase($loader); + + //add current user as participant + $validationParticipant = new PhraseaFixture\ValidationParticipant\LoadParticipantWithSession(); + $validationParticipant->setSession($validationSession->validationSession); + $validationParticipant->setUser($currentUser); + + $loader = new Loader(); + $loader->addFixture($validationParticipant); + $this->insertFixtureInDatabase($loader); + } + catch (\Exception $e) + { + $this->fail($e->getMessage()); + } + + return; + } + +} \ No newline at end of file From fadc0200f240fb344dcad3e0ed1bf49fc9f4ef0a Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Tue, 20 Dec 2011 13:35:15 +0100 Subject: [PATCH 06/10] enhance basket tests --- lib/unitTest/basketTest.php | 223 ++++++++++++++++++++++++++++++++---- 1 file changed, 203 insertions(+), 20 deletions(-) diff --git a/lib/unitTest/basketTest.php b/lib/unitTest/basketTest.php index f6b5884a01..e9941dab2c 100644 --- a/lib/unitTest/basketTest.php +++ b/lib/unitTest/basketTest.php @@ -27,6 +27,7 @@ class basketTest extends PhraseanetWebTestCaseAuthenticatedAbstract protected $client; protected $loader; + protected static $need_records = 2; public function setUp() { @@ -44,7 +45,11 @@ class basketTest extends PhraseanetWebTestCaseAuthenticatedAbstract { $route = '/baskets/'; - $this->client->request('POST', $route, array('name' => 'panier', 'desc' => 'mon beau panier')); + $this->client->request( + 'POST', $route, array( + 'name' => 'panier', + 'desc' => 'mon beau panier') + ); $response = $this->client->getResponse(); @@ -59,6 +64,32 @@ class basketTest extends PhraseanetWebTestCaseAuthenticatedAbstract $this->assertEquals(302, $response->getStatusCode()); } + public function testRootPostJSON() + { + $route = '/baskets/'; + + $this->client->request( + 'POST', $route, array( + 'name' => 'panier', + 'desc' => 'mon beau panier') + , array(), array( + "HTTP_ACCEPT" => "application/json" + ) + ); + + $response = $this->client->getResponse(); + + $query = self::$core->getEntityManager()->createQuery( + 'SELECT COUNT(b.id) FROM \Entities\Basket b' + ); + + $count = $query->getSingleScalarResult(); + + $this->assertEquals(1, $count); + + $this->assertEquals(200, $response->getStatusCode()); + } + public function testCreateGet() { $route = '/baskets/create/'; @@ -69,9 +100,14 @@ class basketTest extends PhraseanetWebTestCaseAuthenticatedAbstract $this->assertEquals(200, $response->getStatusCode()); - $this->assertEquals($crawler->filter("form[action='/prod/baskets/']")->count(), 1); - $this->assertEquals($crawler->filter("form[action='/prod/baskets/'] input[name='name']")->count(), 1); - $this->assertEquals($crawler->filter("form[action='/prod/baskets/'] textarea[name='description']")->count(), 1); + $filter = "form[action='/prod/baskets/']"; + $this->assertEquals(1, $crawler->filter($filter)->count()); + + $filter = "form[action='/prod/baskets/'] input[name='name']"; + $this->assertEquals(1, $crawler->filter($filter)->count()); + + $filter = "form[action='/prod/baskets/'] textarea[name='description']"; + $this->assertEquals(1, $crawler->filter($filter)->count()); } public function testBasketGet() @@ -87,6 +123,82 @@ class basketTest extends PhraseanetWebTestCaseAuthenticatedAbstract $this->assertEquals(200, $response->getStatusCode()); } + public function testBasketDeleteElementPost() + { + /* @var $em \Doctrine\ORM\EntityManager */ + $em = self::$core->getEntityManager(); + + $basket = $this->insertOneBasket(); + + $record = self::$record_1; + + $basket_element = new \Entities\BasketElement(); + $basket_element->setBasket($basket); + $basket_element->setRecord($record); + $basket_element->setLastInBasket(); + + $basket->addBasketElement($basket_element); + + $em->persist($basket); + + $em->flush(); + + $route = sprintf( + "/baskets/%s/%s/delete/", $basket->getId(), $basket_element->getId() + ); + + $crawler = $this->client->request('POST', $route); + + $response = $this->client->getResponse(); + + $em = self::$core->getEntityManager(); + /* @var $em \Doctrine\ORM\EntityManager */ + + $em->refresh($basket); + + $this->assertEquals(302, $response->getStatusCode()); + + $this->assertEquals(0, $basket->getElements()->count()); + } + + public function testBasketDeleteElementPostJSON() + { + /* @var $em \Doctrine\ORM\EntityManager */ + $em = self::$core->getEntityManager(); + + $basket = $this->insertOneBasket(); + + $record = self::$record_1; + + $basket_element = new \Entities\BasketElement(); + $basket_element->setBasket($basket); + $basket_element->setRecord($record); + $basket_element->setLastInBasket(); + + $basket->addBasketElement($basket_element); + + $em->persist($basket); + + $em->flush(); + + $route = sprintf( + "/baskets/%s/%s/delete/", $basket->getId(), $basket_element->getId() + ); + + $crawler = $this->client->request( + 'POST', $route, array(), array(), array( + "HTTP_ACCEPT" => "application/json") + ); + + $response = $this->client->getResponse(); + + $em->refresh($basket); + + $this->assertEquals(200, $response->getStatusCode()); + + $this->assertEquals(0, $basket->getElements()->count()); + } + public function testBasketDeletePost() { $basket = $this->insertOneBasket(); @@ -114,7 +226,10 @@ class basketTest extends PhraseanetWebTestCaseAuthenticatedAbstract $route = sprintf('/baskets/%s/delete/', $basket->getId()); - $crawler = $this->client->request('POST', $route, array(), array(), array("HTTP_ACCEPT" => "application/json")); + $crawler = $this->client->request( + 'POST', $route, array(), array(), array( + "HTTP_ACCEPT" => "application/json") + ); $this->client->getRequest()->setRequestFormat('json'); @@ -137,7 +252,11 @@ class basketTest extends PhraseanetWebTestCaseAuthenticatedAbstract $route = sprintf('/baskets/%s/update/', $basket->getId()); - $crawler = $this->client->request('POST', $route, array('name' => 'new_name', 'description' => 'new_desc')); + $crawler = $this->client->request( + 'POST', $route, array( + 'name' => 'new_name', + 'description' => 'new_desc') + ); $response = $this->client->getResponse(); @@ -157,7 +276,13 @@ class basketTest extends PhraseanetWebTestCaseAuthenticatedAbstract $route = sprintf('/baskets/%s/update/', $basket->getId()); - $crawler = $this->client->request('POST', $route, array('name' => 'new_name', 'description' => 'new_desc'), array(), array("HTTP_ACCEPT" => "application/json")); + $crawler = $this->client->request( + 'POST', $route, array( + 'name' => 'new_name', + 'description' => 'new_desc' + ), array(), array( + "HTTP_ACCEPT" => "application/json") + ); $response = $this->client->getResponse(); @@ -177,13 +302,18 @@ class basketTest extends PhraseanetWebTestCaseAuthenticatedAbstract $route = sprintf('/baskets/%s/update/', $basket->getId()); - $crawler = $this->client->request('GET', $route, array('name' => 'new_name', 'description' => 'new_desc')); + $crawler = $this->client->request( + 'GET', $route, array( + 'name' => 'new_name', + 'description' => 'new_desc') + ); $response = $this->client->getResponse(); $this->assertEquals(200, $response->getStatusCode()); - $this->assertEquals($crawler->filter("form[action='/prod/baskets/" . $basket->getId() . "/update/']")->count(), 1); + $filter = "form[action='/prod/baskets/" . $basket->getId() . "/update/']"; + $this->assertEquals($crawler->filter($filter)->count(), 1); $node = $crawler ->filter('input[name=name]'); @@ -231,7 +361,13 @@ class basketTest extends PhraseanetWebTestCaseAuthenticatedAbstract $route = sprintf('/baskets/%s/archive/', $basket->getId()); - $crawler = $this->client->request('POST', $route, array('archive' => '1'), array(), array("HTTP_ACCEPT" => "application/json")); + $crawler = $this->client->request( + 'POST', $route, array( + 'archive' => '1' + ), array(), array( + "HTTP_ACCEPT" => "application/json" + ) + ); $response = $this->client->getResponse(); @@ -241,7 +377,13 @@ class basketTest extends PhraseanetWebTestCaseAuthenticatedAbstract $this->assertTrue($basket->getArchived()); - $crawler = $this->client->request('POST', $route, array('archive' => '0'), array(), array("HTTP_ACCEPT" => "application/json")); + $crawler = $this->client->request( + 'POST', $route, array( + 'archive' => '0' + ), array(), array( + "HTTP_ACCEPT" => "application/json" + ) + ); $response = $this->client->getResponse(); @@ -253,24 +395,63 @@ class basketTest extends PhraseanetWebTestCaseAuthenticatedAbstract $this->assertEquals(200, $response->getStatusCode()); } - + public function testAddElementPost() { $basket = $this->insertOneBasket(); $route = sprintf('/baskets/%s/addElements/', $basket->getId()); - $records = array(self::$record_1->get_serialize_key(), self::$record_2->get_serialize_key()); - + $records = array( + self::$record_1->get_serialize_key(), + self::$record_2->get_serialize_key() + ); + $lst = implode(';', $records); - - $crawler = $this->client->request('POST', $route, array('lst' => $lst), array(), array("HTTP_ACCEPT" => "application/json")); + + $crawler = $this->client->request('POST', $route, array('lst' => $lst)); $response = $this->client->getResponse(); - + $this->assertEquals(302, $response->getStatusCode()); - - $basket->getElements(); + + $em = self::$core->getEntityManager(); + /* @var $em \Doctrine\ORM\EntityManager */ + $basket = $em->getRepository('Entities\Basket')->find($basket->getId()); + + $this->assertEquals(2, $basket->getElements()->count()); + } + + public function testAddElementPostJSON() + { + $basket = $this->insertOneBasket(); + + $route = sprintf('/baskets/%s/addElements/', $basket->getId()); + + $records = array( + self::$record_1->get_serialize_key(), + self::$record_2->get_serialize_key() + ); + + $lst = implode(';', $records); + + $crawler = $this->client->request( + 'POST', $route, array( + 'lst' => $lst + ), array(), array( + "HTTP_ACCEPT" => "application/json" + ) + ); + + $response = $this->client->getResponse(); + + $em = self::$core->getEntityManager(); + /* @var $em \Doctrine\ORM\EntityManager */ + $basket = $em->getRepository('Entities\Basket')->find($basket->getId()); + + $this->assertEquals(200, $response->getStatusCode()); + + $this->assertEquals(2, $basket->getElements()->count()); } /** @@ -279,7 +460,9 @@ class basketTest extends PhraseanetWebTestCaseAuthenticatedAbstract */ protected function insertOneBasket() { - $basketFixture = new MyFixture\Root(self::$user); + $basketFixture = new MyFixture\LoadOneBasket(); + + $basketFixture->setUser(self::$user); $this->loader->addFixture($basketFixture); From 572f68cb6182052d9db1f387840ff8040725393d Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Tue, 20 Dec 2011 13:36:32 +0100 Subject: [PATCH 07/10] use count method --- lib/Doctrine/Entities/BasketElement.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/Entities/BasketElement.php b/lib/Doctrine/Entities/BasketElement.php index f8ecf3d5d4..ed0db18c92 100644 --- a/lib/Doctrine/Entities/BasketElement.php +++ b/lib/Doctrine/Entities/BasketElement.php @@ -201,7 +201,7 @@ class BasketElement public function setLastInBasket() { - $this->setOrd(count($this->getBasket()->getElements()) + 1); + $this->setOrd($this->getBasket()->getElements()->count() + 1); } /** * @var Entities\ValidationData From cea1e026bf901502751887c663cb4e4bcc8d31dc Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Tue, 20 Dec 2011 13:37:23 +0100 Subject: [PATCH 08/10] add setter --- .../Entities/ValidationParticipant.php | 227 +++++++++--------- 1 file changed, 120 insertions(+), 107 deletions(-) diff --git a/lib/Doctrine/Entities/ValidationParticipant.php b/lib/Doctrine/Entities/ValidationParticipant.php index c9b9dc2a1c..c588a8892a 100644 --- a/lib/Doctrine/Entities/ValidationParticipant.php +++ b/lib/Doctrine/Entities/ValidationParticipant.php @@ -17,124 +17,137 @@ namespace Entities; */ class ValidationParticipant { - - /** - * @var integer $id - */ - private $id; - /** - * @var integer $usr_id - */ - private $usr_id; + /** + * @var integer $id + */ + private $id; - /** - * @var Entities\ValidationData - */ - private $datases; + /** + * @var integer $usr_id + */ + private $usr_id; - /** - * @var Entities\ValidationSession - */ - private $session; + /** + * @var Entities\ValidationData + */ + private $datases; - public function __construct() - { - $this->datases = new \Doctrine\Common\Collections\ArrayCollection(); - } - - /** - * Get id - * - * @return integer - */ - public function getId() - { - return $this->id; - } + /** + * @var Entities\ValidationSession + */ + private $session; - /** - * Set usr_id - * - * @param integer $usrId - */ - public function setUsrId($usrId) - { - $this->usr_id = $usrId; - } + public function __construct() + { + $this->datases = new \Doctrine\Common\Collections\ArrayCollection(); + } - /** - * Get usr_id - * - * @return integer - */ - public function getUsrId() - { - return $this->usr_id; - } + /** + * Get id + * + * @return integer + */ + public function getId() + { + return $this->id; + } - /** - * Add datases - * - * @param Entities\ValidationData $datases - */ - public function addValidationData(\Entities\ValidationData $datases) - { - $this->datases[] = $datases; - } + /** + * Set usr_id + * + * @param integer $usrId + */ + public function setUsrId($usrId) + { + $this->usr_id = $usrId; + } - /** - * Get datases - * - * @return Doctrine\Common\Collections\Collection - */ - public function getDatases() - { - return $this->datases; - } + /** + * Get usr_id + * + * @return integer + */ + public function getUsrId() + { + return $this->usr_id; + } - /** - * Set session - * - * @param Entities\ValidationSession $session - */ - public function setSession(\Entities\ValidationSession $session) - { - $this->session = $session; - } + /** + * Add datases + * + * @param Entities\ValidationData $datases + */ + public function addValidationData(\Entities\ValidationData $datases) + { + $this->datases[] = $datases; + } - /** - * Get session - * - * @return Entities\ValidationSession - */ - public function getSession() - { - return $this->session; - } - /** - * @var boolean $is_aware - */ - private $is_aware = false; + /** + * Get datases + * + * @return Doctrine\Common\Collections\Collection + */ + public function getDatases() + { + return $this->datases; + } + + /** + * Set session + * + * @param Entities\ValidationSession $session + */ + public function setSession(\Entities\ValidationSession $session) + { + $this->session = $session; + } + + /** + * Get session + * + * @return Entities\ValidationSession + */ + public function getSession() + { + return $this->session; + } + + /** + * @var boolean $is_aware + */ + private $is_aware = false; - /** - * Set is_aware - * - * @param boolean $isAware - */ - public function setIsAware($isAware) - { - $this->is_aware = $isAware; - } + /** + * Set is_aware + * + * @param boolean $isAware + */ + public function setIsAware($isAware) + { + $this->is_aware = $isAware; + } + + /** + * Get is_aware + * + * @return boolean + */ + public function getIsAware() + { + return $this->is_aware; + } + + /** + * + * @param \User_Adapter $user + * @return ValidationParticipant + */ + public function setParticipant(\User_Adapter $user) + { + $this->usr_id = $user->get_id(); + return $this; + } - /** - * Get is_aware - * - * @return boolean - */ - public function getIsAware() - { - return $this->is_aware; - } } \ No newline at end of file From d509139a9e188427b37bff77580b200ee81f3f1c Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Tue, 20 Dec 2011 13:39:24 +0100 Subject: [PATCH 09/10] change constraint name --- lib/conf.d/Doctrine/Entities.BasketElement.dcm.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/conf.d/Doctrine/Entities.BasketElement.dcm.yml b/lib/conf.d/Doctrine/Entities.BasketElement.dcm.yml index 92b2d61e84..f49e21c554 100644 --- a/lib/conf.d/Doctrine/Entities.BasketElement.dcm.yml +++ b/lib/conf.d/Doctrine/Entities.BasketElement.dcm.yml @@ -2,7 +2,7 @@ Entities\BasketElement: type: entity table: BasketElements uniqueConstraints: - user_story: + unique_recordcle: columns: basket_id,sbas_id,record_id id: id: From 232d86cf8d609fbca141e4fea549c6b8fb588c05 Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Tue, 20 Dec 2011 13:39:50 +0100 Subject: [PATCH 10/10] add cascade property on relationship --- lib/conf.d/Doctrine/Entities.Basket.dcm.yml | 1 + lib/conf.d/Doctrine/Entities.ValidationParticipant.dcm.yml | 3 ++- lib/conf.d/Doctrine/Entities.ValidationSession.dcm.yml | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/conf.d/Doctrine/Entities.Basket.dcm.yml b/lib/conf.d/Doctrine/Entities.Basket.dcm.yml index ca5236f7fc..398b7d4f62 100644 --- a/lib/conf.d/Doctrine/Entities.Basket.dcm.yml +++ b/lib/conf.d/Doctrine/Entities.Basket.dcm.yml @@ -42,6 +42,7 @@ Entities\Basket: elements: targetEntity: BasketElement mappedBy: basket + cascade: ["ALL"] diff --git a/lib/conf.d/Doctrine/Entities.ValidationParticipant.dcm.yml b/lib/conf.d/Doctrine/Entities.ValidationParticipant.dcm.yml index 5897c49cda..53105fef1e 100644 --- a/lib/conf.d/Doctrine/Entities.ValidationParticipant.dcm.yml +++ b/lib/conf.d/Doctrine/Entities.ValidationParticipant.dcm.yml @@ -22,4 +22,5 @@ Entities\ValidationParticipant: inversedBy: participants joinColumn: name: ValidationSession_id - referencedColumnName: id \ No newline at end of file + referencedColumnName: id + cascade: ["persist"] \ No newline at end of file diff --git a/lib/conf.d/Doctrine/Entities.ValidationSession.dcm.yml b/lib/conf.d/Doctrine/Entities.ValidationSession.dcm.yml index 3a5bd076b6..624db5a8ce 100644 --- a/lib/conf.d/Doctrine/Entities.ValidationSession.dcm.yml +++ b/lib/conf.d/Doctrine/Entities.ValidationSession.dcm.yml @@ -31,6 +31,7 @@ Entities\ValidationSession: joinColumn: name: basket_id referencedColumnName: id + cascade: ["persist"] oneToMany: participants: targetEntity: ValidationParticipant