Fix tests

This commit is contained in:
Romain Neutron
2012-07-27 13:19:10 +02:00
parent 9f11445265
commit cc4bffe88d
2 changed files with 44 additions and 40 deletions

View File

@@ -150,8 +150,8 @@ class databox_subdefsStructure implements IteratorAggregate
. 'subdef[@name="' . $name . '"]' . 'subdef[@name="' . $name . '"]'
); );
if ($nodes->length > 0) { for($i = 0; $i < $nodes->length; $i++) {
$node = $nodes->item(0); $node = $nodes->item($i);
$parent = $node->parentNode; $parent = $node->parentNode;
$parent->removeChild($node); $parent->removeChild($node);
} }

View File

@@ -5,21 +5,24 @@ require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.
class ControllerSubdefsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract class ControllerSubdefsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{ {
protected $client; protected $client;
protected $app;
protected $databox;
public function createApplication() public function createApplication()
{ {
$app = require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Admin.php'; $this->app = require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Admin.php';
$app['debug'] = true; $this->app['debug'] = true;
unset($app['exception_handler']); unset($this->app['exception_handler']);
return $app; return $this->app;
} }
public function setUp() public function setUp()
{ {
parent::setUp(); parent::setUp();
$this->client = $this->createClient(); $this->client = $this->createClient();
$this->databox = array_shift($this->app['phraseanet.appbox']->get_databoxes());
} }
/** /**
@@ -27,37 +30,38 @@ class ControllerSubdefsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
*/ */
public function testRouteGetSubdef() public function testRouteGetSubdef()
{ {
$appbox = appbox::get_instance(\bootstrap::getCore()); $this->client->request("GET", "/subdefs/" . $this->databox->get_sbas_id() . "/");
$databox = array_shift($appbox->get_databoxes());
$this->client->request("GET", "/subdefs/" . $databox->get_sbas_id() . "/");
$this->assertTrue($this->client->getResponse()->isOk()); $this->assertTrue($this->client->getResponse()->isOk());
} }
public function getName()
{
return 'testname' . time() . mt_rand(10000, 99999);
}
public function testPostRouteAddSubdef() public function testPostRouteAddSubdef()
{ {
$appbox = appbox::get_instance(\bootstrap::getCore()); $name = $this->getName();
$databox = array_shift($appbox->get_databoxes()); $this->client->request("POST", "/subdefs/" . $this->databox->get_sbas_id() . "/", array('add_subdef' => array(
$this->client->request("POST", "/subdefs/" . $databox->get_sbas_id() . "/", array('add_subdef' => array(
'class' => 'thumbnail', 'class' => 'thumbnail',
'name' => 'aname', 'name' => $name,
'group' => 'image' 'group' => 'image'
))); )));
$this->assertTrue($this->client->getResponse()->isRedirect()); $this->assertTrue($this->client->getResponse()->isRedirect());
$subdefs = $databox->get_subdef_structure(); $subdefs = $this->databox->get_subdef_structure();
$subdefs->get_subdef("image", "aname"); $subdefs->get_subdef("image", $name);
$subdefs->delete_subdef('image', 'aname'); $subdefs->delete_subdef('image', $name);
} }
public function testPostRouteDeleteSubdef() public function testPostRouteDeleteSubdef()
{ {
$appbox = appbox::get_instance(\bootstrap::getCore()); $subdefs = $this->databox->get_subdef_structure();
$databox = array_shift($appbox->get_databoxes()); $name = $this->getName();
$subdefs = $databox->get_subdef_structure(); $subdefs->add_subdef("image", $name, "thumbnail");
$subdefs->add_subdef("image", "name", "class"); $this->client->request("POST", "/subdefs/" . $this->databox->get_sbas_id() . "/", array('delete_subdef' => 'image_' . $name));
$this->client->request("POST", "/subdefs/" . $databox->get_sbas_id() . "/", array('delete_subdef' => 'group_name'));
$this->assertTrue($this->client->getResponse()->isRedirect()); $this->assertTrue($this->client->getResponse()->isRedirect());
try { try {
$subdefs->get_subdef("image", "name"); $subdefs->get_subdef("image", $name);
$this->fail("should raise an exception"); $this->fail("should raise an exception");
} catch (\Exception $e) { } catch (\Exception $e) {
@@ -66,27 +70,27 @@ class ControllerSubdefsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
public function testPostRouteAddSubdefWithNoParams() public function testPostRouteAddSubdefWithNoParams()
{ {
$appbox = appbox::get_instance(\bootstrap::getCore()); $subdefs = $this->databox->get_subdef_structure();
$databox = array_shift($appbox->get_databoxes()); $name = $this->getName();
$subdefs = $databox->get_subdef_structure(); $subdefs->add_subdef("image", $name, "thumbnail");
$subdefs->add_subdef("image", "name", "class"); $this->client->request("POST", "/subdefs/" . $this->databox->get_sbas_id() . "/"
$this->client->request("POST", "/subdefs/" . $databox->get_sbas_id() . "/"
, array('subdefs' => array( , array('subdefs' => array(
'image_name' 'image_' . $name
) )
, 'image_name_class' => 'class' , 'image_' . $name . '_class' => 'thumbnail'
, 'image_name_downloadable' => 0 , 'image_' . $name . '_downloadable' => 0
, 'image_name_mediatype' => 'image' , 'image_' . $name . '_mediatype' => 'image'
, 'image_name_image' => array( , 'image_' . $name . '_image' => array(
'size' => 400 'size' => 400,
, 'resolution' => 83 'resolution' => 83,
, 'strip' => 0 'strip' => 0,
, 'quality' => 90 'quality' => 90,
)) ))
); );
$this->assertTrue($this->client->getResponse()->isRedirect()); $this->assertTrue($this->client->getResponse()->isRedirect());
$subdef = $subdefs->get_subdef("image", "name"); $subdefs = new databox_subdefsStructure( $this->databox);
$subdef = $subdefs->get_subdef("image", $name);
/* @var $subdef \databox_subdef */ /* @var $subdef \databox_subdef */
$this->assertFalse($subdef->is_downloadable()); $this->assertFalse($subdef->is_downloadable());
@@ -100,6 +104,6 @@ class ControllerSubdefsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->assertEquals(90, $options[\Alchemy\Phrasea\Media\Subdef\Image::OPTION_QUALITY]->getValue()); $this->assertEquals(90, $options[\Alchemy\Phrasea\Media\Subdef\Image::OPTION_QUALITY]->getValue());
$this->assertFalse($options[\Alchemy\Phrasea\Media\Subdef\Image::OPTION_STRIP]->getValue()); $this->assertFalse($options[\Alchemy\Phrasea\Media\Subdef\Image::OPTION_STRIP]->getValue());
$subdefs->delete_subdef("image", "name"); $subdefs->delete_subdef("image", $name);
} }
} }