Updated unitTests

This commit is contained in:
Romain Neutron
2011-12-26 12:19:58 +01:00
parent cf71abc285
commit 4d84bc3f66

View File

@@ -22,7 +22,7 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
{ {
parent::setUp(); parent::setUp();
$appbox = appbox::get_instance(); $appbox = appbox::get_instance();
$this->object = new API_V1_adapter(FALSE, $appbox); $this->object = new API_V1_adapter(FALSE, $appbox, self::$core);
} }
public function testGet_error_code() public function testGet_error_code()
@@ -371,9 +371,15 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
$session = $appbox->get_session(); $session = $appbox->get_session();
$usr_id = $session->get_usr_id(); $usr_id = $session->get_usr_id();
$basket = basket_adapter::getInstance(appbox::get_instance(), $ssel_id, $usr_id); $em = self::$core->getEntityManager();
$this->assertTrue($basket instanceof basket_adapter); $repo = $em->getRepository('\Entities\Basket');
$basket->delete();
/* @var $repo \Repositories\BasketRepository */
$repo->findUserBasket($ssel_id, self::$core->getAuthenticatedUser());
$this->assertTrue($basket instanceof \Entities\Basket);
$em->remove($Basket);
$em->flush();
} }
public function testDelete_basket() public function testDelete_basket()
@@ -381,8 +387,17 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
$appbox = appbox::get_instance(); $appbox = appbox::get_instance();
$usr_id = $appbox->get_session()->get_usr_id(); $usr_id = $appbox->get_session()->get_usr_id();
$user = User_Adapter::getInstance($usr_id, $appbox); $user = User_Adapter::getInstance($usr_id, $appbox);
$basket = basket_adapter::create($appbox, 'test suppression', $user);
$ssel_id = $basket->get_ssel_id(); $em = self::$core->getEntityManager();
$Basket = new Entities\Basket();
$Basket->setName('Delete test');
$Basket->setOwner($user);
$em->persist($Basket);
$em->flush();
$ssel_id = $basket->getId();
$request = new Request(array(), array(), array(), array(), array(), array('HTTP_Accept' => 'application/json')); $request = new Request(array(), array(), array(), array(), array(), array('HTTP_Accept' => 'application/json'));
$result = $this->object->delete_basket($request, $ssel_id); $result = $this->object->delete_basket($request, $ssel_id);
@@ -390,12 +405,14 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
$this->assertEquals('application/json', $result->get_content_type()); $this->assertEquals('application/json', $result->get_content_type());
$this->assertTrue(is_object(json_decode($result->format()))); $this->assertTrue(is_object(json_decode($result->format())));
$repo = $em->getRepository('\Entities\Basket');
try try
{ {
basket_adapter::getInstance($appbox, $ssel_id, $usr_id); $repo->findUserBasket($ssel_id, $user);
$this->fail('An exception should have been raised'); $this->fail('An exception should have been raised');
} }
catch (Exception_Basket_NotFound $e) catch (Exception_NotFound $e)
{ {
} }