This commit is contained in:
Nicolas Le Goff
2011-12-19 19:08:20 +01:00
parent 9a7c326d6c
commit d4367e0944
4 changed files with 233 additions and 35 deletions

View File

@@ -16,7 +16,7 @@
* @link www.phraseanet.com * @link www.phraseanet.com
*/ */
namespace PhraseaFixture\Basket; namespace PhraseaFixture;
class AbstractUser class AbstractUser
{ {

View File

@@ -21,10 +21,13 @@ use Doctrine\Common\DataFixtures\FixtureInterface;
* @license http://opensource.org/licenses/gpl-3.0 GPLv3 * @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com * @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) public function load($manager)
{ {
@@ -34,7 +37,7 @@ class Root extends AbstractUser implements FixtureInterface
$basket->setOwner($this->user); $basket->setOwner($this->user);
$manager->persist($basket); $manager->persist($basket);
$manager->flush(); $manager->flush();
$this->basketId = $basket->getId(); $this->basket = $basket;
} }
} }

View File

@@ -35,11 +35,6 @@ class basketTest extends PhraseanetWebTestCaseAuthenticatedAbstract
$this->loader = new Loader(); $this->loader = new Loader();
} }
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
}
public function createApplication() public function createApplication()
{ {
return require __DIR__ . '/../Alchemy/Phrasea/Application/Prod.php'; return require __DIR__ . '/../Alchemy/Phrasea/Application/Prod.php';
@@ -77,14 +72,212 @@ class basketTest extends PhraseanetWebTestCaseAuthenticatedAbstract
$this->assertEquals($crawler->filter("form[action='/prod/baskets/']")->count(), 1); $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/'] input[name='name']")->count(), 1);
$this->assertEquals($crawler->filter("form[action='/prod/baskets/'] textarea[name='description']")->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() public function testBasketGet()
{
$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(302, $response->getStatusCode());
$basket->getElements();
}
/**
*
* @return \Entities\Basket
*/
protected function insertOneBasket()
{ {
$basketFixture = new MyFixture\Root(self::$user); $basketFixture = new MyFixture\Root(self::$user);
@@ -92,13 +285,15 @@ class basketTest extends PhraseanetWebTestCaseAuthenticatedAbstract
$this->insertFixtureInDatabase($this->loader); $this->insertFixtureInDatabase($this->loader);
$route = sprintf('/baskets/%s/', $basketFixture->basketId); $query = self::$core->getEntityManager()->createQuery(
'SELECT COUNT(b.id) FROM \Entities\Basket b'
);
$crawler = $this->client->request('GET', $route); $count = $query->getSingleScalarResult();
$response = $this->client->getResponse(); $this->assertEquals(1, $count);
$this->assertEquals(200, $response->getStatusCode());
return $basketFixture->basket;
} }
} }