diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Basket.php b/lib/Alchemy/Phrasea/Controller/Prod/Basket.php index afbaf0d372..b9d75c72e2 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Basket.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Basket.php @@ -134,7 +134,7 @@ 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) { $em = $app['Core']->getEntityManager(); @@ -184,7 +184,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) { $em = $app['Core']->getEntityManager(); 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 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 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.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: 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 diff --git a/lib/conf.d/PhraseaFixture/AbstractWZ.php b/lib/conf.d/PhraseaFixture/AbstractWZ.php new file mode 100644 index 0000000000..bdd5c09863 --- /dev/null +++ b/lib/conf.d/PhraseaFixture/AbstractWZ.php @@ -0,0 +1,50 @@ +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/AbstractUser.php b/lib/conf.d/PhraseaFixture/Basket/AbstractUser.php deleted file mode 100644 index 64fa80a3bb..0000000000 --- a/lib/conf.d/PhraseaFixture/Basket/AbstractUser.php +++ /dev/null @@ -1,30 +0,0 @@ -user = $user; - } - -} \ 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 65% rename from lib/conf.d/PhraseaFixture/Basket/Root.php rename to lib/conf.d/PhraseaFixture/Basket/LoadOneBasket.php index e065f3ea55..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,20 +20,35 @@ 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 LoadOneBasket extends \PhraseaFixture\AbstractWZ implements FixtureInterface { - - public $basketId; - + + /** + * + * @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->basketId = $basket->getId(); + + $this->basket = $basket; + + $this->addReference('one-basket', $basket); } } \ No newline at end of file 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 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 diff --git a/lib/unitTest/basketTest.php b/lib/unitTest/basketTest.php index 2b1bec474f..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() { @@ -35,11 +36,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 +44,439 @@ class basketTest extends PhraseanetWebTestCaseAuthenticatedAbstract public function testRootPost() { $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(); - + $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 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/'; - - $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!')); - + $crawler = $this->client->request('GET', $route); + + $response = $this->client->getResponse(); + + $this->assertEquals(200, $response->getStatusCode()); + + $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() { - $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 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(); + + $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()); + + $filter = "form[action='/prod/baskets/" . $basket->getId() . "/update/']"; + $this->assertEquals($crawler->filter($filter)->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)); + + $response = $this->client->getResponse(); + + $this->assertEquals(302, $response->getStatusCode()); + + $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()); + } + + /** + * + * @return \Entities\Basket + */ + protected function insertOneBasket() + { + $basketFixture = new MyFixture\LoadOneBasket(); + + $basketFixture->setUser(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/templates/web/common/thumbnail.html b/templates/web/common/thumbnail.html index d812c2f96b..be44d1abd0 100644 --- a/templates/web/common/thumbnail.html +++ b/templates/web/common/thumbnail.html @@ -41,6 +41,107 @@ + {% if session.is_authenticated() == true %} + {% set url = thumbnail.get_url() %} + {% else %} + {% set url = thumbnail.get_permalink().get_url() %} + {% endif %} + {% if wrap %} +