Merge with Legoff's changes

This commit is contained in:
Romain Neutron
2011-12-20 14:10:53 +01:00
17 changed files with 1048 additions and 185 deletions

View File

@@ -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();

View File

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

View File

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

View File

@@ -42,6 +42,7 @@ Entities\Basket:
elements:
targetEntity: BasketElement
mappedBy: basket
cascade: ["ALL"]

View File

@@ -2,7 +2,7 @@ Entities\BasketElement:
type: entity
table: BasketElements
uniqueConstraints:
user_story:
unique_recordcle:
columns: basket_id,sbas_id,record_id
id:
id:

View File

@@ -22,4 +22,5 @@ Entities\ValidationParticipant:
inversedBy: participants
joinColumn:
name: ValidationSession_id
referencedColumnName: id
referencedColumnName: id
cascade: ["persist"]

View File

@@ -31,6 +31,7 @@ Entities\ValidationSession:
joinColumn:
name: basket_id
referencedColumnName: id
cascade: ["persist"]
oneToMany:
participants:
targetEntity: ValidationParticipant

View File

@@ -0,0 +1,50 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* 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
*/
abstract class AbstractWZ extends AbstractFixture
{
protected $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;
}
}

View File

@@ -1,30 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
namespace PhraseaFixture\Basket;
class AbstractUser
{
protected $user;
public function __construct(\User_Adapter $user)
{
$this->user = $user;
}
}

View File

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

View File

@@ -0,0 +1,57 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PhraseaFixture\Story;
use Doctrine\ORM\EntityManager;
use Doctrine\Common\DataFixtures\FixtureInterface;
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class LoadOneStory extends \PhraseaFixture\AbstractWZ implements FixtureInterface
{
/**
*
* @var \Entities\StoryWZ
*/
public $story;
public function load($manager)
{
$story = new \Entities\StoryWZ();
if (null === $this->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);
}
}

View File

@@ -0,0 +1,54 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PhraseaFixture\ValidationParticipant;
use Doctrine\ORM\EntityManager;
use Doctrine\Common\DataFixtures\FixtureInterface;
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class LoadOneParticipant extends \PhraseaFixture\AbstractWZ implements FixtureInterface
{
/**
*
* @var \Entities\ValidationParticipant
*/
public $validationParticipant;
public function load($manager)
{
$validationParticipant = new \Entities\ValidationParticipant();
if (null === $this->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);
}
}

View File

@@ -0,0 +1,66 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PhraseaFixture\ValidationParticipant;
use Doctrine\ORM\EntityManager;
use Doctrine\Common\DataFixtures\FixtureInterface;
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class LoadParticipantWithSession extends \PhraseaFixture\AbstractWZ implements FixtureInterface
{
/**
*
* @var \Entities\ValidationParticipant
*/
public $validationParticipant;
/**
*
* @var \Entities\ValidationSession
*/
private $session;
public function load($manager)
{
$validationParticipant = new \Entities\ValidationParticipant();
if (null === $this->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;
}
}

View File

@@ -0,0 +1,61 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PhraseaFixture\ValidationSession;
use Doctrine\ORM\EntityManager;
use Doctrine\Common\DataFixtures\FixtureInterface;
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class LoadOneValidationSession extends \PhraseaFixture\AbstractWZ implements FixtureInterface
{
/**
*
* @var \Entities\ValidationSession
*/
public $validationSession;
public function load($manager)
{
$validationSession = new \Entities\ValidationSession();
$validationSession->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);
}
}

View File

@@ -0,0 +1,96 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
require_once __DIR__ . '/PhraseanetWebTestCaseAuthenticatedAbstract.class.inc';
use Doctrine\Common\DataFixtures\Loader;
use Alchemy\Phrasea\Helper;
use Alchemy\Phrasea\RouteProcessor as routeProcessor;
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class WorkZoneTest extends PhraseanetWebTestCaseAuthenticatedAbstract
{
protected $client;
protected static $need_records = 1;
public function setUp()
{
parent::setUp();
$this->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;
}
}

View File

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

View File

@@ -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 %}
<div style="width:{{b_width|round}}px;height:{{b_height|round}}px;" class="thumb_wrapper {{extraclass|default('')}}">
{% endif %}
{% if record_type == 'VIDEO_MP4' or record_type == 'VIDEO_FLV' %}
{% set random = thumbnail.get_random() %}
<div class="record record_video imgTips" style="width:{{d_width|round}}px;height:{{d_height|round}}px;top:{{top|round}}px;">
<div id="preview{{random}}" class="PNB"></div>
<input type="hidden" name="width" value="{{thumbnail.get_width()}}"/>
<input type="hidden" name="height" value="{{thumbnail.get_height()}}"/>
</div>
<script type="text/javascript">
flowplayer("preview{{random}}",
{src:"/include/jslibs/flowplayer/flowplayer-3.2.6.swf", wmode: "transparent"},
{clip:{url:"{{url}}",autoPlay: true,autoBuffering:true,provider: "h264streaming",scaling:"fit"},
onError:function(code,message){getNewVideoToken({{thumbnail.get_sbas_id()}}, {{thumbnail.get_record_id()}}, this);}, plugins: {h264streaming: {url: "/include/jslibs/flowplayer/flowplayer.pseudostreaming-3.2.6.swf"}}});
</script>
{% elseif record_type == 'FLEXPAPER' %}
{% set random = thumbnail.get_random() %}
<div class="record record_document imgTips" style="position:relative;width:{{d_width|round}}px;height:{{d_height|round}}px;top:{{top|round}}px;">
<div id="preview_{{thumbnail.get_sbas_id()}}_{{thumbnail.get_record_id()}}_{{random}}" class="PNB" style=""></div>
<input type="hidden" name="width" value="{{d_width}}"/>
<input type="hidden" name="height" value="{{d_height}}"/>
</div>
<script type="text/javascript">
swfobject.embedSWF("/include/FlexPaper_flash/FlexPaperViewer.swf",
"preview_{{thumbnail.get_sbas_id()}}_{{thumbnail.get_record_id()}}_{{random}}",
"100%", "100%", "9.0.0", false, false,
{menu: "false",flashvars: "SwfFile={{url}}&Scale=0.6&ZoomTransition=easeOut&ZoomTime=0.5&ZoomInterval=0.1&FitPageOnLoad=true&FitWidthOnLoad=true&PrintEnabled=true&FullScreenAsMaxWindow=false&localeChain={{session.get_locale()}}", movie: "/include/FlexPaper_flash/FlexPaperViewer.swf", allowFullScreen :"true",wmode: "transparent"}, false);</script>
{% elseif record_type == 'AUDIO_MP3' %}
{% set random = thumbnail.get_random() %}
<div class="record record_audio audioTips" style="width:{{d_width|round}}px;height:{{d_height|round}}px;top:{{top|round}}px;">
<div id="preview_{{thumbnail.get_sbas_id()}}_{{thumbnail.get_record_id()}}_{{random}}" class="PNB" style=""></div>
<input type="hidden" name="width" value="{{thumbnail.get_width()}}"/>
<input type="hidden" name="height" value="{{thumbnail.get_height()}}"/>
</div>
<script type="text/javascript">
swfobject.embedSWF("/include/jslibs/audio-player/player.swf",
"preview_{{thumbnail.get_sbas_id()}}_{{thumbnail.get_record_id()}}_{{random}}",
"{{d_width}}", "{{d_height}}", "9.0.0", false, false,
{menu: "false",flashvars: "playerID=2&autostart=yes&noinfo=yes&animation=no&remaining=yes&soundFile={{url}}", movie: "/include/jslibs/audio-player/player.swf", allowFullScreen :"true",wmode: "transparent"}, false);</script>
{% else %}
<img class="record record_image imgTips zoomable thumb" oncontextMenu="return(false);"
style="width:{{d_width|round}}px;height:{{d_height|round}}px;top:{{top|round}}px;"
src="{{url}}" ondragstart="return false;">
<input type="hidden" name="width" value="{{thumbnail.get_width()}}"/>
<input type="hidden" name="height" value="{{thumbnail.get_height()}}"/>
{% endif %}
{% if wrap %}
</div>
{% endif %}
{% endmacro %}
{% macro format_fit(thumbnail, b_w, b_h, extraclass, session, wrap)%}
{% set record_type = thumbnail.get_type() %}
{% if record_type == 'AUDIO_MP3' %}
{% set d_width = 320 %}
{% set d_height = 60 %}
{% set top = 0 %}
{% elseif record_type == 'FLEXPAPER' %}
{% set d_width = 800 %}
{% set d_height = 600 %}
{% set top = 0 %}
{% else %}
{% set b_width = b_w %}
{% set b_height = b_h|default(b_w) %}
{% set b_ratio = b_width / b_height %}
{% set i_ratio = thumbnail.get_width() / thumbnail.get_height() %}
{% if i_ratio > b_ratio%}
{% set d_height = b_height %}
{% set d_width = d_height * thumbnail.get_width() / thumbnail.get_height() %}
{% set left = (b_height - d_height) / 2 %}
{% else %}
{% if b_height > thumbnail.get_height() %}
{% set d_height = thumbnail.get_height() %}
{% else %}
{% set d_height = b_height %}
{% endif %}
{% set d_width = d_height * thumbnail.get_width() / thumbnail.get_height() %}
{% set top = ((b_height - d_height) / 2) %}
{% endif %}
{% endif %}
{% if session.is_authenticated() == true %}
{% set url = thumbnail.get_url() %}
{% else %}