Fix CS in unit tests + remove unused unit tests

This commit is contained in:
Romain Neutron
2012-05-10 17:08:01 +02:00
parent 21c2d15754
commit 17cd58f5e1
224 changed files with 16423 additions and 22543 deletions

View File

@@ -4,7 +4,6 @@ require_once __DIR__ . '/PhraseanetPHPUnitAuthenticatedAbstract.class.inc';
class ACLTest extends PhraseanetPHPUnitAuthenticatedAbstract class ACLTest extends PhraseanetPHPUnitAuthenticatedAbstract
{ {
/** /**
* @var ACL * @var ACL
*/ */
@@ -22,25 +21,19 @@ class ACLTest extends PhraseanetPHPUnitAuthenticatedAbstract
* In case first test fails * In case first test fails
*/ */
$usr_id = User_Adapter::get_usr_id_from_login('test_phpunit2'); $usr_id = User_Adapter::get_usr_id_from_login('test_phpunit2');
try try {
{ $appbox = appbox::get_instance(\bootstrap::getCore());
$appbox = appbox::get_instance(\bootstrap::getCore());
$template = User_Adapter::getInstance($usr_id, $appbox); $template = User_Adapter::getInstance($usr_id, $appbox);
$template->delete(); $template->delete();
} } catch (Exception $e) {
catch (Exception $e)
{
} }
$usr_id = User_Adapter::get_usr_id_from_login('test_phpunit3'); $usr_id = User_Adapter::get_usr_id_from_login('test_phpunit3');
try try {
{
$appbox = appbox::get_instance(\bootstrap::getCore()); $appbox = appbox::get_instance(\bootstrap::getCore());
$cobaye = User_Adapter::getInstance($usr_id, $appbox); $cobaye = User_Adapter::getInstance($usr_id, $appbox);
$cobaye->delete(); $cobaye->delete();
} } catch (Exception $e) {
catch (Exception $e)
{
} }
parent::tearDownAfterClass(); parent::tearDownAfterClass();
@@ -48,16 +41,14 @@ class ACLTest extends PhraseanetPHPUnitAuthenticatedAbstract
public function testApply_model() public function testApply_model()
{ {
$appbox = appbox::get_instance(\bootstrap::getCore()); $appbox = appbox::get_instance(\bootstrap::getCore());
$template = User_Adapter::create($appbox, 'test_phpunit2', 'blabla2', 'test2@example.com', false); $template = User_Adapter::create($appbox, 'test_phpunit2', 'blabla2', 'test2@example.com', false);
$template->set_template(self::$user); $template->set_template(self::$user);
$base_ids = array(); $base_ids = array();
foreach ($appbox->get_databoxes() as $databox) foreach ($appbox->get_databoxes() as $databox) {
{ foreach ($databox->get_collections() as $collection) {
foreach ($databox->get_collections() as $collection) $base_id = $collection->get_base_id();
{
$base_id = $collection->get_base_id();
$base_ids[] = $base_id; $base_ids[] = $base_id;
} }
} }
@@ -65,10 +56,8 @@ class ACLTest extends PhraseanetPHPUnitAuthenticatedAbstract
$cobaye = User_Adapter::create($appbox, 'test_phpunit3', 'blabla3', 'test3@example.com', false); $cobaye = User_Adapter::create($appbox, 'test_phpunit3', 'blabla3', 'test3@example.com', false);
$cobaye->ACL()->apply_model($template, $base_ids); $cobaye->ACL()->apply_model($template, $base_ids);
foreach ($appbox->get_databoxes() as $databox) foreach ($appbox->get_databoxes() as $databox) {
{ foreach ($databox->get_collections() as $collection) {
foreach ($databox->get_collections() as $collection)
{
$base_id = $collection->get_base_id(); $base_id = $collection->get_base_id();
$this->assertTrue($cobaye->ACL()->has_access_to_base($base_id)); $this->assertTrue($cobaye->ACL()->has_access_to_base($base_id));
} }
@@ -83,10 +72,8 @@ class ACLTest extends PhraseanetPHPUnitAuthenticatedAbstract
$appbox = appbox::get_instance(\bootstrap::getCore()); $appbox = appbox::get_instance(\bootstrap::getCore());
$base_ids = array(); $base_ids = array();
foreach ($appbox->get_databoxes() as $databox) foreach ($appbox->get_databoxes() as $databox) {
{ foreach ($databox->get_collections() as $collection) {
foreach ($databox->get_collections() as $collection)
{
$base_id = $collection->get_base_id(); $base_id = $collection->get_base_id();
self::$user->ACL()->revoke_access_from_bases(array($base_id)); self::$user->ACL()->revoke_access_from_bases(array($base_id));
$this->assertFalse(self::$user->ACL()->has_access_to_base($base_id)); $this->assertFalse(self::$user->ACL()->has_access_to_base($base_id));
@@ -97,8 +84,7 @@ class ACLTest extends PhraseanetPHPUnitAuthenticatedAbstract
} }
self::$user->ACL()->revoke_access_from_bases($base_ids); self::$user->ACL()->revoke_access_from_bases($base_ids);
foreach ($base_ids as $base_id) foreach ($base_ids as $base_id) {
{
$this->assertFalse(self::$user->ACL()->has_access_to_base($base_id)); $this->assertFalse(self::$user->ACL()->has_access_to_base($base_id));
} }
} }
@@ -107,10 +93,8 @@ class ACLTest extends PhraseanetPHPUnitAuthenticatedAbstract
{ {
$appbox = appbox::get_instance(\bootstrap::getCore()); $appbox = appbox::get_instance(\bootstrap::getCore());
foreach ($appbox->get_databoxes() as $databox) foreach ($appbox->get_databoxes() as $databox) {
{ foreach ($databox->get_collections() as $collection) {
foreach ($databox->get_collections() as $collection)
{
$base_id = $collection->get_base_id(); $base_id = $collection->get_base_id();
$this->assertFalse(self::$user->ACL()->has_access_to_base($base_id)); $this->assertFalse(self::$user->ACL()->has_access_to_base($base_id));
self::$user->ACL()->give_access_to_base(array($base_id)); self::$user->ACL()->give_access_to_base(array($base_id));
@@ -123,12 +107,10 @@ class ACLTest extends PhraseanetPHPUnitAuthenticatedAbstract
{ {
$appbox = appbox::get_instance(\bootstrap::getCore()); $appbox = appbox::get_instance(\bootstrap::getCore());
foreach ($appbox->get_databoxes() as $databox) foreach ($appbox->get_databoxes() as $databox) {
{ $sbas_id = $databox->get_sbas_id();
$sbas_id = $databox->get_sbas_id();
$base_ids = array(); $base_ids = array();
foreach ($databox->get_collections() as $collection) foreach ($databox->get_collections() as $collection) {
{
$base_ids[] = $collection->get_base_id(); $base_ids[] = $collection->get_base_id();
} }
@@ -143,12 +125,10 @@ class ACLTest extends PhraseanetPHPUnitAuthenticatedAbstract
public function testRevoke_unused_sbas_rights() public function testRevoke_unused_sbas_rights()
{ {
$appbox = appbox::get_instance(\bootstrap::getCore()); $appbox = appbox::get_instance(\bootstrap::getCore());
foreach ($appbox->get_databoxes() as $databox) foreach ($appbox->get_databoxes() as $databox) {
{ $sbas_id = $databox->get_sbas_id();
$sbas_id = $databox->get_sbas_id();
$base_ids = array(); $base_ids = array();
foreach ($databox->get_collections() as $collection) foreach ($databox->get_collections() as $collection) {
{
$base_ids[] = $collection->get_base_id(); $base_ids[] = $collection->get_base_id();
} }
@@ -168,13 +148,11 @@ class ACLTest extends PhraseanetPHPUnitAuthenticatedAbstract
public function testSet_quotas_on_base() public function testSet_quotas_on_base()
{ {
$appbox = appbox::get_instance(\bootstrap::getCore()); $appbox = appbox::get_instance(\bootstrap::getCore());
foreach ($appbox->get_databoxes() as $databox) foreach ($appbox->get_databoxes() as $databox) {
{ foreach ($databox->get_collections() as $collection) {
foreach ($databox->get_collections() as $collection)
{
$base_id = $collection->get_base_id(); $base_id = $collection->get_base_id();
$droits = 50; $droits = 50;
$restes = 40; $restes = 40;
self::$user->ACL()->give_access_to_base(array($base_id)); self::$user->ACL()->give_access_to_base(array($base_id));
self::$user->ACL()->set_quotas_on_base($base_id, $droits, $restes); self::$user->ACL()->set_quotas_on_base($base_id, $droits, $restes);
@@ -192,24 +170,19 @@ class ACLTest extends PhraseanetPHPUnitAuthenticatedAbstract
{ {
$appbox = appbox::get_instance(\bootstrap::getCore()); $appbox = appbox::get_instance(\bootstrap::getCore());
$first = true; $first = true;
$base_ref = null; $base_ref = null;
foreach ($appbox->get_databoxes() as $databox) foreach ($appbox->get_databoxes() as $databox) {
{ foreach ($databox->get_collections() as $collection) {
foreach ($databox->get_collections() as $collection)
{
$base_id = $collection->get_base_id(); $base_id = $collection->get_base_id();
self::$user->ACL()->give_access_to_base(array($base_id)); self::$user->ACL()->give_access_to_base(array($base_id));
if ($first) if ($first) {
{
self::$user->ACL()->update_rights_to_base($base_id, array('imgtools' => true, 'chgstatus' => true, 'canaddrecord' => true, 'canputinalbum' => true)); self::$user->ACL()->update_rights_to_base($base_id, array('imgtools' => true, 'chgstatus' => true, 'canaddrecord' => true, 'canputinalbum' => true));
$base_ref = $base_id; $base_ref = $base_id;
} } else {
else
{
self::$user->ACL()->duplicate_right_from_bas($base_ref, $base_id); self::$user->ACL()->duplicate_right_from_bas($base_ref, $base_id);
} }
@@ -227,7 +200,7 @@ class ACLTest extends PhraseanetPHPUnitAuthenticatedAbstract
{ {
// Remove the following lines when you implement this test. // Remove the following lines when you implement this test.
$this->markTestIncomplete( $this->markTestIncomplete(
'This test has not been implemented yet.' 'This test has not been implemented yet.'
); );
} }
@@ -236,23 +209,21 @@ class ACLTest extends PhraseanetPHPUnitAuthenticatedAbstract
$appbox = appbox::get_instance(\bootstrap::getCore()); $appbox = appbox::get_instance(\bootstrap::getCore());
$rights_false = array( $rights_false = array(
'imgtools' => false 'imgtools' => false
, 'chgstatus' => false , 'chgstatus' => false
, 'canaddrecord' => false , 'canaddrecord' => false
, 'canputinalbum' => false , 'canputinalbum' => false
); );
$rights_true = array( $rights_true = array(
'imgtools' => true 'imgtools' => true
, 'chgstatus' => true , 'chgstatus' => true
, 'canaddrecord' => true , 'canaddrecord' => true
); );
foreach ($appbox->get_databoxes() as $databox) foreach ($appbox->get_databoxes() as $databox) {
{ foreach ($databox->get_collections() as $collection) {
foreach ($databox->get_collections() as $collection)
{
$base_id = $collection->get_base_id(); $base_id = $collection->get_base_id();
self::$user->ACL()->give_access_to_base(array($base_id)); self::$user->ACL()->give_access_to_base(array($base_id));
self::$user->ACL()->update_rights_to_base($base_id, $rights_false); self::$user->ACL()->update_rights_to_base($base_id, $rights_false);
@@ -283,13 +254,11 @@ class ACLTest extends PhraseanetPHPUnitAuthenticatedAbstract
{ {
$appbox = appbox::get_instance(\bootstrap::getCore()); $appbox = appbox::get_instance(\bootstrap::getCore());
foreach ($appbox->get_databoxes() as $databox) foreach ($appbox->get_databoxes() as $databox) {
{ foreach ($databox->get_collections() as $collection) {
foreach ($databox->get_collections() as $collection)
{
$base_id = $collection->get_base_id(); $base_id = $collection->get_base_id();
$droits = 50; $droits = 50;
$restes = 40; $restes = 40;
self::$user->ACL()->give_access_to_base(array($base_id)); self::$user->ACL()->give_access_to_base(array($base_id));
self::$user->ACL()->set_quotas_on_base($base_id, $droits, $restes); self::$user->ACL()->set_quotas_on_base($base_id, $droits, $restes);
@@ -306,13 +275,11 @@ class ACLTest extends PhraseanetPHPUnitAuthenticatedAbstract
public function testRemove_remaining() public function testRemove_remaining()
{ {
$appbox = appbox::get_instance(\bootstrap::getCore()); $appbox = appbox::get_instance(\bootstrap::getCore());
foreach ($appbox->get_databoxes() as $databox) foreach ($appbox->get_databoxes() as $databox) {
{ foreach ($databox->get_collections() as $collection) {
foreach ($databox->get_collections() as $collection)
{
$base_id = $collection->get_base_id(); $base_id = $collection->get_base_id();
$droits = 50; $droits = 50;
$restes = 40; $restes = 40;
self::$user->ACL()->give_access_to_base(array($base_id)); self::$user->ACL()->give_access_to_base(array($base_id));
self::$user->ACL()->set_quotas_on_base($base_id, $droits, $restes); self::$user->ACL()->set_quotas_on_base($base_id, $droits, $restes);
@@ -338,15 +305,14 @@ class ACLTest extends PhraseanetPHPUnitAuthenticatedAbstract
$rights = array( $rights = array(
'bas_modify_struct' => true 'bas_modify_struct' => true
); );
$this->assertFalse(self::$user->ACL()->has_right('bas_modify_struct')); $this->assertFalse(self::$user->ACL()->has_right('bas_modify_struct'));
$this->assertFalse(self::$user->ACL()->has_right('bas_modif_th')); $this->assertFalse(self::$user->ACL()->has_right('bas_modif_th'));
foreach ($appbox->get_databoxes() as $databox) foreach ($appbox->get_databoxes() as $databox) {
{
self::$user->ACL()->give_access_to_sbas(array($databox->get_sbas_id())); self::$user->ACL()->give_access_to_sbas(array($databox->get_sbas_id()));
self::$user->ACL()->update_rights_to_sbas($databox->get_sbas_id(), $rights); self::$user->ACL()->update_rights_to_sbas($databox->get_sbas_id(), $rights);
break; break;
@@ -361,22 +327,21 @@ class ACLTest extends PhraseanetPHPUnitAuthenticatedAbstract
$appbox = appbox::get_instance(\bootstrap::getCore()); $appbox = appbox::get_instance(\bootstrap::getCore());
$rights_false = array( $rights_false = array(
'bas_modify_struct' => false 'bas_modify_struct' => false
, 'bas_manage' => false , 'bas_manage' => false
, 'bas_chupub' => false , 'bas_chupub' => false
, 'bas_modif_th' => false , 'bas_modif_th' => false
); );
$rights_true = array( $rights_true = array(
'bas_modify_struct' => true 'bas_modify_struct' => true
, 'bas_manage' => true , 'bas_manage' => true
, 'bas_chupub' => true , 'bas_chupub' => true
, 'bas_modif_th' => true , 'bas_modif_th' => true
); );
foreach ($appbox->get_databoxes() as $databox) foreach ($appbox->get_databoxes() as $databox) {
{
self::$user->ACL()->give_access_to_sbas(array($databox->get_sbas_id())); self::$user->ACL()->give_access_to_sbas(array($databox->get_sbas_id()));
self::$user->ACL()->update_rights_to_sbas($databox->get_sbas_id(), $rights_false); self::$user->ACL()->update_rights_to_sbas($databox->get_sbas_id(), $rights_false);
$this->assertFalse(self::$user->ACL()->has_right_on_sbas($databox->get_sbas_id(), 'bas_modify_struct')); $this->assertFalse(self::$user->ACL()->has_right_on_sbas($databox->get_sbas_id(), 'bas_modify_struct'));
@@ -399,10 +364,8 @@ class ACLTest extends PhraseanetPHPUnitAuthenticatedAbstract
public function testGet_mask_and() public function testGet_mask_and()
{ {
$appbox = appbox::get_instance(\bootstrap::getCore()); $appbox = appbox::get_instance(\bootstrap::getCore());
foreach ($appbox->get_databoxes() as $databox) foreach ($appbox->get_databoxes() as $databox) {
{ foreach ($databox->get_collections() as $collection) {
foreach ($databox->get_collections() as $collection)
{
$base_id = $collection->get_base_id(); $base_id = $collection->get_base_id();
self::$user->ACL()->give_access_to_base(array($base_id)); self::$user->ACL()->give_access_to_base(array($base_id));
@@ -423,10 +386,8 @@ class ACLTest extends PhraseanetPHPUnitAuthenticatedAbstract
public function testGet_mask_xor() public function testGet_mask_xor()
{ {
$appbox = appbox::get_instance(\bootstrap::getCore()); $appbox = appbox::get_instance(\bootstrap::getCore());
foreach ($appbox->get_databoxes() as $databox) foreach ($appbox->get_databoxes() as $databox) {
{ foreach ($databox->get_collections() as $collection) {
foreach ($databox->get_collections() as $collection)
{
$base_id = $collection->get_base_id(); $base_id = $collection->get_base_id();
self::$user->ACL()->give_access_to_base(array($base_id)); self::$user->ACL()->give_access_to_base(array($base_id));
@@ -446,13 +407,11 @@ class ACLTest extends PhraseanetPHPUnitAuthenticatedAbstract
public function testHas_access_to_base() public function testHas_access_to_base()
{ {
$appbox = appbox::get_instance(\bootstrap::getCore()); $appbox = appbox::get_instance(\bootstrap::getCore());
$base_ids = array(); $base_ids = array();
$n = 0; $n = 0;
foreach ($appbox->get_databoxes() as $databox) foreach ($appbox->get_databoxes() as $databox) {
{ foreach ($databox->get_collections() as $collection) {
foreach ($databox->get_collections() as $collection)
{
$base_ids[] = $collection->get_base_id(); $base_ids[] = $collection->get_base_id();
$n ++; $n ++;
} }
@@ -468,27 +427,26 @@ class ACLTest extends PhraseanetPHPUnitAuthenticatedAbstract
$this->assertEquals(count($base_ids), count($bases)); $this->assertEquals(count($base_ids), count($bases));
$sql = 'SELECT actif FROM basusr WHERE usr_id = :usr_id AND base_id = :base_id'; $sql = 'SELECT actif FROM basusr WHERE usr_id = :usr_id AND base_id = :base_id';
$stmt = $appbox->get_connection()->prepare($sql); $stmt = $appbox->get_connection()->prepare($sql);
foreach ($bases as $base_id) foreach ($bases as $base_id) {
{
$stmt->execute(array(':usr_id' => $appbox->get_session()->get_usr_id(), ':base_id' => $base_id)); $stmt->execute(array(':usr_id' => $appbox->get_session()->get_usr_id(), ':base_id' => $base_id));
$row = $stmt->fetch(PDO::FETCH_ASSOC); $row = $stmt->fetch(PDO::FETCH_ASSOC);
$this->assertEquals(1, $row['actif']); $this->assertEquals(1, $row['actif']);
$this->assertTrue(self::$user->ACL()->has_access_to_base($base_id)); $this->assertTrue(self::$user->ACL()->has_access_to_base($base_id));
self::$user->ACL()->update_rights_to_base($base_id, array('actif' => false)); self::$user->ACL()->update_rights_to_base($base_id, array('actif' => false));
$stmt->execute(array(':usr_id' => $appbox->get_session()->get_usr_id(), ':base_id' => $base_id)); $stmt->execute(array(':usr_id' => $appbox->get_session()->get_usr_id(), ':base_id' => $base_id));
$row = $stmt->fetch(PDO::FETCH_ASSOC); $row = $stmt->fetch(PDO::FETCH_ASSOC);
$this->assertEquals(0, $row['actif']); $this->assertEquals(0, $row['actif']);
$this->assertFalse(self::$user->ACL()->has_access_to_base($base_id)); $this->assertFalse(self::$user->ACL()->has_access_to_base($base_id));
self::$user->ACL()->update_rights_to_base($base_id, array('actif' => true)); self::$user->ACL()->update_rights_to_base($base_id, array('actif' => true));
$stmt->execute(array(':usr_id' => $appbox->get_session()->get_usr_id(), ':base_id' => $base_id)); $stmt->execute(array(':usr_id' => $appbox->get_session()->get_usr_id(), ':base_id' => $base_id));
$row = $stmt->fetch(PDO::FETCH_ASSOC); $row = $stmt->fetch(PDO::FETCH_ASSOC);
$this->assertEquals(1, $row['actif']); $this->assertEquals(1, $row['actif']);
$this->assertTrue(self::$user->ACL()->has_access_to_base($base_id)); $this->assertTrue(self::$user->ACL()->has_access_to_base($base_id));
@@ -497,8 +455,7 @@ class ACLTest extends PhraseanetPHPUnitAuthenticatedAbstract
} }
self::$user->ACL()->give_access_to_base($base_ids); self::$user->ACL()->give_access_to_base($base_ids);
foreach ($bases as $base_id) foreach ($bases as $base_id) {
{
$this->assertTrue(self::$user->ACL()->has_access_to_base($base_id)); $this->assertTrue(self::$user->ACL()->has_access_to_base($base_id));
} }
$stmt->closeCursor(); $stmt->closeCursor();
@@ -507,13 +464,11 @@ class ACLTest extends PhraseanetPHPUnitAuthenticatedAbstract
public function testGet_granted_base() public function testGet_granted_base()
{ {
$appbox = appbox::get_instance(\bootstrap::getCore()); $appbox = appbox::get_instance(\bootstrap::getCore());
$base_ids = array(); $base_ids = array();
$n = 0; $n = 0;
foreach ($appbox->get_databoxes() as $databox) foreach ($appbox->get_databoxes() as $databox) {
{ foreach ($databox->get_collections() as $collection) {
foreach ($databox->get_collections() as $collection)
{
$base_ids[] = $collection->get_base_id(); $base_ids[] = $collection->get_base_id();
$n ++; $n ++;
} }
@@ -528,17 +483,13 @@ class ACLTest extends PhraseanetPHPUnitAuthenticatedAbstract
$this->assertEquals(count($bases), count($base_ids)); $this->assertEquals(count($bases), count($base_ids));
$this->assertEquals($n, count($base_ids)); $this->assertEquals($n, count($base_ids));
foreach ($bases as $base_id) foreach ($bases as $base_id) {
{ try {
try
{
$collection = collection::get_from_base_id($base_id); $collection = collection::get_from_base_id($base_id);
$this->assertTrue($collection instanceof collection); $this->assertTrue($collection instanceof collection);
$this->assertEquals($base_id, $collection->get_base_id()); $this->assertEquals($base_id, $collection->get_base_id());
unset($collection); unset($collection);
} } catch (Exception $e) {
catch (Exception $e)
{
$this->fail('get granted base should returned OK collection'); $this->fail('get granted base should returned OK collection');
} }
} }
@@ -546,11 +497,10 @@ class ACLTest extends PhraseanetPHPUnitAuthenticatedAbstract
public function testGet_granted_sbas() public function testGet_granted_sbas()
{ {
$appbox = appbox::get_instance(\bootstrap::getCore()); $appbox = appbox::get_instance(\bootstrap::getCore());
$sbas_ids = array(); $sbas_ids = array();
$n = 0; $n = 0;
foreach ($appbox->get_databoxes() as $databox) foreach ($appbox->get_databoxes() as $databox) {
{
$sbas_ids[] = $databox->get_sbas_id(); $sbas_ids[] = $databox->get_sbas_id();
$n ++; $n ++;
} }
@@ -561,16 +511,12 @@ class ACLTest extends PhraseanetPHPUnitAuthenticatedAbstract
$this->assertEquals(count($sbas), count($sbas_ids)); $this->assertEquals(count($sbas), count($sbas_ids));
$this->assertEquals($n, count($sbas_ids)); $this->assertEquals($n, count($sbas_ids));
foreach ($sbas as $sbas_id => $databox) foreach ($sbas as $sbas_id => $databox) {
{ try {
try
{
$this->assertTrue($databox instanceof databox); $this->assertTrue($databox instanceof databox);
$this->assertEquals($sbas_id, $databox->get_sbas_id()); $this->assertEquals($sbas_id, $databox->get_sbas_id());
unset($databox); unset($databox);
} } catch (Exception $e) {
catch (Exception $e)
{
$this->fail('get granted sbas should returned OK collection'); $this->fail('get granted sbas should returned OK collection');
} }
} }
@@ -580,12 +526,10 @@ class ACLTest extends PhraseanetPHPUnitAuthenticatedAbstract
{ {
$appbox = appbox::get_instance(\bootstrap::getCore()); $appbox = appbox::get_instance(\bootstrap::getCore());
foreach ($appbox->get_databoxes() as $databox) foreach ($appbox->get_databoxes() as $databox) {
{
$base_ids = array(); $base_ids = array();
foreach ($databox->get_collections() as $collection) foreach ($databox->get_collections() as $collection) {
{ $base_id = $collection->get_base_id();
$base_id = $collection->get_base_id();
$base_ids[] = $base_id; $base_ids[] = $base_id;
} }
self::$user->ACL()->revoke_access_from_bases($base_ids); self::$user->ACL()->revoke_access_from_bases($base_ids);
@@ -601,14 +545,12 @@ class ACLTest extends PhraseanetPHPUnitAuthenticatedAbstract
$this->assertFalse(self::$user->ACL()->has_access_to_module('report')); $this->assertFalse(self::$user->ACL()->has_access_to_module('report'));
$found = false; $found = false;
foreach ($appbox->get_databoxes() as $databox) foreach ($appbox->get_databoxes() as $databox) {
{ foreach ($databox->get_collections() as $collection) {
foreach ($databox->get_collections() as $collection) $base_id = $collection->get_base_id();
{
$base_id = $collection->get_base_id();
$base_ids[] = $base_id; $base_ids[] = $base_id;
self::$user->ACL()->update_rights_to_base($base_id, array('canreport' => true)); self::$user->ACL()->update_rights_to_base($base_id, array('canreport' => true));
$found = true; $found = true;
break; break;
} }
if ($found) if ($found)
@@ -618,10 +560,9 @@ class ACLTest extends PhraseanetPHPUnitAuthenticatedAbstract
$this->assertFalse(self::$user->ACL()->has_access_to_module('thesaurus')); $this->assertFalse(self::$user->ACL()->has_access_to_module('thesaurus'));
$this->assertFalse(self::$user->ACL()->has_access_to_module('upload')); $this->assertFalse(self::$user->ACL()->has_access_to_module('upload'));
foreach ($appbox->get_databoxes() as $databox) foreach ($appbox->get_databoxes() as $databox) {
{
self::$user->ACL()->update_rights_to_sbas($databox->get_sbas_id(), array('bas_modif_th' => true)); self::$user->ACL()->update_rights_to_sbas($databox->get_sbas_id(), array('bas_modif_th' => true));
$found = true; $found = true;
} }
$this->assertTrue(self::$user->ACL()->has_access_to_module('report')); $this->assertTrue(self::$user->ACL()->has_access_to_module('report'));
$this->assertTrue(self::$user->ACL()->has_access_to_module('thesaurus')); $this->assertTrue(self::$user->ACL()->has_access_to_module('thesaurus'));
@@ -629,14 +570,12 @@ class ACLTest extends PhraseanetPHPUnitAuthenticatedAbstract
$found = false; $found = false;
foreach ($appbox->get_databoxes() as $databox) foreach ($appbox->get_databoxes() as $databox) {
{ foreach ($databox->get_collections() as $collection) {
foreach ($databox->get_collections() as $collection) $base_id = $collection->get_base_id();
{
$base_id = $collection->get_base_id();
$base_ids[] = $base_id; $base_ids[] = $base_id;
self::$user->ACL()->update_rights_to_base($base_id, array('canaddrecord' => true)); self::$user->ACL()->update_rights_to_base($base_id, array('canaddrecord' => true));
$found = true; $found = true;
break; break;
} }
if ($found) if ($found)
@@ -653,10 +592,8 @@ class ACLTest extends PhraseanetPHPUnitAuthenticatedAbstract
$found = false; $found = false;
foreach ($appbox->get_databoxes() as $databox) foreach ($appbox->get_databoxes() as $databox) {
{ foreach ($databox->get_collections() as $collection) {
foreach ($databox->get_collections() as $collection)
{
$base_id = $collection->get_base_id(); $base_id = $collection->get_base_id();
if ( ! self::$user->ACL()->has_access_to_base($base_id)) if ( ! self::$user->ACL()->has_access_to_base($base_id))
@@ -702,10 +639,8 @@ class ACLTest extends PhraseanetPHPUnitAuthenticatedAbstract
$found = false; $found = false;
foreach ($appbox->get_databoxes() as $databox) foreach ($appbox->get_databoxes() as $databox) {
{ foreach ($databox->get_collections() as $collection) {
foreach ($databox->get_collections() as $collection)
{
$base_id = $collection->get_base_id(); $base_id = $collection->get_base_id();
if ( ! self::$user->ACL()->has_access_to_base($base_id)) if ( ! self::$user->ACL()->has_access_to_base($base_id))
@@ -751,5 +686,4 @@ class ACLTest extends PhraseanetPHPUnitAuthenticatedAbstract
{ {
$this->testget_limits(); $this->testget_limits();
} }
} }

View File

@@ -55,6 +55,7 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
public function tearDown() public function tearDown()
{ {
$this->unsetToken(); $this->unsetToken();
parent::tearDown();
} }
public static function setUpBeforeClass() public static function setUpBeforeClass()
@@ -91,6 +92,7 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
self::$adminAccount->delete(); self::$adminAccount->delete();
self::$adminApplication->delete(); self::$adminApplication->delete();
} }
parent::tearDownAfterClass();
} }
public function createApplication() public function createApplication()
@@ -1429,8 +1431,8 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
$this->assertTrue(is_object($record->technical_informations)); $this->assertTrue(is_object($record->technical_informations));
foreach ($record->technical_informations as $key => $value) { foreach ($record->technical_informations as $key => $value) {
if(is_string($value)) if (is_string($value))
$this->assertFalse(ctype_digit ($value)); $this->assertFalse(ctype_digit($value));
else else
$this->assertTrue(is_int($value)); $this->assertTrue(is_int($value));
} }

View File

@@ -61,6 +61,7 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
public function tearDown() public function tearDown()
{ {
$this->unsetToken(); $this->unsetToken();
parent::tearDown();
} }
public static function setUpBeforeClass() public static function setUpBeforeClass()
@@ -96,6 +97,7 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
self::$adminAccount->delete(); self::$adminAccount->delete();
self::$adminApplication->delete(); self::$adminApplication->delete();
} }
parent::tearDownAfterClass();
} }
public function createApplication() public function createApplication()

View File

@@ -7,321 +7,317 @@ use Symfony\Component\HttpFoundation\Response;
class ApplicationLightboxTest extends PhraseanetWebTestCaseAuthenticatedAbstract class ApplicationLightboxTest extends PhraseanetWebTestCaseAuthenticatedAbstract
{ {
protected $client;
protected $feed;
protected $entry;
protected $item;
protected $validation_basket;
protected static $need_records = 1;
protected $client; public function setUp()
protected $feed; {
protected $entry; parent::setUp();
protected $item; $this->client = $this->createClient();
protected $validation_basket; $appbox = appbox::get_instance(\bootstrap::getCore());
protected static $need_records = 1; $this->feed = Feed_Adapter::create($appbox, self::$user, "salut", 'coucou');
$publisher = array_shift($this->feed->get_publishers());
$this->entry = Feed_Entry_Adapter::create($appbox, $this->feed, $publisher, 'title', "sub Titkle", " jean pierre", "jp@test.com");
$this->item = Feed_Entry_Item::create($appbox, $this->entry, self::$record_1);
}
// protected static $need_subdefs = true; public function tearDown()
{
if ($this->feed instanceof Feed_Adapter)
$this->feed->delete();
parent::tearDown();
}
public function setUp() public function createApplication()
{ {
parent::setUp(); return require __DIR__ . '/../../../../lib/Alchemy/Phrasea/Application/Lightbox.php';
$this->client = $this->createClient(); }
$appbox = appbox::get_instance(\bootstrap::getCore());
$this->feed = Feed_Adapter::create($appbox, self::$user, "salut", 'coucou');
$publisher = array_shift($this->feed->get_publishers());
$this->entry = Feed_Entry_Adapter::create($appbox, $this->feed, $publisher, 'title', "sub Titkle", " jean pierre", "jp@test.com");
$this->item = Feed_Entry_Item::create($appbox, $this->entry, self::$record_1);
}
public function tearDown() public function testRouteSlash()
{ {
if($this->feed instanceof Feed_Adapter) $baskets = $this->insertFiveBasket();
$this->feed->delete();
parent::tearDown();
}
public function createApplication() $this->set_user_agent(self::USER_AGENT_FIREFOX8MAC);
{
return require __DIR__ . '/../../../../lib/Alchemy/Phrasea/Application/Lightbox.php';
}
public function testRouteSlash() $crawler = $this->client->request('GET', '/');
{ $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$baskets = $this->insertFiveBasket(); $this->assertEquals('UTF-8', $this->client->getResponse()->getCharset());
$this->assertEquals(5, $crawler->filter('div.basket_wrapper')->count());
$this->set_user_agent(self::USER_AGENT_FIREFOX8MAC); $this->set_user_agent(self::USER_AGENT_IE6);
$crawler = $this->client->request('GET', '/'); $crawler = $this->client->request('GET', '/');
$this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$this->assertEquals('UTF-8', $this->client->getResponse()->getCharset()); $this->assertEquals('UTF-8', $this->client->getResponse()->getCharset());
$this->assertEquals(5, $crawler->filter('div.basket_wrapper')->count()); $this->assertEquals($crawler->filter('div.basket_wrapper')->count(), count($baskets));
$this->set_user_agent(self::USER_AGENT_IE6); $this->set_user_agent(self::USER_AGENT_IPHONE);
$crawler = $this->client->request('GET', '/'); $crawler = $this->client->request('GET', '/');
$this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$this->assertEquals('UTF-8', $this->client->getResponse()->getCharset()); $this->assertEquals('UTF-8', $this->client->getResponse()->getCharset());
$this->assertEquals($crawler->filter('div.basket_wrapper')->count(), count($baskets)); }
$this->set_user_agent(self::USER_AGENT_IPHONE); public function testAjaxNoteForm()
{
$basket = $this->insertOneValidationBasket();
$basket_element = $basket->getELements()->first();
$crawler = $this->client->request('GET', '/'); $this->set_user_agent(self::USER_AGENT_FIREFOX8MAC);
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$this->assertEquals('UTF-8', $this->client->getResponse()->getCharset());
}
public function testAjaxNoteForm() $crawler = $this->client->request('GET', '/ajax/NOTE_FORM/' . $basket_element->getId() . '/');
{ $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$basket = $this->insertOneValidationBasket(); $this->assertEquals('', trim($this->client->getResponse()->getContent()));
$basket_element = $basket->getELements()->first();
$this->set_user_agent(self::USER_AGENT_FIREFOX8MAC); $this->set_user_agent(self::USER_AGENT_IE6);
$crawler = $this->client->request('GET', '/ajax/NOTE_FORM/' . $basket_element->getId() . '/'); $crawler = $this->client->request('GET', '/ajax/NOTE_FORM/' . $basket_element->getId() . '/');
$this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$this->assertEquals('', trim($this->client->getResponse()->getContent())); $this->assertEquals('', trim($this->client->getResponse()->getContent()));
$this->set_user_agent(self::USER_AGENT_IE6); $this->set_user_agent(self::USER_AGENT_IPHONE);
$crawler = $this->client->request('GET', '/ajax/NOTE_FORM/' . $basket_element->getId() . '/'); $crawler = $this->client->request('GET', '/ajax/NOTE_FORM/' . $basket_element->getId() . '/');
$this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$this->assertEquals('', trim($this->client->getResponse()->getContent())); $this->assertNotEquals('', trim($this->client->getResponse()->getContent()));
}
$this->set_user_agent(self::USER_AGENT_IPHONE); public function testAjaxElement()
{
$basket_element = $this->insertOneBasketElement();
$crawler = $this->client->request('GET', '/ajax/NOTE_FORM/' . $basket_element->getId() . '/'); $this->set_user_agent(self::USER_AGENT_FIREFOX8MAC);
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$this->assertNotEquals('', trim($this->client->getResponse()->getContent()));
}
public function testAjaxElement() $crawler = $this->client->request('GET', '/ajax/LOAD_BASKET_ELEMENT/' . $basket_element->getId() . '/');
{ $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$basket_element = $this->insertOneBasketElement(); $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-type'));
$datas = json_decode($this->client->getResponse()->getContent());
$this->set_user_agent(self::USER_AGENT_FIREFOX8MAC); $this->assertObjectHasAttribute('number', $datas);
$this->assertObjectHasAttribute('title', $datas);
$this->assertObjectHasAttribute('preview', $datas);
$this->assertObjectHasAttribute('options_html', $datas);
$this->assertObjectHasAttribute('agreement_html', $datas);
$this->assertObjectHasAttribute('selector_html', $datas);
$this->assertObjectHasAttribute('note_html', $datas);
$this->assertObjectHasAttribute('caption', $datas);
$crawler = $this->client->request('GET', '/ajax/LOAD_BASKET_ELEMENT/' . $basket_element->getId() . '/'); $this->set_user_agent(self::USER_AGENT_IE6);
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-type'));
$datas = json_decode($this->client->getResponse()->getContent());
$this->assertObjectHasAttribute('number', $datas); $crawler = $this->client->request('GET', '/ajax/LOAD_BASKET_ELEMENT/' . $basket_element->getId() . '/');
$this->assertObjectHasAttribute('title', $datas); $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$this->assertObjectHasAttribute('preview', $datas); $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-type'));
$this->assertObjectHasAttribute('options_html', $datas); $datas = json_decode($this->client->getResponse()->getContent());
$this->assertObjectHasAttribute('agreement_html', $datas);
$this->assertObjectHasAttribute('selector_html', $datas);
$this->assertObjectHasAttribute('note_html', $datas);
$this->assertObjectHasAttribute('caption', $datas);
$this->set_user_agent(self::USER_AGENT_IE6); $this->assertObjectHasAttribute('number', $datas);
$this->assertObjectHasAttribute('title', $datas);
$this->assertObjectHasAttribute('preview', $datas);
$this->assertObjectHasAttribute('options_html', $datas);
$this->assertObjectHasAttribute('agreement_html', $datas);
$this->assertObjectHasAttribute('selector_html', $datas);
$this->assertObjectHasAttribute('note_html', $datas);
$this->assertObjectHasAttribute('caption', $datas);
$crawler = $this->client->request('GET', '/ajax/LOAD_BASKET_ELEMENT/' . $basket_element->getId() . '/'); $this->set_user_agent(self::USER_AGENT_IPHONE);
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-type'));
$datas = json_decode($this->client->getResponse()->getContent());
$this->assertObjectHasAttribute('number', $datas); $crawler = $this->client->request('GET', '/ajax/LOAD_BASKET_ELEMENT/' . $basket_element->getId() . '/');
$this->assertObjectHasAttribute('title', $datas); $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$this->assertObjectHasAttribute('preview', $datas); $this->assertNotEquals('application/json', $this->client->getResponse()->headers->get('Content-type'));
$this->assertObjectHasAttribute('options_html', $datas); }
$this->assertObjectHasAttribute('agreement_html', $datas);
$this->assertObjectHasAttribute('selector_html', $datas);
$this->assertObjectHasAttribute('note_html', $datas);
$this->assertObjectHasAttribute('caption', $datas);
$this->set_user_agent(self::USER_AGENT_IPHONE); public function testAjaxFeedItem()
{
$this->set_user_agent(self::USER_AGENT_FIREFOX8MAC);
$crawler = $this->client->request('GET', '/ajax/LOAD_BASKET_ELEMENT/' . $basket_element->getId() . '/'); $crawler = $this->client->request('GET', '/ajax/LOAD_FEED_ITEM/' . $this->entry->get_id() . '/' . $this->item->get_id() . '/');
$this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$this->assertNotEquals('application/json', $this->client->getResponse()->headers->get('Content-type')); $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-type'));
} $datas = json_decode($this->client->getResponse()->getContent());
public function testAjaxFeedItem() $this->assertObjectHasAttribute('number', $datas);
{ $this->assertObjectHasAttribute('title', $datas);
$this->set_user_agent(self::USER_AGENT_FIREFOX8MAC); $this->assertObjectHasAttribute('preview', $datas);
$this->assertObjectHasAttribute('options_html', $datas);
$this->assertObjectHasAttribute('agreement_html', $datas);
$this->assertObjectHasAttribute('selector_html', $datas);
$this->assertObjectHasAttribute('note_html', $datas);
$this->assertObjectHasAttribute('caption', $datas);
$crawler = $this->client->request('GET', '/ajax/LOAD_FEED_ITEM/' . $this->entry->get_id() . '/' . $this->item->get_id() . '/'); $this->set_user_agent(self::USER_AGENT_IE6);
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-type'));
$datas = json_decode($this->client->getResponse()->getContent());
$this->assertObjectHasAttribute('number', $datas); $crawler = $this->client->request('GET', '/ajax/LOAD_FEED_ITEM/' . $this->entry->get_id() . '/' . $this->item->get_id() . '/');
$this->assertObjectHasAttribute('title', $datas); $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$this->assertObjectHasAttribute('preview', $datas); $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-type'));
$this->assertObjectHasAttribute('options_html', $datas); $datas = json_decode($this->client->getResponse()->getContent());
$this->assertObjectHasAttribute('agreement_html', $datas);
$this->assertObjectHasAttribute('selector_html', $datas);
$this->assertObjectHasAttribute('note_html', $datas);
$this->assertObjectHasAttribute('caption', $datas);
$this->set_user_agent(self::USER_AGENT_IE6); $this->assertObjectHasAttribute('number', $datas);
$this->assertObjectHasAttribute('title', $datas);
$this->assertObjectHasAttribute('preview', $datas);
$this->assertObjectHasAttribute('options_html', $datas);
$this->assertObjectHasAttribute('agreement_html', $datas);
$this->assertObjectHasAttribute('selector_html', $datas);
$this->assertObjectHasAttribute('note_html', $datas);
$this->assertObjectHasAttribute('caption', $datas);
$crawler = $this->client->request('GET', '/ajax/LOAD_FEED_ITEM/' . $this->entry->get_id() . '/' . $this->item->get_id() . '/'); $this->set_user_agent(self::USER_AGENT_IPHONE);
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-type'));
$datas = json_decode($this->client->getResponse()->getContent());
$this->assertObjectHasAttribute('number', $datas); $crawler = $this->client->request('GET', '/ajax/LOAD_FEED_ITEM/' . $this->entry->get_id() . '/' . $this->item->get_id() . '/');
$this->assertObjectHasAttribute('title', $datas); $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$this->assertObjectHasAttribute('preview', $datas); $this->assertNotEquals('application/json', $this->client->getResponse()->headers->get('Content-type'));
$this->assertObjectHasAttribute('options_html', $datas); }
$this->assertObjectHasAttribute('agreement_html', $datas);
$this->assertObjectHasAttribute('selector_html', $datas);
$this->assertObjectHasAttribute('note_html', $datas);
$this->assertObjectHasAttribute('caption', $datas);
$this->set_user_agent(self::USER_AGENT_IPHONE); public function testValidate()
{
$crawler = $this->client->request('GET', '/ajax/LOAD_FEED_ITEM/' . $this->entry->get_id() . '/' . $this->item->get_id() . '/'); $basket = $this->insertOneValidationBasket();
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$this->assertNotEquals('application/json', $this->client->getResponse()->headers->get('Content-type'));
}
public function testValidate() $this->set_user_agent(self::USER_AGENT_FIREFOX8MAC);
{
$basket = $this->insertOneValidationBasket(); $crawler = $this->client->request('GET', '/validate/' . $basket->getId() . '/');
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$this->assertEquals('UTF-8', $this->client->getResponse()->getCharset());
$this->set_user_agent(self::USER_AGENT_FIREFOX8MAC); $this->set_user_agent(self::USER_AGENT_IE6);
$crawler = $this->client->request('GET', '/validate/' . $basket->getId() . '/'); $crawler = $this->client->request('GET', '/validate/' . $basket->getId() . '/');
$this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$this->assertEquals('UTF-8', $this->client->getResponse()->getCharset()); $this->assertEquals('UTF-8', $this->client->getResponse()->getCharset());
$this->set_user_agent(self::USER_AGENT_IE6); $this->set_user_agent(self::USER_AGENT_IPHONE);
$crawler = $this->client->request('GET', '/validate/' . $basket->getId() . '/'); $crawler = $this->client->request('GET', '/validate/' . $basket->getId() . '/');
$this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$this->assertEquals('UTF-8', $this->client->getResponse()->getCharset()); $this->assertEquals('UTF-8', $this->client->getResponse()->getCharset());
}
$this->set_user_agent(self::USER_AGENT_IPHONE); public function testCompare()
{
$basket = $this->insertOneBasket();
$crawler = $this->client->request('GET', '/validate/' . $basket->getId() . '/'); $this->set_user_agent(self::USER_AGENT_FIREFOX8MAC);
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$this->assertEquals('UTF-8', $this->client->getResponse()->getCharset());
}
public function testCompare() $crawler = $this->client->request('GET', '/compare/' . $basket->getId() . '/');
{ $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$basket = $this->insertOneBasket(); $this->assertEquals('UTF-8', $this->client->getResponse()->getCharset());
$this->set_user_agent(self::USER_AGENT_FIREFOX8MAC); $this->set_user_agent(self::USER_AGENT_IE6);
$crawler = $this->client->request('GET', '/compare/' . $basket->getId() . '/'); $crawler = $this->client->request('GET', '/compare/' . $basket->getId() . '/');
$this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$this->assertEquals('UTF-8', $this->client->getResponse()->getCharset()); $this->assertEquals('UTF-8', $this->client->getResponse()->getCharset());
$this->set_user_agent(self::USER_AGENT_IE6); $this->set_user_agent(self::USER_AGENT_IPHONE);
$crawler = $this->client->request('GET', '/compare/' . $basket->getId() . '/'); $crawler = $this->client->request('GET', '/compare/' . $basket->getId() . '/');
$this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$this->assertEquals('UTF-8', $this->client->getResponse()->getCharset()); $this->assertEquals('UTF-8', $this->client->getResponse()->getCharset());
}
$this->set_user_agent(self::USER_AGENT_IPHONE); public function testFeedEntry()
{
$this->set_user_agent(self::USER_AGENT_FIREFOX8MAC);
$crawler = $this->client->request('GET', '/compare/' . $basket->getId() . '/'); $crawler = $this->client->request('GET', '/feeds/entry/' . $this->entry->get_id() . '/');
$this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$this->assertEquals('UTF-8', $this->client->getResponse()->getCharset()); $this->assertEquals('UTF-8', $this->client->getResponse()->getCharset());
}
public function testFeedEntry() $this->set_user_agent(self::USER_AGENT_IE6);
{
$this->set_user_agent(self::USER_AGENT_FIREFOX8MAC);
$crawler = $this->client->request('GET', '/feeds/entry/' . $this->entry->get_id() . '/'); $crawler = $this->client->request('GET', '/feeds/entry/' . $this->entry->get_id() . '/');
$this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$this->assertEquals('UTF-8', $this->client->getResponse()->getCharset()); $this->assertEquals('UTF-8', $this->client->getResponse()->getCharset());
$this->set_user_agent(self::USER_AGENT_IE6); $this->set_user_agent(self::USER_AGENT_IPHONE);
$crawler = $this->client->request('GET', '/feeds/entry/' . $this->entry->get_id() . '/'); $crawler = $this->client->request('GET', '/feeds/entry/' . $this->entry->get_id() . '/');
$this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$this->assertEquals('UTF-8', $this->client->getResponse()->getCharset()); $this->assertEquals('UTF-8', $this->client->getResponse()->getCharset());
}
$this->set_user_agent(self::USER_AGENT_IPHONE); public function testAjaxReport()
{
$validationBasket = $this->insertOneValidationBasket();
$crawler = $this->client->request('GET', '/feeds/entry/' . $this->entry->get_id() . '/'); $this->set_user_agent(self::USER_AGENT_FIREFOX8MAC);
$this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $crawler = $this->client->request('GET', '/ajax/LOAD_REPORT/' . $validationBasket->getId() . '/');
$this->assertEquals('UTF-8', $this->client->getResponse()->getCharset()); $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
} $this->assertEquals('UTF-8', $this->client->getResponse()->getCharset());
}
public function testAjaxReport() public function testAjaxSetNote()
{ {
$validationBasket = $this->insertOneValidationBasket(); $validationBasket = $this->insertOneValidationBasket();
$validationBasketElement = $validationBasket->getElements()->first();
$this->set_user_agent(self::USER_AGENT_FIREFOX8MAC); $crawler = $this->client->request('POST', '/ajax/SET_NOTE/' . $validationBasketElement->getId() . '/');
$crawler = $this->client->request('GET', '/ajax/LOAD_REPORT/' . $validationBasket->getId() . '/'); $this->assertEquals(400, $this->client->getResponse()->getStatusCode());
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$this->assertEquals('UTF-8', $this->client->getResponse()->getCharset());
}
public function testAjaxSetNote() $crawler = $this->client->request(
{
$validationBasket = $this->insertOneValidationBasket();
$validationBasketElement = $validationBasket->getElements()->first();
$crawler = $this->client->request('POST', '/ajax/SET_NOTE/' . $validationBasketElement->getId() . '/');
$this->assertEquals(400, $this->client->getResponse()->getStatusCode());
$crawler = $this->client->request(
'POST' 'POST'
, '/ajax/SET_NOTE/' . $validationBasketElement->getId() . '/' , '/ajax/SET_NOTE/' . $validationBasketElement->getId() . '/'
, array('note' => 'une jolie note') , array('note' => 'une jolie note')
); );
$this->assertEquals(200, $this->client->getResponse()->getStatusCode(), sprintf('set note to element %s ', $validationBasketElement->getId())); $this->assertEquals(200, $this->client->getResponse()->getStatusCode(), sprintf('set note to element %s ', $validationBasketElement->getId()));
$this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-type')); $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-type'));
$datas = json_decode($this->client->getResponse()->getContent()); $datas = json_decode($this->client->getResponse()->getContent());
$this->assertTrue(is_object($datas), 'asserting good json datas'); $this->assertTrue(is_object($datas), 'asserting good json datas');
$this->assertObjectHasAttribute('datas', $datas); $this->assertObjectHasAttribute('datas', $datas);
$this->assertObjectHasAttribute('error', $datas); $this->assertObjectHasAttribute('error', $datas);
} }
public function testAjaxSetAgreement() public function testAjaxSetAgreement()
{ {
$validationBasket = $this->insertOneValidationBasket(); $validationBasket = $this->insertOneValidationBasket();
$validationBasketElement = $validationBasket->getElements()->first(); $validationBasketElement = $validationBasket->getElements()->first();
$crawler = $this->client->request( $crawler = $this->client->request(
'POST' 'POST'
, '/ajax/SET_ELEMENT_AGREEMENT/' . $validationBasketElement->getId() . '/' , '/ajax/SET_ELEMENT_AGREEMENT/' . $validationBasketElement->getId() . '/'
); );
$this->assertEquals(400, $this->client->getResponse()->getStatusCode()); $this->assertEquals(400, $this->client->getResponse()->getStatusCode());
$crawler = $this->client->request( $crawler = $this->client->request(
'POST' 'POST'
, '/ajax/SET_ELEMENT_AGREEMENT/' . $validationBasketElement->getId() . '/' , '/ajax/SET_ELEMENT_AGREEMENT/' . $validationBasketElement->getId() . '/'
, array('agreement' => 1) , array('agreement' => 1)
); );
$this->assertEquals(200, $this->client->getResponse()->getStatusCode(), sprintf('set note to element %s ', $validationBasketElement->getId())); $this->assertEquals(200, $this->client->getResponse()->getStatusCode(), sprintf('set note to element %s ', $validationBasketElement->getId()));
$this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-type')); $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-type'));
$datas = json_decode($this->client->getResponse()->getContent()); $datas = json_decode($this->client->getResponse()->getContent());
$this->assertTrue(is_object($datas), 'asserting good json datas'); $this->assertTrue(is_object($datas), 'asserting good json datas');
$this->assertObjectHasAttribute('datas', $datas); $this->assertObjectHasAttribute('datas', $datas);
$this->assertObjectHasAttribute('error', $datas); $this->assertObjectHasAttribute('error', $datas);
} }
public function testAjaxSetRelease() public function testAjaxSetRelease()
{ {
$basket = $this->insertOneBasket(); $basket = $this->insertOneBasket();
$crawler = $this->client->request('POST', '/ajax/SET_RELEASE/' . $basket->getId() . '/'); $crawler = $this->client->request('POST', '/ajax/SET_RELEASE/' . $basket->getId() . '/');
$this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-type')); $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-type'));
$datas = json_decode($this->client->getResponse()->getContent()); $datas = json_decode($this->client->getResponse()->getContent());
$this->assertTrue(is_object($datas), 'asserting good json datas'); $this->assertTrue(is_object($datas), 'asserting good json datas');
$this->assertTrue($datas->error); $this->assertTrue($datas->error);
$validationBasket = $this->insertOneValidationBasket(); $validationBasket = $this->insertOneValidationBasket();
$crawler = $this->client->request('POST', '/ajax/SET_RELEASE/' . $validationBasket->getId() . '/'); $crawler = $this->client->request('POST', '/ajax/SET_RELEASE/' . $validationBasket->getId() . '/');
$this->assertEquals(200, $this->client->getResponse()->getStatusCode(), sprintf('set note to element %s ', $validationBasket->getId())); $this->assertEquals(200, $this->client->getResponse()->getStatusCode(), sprintf('set note to element %s ', $validationBasket->getId()));
$this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-type')); $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-type'));
$datas = json_decode($this->client->getResponse()->getContent());
$this->assertTrue(is_object($datas), 'asserting good json datas');
$this->assertObjectHasAttribute('datas', $datas);
$this->assertObjectHasAttribute('error', $datas);
}
$datas = json_decode($this->client->getResponse()->getContent());
$this->assertTrue(is_object($datas), 'asserting good json datas');
$this->assertObjectHasAttribute('datas', $datas);
$this->assertObjectHasAttribute('error', $datas);
}
} }

View File

@@ -9,153 +9,138 @@ use Silex\WebTestCase;
* Test oauthv2 flow based on ietf authv2 spec * Test oauthv2 flow based on ietf authv2 spec
* @link http://tools.ietf.org/html/draft-ietf-oauth-v2-18 * @link http://tools.ietf.org/html/draft-ietf-oauth-v2-18
*/ */
/**
*
*
*/
class oauthv2_application_test extends \PhraseanetWebTestCaseAuthenticatedAbstract class oauthv2_application_test extends \PhraseanetWebTestCaseAuthenticatedAbstract
{ {
/** /**
* *
* @var API_OAuth2_Application * @var API_OAuth2_Application
*/ */
public static $appli; public static $appli;
public static $account_id; public static $account_id;
public static $account; public static $account;
public $oauth; public $oauth;
protected $client; protected $client;
protected $queryParameters; protected $queryParameters;
public static function setUpBeforeClass() public static function setUpBeforeClass()
{ {
parent::setUpBeforeClass(); parent::setUpBeforeClass();
$parameters = array(
'type' => 'web'
, 'name' => 'test'
, 'description' => 'une description'
, 'callback' => 'http://callback.com/callback/'
, 'website' => 'http://website.com/'
);
self::$appli = API_OAuth2_Application::create(appbox::get_instance(\bootstrap::getCore()), self::$user, 'test'); self::$appli = API_OAuth2_Application::create(appbox::get_instance(\bootstrap::getCore()), self::$user, 'test');
self::$appli->set_description('une description') self::$appli->set_description('une description')
->set_redirect_uri('http://callback.com/callback/') ->set_redirect_uri('http://callback.com/callback/')
->set_website('http://website.com/') ->set_website('http://website.com/')
->set_type(API_OAuth2_Application::WEB_TYPE); ->set_type(API_OAuth2_Application::WEB_TYPE);
}
public static function tearDownAfterClass()
{
if (self::$appli !== false) {
self::deleteInsertedRow(appbox::get_instance(\bootstrap::getCore()), self::$appli);
}
parent::tearDownAfterClass();
}
} public function setUp()
{
parent::setUp();
$this->client = $this->createClient();
public static function tearDownAfterClass() $this->queryParameters = array(
{ "response_type" => "code",
parent::tearDownAfterClass(); "client_id" => self::$appli->get_client_id(),
if (self::$appli !== false) "redirect_uri" => self::$appli->get_redirect_uri(),
self::deleteInsertedRow(appbox::get_instance(\bootstrap::getCore()), self::$appli); "scope" => "",
} "state" => "valueTest"
);
}
public function setUp() public static function deleteInsertedRow(appbox $appbox, API_OAuth2_Application $app)
{ {
parent::setUp(); $conn = $appbox->get_connection();
$this->client = $this->createClient(); $sql = '
$this->queryParameters = array(
"response_type" => "code",
"client_id" => self::$appli->get_client_id(),
"redirect_uri" => self::$appli->get_redirect_uri(),
"scope" => "",
"state" => "valueTest"
);
}
public static function deleteInsertedRow(appbox $appbox, API_OAuth2_Application $app)
{
$conn = $appbox->get_connection();
$sql = '
DELETE FROM api_applications DELETE FROM api_applications
WHERE application_id = :id WHERE application_id = :id
'; ';
$t = array(':id' => $app->get_id()); $t = array(':id' => $app->get_id());
$stmt = $conn->prepare($sql); $stmt = $conn->prepare($sql);
$stmt->execute($t); $stmt->execute($t);
$sql = ' $sql = '
DELETE FROM api_accounts DELETE FROM api_accounts
WHERE api_account_id = :id WHERE api_account_id = :id
'; ';
$acc = self::getAccount(); $acc = self::getAccount();
$t = array(':id' => $acc->get_id()); $t = array(':id' => $acc->get_id());
$stmt = $conn->prepare($sql); $stmt = $conn->prepare($sql);
$stmt->execute($t); $stmt->execute($t);
} }
public static function getApp($rowId) public static function getApp($rowId)
{ {
$sql = "SELECT * FROM api_applications WHERE application_id = :app_id"; $sql = "SELECT * FROM api_applications WHERE application_id = :app_id";
$t = array(":app_id" => $rowId); $t = array(":app_id" => $rowId);
$appbox = appbox::get_instance(\bootstrap::getCore()); $appbox = appbox::get_instance(\bootstrap::getCore());
$conn = $appbox->get_connection(); $conn = $appbox->get_connection();
$stmt = $conn->prepare($sql); $stmt = $conn->prepare($sql);
$stmt->execute($t); $stmt->execute($t);
$result = $stmt->fetch(PDO::FETCH_ASSOC); $result = $stmt->fetch(PDO::FETCH_ASSOC);
return $result; return $result;
} }
public static function getAccount() public static function getAccount()
{
$sql = "SELECT api_account_id FROM api_accounts WHERE application_id = :app_id AND usr_id = :usr_id";
$t = array(":app_id" => self::$appli->get_id(), ":usr_id" => self::$user->get_id());
$appbox = appbox::get_instance(\bootstrap::getCore());
$conn = $appbox->get_connection();
$stmt = $conn->prepare($sql);
$stmt->execute($t);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
return new API_OAuth2_Account(appbox::get_instance(\bootstrap::getCore()), $row["api_account_id"]);
}
public function setQueryParameters($parameter, $value)
{
$this->queryParameters[$parameter] = $value;
}
public function unsetQueryParameter($parameter)
{
if (isset($this->queryParameters[$parameter]))
unset($this->queryParameters[$parameter]);
}
public function createApplication()
{
return require __DIR__ . '/../../../../lib/Alchemy/Phrasea/Application/OAuth2.php';
}
public function testAuthorizeRedirect()
{
//session off
$apps = API_OAuth2_Application::load_authorized_app_by_user(appbox::get_instance(\bootstrap::getCore()), self::$user);
foreach($apps as $app)
{ {
if($app->get_client_id() == self::$appli->get_client_id()) $sql = "SELECT api_account_id FROM api_accounts WHERE application_id = :app_id AND usr_id = :usr_id";
{ $t = array(":app_id" => self::$appli->get_id(), ":usr_id" => self::$user->get_id());
$authorize = true; $appbox = appbox::get_instance(\bootstrap::getCore());
$conn = $appbox->get_connection();
$stmt = $conn->prepare($sql);
$stmt->execute($t);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$this->client->followRedirects(); return new API_OAuth2_Account(appbox::get_instance(\bootstrap::getCore()), $row["api_account_id"]);
}
} }
}
public function testAuthorize() public function setQueryParameters($parameter, $value)
{ {
$acc = self::getAccount(); $this->queryParameters[$parameter] = $value;
$acc->set_revoked(true); // revoked to show form }
$crawler = $this->client->request('GET', '/authorize', $this->queryParameters); public function unsetQueryParameter($parameter)
$this->assertTrue($this->client->getResponse()->isSuccessful()); {
$this->assertRegExp("/" . self::$appli->get_client_id() . "/", $this->client->getResponse()->getContent()); if (isset($this->queryParameters[$parameter]))
$this->assertRegExp("/" . str_replace("/", '\/', self::$appli->get_redirect_uri()) . "/", $this->client->getResponse()->getContent()); unset($this->queryParameters[$parameter]);
$this->assertRegExp("/" . $this->queryParameters["response_type"] . "/", $this->client->getResponse()->getContent()); }
$this->assertRegExp("/" . $this->queryParameters["scope"] . "/", $this->client->getResponse()->getContent());
$this->assertRegExp("/" . $this->queryParameters["state"] . "/", $this->client->getResponse()->getContent()); public function createApplication()
} {
return require __DIR__ . '/../../../../lib/Alchemy/Phrasea/Application/OAuth2.php';
}
public function testAuthorizeRedirect()
{
//session off
$apps = API_OAuth2_Application::load_authorized_app_by_user(appbox::get_instance(\bootstrap::getCore()), self::$user);
foreach ($apps as $app) {
if ($app->get_client_id() == self::$appli->get_client_id()) {
$authorize = true;
$this->client->followRedirects();
}
}
}
public function testAuthorize()
{
$acc = self::getAccount();
$acc->set_revoked(true); // revoked to show form
$crawler = $this->client->request('GET', '/authorize', $this->queryParameters);
$this->assertTrue($this->client->getResponse()->isSuccessful());
$this->assertRegExp("/" . self::$appli->get_client_id() . "/", $this->client->getResponse()->getContent());
$this->assertRegExp("/" . str_replace("/", '\/', self::$appli->get_redirect_uri()) . "/", $this->client->getResponse()->getContent());
$this->assertRegExp("/" . $this->queryParameters["response_type"] . "/", $this->client->getResponse()->getContent());
$this->assertRegExp("/" . $this->queryParameters["scope"] . "/", $this->client->getResponse()->getContent());
$this->assertRegExp("/" . $this->queryParameters["state"] . "/", $this->client->getResponse()->getContent());
}
} }

View File

@@ -1,20 +1,5 @@
<?php <?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
*/
require_once __DIR__ . '/../../../PhraseanetWebTestCaseAuthenticatedAbstract.class.inc'; require_once __DIR__ . '/../../../PhraseanetWebTestCaseAuthenticatedAbstract.class.inc';
use Silex\WebTestCase; use Silex\WebTestCase;
@@ -23,109 +8,91 @@ use Symfony\Component\HttpFoundation\Response;
class ApplicationOverviewTest extends PhraseanetWebTestCaseAuthenticatedAbstract class ApplicationOverviewTest extends PhraseanetWebTestCaseAuthenticatedAbstract
{ {
protected static $need_records = 1;
protected static $need_subdefs = true;
protected static $need_records = 1; public function setUp()
protected static $need_subdefs = true;
public function setUp()
{
parent::setUp();
$this->client = $this->createClient();
}
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
}
public static function tearDownAfterClass()
{
parent::tearDownAfterClass();
}
public function createApplication()
{
return require __DIR__ . '/../../../../lib/Alchemy/Phrasea/Application/Overview.php';
}
function testDatafilesRouteAuthenticated()
{
$registry = registry::get_instance();
$crawler = $this->client->request('GET', '/datafiles/' . self::$record_1->get_sbas_id() . '/' . self::$record_1->get_record_id() . '/preview/');
$response = $this->client->getResponse();
if (self::$record_1->get_preview()->get_baseurl() !== '')
{ {
$this->assertEquals(302, $response->getStatusCode()); parent::setUp();
$url = p4string::delEndSlash($registry->get('GV_ServerName')) . $response->headers->get('Location'); $this->client = $this->createClient();
$headers = http_query::getHttpHeaders($url);
$this->assertEquals(self::$record_1->get_preview()->get_mime(), $headers['content_type']);
$this->assertEquals(self::$record_1->get_preview()->get_size(), $headers['download_content_length']);
}
else
{
$this->assertEquals(200, $response->getStatusCode());
$content_disposition = explode(';', $response->headers->get('content-disposition'));
$this->assertEquals($content_disposition[0], 'attachment');
$this->assertEquals(self::$record_1->get_preview()->get_mime(), $response->headers->get('content-type'));
$this->assertEquals(self::$record_1->get_preview()->get_size(), $response->headers->get('content-length'));
} }
$crawler = $this->client->request('GET', '/datafiles/' . self::$record_1->get_sbas_id() . '/' . self::$record_1->get_record_id() . '/asubdefthatdoesnotexists/'); public function createApplication()
$response = $this->client->getResponse();
$this->assertEquals(404, $response->getStatusCode());
}
function testDatafilesRouteNotAuthenticated()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$appbox->get_session()->logout();
$crawler = $this->client->request('GET', '/datafiles/' . self::$record_1->get_sbas_id() . '/' . self::$record_1->get_record_id() . '/preview/');
$response = $this->client->getResponse();
$this->assertEquals(403, $response->getStatusCode());
$crawler = $this->client->request('GET', '/datafiles/' . self::$record_1->get_sbas_id() . '/' . self::$record_1->get_record_id() . '/notfoundreview/');
$response = $this->client->getResponse();
$this->assertEquals(403, $response->getStatusCode());
}
function testPermalinkAuthenticated()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$this->assertTrue($appbox->get_session()->is_authenticated());
$this->get_a_permalink();
}
function testPermalinkNotAuthenticated()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$appbox->get_session()->logout();
$this->assertFalse($appbox->get_session()->is_authenticated());
$this->get_a_permalink();
}
protected function get_a_permalink()
{
$token = self::$record_1->get_preview()->get_permalink()->get_token();
$url = '/permalink/v1/whateverIwannt/' . self::$record_1->get_sbas_id() . '/' . self::$record_1->get_record_id() . '/' . $token . '/preview/';
$crawler = $this->client->request('GET', $url);
$response = $this->client->getResponse();
if (self::$record_1->get_preview()->get_baseurl() !== '')
{ {
$this->assertEquals(302, $response->getStatusCode()); return require __DIR__ . '/../../../../lib/Alchemy/Phrasea/Application/Overview.php';
}
else
{
$this->assertEquals(200, $response->getStatusCode());
} }
$url = $url . 'view/'; function testDatafilesRouteAuthenticated()
$crawler = $this->client->request('GET', $url); {
$response = $this->client->getResponse(); $registry = registry::get_instance();
$this->assertEquals(200, $response->getStatusCode()); $crawler = $this->client->request('GET', '/datafiles/' . self::$record_1->get_sbas_id() . '/' . self::$record_1->get_record_id() . '/preview/');
} $response = $this->client->getResponse();
if (self::$record_1->get_preview()->get_baseurl() !== '') {
$this->assertEquals(302, $response->getStatusCode());
$url = p4string::delEndSlash($registry->get('GV_ServerName')) . $response->headers->get('Location');
$headers = http_query::getHttpHeaders($url);
$this->assertEquals(self::$record_1->get_preview()->get_mime(), $headers['content_type']);
$this->assertEquals(self::$record_1->get_preview()->get_size(), $headers['download_content_length']);
} else {
$this->assertEquals(200, $response->getStatusCode());
$content_disposition = explode(';', $response->headers->get('content-disposition'));
$this->assertEquals($content_disposition[0], 'attachment');
$this->assertEquals(self::$record_1->get_preview()->get_mime(), $response->headers->get('content-type'));
$this->assertEquals(self::$record_1->get_preview()->get_size(), $response->headers->get('content-length'));
}
$crawler = $this->client->request('GET', '/datafiles/' . self::$record_1->get_sbas_id() . '/' . self::$record_1->get_record_id() . '/asubdefthatdoesnotexists/');
$response = $this->client->getResponse();
$this->assertEquals(404, $response->getStatusCode());
}
function testDatafilesRouteNotAuthenticated()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$appbox->get_session()->logout();
$crawler = $this->client->request('GET', '/datafiles/' . self::$record_1->get_sbas_id() . '/' . self::$record_1->get_record_id() . '/preview/');
$response = $this->client->getResponse();
$this->assertEquals(403, $response->getStatusCode());
$crawler = $this->client->request('GET', '/datafiles/' . self::$record_1->get_sbas_id() . '/' . self::$record_1->get_record_id() . '/notfoundreview/');
$response = $this->client->getResponse();
$this->assertEquals(403, $response->getStatusCode());
}
function testPermalinkAuthenticated()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$this->assertTrue($appbox->get_session()->is_authenticated());
$this->get_a_permalink();
}
function testPermalinkNotAuthenticated()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$appbox->get_session()->logout();
$this->assertFalse($appbox->get_session()->is_authenticated());
$this->get_a_permalink();
}
protected function get_a_permalink()
{
$token = self::$record_1->get_preview()->get_permalink()->get_token();
$url = '/permalink/v1/whateverIwannt/' . self::$record_1->get_sbas_id() . '/' . self::$record_1->get_record_id() . '/' . $token . '/preview/';
$crawler = $this->client->request('GET', $url);
$response = $this->client->getResponse();
if (self::$record_1->get_preview()->get_baseurl() !== '') {
$this->assertEquals(302, $response->getStatusCode());
} else {
$this->assertEquals(200, $response->getStatusCode());
}
$url = $url . 'view/';
$crawler = $this->client->request('GET', $url);
$response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode());
}
} }

View File

@@ -7,57 +7,55 @@ use Symfony\Component\HttpFoundation\Response;
class ApplicationRootTest extends PhraseanetWebTestCaseAuthenticatedAbstract class ApplicationRootTest extends PhraseanetWebTestCaseAuthenticatedAbstract
{ {
protected $client;
protected static $need_records = false;
protected $client; public function createApplication()
protected static $need_records = false; {
return require __DIR__ . '/../../../../lib/Alchemy/Phrasea/Application/Root.php';
}
public function createApplication() public function setUp()
{ {
return require __DIR__ . '/../../../../lib/Alchemy/Phrasea/Application/Root.php'; parent::setUp();
} $this->client = $this->createClient();
}
public function setUp() public function testRouteSlash()
{ {
parent::setUp(); $crawler = $this->client->request('GET', '/');
$this->client = $this->createClient(); $response = $this->client->getResponse();
} $this->assertEquals(302, $response->getStatusCode());
$this->assertRegExp('/^\/login\/\?redirect=[\/a-zA-Z]+/', $response->headers->get('location'));
}
public function testRouteSlash() public function testRouteRobots()
{ {
$crawler = $this->client->request('GET', '/'); $registry = \registry::get_instance();
$response = $this->client->getResponse();
$this->assertEquals(302, $response->getStatusCode());
$this->assertRegExp('/^\/login\/\?redirect=[\/a-zA-Z]+/', $response->headers->get('location'));
}
public function testRouteRobots() $original_value = $registry->get('GV_allow_search_engine');
{
$registry = \registry::get_instance();
$original_value = $registry->get('GV_allow_search_engine'); $registry->set('GV_allow_search_engine', false, \registry::TYPE_BOOLEAN);
$registry->set('GV_allow_search_engine', false, \registry::TYPE_BOOLEAN); $crawler = $this->client->request('GET', '/robots.txt');
$response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('text/plain; charset=UTF-8', $response->headers->get('Content-Type'));
$this->assertEquals('UTF-8', $response->getCharset());
$crawler = $this->client->request('GET', '/robots.txt'); $this->assertRegExp('/^Disallow: \/$/m', $response->getContent());
$response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('text/plain; charset=UTF-8', $response->headers->get('Content-Type'));
$this->assertEquals('UTF-8', $response->getCharset());
$this->assertRegExp('/^Disallow: \/$/m', $response->getContent()); $registry = \registry::get_instance();
$registry->set('GV_allow_search_engine', true, \registry::TYPE_BOOLEAN);
$registry = \registry::get_instance(); $crawler = $this->client->request('GET', '/robots.txt');
$registry->set('GV_allow_search_engine', true, \registry::TYPE_BOOLEAN); $response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('text/plain; charset=UTF-8', $response->headers->get('Content-Type'));
$this->assertEquals('UTF-8', $response->getCharset());
$crawler = $this->client->request('GET', '/robots.txt'); $this->assertRegExp('/^Allow: \/$/m', $response->getContent());
$response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('text/plain; charset=UTF-8', $response->headers->get('Content-Type'));
$this->assertEquals('UTF-8', $response->getCharset());
$this->assertRegExp('/^Allow: \/$/m', $response->getContent());
$registry->set('GV_allow_search_engine', $original_value, \registry::TYPE_BOOLEAN);
}
$registry->set('GV_allow_search_engine', $original_value, \registry::TYPE_BOOLEAN);
}
} }

View File

@@ -21,7 +21,6 @@ class ApplicationSetupTest extends PhraseanetWebTestCaseAbstract
* @var \connection_pdo * @var \connection_pdo
*/ */
protected $connection; protected $connection;
protected $registry = array(); protected $registry = array();
public function createApplication() public function createApplication()
@@ -62,7 +61,7 @@ class ApplicationSetupTest extends PhraseanetWebTestCaseAbstract
foreach ($params as $param) { foreach ($params as $param) {
$this->registry[$param] = $registry->get($param); $this->registry[$param] = $registry->get($param);
} }
$this->markTestSkipped('To review'); $this->markTestSkipped('To review');
} }
public function tearDown() public function tearDown()
@@ -194,24 +193,21 @@ class ApplicationSetupTest extends PhraseanetWebTestCaseAbstract
public function temporaryReInstall() public function temporaryReInstall()
{ {
if (file_exists($this->root . 'config/config.yml.unitTests')) { if (file_exists($this->root . 'config/config.yml.unitTests')) {
if(file_exists($this->root . 'config/config.yml')) if (file_exists($this->root . 'config/config.yml')) {
{
unlink($this->root . 'config/config.yml'); unlink($this->root . 'config/config.yml');
} }
rename($this->root . 'config/config.yml.unitTests', $this->root . 'config/config.yml'); rename($this->root . 'config/config.yml.unitTests', $this->root . 'config/config.yml');
} }
if (file_exists($this->root . 'config/services.yml.unitTests')) { if (file_exists($this->root . 'config/services.yml.unitTests')) {
if(file_exists($this->root . 'config/services.yml')) if (file_exists($this->root . 'config/services.yml')) {
{
unlink($this->root . 'config/services.yml'); unlink($this->root . 'config/services.yml');
} }
rename($this->root . 'config/services.yml.unitTests', $this->root . 'config/services.yml'); rename($this->root . 'config/services.yml.unitTests', $this->root . 'config/services.yml');
} }
if (file_exists($this->root . 'config/connexions.yml.unitTests')) { if (file_exists($this->root . 'config/connexions.yml.unitTests')) {
if(file_exists($this->root . 'config/connexions.yml')) if (file_exists($this->root . 'config/connexions.yml')) {
{
unlink($this->root . 'config/connexions.yml'); unlink($this->root . 'config/connexions.yml');
} }

View File

@@ -4,46 +4,43 @@ require_once __DIR__ . '/../../../PhraseanetPHPUnitAbstract.class.inc';
class ApcCacheTest extends \PHPUnit_Framework_TestCase class ApcCacheTest extends \PHPUnit_Framework_TestCase
{ {
/**
* @var ApcCache
*/
protected $object;
/** public function setUp()
* @var ApcCache
*/
protected $object;
public function setUp()
{
if (!extension_loaded('apc'))
{ {
$this->markTestSkipped('Apc is not installed'); if ( ! extension_loaded('apc')) {
$this->markTestSkipped('Apc is not installed');
}
$this->object = new \Alchemy\Phrasea\Cache\ApcCache;
} }
$this->object = new \Alchemy\Phrasea\Cache\ApcCache;
}
public function testIsServer() public function testIsServer()
{ {
$this->assertTrue(is_bool($this->object->isServer())); $this->assertTrue(is_bool($this->object->isServer()));
} }
public function testGetStats() public function testGetStats()
{ {
$this->assertTrue(is_array($this->object->getStats()) || is_null($this->object->getStats())); $this->assertTrue(is_array($this->object->getStats()) || is_null($this->object->getStats()));
} }
public function testGet() public function testGet()
{ {
// Remove the following lines when you implement this test. // Remove the following lines when you implement this test.
$this->markTestIncomplete( $this->markTestIncomplete(
'This test has not been implemented yet.' 'This test has not been implemented yet.'
); );
} }
public function testDeleteMulti()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
public function testDeleteMulti()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
} }

View File

@@ -4,42 +4,40 @@ require_once __DIR__ . '/../../../PhraseanetPHPUnitAbstract.class.inc';
class ArrayCacheTest extends \PHPUnit_Framework_TestCase class ArrayCacheTest extends \PHPUnit_Framework_TestCase
{ {
/**
* @var ArrayCache
*/
protected $object;
/** public function setUp()
* @var ArrayCache {
*/ $this->object = new \Alchemy\Phrasea\Cache\ArrayCache;
protected $object; }
public function setUp() public function testIsServer()
{ {
$this->object = new \Alchemy\Phrasea\Cache\ArrayCache; $this->assertTrue(is_bool($this->object->isServer()));
} }
public function testIsServer() public function testGetStats()
{ {
$this->assertTrue(is_bool($this->object->isServer())); $this->assertTrue(is_array($this->object->getStats()) || is_null($this->object->getStats()));
} }
public function testGetStats() public function testGet()
{ {
$this->assertTrue(is_array($this->object->getStats()) || is_null($this->object->getStats())); // Remove the following lines when you implement this test.
} $this->markTestIncomplete(
'This test has not been implemented yet.'
public function testGet() );
{ }
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
public function testDeleteMulti()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
public function testDeleteMulti()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
} }

View File

@@ -1,43 +0,0 @@
<?php
require_once __DIR__ . '/../../../PhraseanetPHPUnitAbstract.class.inc';
class ManagerTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Manager
*/
protected $object;
public function setUp()
{
// $this->object = new \Alchemy\Phrasea\Cache\Manager(self::);
}
/**
* @covers {className}::{origMethodName}
* @todo Implement testFlushAll().
*/
public function testFlushAll()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @covers {className}::{origMethodName}
* @todo Implement testGet().
*/
public function testGet()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
}

View File

@@ -4,55 +4,51 @@ require_once __DIR__ . '/../../../PhraseanetPHPUnitAbstract.class.inc';
class MemcacheCacheTest extends \PHPUnit_Framework_TestCase class MemcacheCacheTest extends \PHPUnit_Framework_TestCase
{ {
/**
* @var MemcacheCache
*/
protected $object;
/** public function setUp()
* @var MemcacheCache
*/
protected $object;
public function setUp()
{
$this->object = new \Alchemy\Phrasea\Cache\MemcacheCache;
if(!class_exists('Memcache'))
{ {
$this->markTestSkipped('No memcache extension'); $this->object = new \Alchemy\Phrasea\Cache\MemcacheCache;
if ( ! class_exists('Memcache')) {
$this->markTestSkipped('No memcache extension');
}
$memcache = new Memcache();
if ( ! @$memcache->connect('localhost', 11211)) {
$this->markTestSkipped('No memcache server');
}
$this->object->setMemcache($memcache);
} }
$memcache = new Memcache(); public function testIsServer()
if(!@$memcache->connect('localhost', 11211))
{ {
$this->markTestSkipped('No memcache server'); $this->assertTrue(is_bool($this->object->isServer()));
} }
$this->object->setMemcache($memcache); public function testGetStats()
} {
$this->assertTrue(is_array($this->object->getStats()) || is_null($this->object->getStats()));
}
public function testIsServer() public function testGet()
{ {
$this->assertTrue(is_bool($this->object->isServer())); // Remove the following lines when you implement this test.
} $this->markTestIncomplete(
'This test has not been implemented yet.'
public function testGetStats() );
{ }
$this->assertTrue(is_array($this->object->getStats()) || is_null($this->object->getStats()));
}
public function testGet()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
public function testDeleteMulti()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
public function testDeleteMulti()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
} }

View File

@@ -1,70 +1,47 @@
<?php <?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
*/
require_once __DIR__ . '/../../../PhraseanetPHPUnitAbstract.class.inc'; require_once __DIR__ . '/../../../PhraseanetPHPUnitAbstract.class.inc';
class RedisTest extends \PhraseanetPHPUnitAbstract class RedisTest extends \PhraseanetPHPUnitAbstract
{ {
public function testBasics() public function testBasics()
{
if (extension_loaded('Redis'))
{ {
$redis = new Redis(); if (extension_loaded('Redis')) {
try $redis = new Redis();
{ try {
$ok = @$redis->connect('127.0.0.1', 6379); $ok = @$redis->connect('127.0.0.1', 6379);
} } catch (\Exception $e) {
catch(\Exception $e) $ok = false;
{ }
$ok = false; if ( ! $ok) {
} $this->markTestSkipped('The ' . __CLASS__ . ' requires the use of redis');
if (!$ok) }
{ } else {
$this->markTestSkipped('The ' . __CLASS__ . ' requires the use of redis'); $this->markTestSkipped('The ' . __CLASS__ . ' requires the use of redis');
} }
$cache = new \Alchemy\Phrasea\Cache\RedisCache();
$cache->setRedis($redis);
// Test save
$cache->save('test_key', 'testing this out');
// Test contains to test that save() worked
$this->assertTrue($cache->contains('test_key'));
$cache->save('test_key1', 'testing this out', 20);
// Test contains to test that save() worked
$this->assertTrue($cache->contains('test_key1'));
// Test fetch
$this->assertEquals('testing this out', $cache->fetch('test_key'));
// Test delete
$cache->save('test_key2', 'test2');
$cache->delete('test_key2');
$this->assertFalse($cache->contains('test_key2'));
$this->assertEquals($redis, $cache->getRedis());
} }
else
{
$this->markTestSkipped('The ' . __CLASS__ . ' requires the use of redis');
}
$cache = new \Alchemy\Phrasea\Cache\RedisCache();
$cache->setRedis($redis);
// Test save
$cache->save('test_key', 'testing this out');
// Test contains to test that save() worked
$this->assertTrue($cache->contains('test_key'));
$cache->save('test_key1', 'testing this out', 20);
// Test contains to test that save() worked
$this->assertTrue($cache->contains('test_key1'));
// Test fetch
$this->assertEquals('testing this out', $cache->fetch('test_key'));
// Test delete
$cache->save('test_key2', 'test2');
$cache->delete('test_key2');
$this->assertFalse($cache->contains('test_key2'));
$this->assertEquals($redis, $cache->getRedis());
}
} }

View File

@@ -4,47 +4,44 @@ require_once __DIR__ . '/../../../PhraseanetPHPUnitAbstract.class.inc';
class XcacheCacheTest extends \PHPUnit_Framework_TestCase class XcacheCacheTest extends \PHPUnit_Framework_TestCase
{ {
/**
* @var XcacheCache
*/
protected $object;
/** public function setUp()
* @var XcacheCache
*/
protected $object;
public function setUp()
{
if(!function_exists('xcache_info'))
{ {
$this->markTestSkipped('Xcache not loaded'); if ( ! function_exists('xcache_info')) {
$this->markTestSkipped('Xcache not loaded');
}
$this->object = new \Alchemy\Phrasea\Cache\XcacheCache;
} }
$this->object = new \Alchemy\Phrasea\Cache\XcacheCache; public function testIsServer()
} {
$this->assertTrue(is_bool($this->object->isServer()));
}
public function testIsServer() public function testGetStats()
{ {
$this->assertTrue(is_bool($this->object->isServer())); $this->assertTrue(is_array($this->object->getStats()) || is_null($this->object->getStats()));
} }
public function testGetStats() public function testGet()
{ {
$this->assertTrue(is_array($this->object->getStats()) || is_null($this->object->getStats())); // Remove the following lines when you implement this test.
} $this->markTestIncomplete(
'This test has not been implemented yet.'
public function testGet() );
{ }
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
public function testDeleteMulti()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
public function testDeleteMulti()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
} }

View File

@@ -4,263 +4,238 @@ require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.
class DescriptionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract class DescriptionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{ {
protected $client;
protected static $need_records = false;
/** public function createApplication()
* As controllers use WebTestCase, it requires a client
*/
protected $client;
/**
* If the controller tests require some records, specify it her
*
* For example, this will loacd 2 records
* (self::$record_1 and self::$record_2) :
*
* $need_records = 2;
*
*/
protected static $need_records = false;
/**
* The application loader
*/
public function createApplication()
{
return require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Admin.php';
}
public function setUp()
{
parent::setUp();
$this->client = $this->createClient();
}
/**
* Default route test
*/
public function testRouteDescription()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$databox = array_shift($appbox->get_databoxes());
$name = "testtest" . uniqid();
$field = \databox_field::create($databox, $name);
$id = $field->get_id();
$this->client->request("POST", "/description/" . $databox->get_sbas_id() . "/", array(
'field_ids' => array($id)
, 'name_' . $id => $name
, 'multi_' . $id => 1
, 'indexable_' . $id => 1
, 'src_' . $id => '/rdf:RDF/rdf:Description/IPTC:SupplementalCategories'
, 'required_' . $id => 0
, 'readonly_' . $id => 0
, 'type_' . $id => 'string'
, 'vocabulary_' . $id => 'User'
));
$this->assertTrue($this->client->getResponse()->isRedirect());
$field->delete();
}
public function testPostDelete()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$databox = array_shift($appbox->get_databoxes());
$name = "test" . uniqid();
$field = \databox_field::create($databox, $name);
$id = $field->get_id();
$this->client->request("POST", "/description/" . $databox->get_sbas_id() . "/", array(
'todelete_ids' => array($id)
));
$this->assertTrue($this->client->getResponse()->isRedirect());
try
{ {
$field = \databox_field::get_instance($databox, $id); return require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Admin.php';
$field->delete();
$this->fail("should raise an exception");
} }
catch (\Exception $e)
{
public function setUp()
{
parent::setUp();
$this->client = $this->createClient();
} }
}
public function testPostCreate() /**
{ * Default route test
$appbox = appbox::get_instance(\bootstrap::getCore()); */
$databox = array_shift($appbox->get_databoxes()); public function testRouteDescription()
$name = 'test' . uniqid();
$this->client->request("POST", "/description/" . $databox->get_sbas_id() . "/", array(
'newfield' => $name
));
$this->assertTrue($this->client->getResponse()->isRedirect());
$fields = $databox->get_meta_structure();
$find = false;
foreach ($fields as $field)
{ {
if ($field->get_name() === databox_field::generateName($name)) $appbox = appbox::get_instance(\bootstrap::getCore());
{ $databox = array_shift($appbox->get_databoxes());
$name = "testtest" . uniqid();
$field = \databox_field::create($databox, $name);
$id = $field->get_id();
$this->client->request("POST", "/description/" . $databox->get_sbas_id() . "/", array(
'field_ids' => array($id)
, 'name_' . $id => $name
, 'multi_' . $id => 1
, 'indexable_' . $id => 1
, 'src_' . $id => '/rdf:RDF/rdf:Description/IPTC:SupplementalCategories'
, 'required_' . $id => 0
, 'readonly_' . $id => 0
, 'type_' . $id => 'string'
, 'vocabulary_' . $id => 'User'
));
$this->assertTrue($this->client->getResponse()->isRedirect());
$field->delete(); $field->delete();
$find = true;
}
} }
if (!$find) public function testPostDelete()
{ {
$this->fail("should have create a new field"); $appbox = appbox::get_instance(\bootstrap::getCore());
$databox = array_shift($appbox->get_databoxes());
$name = "test" . uniqid();
$field = \databox_field::create($databox, $name);
$id = $field->get_id();
$this->client->request("POST", "/description/" . $databox->get_sbas_id() . "/", array(
'todelete_ids' => array($id)
));
$this->assertTrue($this->client->getResponse()->isRedirect());
try {
$field = \databox_field::get_instance($databox, $id);
$field->delete();
$this->fail("should raise an exception");
} catch (\Exception $e) {
}
} }
}
public function testPostDescriptionException() public function testPostCreate()
{ {
$appbox = appbox::get_instance(\bootstrap::getCore()); $appbox = appbox::get_instance(\bootstrap::getCore());
$databox = array_shift($appbox->get_databoxes()); $databox = array_shift($appbox->get_databoxes());
$this->client->request("POST", "/description/" . $databox->get_sbas_id() . "/", array( $name = 'test' . uniqid();
'todelete_ids' => array('unknow_id')
));
$this->assertTrue($this->client->getResponse()->isRedirect()); $this->client->request("POST", "/description/" . $databox->get_sbas_id() . "/", array(
'newfield' => $name
));
$name = "test" . uniqid(); $this->assertTrue($this->client->getResponse()->isRedirect());
$field = \databox_field::create($databox, $name);
$id = $field->get_id();
$this->client->request("POST", "/description/" . $databox->get_sbas_id() . "/", array(
'field_ids' => array($id)
, 'name_' . $id => $name
, 'multi_' . $id => 1
, 'indexable_' . $id => 1
, 'src_' . $id => '/rdf:RDF/rdf:Description/IPTC:SupplementalCategories'
, 'required_' . $id => 0
, 'readonly_' . $id => 0
, 'type_' . $id => 'string'
, 'vocabulary_' . $id => 'Unknow_Vocabulary'
));
$this->assertTrue($this->client->getResponse()->isRedirect()); $fields = $databox->get_meta_structure();
$field->delete(); $find = false;
$name = "test" . uniqid(); foreach ($fields as $field) {
$field = \databox_field::create($databox, $name); if ($field->get_name() === databox_field::generateName($name)) {
$id = $field->get_id(); $field->delete();
$this->client->request("POST", "/description/" . $databox->get_sbas_id() . "/", array( $find = true;
'field_ids' => array($id) }
, 'multi_' . $id => 1 }
, 'indexable_' . $id => 1
, 'src_' . $id => '/rdf:RDF/rdf:Description/IPTC:SupplementalCategories'
, 'required_' . $id => 0
, 'readonly_' . $id => 0
, 'type_' . $id => 'string'
, 'vocabulary_' . $id => 'Unknow_Vocabulary'
));
$this->assertTrue($this->client->getResponse()->isRedirect()); if ( ! $find) {
$field->delete(); $this->fail("should have create a new field");
}
}
$name = "test" . uniqid(); public function testPostDescriptionException()
$field = \databox_field::create($databox, $name); {
$field->set_multi(false); $appbox = appbox::get_instance(\bootstrap::getCore());
$field->set_indexable(false); $databox = array_shift($appbox->get_databoxes());
$field->set_required(true);
$field->set_readonly(true);
$id = $field->get_id();
$this->client->request("POST", "/description/" . $databox->get_sbas_id() . "/", array(
'field_ids' => array($id)
, 'name_' . $id => $name
, 'multi_' . $id => 1
, 'indexable_' . $id => 1
, 'src_' . $id => 'unknow_Source'
, 'required_' . $id => 0
, 'readonly_' . $id => 0
, 'type_' . $id => 'string'
, 'vocabulary_' . $id => 'Unknow_Vocabulary'
));
$this->assertTrue($this->client->getResponse()->isRedirect()); $this->client->request("POST", "/description/" . $databox->get_sbas_id() . "/", array(
$this->assertTrue($field->is_readonly()); 'todelete_ids' => array('unknow_id')
$this->assertTrue($field->is_required()); ));
$this->assertFalse($field->is_multi());
$this->assertFalse($field->is_indexable()); $this->assertTrue($this->client->getResponse()->isRedirect());
$field->delete();
$name = "test" . uniqid();
$field = \databox_field::create($databox, $name);
$id = $field->get_id();
$this->client->request("POST", "/description/" . $databox->get_sbas_id() . "/", array(
'field_ids' => array($id)
, 'name_' . $id => $name
, 'multi_' . $id => 1
, 'indexable_' . $id => 1
, 'src_' . $id => '/rdf:RDF/rdf:Description/IPTC:SupplementalCategories'
, 'required_' . $id => 0
, 'readonly_' . $id => 0
, 'type_' . $id => 'string'
, 'vocabulary_' . $id => 'Unknow_Vocabulary'
));
$this->assertTrue($this->client->getResponse()->isRedirect());
$field->delete();
$name = "test" . uniqid();
$field = \databox_field::create($databox, $name);
$id = $field->get_id();
$this->client->request("POST", "/description/" . $databox->get_sbas_id() . "/", array(
'field_ids' => array($id)
, 'multi_' . $id => 1
, 'indexable_' . $id => 1
, 'src_' . $id => '/rdf:RDF/rdf:Description/IPTC:SupplementalCategories'
, 'required_' . $id => 0
, 'readonly_' . $id => 0
, 'type_' . $id => 'string'
, 'vocabulary_' . $id => 'Unknow_Vocabulary'
));
$this->assertTrue($this->client->getResponse()->isRedirect());
$field->delete();
$name = "test" . uniqid();
$field = \databox_field::create($databox, $name);
$field->set_multi(false);
$field->set_indexable(false);
$field->set_required(true);
$field->set_readonly(true);
$id = $field->get_id();
$this->client->request("POST", "/description/" . $databox->get_sbas_id() . "/", array(
'field_ids' => array($id)
, 'name_' . $id => $name
, 'multi_' . $id => 1
, 'indexable_' . $id => 1
, 'src_' . $id => 'unknow_Source'
, 'required_' . $id => 0
, 'readonly_' . $id => 0
, 'type_' . $id => 'string'
, 'vocabulary_' . $id => 'Unknow_Vocabulary'
));
$this->assertTrue($this->client->getResponse()->isRedirect());
$this->assertTrue($field->is_readonly());
$this->assertTrue($field->is_required());
$this->assertFalse($field->is_multi());
$this->assertFalse($field->is_indexable());
$field->delete();
$name = "test" . uniqid(); $name = "test" . uniqid();
$field = \databox_field::create($databox, $name); $field = \databox_field::create($databox, $name);
$id = $field->get_id(); $id = $field->get_id();
$this->client->request("POST", "/description/" . $databox->get_sbas_id() . "/", array( $this->client->request("POST", "/description/" . $databox->get_sbas_id() . "/", array(
'field_ids' => array('unknow_id') 'field_ids' => array('unknow_id')
, 'name_' . $id => $name , 'name_' . $id => $name
, 'multi_' . $id => 1 , 'multi_' . $id => 1
, 'indexable_' . $id => 1 , 'indexable_' . $id => 1
, 'src_' . $id => '/rdf:RDF/rdf:Description/IPTC:SupplementalCategories' , 'src_' . $id => '/rdf:RDF/rdf:Description/IPTC:SupplementalCategories'
, 'required_' . $id => 0 , 'required_' . $id => 0
, 'readonly_' . $id => 0 , 'readonly_' . $id => 0
, 'type_' . $id => 'string' , 'type_' . $id => 'string'
, 'vocabulary_' . $id => 'Unknow_Vocabulary' , 'vocabulary_' . $id => 'Unknow_Vocabulary'
)); ));
$this->assertTrue($this->client->getResponse()->isRedirect()); $this->assertTrue($this->client->getResponse()->isRedirect());
$field->delete(); $field->delete();
} }
public function testPostDescriptionRights() public function testPostDescriptionRights()
{ {
$appbox = appbox::get_instance(\bootstrap::getCore()); $appbox = appbox::get_instance(\bootstrap::getCore());
$session = $appbox->get_session(); $session = $appbox->get_session();
$auth = new Session_Authentication_None(self::$user_alt1); $auth = new Session_Authentication_None(self::$user_alt1);
$session->authenticate($auth); $session->authenticate($auth);
$databox = array_shift($appbox->get_databoxes()); $databox = array_shift($appbox->get_databoxes());
$name = "test" . uniqid(); $name = "test" . uniqid();
$field = \databox_field::create($databox, $name); $field = \databox_field::create($databox, $name);
$id = $field->get_id(); $id = $field->get_id();
$this->client->request("POST", "/description/" . $databox->get_sbas_id() . "/", array( $this->client->request("POST", "/description/" . $databox->get_sbas_id() . "/", array(
'field_ids' => array($id) 'field_ids' => array($id)
, 'name_' . $id => $name , 'name_' . $id => $name
, 'multi_' . $id => 1 , 'multi_' . $id => 1
, 'indexable_' . $id => 1 , 'indexable_' . $id => 1
, 'src_' . $id => '/rdf:RDF/rdf:Description/IPTC:SupplementalCategories' , 'src_' . $id => '/rdf:RDF/rdf:Description/IPTC:SupplementalCategories'
, 'required_' . $id => 0 , 'required_' . $id => 0
, 'readonly_' . $id => 0 , 'readonly_' . $id => 0
, 'type_' . $id => 'string' , 'type_' . $id => 'string'
, 'vocabulary_' . $id => 'User' , 'vocabulary_' . $id => 'User'
)); ));
$this->assertFalse($this->client->getResponse()->isOk()); $this->assertFalse($this->client->getResponse()->isOk());
$this->assertEquals("You are not allowed to access this zone", $this->client->getResponse()->getContent()); $this->assertEquals("You are not allowed to access this zone", $this->client->getResponse()->getContent());
$field->delete(); $field->delete();
} }
public function testGetDescriptionException() public function testGetDescriptionException()
{ {
$appbox = appbox::get_instance(\bootstrap::getCore()); $appbox = appbox::get_instance(\bootstrap::getCore());
$session = $appbox->get_session(); $session = $appbox->get_session();
$auth = new Session_Authentication_None(self::$user_alt1); $auth = new Session_Authentication_None(self::$user_alt1);
$session->authenticate($auth); $session->authenticate($auth);
$databox = array_shift($appbox->get_databoxes()); $databox = array_shift($appbox->get_databoxes());
$this->client->request("GET", "/description/" . $databox->get_sbas_id() . "/"); $this->client->request("GET", "/description/" . $databox->get_sbas_id() . "/");
$this->assertFalse($this->client->getResponse()->isOk()); $this->assertFalse($this->client->getResponse()->isOk());
$this->assertEquals("You are not allowed to access this zone", $this->client->getResponse()->getContent()); $this->assertEquals("You are not allowed to access this zone", $this->client->getResponse()->getContent());
} }
public function testGetDescription() public function testGetDescription()
{ {
$appbox = appbox::get_instance(\bootstrap::getCore()); $appbox = appbox::get_instance(\bootstrap::getCore());
$databox = array_shift($appbox->get_databoxes()); $databox = array_shift($appbox->get_databoxes());
$this->client->request("GET", "/description/" . $databox->get_sbas_id() . "/");
$this->assertTrue($this->client->getResponse()->isOk());
}
$this->client->request("GET", "/description/" . $databox->get_sbas_id() . "/");
$this->assertTrue($this->client->getResponse()->isOk());
}
} }

View File

@@ -4,79 +4,61 @@ require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.
class ControllerFieldsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract class ControllerFieldsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{ {
protected $client;
protected static $need_records = false;
/** public function createApplication()
* As controllers use WebTestCase, it requires a client {
*/ return require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Admin.php';
protected $client; }
/** public function setUp()
* If the controller tests require some records, specify it her {
* parent::setUp();
* For example, this will loacd 2 records $this->client = $this->createClient();
* (self::$record_1 and self::$record_2) : }
*
* $need_records = 2;
*
*/
protected static $need_records = false;
/** /**
* The application loader * Default route test
*/ */
public function createApplication() public function testCheckMulti()
{ {
return require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Admin.php'; $appbox = \appbox::get_instance(\bootstrap::getCore());
} $databox = array_shift($appbox->get_databoxes());
public function setUp() $field = \databox_field::create($databox, "test" . time());
{ $source = $field->get_source();
parent::setUp();
$this->client = $this->createClient();
}
/** $this->client->request("GET", "/fields/checkmulti/", array(
* Default route test 'souce' => $source, 'multi' => 'false'));
*/
public function testCheckMulti()
{
$appbox = \appbox::get_instance(\bootstrap::getCore());
$databox = array_shift($appbox->get_databoxes());
$field = \databox_field::create($databox, "test" . time()); $response = $this->client->getResponse();
$source = $field->get_source(); $this->assertEquals("application/json", $response->headers->get("content-type"));
$datas = json_decode($response->getContent());
$this->assertTrue(is_object($datas));
$this->assertTrue( ! ! $datas->result);
$this->assertEquals($field->is_multi(), ! ! $datas->is_multi);
$field->delete();
}
$this->client->request("GET", "/fields/checkmulti/", array( public function testCheckReadOnly()
'souce' => $source, 'multi' => 'false')); {
$appbox = \appbox::get_instance(\bootstrap::getCore());
$databox = array_shift($appbox->get_databoxes());
$response = $this->client->getResponse(); $field = \databox_field::create($databox, "test" . time());
$this->assertEquals("application/json", $response->headers->get("content-type")); $source = $field->get_source();
$datas = json_decode($response->getContent());
$this->assertTrue(is_object($datas));
$this->assertTrue(!!$datas->result);
$this->assertEquals($field->is_multi(), !!$datas->is_multi);
$field->delete();
}
public function testCheckReadOnly() $this->client->request("GET", "/fields/checkreadonly/", array(
{ 'souce' => $source, 'readonly' => 'false'));
$appbox = \appbox::get_instance(\bootstrap::getCore());
$databox = array_shift($appbox->get_databoxes());
$field = \databox_field::create($databox, "test" . time()); $response = $this->client->getResponse();
$source = $field->get_source(); $this->assertEquals("application/json", $response->headers->get("content-type"));
$datas = json_decode($response->getContent());
$this->client->request("GET", "/fields/checkreadonly/", array( $this->assertTrue(is_object($datas));
'souce' => $source, 'readonly' => 'false')); $this->assertTrue( ! ! $datas->result);
$this->assertEquals($field->is_readonly(), ! ! $datas->is_readonly);
$response = $this->client->getResponse();
$this->assertEquals("application/json", $response->headers->get("content-type"));
$datas = json_decode($response->getContent());
$this->assertTrue(is_object($datas));
$this->assertTrue(!!$datas->result);
$this->assertEquals($field->is_readonly(), !!$datas->is_readonly);
$field->delete();
}
$field->delete();
}
} }

View File

@@ -7,382 +7,360 @@ use Symfony\Component\HttpFoundation\Response;
class Module_Admin_Route_PublicationTest extends PhraseanetWebTestCaseAuthenticatedAbstract class Module_Admin_Route_PublicationTest extends PhraseanetWebTestCaseAuthenticatedAbstract
{ {
public static $account = null;
public static $api = null;
protected $client;
public static $account = null; public function setUp()
public static $api = null;
protected $client;
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
}
public static function tearDownAfterClass()
{
parent::tearDownAfterClass();
}
public function setUp()
{
parent::setUp();
$this->client = $this->createClient();
}
public function createApplication()
{
return require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Admin.php';
}
public function testList()
{
$crawler = $this->client->request('GET', '/publications/list/');
$pageContent = $this->client->getResponse()->getContent();
$this->assertTrue($this->client->getResponse()->isOk());
$feeds = Feed_Collection::load_all(appbox::get_instance(\bootstrap::getCore()), self::$user);
foreach ($feeds->get_feeds() as $feed)
{ {
$this->assertRegExp('/\/admin\/publications\/feed\/' . $feed->get_id() . '/', $pageContent); parent::setUp();
if ($feed->get_collection() != null) $this->client = $this->createClient();
$this->assertRegExp('/' . $feed->get_collection()->get_name() . '/', $pageContent);
if ($feed->is_owner(self::$user))
$this->assertEquals(1, $crawler->filterXPath("//form[@action='/admin/publications/feed/" . $feed->get_id() . "/delete/']")->count());
} }
}
public function testCreate() public function createApplication()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
foreach ($appbox->get_databoxes() as $databox)
{ {
foreach ($databox->get_collections() as $collection) return require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Admin.php';
{
$base_id = $collection->get_base_id();
break;
}
} }
$feeds = Feed_Collection::load_all($appbox, self::$user);
$count = sizeof($feeds->get_feeds());
$crawler = $this->client->request('POST', '/publications/create/', array("title" => "hello", "subtitle" => "coucou", "base_id" => $base_id)); public function testList()
{
$crawler = $this->client->request('GET', '/publications/list/');
$pageContent = $this->client->getResponse()->getContent();
$this->assertTrue($this->client->getResponse()->isOk());
$feeds = Feed_Collection::load_all(appbox::get_instance(\bootstrap::getCore()), self::$user);
$this->assertTrue($this->client->getResponse()->isRedirect('/admin/publications/list/')); foreach ($feeds->get_feeds() as $feed) {
$this->assertRegExp('/\/admin\/publications\/feed\/' . $feed->get_id() . '/', $pageContent);
if ($feed->get_collection() != null)
$this->assertRegExp('/' . $feed->get_collection()->get_name() . '/', $pageContent);
if ($feed->is_owner(self::$user))
$this->assertEquals(1, $crawler->filterXPath("//form[@action='/admin/publications/feed/" . $feed->get_id() . "/delete/']")->count());
}
}
$feeds = Feed_Collection::load_all(appbox::get_instance(\bootstrap::getCore()), self::$user); public function testCreate()
$count_after = sizeof($feeds->get_feeds()); {
$this->assertGreaterThan($count, $count_after); $appbox = appbox::get_instance(\bootstrap::getCore());
$feed = array_pop($feeds->get_feeds()); foreach ($appbox->get_databoxes() as $databox) {
foreach ($databox->get_collections() as $collection) {
$base_id = $collection->get_base_id();
break;
}
}
$feeds = Feed_Collection::load_all($appbox, self::$user);
$count = sizeof($feeds->get_feeds());
$feed->delete(); $crawler = $this->client->request('POST', '/publications/create/', array("title" => "hello", "subtitle" => "coucou", "base_id" => $base_id));
}
public function testGetFeed() $this->assertTrue($this->client->getResponse()->isRedirect('/admin/publications/list/'));
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$feed = Feed_Adapter::create($appbox, self::$user, "salut", 'coucou');
$crawler = $this->client->request('GET', '/publications/feed/' . $feed->get_id() . '/');
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertEquals(1, $crawler->filterXPath("//form[@action='/admin/publications/feed/" . $feed->get_id() . "/update/']")->count());
$this->assertEquals(1, $crawler->filterXPath("//input[@value='salut']")->count());
$this->assertEquals(1, $crawler->filterXPath("//input[@value='coucou']")->count());
$feed->delete(); $feeds = Feed_Collection::load_all(appbox::get_instance(\bootstrap::getCore()), self::$user);
} $count_after = sizeof($feeds->get_feeds());
$this->assertGreaterThan($count, $count_after);
public function testUpdateFeedNotOwner() $feed = array_pop($feeds->get_feeds());
{
$appbox = appbox::get_instance(\bootstrap::getCore());
//is not owner
$stub = $this->getMock("user_adapter", array(), array(), "", false);
//return a different userid
$stub->expects($this->any())->method("get_id")->will($this->returnValue(99999999));
$feed = Feed_Adapter::create($appbox, $stub, "salut", 'coucou'); $feed->delete();
$this->client->request("POST", "/publications/feed/" . $feed->get_id() . "/update/"); }
$this->assertTrue($this->client->getResponse()->isRedirect(), 'update fails, i\'m redirected');
$this->assertTrue( public function testGetFeed()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$feed = Feed_Adapter::create($appbox, self::$user, "salut", 'coucou');
$crawler = $this->client->request('GET', '/publications/feed/' . $feed->get_id() . '/');
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertEquals(1, $crawler->filterXPath("//form[@action='/admin/publications/feed/" . $feed->get_id() . "/update/']")->count());
$this->assertEquals(1, $crawler->filterXPath("//input[@value='salut']")->count());
$this->assertEquals(1, $crawler->filterXPath("//input[@value='coucou']")->count());
$feed->delete();
}
public function testUpdateFeedNotOwner()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
//is not owner
$stub = $this->getMock("user_adapter", array(), array(), "", false);
//return a different userid
$stub->expects($this->any())->method("get_id")->will($this->returnValue(99999999));
$feed = Feed_Adapter::create($appbox, $stub, "salut", 'coucou');
$this->client->request("POST", "/publications/feed/" . $feed->get_id() . "/update/");
$this->assertTrue($this->client->getResponse()->isRedirect(), 'update fails, i\'m redirected');
$this->assertTrue(
strpos( strpos(
$this->client->getResponse()->headers->get('Location') $this->client->getResponse()->headers->get('Location')
, '/admin/publications/feed/' . $feed->get_id() . '/?' , '/admin/publications/feed/' . $feed->get_id() . '/?'
) === 0); ) === 0);
$feed->delete(); $feed->delete();
} }
public function testUpdatedFeedException() public function testUpdatedFeedException()
{ {
$appbox = appbox::get_instance(\bootstrap::getCore()); $appbox = appbox::get_instance(\bootstrap::getCore());
$feed = Feed_Adapter::create($appbox, self::$user, "salut", 'coucou'); $feed = Feed_Adapter::create($appbox, self::$user, "salut", 'coucou');
$this->client->request("POST", "/publications/feed/" . $feed->get_id() . "/update/", array( $this->client->request("POST", "/publications/feed/" . $feed->get_id() . "/update/", array(
'title' => 'test' 'title' => 'test'
, 'subtitle' => 'test' , 'subtitle' => 'test'
, 'public' => '1' , 'public' => '1'
)); ));
$feed = new Feed_Adapter($appbox, $feed->get_id()); $feed = new Feed_Adapter($appbox, $feed->get_id());
$this->assertTrue( $this->assertTrue(
strpos( strpos(
$this->client->getResponse()->headers->get('Location') $this->client->getResponse()->headers->get('Location')
, '/admin/publications/list/' , '/admin/publications/list/'
) === 0); ) === 0);
$this->assertEquals('test', $feed->get_title()); $this->assertEquals('test', $feed->get_title());
$this->assertEquals('test', $feed->get_subtitle()); $this->assertEquals('test', $feed->get_subtitle());
$this->assertTrue($feed->is_public()); $this->assertTrue($feed->is_public());
$this->assertNull($feed->get_collection()); $this->assertNull($feed->get_collection());
$feed->delete(); $feed->delete();
} }
public function testUpdatedFeedOwner() public function testUpdatedFeedOwner()
{ {
$appbox = appbox::get_instance(\bootstrap::getCore()); $appbox = appbox::get_instance(\bootstrap::getCore());
$feed = Feed_Adapter::create($appbox, self::$user, "salut", 'coucou'); $feed = Feed_Adapter::create($appbox, self::$user, "salut", 'coucou');
$this->client->request("POST", "/publications/feed/" . $feed->get_id() . "/update/", array( $this->client->request("POST", "/publications/feed/" . $feed->get_id() . "/update/", array(
'title' => 'test' 'title' => 'test'
, 'subtitle' => 'test' , 'subtitle' => 'test'
, 'public' => '1' , 'public' => '1'
, 'base_id' => self::$collection->get_base_id() , 'base_id' => self::$collection->get_base_id()
)); ));
$this->assertTrue( $this->assertTrue(
strpos( strpos(
$this->client->getResponse()->headers->get('Location') $this->client->getResponse()->headers->get('Location')
, '/admin/publications/list/' , '/admin/publications/list/'
) === 0); ) === 0);
$feed = new Feed_Adapter($appbox, $feed->get_id()); $feed = new Feed_Adapter($appbox, $feed->get_id());
$collection = $feed->get_collection(); $collection = $feed->get_collection();
$this->assertEquals('test', $feed->get_title()); $this->assertEquals('test', $feed->get_title());
$this->assertEquals('test', $feed->get_subtitle()); $this->assertEquals('test', $feed->get_subtitle());
$this->assertFalse($feed->is_public()); $this->assertFalse($feed->is_public());
$this->assertEquals(self::$collection->get_base_id(), $collection->get_base_id()); $this->assertEquals(self::$collection->get_base_id(), $collection->get_base_id());
$this->assertTrue( $this->assertTrue(
strpos( strpos(
$this->client->getResponse()->headers->get('Location') $this->client->getResponse()->headers->get('Location')
, '/admin/publications/list/' , '/admin/publications/list/'
) === 0); ) === 0);
$feed->delete(); $feed->delete();
} }
public function testIconUploadErrorOwner() public function testIconUploadErrorOwner()
{ {
$appbox = appbox::get_instance(\bootstrap::getCore()); $appbox = appbox::get_instance(\bootstrap::getCore());
//is not owner //is not owner
$stub = $this->getMock("user_adapter", array(), array(), "", false); $stub = $this->getMock("user_adapter", array(), array(), "", false);
//return a different userid //return a different userid
$stub->expects($this->any())->method("get_id")->will($this->returnValue(99999999)); $stub->expects($this->any())->method("get_id")->will($this->returnValue(99999999));
$feed = Feed_Adapter::create($appbox, $stub, "salut", 'coucou'); $feed = Feed_Adapter::create($appbox, $stub, "salut", 'coucou');
$this->client->request("POST", "/publications/feed/" . $feed->get_id() . "/iconupload/", array(), array()); $this->client->request("POST", "/publications/feed/" . $feed->get_id() . "/iconupload/", array(), array());
$response = $this->client->getResponse(); $response = $this->client->getResponse();
$this->assertTrue($response->isOk()); $this->assertTrue($response->isOk());
$this->assertRegexp("/ERROR:you are not allowed/", $response->getContent()); $this->assertRegexp("/ERROR:you are not allowed/", $response->getContent());
$feed->delete(); $feed->delete();
} }
public function testIconUploadErrorFileData() public function testIconUploadErrorFileData()
{ {
$appbox = appbox::get_instance(\bootstrap::getCore()); $appbox = appbox::get_instance(\bootstrap::getCore());
$feed = Feed_Adapter::create($appbox, self::$user, "salut", 'coucou'); $feed = Feed_Adapter::create($appbox, self::$user, "salut", 'coucou');
$this->client->request( $this->client->request(
"POST" "POST"
, "/publications/feed/" . $feed->get_id() . "/iconupload/" , "/publications/feed/" . $feed->get_id() . "/iconupload/"
, array() , array()
, array('Filedata' => array('error' => 1)) , array('Filedata' => array('error' => 1))
); );
$response = $this->client->getResponse(); $response = $this->client->getResponse();
$this->assertTrue($response->isOk()); $this->assertTrue($response->isOk());
$this->assertRegexp("/ERROR:error while upload/", $response->getContent()); $this->assertRegexp("/ERROR:error while upload/", $response->getContent());
$feed->delete(); $feed->delete();
} }
public function testIconUploadErrorFileType() public function testIconUploadErrorFileType()
{ {
$appbox = appbox::get_instance(\bootstrap::getCore()); $appbox = appbox::get_instance(\bootstrap::getCore());
$feed = Feed_Adapter::create($appbox, self::$user, "salut", 'coucou'); $feed = Feed_Adapter::create($appbox, self::$user, "salut", 'coucou');
$this->client->request( $this->client->request(
"POST" "POST"
, "/publications/feed/" . $feed->get_id() . "/iconupload/" , "/publications/feed/" . $feed->get_id() . "/iconupload/"
, array() , array()
, array('Filedata' => array('error' => 0, 'tmp_name' => __DIR__ . '/../../../../testfiles/test007.ppt')) , array('Filedata' => array('error' => 0, 'tmp_name' => __DIR__ . '/../../../../testfiles/test007.ppt'))
); );
$response = $this->client->getResponse(); $response = $this->client->getResponse();
$this->assertTrue($response->isOk()); $this->assertTrue($response->isOk());
$this->assertRegexp("/ERROR:bad filetype/", $response->getContent()); $this->assertRegexp("/ERROR:bad filetype/", $response->getContent());
$feed->delete(); $feed->delete();
} }
public function testIconUpload() public function testIconUpload()
{ {
$appbox = appbox::get_instance(\bootstrap::getCore()); $appbox = appbox::get_instance(\bootstrap::getCore());
$feed = Feed_Adapter::create($appbox, self::$user, "salut", 'coucou'); $feed = Feed_Adapter::create($appbox, self::$user, "salut", 'coucou');
copy(__DIR__ . '/../../../../testfiles/logocoll.gif', __DIR__ . '/../../../../testfiles/logocoll1.gif'); copy(__DIR__ . '/../../../../testfiles/logocoll.gif', __DIR__ . '/../../../../testfiles/logocoll1.gif');
$this->client->request( $this->client->request(
"POST" "POST"
, "/publications/feed/" . $feed->get_id() . "/iconupload/" , "/publications/feed/" . $feed->get_id() . "/iconupload/"
, array() , array()
, array('Filedata' => array('error' => 0, 'tmp_name' => __DIR__ . '/../../../../testfiles/logocoll1.gif')) , array('Filedata' => array('error' => 0, 'tmp_name' => __DIR__ . '/../../../../testfiles/logocoll1.gif'))
); );
$response = $this->client->getResponse(); $response = $this->client->getResponse();
$this->assertTrue($response->isOk()); $this->assertTrue($response->isOk());
$feed = new Feed_Adapter($appbox, $feed->get_id()); $feed = new Feed_Adapter($appbox, $feed->get_id());
try try {
{ $file = new SplFileObject(__DIR__ . '/../../../../testfiles/logocoll1.gif');
$file = new SplFileObject(__DIR__ . '/../../../../testfiles/logocoll1.gif'); $this->fail('logo not deleted');
$this->fail('logo not deleted'); } catch (\Exception $e) {
}
catch (\Exception $e)
{
}
$this->assertRegexp("#FILEHREF:/custom/feed_" . $feed->get_id() . ".jpg?[0-9]*#", $response->getContent());
$feed->delete();
} }
$this->assertRegexp("#FILEHREF:/custom/feed_" . $feed->get_id() . ".jpg?[0-9]*#", $response->getContent()); public function testAddPublisher()
$feed->delete();
}
public function testAddPublisher()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$feed = Feed_Adapter::create($appbox, self::$user, "salut", 'coucou');
$this->client->request("POST", "/publications/feed/" . $feed->get_id() . "/addpublisher/", array(
'usr_id' => self::$user_alt1->get_id()
));
$response = $this->client->getResponse();
$this->assertTrue($response->isRedirect());
$feed = new Feed_Adapter($appbox, $feed->get_id());
$publishers = $feed->get_publishers();
$this->assertTrue(isset($publishers[self::$user_alt1->get_id()]));
$this->assertTrue(
strpos(
$this->client->getResponse()->headers->get('Location')
, '/admin/publications/feed/' . $feed->get_id() . '/'
) === 0);
$feed->delete();
}
public function testAddPublisherException()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$feed = Feed_Adapter::create($appbox, self::$user, "salut", 'coucou');
$this->client->request("POST", "/publications/feed/" . $feed->get_id() . "/addpublisher/");
$feed = new Feed_Adapter($appbox, $feed->get_id());
$response = $this->client->getResponse();
$this->assertTrue($response->isRedirect());
$this->assertTrue(
strpos(
$this->client->getResponse()->headers->get('Location')
, '/admin/publications/feed/' . $feed->get_id() . '/?err'
) === 0);
$feed->delete();
}
public function testRemovePublisher()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$feed = Feed_Adapter::create($appbox, self::$user, "salut", 'coucou');
$this->client->request("POST", "/publications/feed/" . $feed->get_id() . "/removepublisher/", array(
'usr_id' => self::$user_alt1->get_id()
));
$response = $this->client->getResponse();
$this->assertTrue($response->isRedirect());
$feed = new Feed_Adapter($appbox, $feed->get_id());
$publishers = $feed->get_publishers();
$this->assertFalse(isset($publishers[self::$user_alt1->get_id()]));
$this->assertTrue(
strpos(
$this->client->getResponse()->headers->get('Location')
, '/admin/publications/feed/' . $feed->get_id() . '/'
) === 0);
$feed->delete();
}
public function testRemovePublisherException()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$feed = Feed_Adapter::create($appbox, self::$user, "salut", 'coucou');
$this->client->request("POST", "/publications/feed/" . $feed->get_id() . "/removepublisher/");
$response = $this->client->getResponse();
$this->assertTrue($response->isRedirect());
$feed = new Feed_Adapter($appbox, $feed->get_id());
$this->assertTrue(
strpos(
$this->client->getResponse()->headers->get('Location')
, '/admin/publications/feed/' . $feed->get_id() . '/?err'
) === 0);
$feed->delete();
}
public function testDeleteFeed()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$feed = Feed_Adapter::create($appbox, self::$user, "salut", 'coucou');
$this->client->request("POST", "/publications/feed/" . $feed->get_id() . "/delete/");
$response = $this->client->getResponse();
$this->assertTrue($response->isRedirect());
try
{
$feed = new Feed_Adapter($appbox, $feed->get_id());
$feed->delete();
$this->fail("fail deleting feed");
}
catch(\Exception $e)
{ {
$appbox = appbox::get_instance(\bootstrap::getCore());
$feed = Feed_Adapter::create($appbox, self::$user, "salut", 'coucou');
$this->client->request("POST", "/publications/feed/" . $feed->get_id() . "/addpublisher/", array(
'usr_id' => self::$user_alt1->get_id()
));
$response = $this->client->getResponse();
$this->assertTrue($response->isRedirect());
$feed = new Feed_Adapter($appbox, $feed->get_id());
$publishers = $feed->get_publishers();
$this->assertTrue(isset($publishers[self::$user_alt1->get_id()]));
$this->assertTrue(
strpos(
$this->client->getResponse()->headers->get('Location')
, '/admin/publications/feed/' . $feed->get_id() . '/'
) === 0);
$feed->delete();
} }
} public function testAddPublisherException()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$feed = Feed_Adapter::create($appbox, self::$user, "salut", 'coucou');
$this->client->request("POST", "/publications/feed/" . $feed->get_id() . "/addpublisher/");
$feed = new Feed_Adapter($appbox, $feed->get_id());
$response = $this->client->getResponse();
$this->assertTrue($response->isRedirect());
$this->assertTrue(
strpos(
$this->client->getResponse()->headers->get('Location')
, '/admin/publications/feed/' . $feed->get_id() . '/?err'
) === 0);
$feed->delete();
}
public function testRemovePublisher()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$feed = Feed_Adapter::create($appbox, self::$user, "salut", 'coucou');
$this->client->request("POST", "/publications/feed/" . $feed->get_id() . "/removepublisher/", array(
'usr_id' => self::$user_alt1->get_id()
));
$response = $this->client->getResponse();
$this->assertTrue($response->isRedirect());
$feed = new Feed_Adapter($appbox, $feed->get_id());
$publishers = $feed->get_publishers();
$this->assertFalse(isset($publishers[self::$user_alt1->get_id()]));
$this->assertTrue(
strpos(
$this->client->getResponse()->headers->get('Location')
, '/admin/publications/feed/' . $feed->get_id() . '/'
) === 0);
$feed->delete();
}
public function testRemovePublisherException()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$feed = Feed_Adapter::create($appbox, self::$user, "salut", 'coucou');
$this->client->request("POST", "/publications/feed/" . $feed->get_id() . "/removepublisher/");
$response = $this->client->getResponse();
$this->assertTrue($response->isRedirect());
$feed = new Feed_Adapter($appbox, $feed->get_id());
$this->assertTrue(
strpos(
$this->client->getResponse()->headers->get('Location')
, '/admin/publications/feed/' . $feed->get_id() . '/?err'
) === 0);
$feed->delete();
}
public function testDeleteFeed()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$feed = Feed_Adapter::create($appbox, self::$user, "salut", 'coucou');
$this->client->request("POST", "/publications/feed/" . $feed->get_id() . "/delete/");
$response = $this->client->getResponse();
$this->assertTrue($response->isRedirect());
try {
$feed = new Feed_Adapter($appbox, $feed->get_id());
$feed->delete();
$this->fail("fail deleting feed");
} catch (\Exception $e) {
}
}
} }

View File

@@ -4,47 +4,29 @@ require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.
class RootTest extends \PhraseanetWebTestCaseAuthenticatedAbstract class RootTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{ {
protected $client;
protected static $need_records = false;
/** public function createApplication()
* As controllers use WebTestCase, it requires a client {
*/ return require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Admin.php';
protected $client; }
/** public function setUp()
* If the controller tests require some records, specify it her {
* parent::setUp();
* For example, this will loacd 2 records $this->client = $this->createClient();
* (self::$record_1 and self::$record_2) : }
*
* $need_records = 2;
*
*/
protected static $need_records = false;
/** /**
* The application loader * Default route test
*/ */
public function createApplication() public function testRouteSlash()
{ {
return require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Admin.php'; $this->client->request('GET', '/', array('section' => 'base:featured'));
} $this->assertTrue($this->client->getResponse()->isOk());
public function setUp()
{
parent::setUp();
$this->client = $this->createClient();
}
/**
* Default route test
*/
public function testRouteSlash()
{
$this->client->request('GET', '/', array('section' => 'base:featured'));
$this->assertTrue($this->client->getResponse()->isOk());
$this->client->request('GET', '/');
$this->assertTrue($this->client->getResponse()->isOk());
}
$this->client->request('GET', '/');
$this->assertTrue($this->client->getResponse()->isOk());
}
} }

View File

@@ -4,26 +4,9 @@ require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.
class ControllerSubdefsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract class ControllerSubdefsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{ {
/**
* As controllers use WebTestCase, it requires a client
*/
protected $client; protected $client;
/**
* If the controller tests require some records, specify it her
*
* For example, this will loacd 2 records
* (self::$record_1 and self::$record_2) :
*
* $need_records = 2;
*
*/
protected static $need_records = false; protected static $need_records = false;
/**
* The application loader
*/
public function createApplication() public function createApplication()
{ {
return require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Admin.php'; return require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Admin.php';
@@ -40,7 +23,7 @@ class ControllerSubdefsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
*/ */
public function testRouteGetSubdef() public function testRouteGetSubdef()
{ {
$appbox = appbox::get_instance(\bootstrap::getCore()); $appbox = appbox::get_instance(\bootstrap::getCore());
$databox = array_shift($appbox->get_databoxes()); $databox = array_shift($appbox->get_databoxes());
$this->client->request("GET", "/subdefs/" . $databox->get_sbas_id() . "/"); $this->client->request("GET", "/subdefs/" . $databox->get_sbas_id() . "/");
$this->assertTrue($this->client->getResponse()->isOk()); $this->assertTrue($this->client->getResponse()->isOk());
@@ -48,13 +31,13 @@ class ControllerSubdefsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
public function testPostRouteAddSubdef() public function testPostRouteAddSubdef()
{ {
$appbox = appbox::get_instance(\bootstrap::getCore()); $appbox = appbox::get_instance(\bootstrap::getCore());
$databox = array_shift($appbox->get_databoxes()); $databox = array_shift($appbox->get_databoxes());
$this->client->request("POST", "/subdefs/" . $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' => 'aname',
'group' => 'image' 'group' => 'image'
))); )));
$this->assertTrue($this->client->getResponse()->isRedirect()); $this->assertTrue($this->client->getResponse()->isRedirect());
$subdefs = $databox->get_subdef_structure(); $subdefs = $databox->get_subdef_structure();
$subdefs->get_subdef("image", "aname"); $subdefs->get_subdef("image", "aname");
@@ -63,46 +46,43 @@ class ControllerSubdefsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
public function testPostRouteDeleteSubdef() public function testPostRouteDeleteSubdef()
{ {
$appbox = appbox::get_instance(\bootstrap::getCore()); $appbox = appbox::get_instance(\bootstrap::getCore());
$databox = array_shift($appbox->get_databoxes()); $databox = array_shift($appbox->get_databoxes());
$subdefs = $databox->get_subdef_structure(); $subdefs = $databox->get_subdef_structure();
$subdefs->add_subdef("image", "name", "class"); $subdefs->add_subdef("image", "name", "class");
$this->client->request("POST", "/subdefs/" . $databox->get_sbas_id() . "/", array('delete_subdef' => 'group_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)
{
} }
} }
public function testPostRouteAddSubdefWithNoParams() public function testPostRouteAddSubdefWithNoParams()
{ {
$appbox = appbox::get_instance(\bootstrap::getCore()); $appbox = appbox::get_instance(\bootstrap::getCore());
$databox = array_shift($appbox->get_databoxes()); $databox = array_shift($appbox->get_databoxes());
$subdefs = $databox->get_subdef_structure(); $subdefs = $databox->get_subdef_structure();
$subdefs->add_subdef("image", "name", "class"); $subdefs->add_subdef("image", "name", "class");
$this->client->request("POST", "/subdefs/" . $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' => 'class'
, '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"); $subdef = $subdefs->get_subdef("image", "name");
/* @var $subdef \databox_subdef */ /* @var $subdef \databox_subdef */
$this->assertFalse($subdef->is_downloadable()); $this->assertFalse($subdef->is_downloadable());
@@ -118,5 +98,4 @@ class ControllerSubdefsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$subdefs->delete_subdef("image", "name"); $subdefs->delete_subdef("image", "name");
} }
} }

View File

@@ -4,359 +4,332 @@ require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.
class ControllerUsersTest extends \PhraseanetWebTestCaseAuthenticatedAbstract class ControllerUsersTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{ {
protected $client;
/** protected static $need_records = false;
* As controllers use WebTestCase, it requires a client protected $usersParameters;
*/
protected $client;
/** public function createApplication()
* If the controller tests require some records, specify it her
*
* For example, this will loacd 2 records
* (self::$record_1 and self::$record_2) :
*
* $need_records = 2;
*
*/
protected static $need_records = false;
protected $usersParameters;
/**
* The application loader
*/
public function createApplication()
{
return require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Admin.php';
}
public function setUp()
{
$this->usersParameters = array("users" => implode(';', array(self::$user->get_id(), self::$user_alt1->get_id())));
parent::setUp();
$this->client = $this->createClient();
}
public function testRouteRightsPost()
{
$this->client->request('POST', '/users/rights/', $this->usersParameters);
$response = $this->client->getResponse();
$this->assertTrue($response->isOk());
}
public function testRouteRightsGet()
{
$this->client->request('GET', '/users/rights/', $this->usersParameters);
$response = $this->client->getResponse();
$this->assertTrue($response->isOk());
}
public function testRouteDelete()
{
$appbox = \appbox::get_instance(\bootstrap::getCore());
$username = uniqid('user_');
$user = User_Adapter::create($appbox, $username, "test", $username . "@email.com", false);
$id = $user->get_id();
$this->client->request('POST', '/users/delete/', array('users' => $id));
$response = $this->client->getResponse();
$this->assertTrue($response->isRedirect());
try
{ {
$user = User_Adapter::getInstance($id, $appbox); return require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Admin.php';
$user->delete();
$this->fail("user not deleted");
} }
catch (\Exception $e)
public function setUp()
{ {
parent::setUp();
$this->usersParameters = array("users" => implode(';', array(self::$user->get_id(), self::$user_alt1->get_id())));
$this->client = $this->createClient();
} }
}
public function testRouteRightsApply() public function testRouteRightsPost()
{ {
$appbox = \appbox::get_instance(\bootstrap::getCore()); $this->client->request('POST', '/users/rights/', $this->usersParameters);
$response = $this->client->getResponse();
$this->assertTrue($response->isOk());
}
$username = uniqid('user_'); public function testRouteRightsGet()
$user = User_Adapter::create($appbox, $username, "test", $username . "@email.com", false); {
$this->client->request('GET', '/users/rights/', $this->usersParameters);
$response = $this->client->getResponse();
$this->assertTrue($response->isOk());
}
$base_id = self::$collection->get_base_id(); public function testRouteDelete()
$_GET['values'] = 'canreport_' . $base_id . '=1&manage_' . self::$collection->get_base_id() . '=1&canpush_' . self::$collection->get_base_id() . '=1'; {
$_GET['user_infos'] = "user_infos[email]=" . $user->get_email(); $appbox = \appbox::get_instance(\bootstrap::getCore());
$this->client->request('POST', '/users/rights/apply/', array('users' => $user->get_id())); $username = uniqid('user_');
$response = $this->client->getResponse(); $user = User_Adapter::create($appbox, $username, "test", $username . "@email.com", false);
$this->assertTrue($response->isOK()); $id = $user->get_id();
$this->assertEquals("application/json", $response->headers->get("content-type"));
$datas = json_decode($response->getContent());
$this->assertTrue(is_object($datas));
$datas = json_decode($response->getContent());
$this->assertFalse($datas->error);
$this->assertTrue($user->ACL()->has_right_on_base($base_id, "manage"));
$this->assertTrue($user->ACL()->has_right_on_base($base_id, "canpush"));
$this->assertTrue($user->ACL()->has_right_on_base($base_id, "canreport"));
$user->delete();
}
public function testRouteRightsApplyException() $this->client->request('POST', '/users/delete/', array('users' => $id));
{ $response = $this->client->getResponse();
$this->markTestIncomplete(); $this->assertTrue($response->isRedirect());
$_GET = array(); try {
$appbox = \appbox::get_instance(\bootstrap::getCore()); $user = User_Adapter::getInstance($id, $appbox);
$username = uniqid('user_'); $user->delete();
$user = User_Adapter::create($appbox, $username, "test", $username . "@email.com", false); $this->fail("user not deleted");
$base_id = self::$collection->get_base_id(); } catch (\Exception $e) {
$_GET['values'] = 'canreport_' . $base_id . '=1&manage_' . self::$collection->get_base_id() . '=1&canpush_' . self::$collection->get_base_id() . '=1';
$_GET['user_infos'] = "user_infos[email]=" . $user->get_email();
$this->client->request('POST', '/users/rights/apply/', array('users' => $user->get_id()));
$response = $this->client->getResponse();
$this->assertTrue($response->isOK());
$this->assertEquals("application/json", $response->headers->get("content-type"));
$datas = json_decode($response->getContent());
$this->assertTrue(is_object($datas));
$this->assertTrue($datas->error);
$user->delete();
}
public function testRouteQuota() }
{ }
$base_id = array_pop(array_keys(self::$user->ACL()->get_granted_base()));
$params = array('base_id'=>$base_id, 'users'=>self::$user->get_id());
$this->client->request('POST', '/users/rights/quotas/', $params); public function testRouteRightsApply()
$response = $this->client->getResponse(); {
$this->assertTrue($response->isOK()); $appbox = \appbox::get_instance(\bootstrap::getCore());
}
public function testRouteQuotaAdd() $username = uniqid('user_');
{ $user = User_Adapter::create($appbox, $username, "test", $username . "@email.com", false);
$params = array(
'base_id' => self::$collection->get_base_id()
, 'quota' => '1', 'droits' => 38, 'restes' => 15);
$this->client->request('POST', '/users/rights/quotas/apply/', $params);
$response = $this->client->getResponse();
$this->assertTrue($response->isOK());
}
public function testRouteQuotaRemove() $base_id = self::$collection->get_base_id();
{ $_GET['values'] = 'canreport_' . $base_id . '=1&manage_' . self::$collection->get_base_id() . '=1&canpush_' . self::$collection->get_base_id() . '=1';
$base_id = array_pop(array_keys(self::$user->ACL()->get_granted_base())); $_GET['user_infos'] = "user_infos[email]=" . $user->get_email();
$params = array('base_id'=>$base_id, 'users'=>self::$user->get_id());
$this->client->request('POST', '/users/rights/quotas/apply/', $params); $this->client->request('POST', '/users/rights/apply/', array('users' => $user->get_id()));
$response = $this->client->getResponse(); $response = $this->client->getResponse();
$this->assertTrue($response->isOK()); $this->assertTrue($response->isOK());
} $this->assertEquals("application/json", $response->headers->get("content-type"));
$datas = json_decode($response->getContent());
$this->assertTrue(is_object($datas));
$datas = json_decode($response->getContent());
$this->assertFalse($datas->error);
$this->assertTrue($user->ACL()->has_right_on_base($base_id, "manage"));
$this->assertTrue($user->ACL()->has_right_on_base($base_id, "canpush"));
$this->assertTrue($user->ACL()->has_right_on_base($base_id, "canreport"));
$user->delete();
}
public function testRouteRightTime() public function testRouteRightsApplyException()
{ {
$base_id = array_pop(array_keys(self::$user->ACL()->get_granted_base())); $this->markTestIncomplete();
$params = array('base_id'=>$base_id, 'users'=>self::$user->get_id()); $_GET = array();
$appbox = \appbox::get_instance(\bootstrap::getCore());
$username = uniqid('user_');
$user = User_Adapter::create($appbox, $username, "test", $username . "@email.com", false);
$base_id = self::$collection->get_base_id();
$_GET['values'] = 'canreport_' . $base_id . '=1&manage_' . self::$collection->get_base_id() . '=1&canpush_' . self::$collection->get_base_id() . '=1';
$_GET['user_infos'] = "user_infos[email]=" . $user->get_email();
$this->client->request('POST', '/users/rights/apply/', array('users' => $user->get_id()));
$response = $this->client->getResponse();
$this->assertTrue($response->isOK());
$this->assertEquals("application/json", $response->headers->get("content-type"));
$datas = json_decode($response->getContent());
$this->assertTrue(is_object($datas));
$this->assertTrue($datas->error);
$user->delete();
}
$this->client->request('POST', '/users/rights/time/', $params); public function testRouteQuota()
$response = $this->client->getResponse(); {
$this->assertTrue($response->isOK()); $base_id = array_pop(array_keys(self::$user->ACL()->get_granted_base()));
} $params = array('base_id' => $base_id, 'users' => self::$user->get_id());
public function testRouteRightTimeApply() $this->client->request('POST', '/users/rights/quotas/', $params);
{ $response = $this->client->getResponse();
$appbox = \appbox::get_instance(\bootstrap::getCore()); $this->assertTrue($response->isOK());
$username = uniqid('user_'); }
$user = User_Adapter::create($appbox, $username, "test", $username . "@email.com", false);
$base_id = self::$collection->get_base_id(); public function testRouteQuotaAdd()
$date = new \Datetime(); {
$date->modify("-10 days"); $params = array(
$dmin = $date->format(DATE_ATOM); 'base_id' => self::$collection->get_base_id()
$date->modify("+30 days"); , 'quota' => '1', 'droits' => 38, 'restes' => 15);
$dmax = $date->format(DATE_ATOM); $this->client->request('POST', '/users/rights/quotas/apply/', $params);
$this->client->request('POST', '/users/rights/time/apply/', array('base_id' => $base_id, 'dmin' => $dmin, 'dmax' => $dmax, 'limit' => 1, 'users' => $user->get_id())); $response = $this->client->getResponse();
$response = $this->client->getResponse(); $this->assertTrue($response->isOK());
$this->assertTrue($response->isOK()); }
public function testRouteQuotaRemove()
{
$base_id = array_pop(array_keys(self::$user->ACL()->get_granted_base()));
$params = array('base_id' => $base_id, 'users' => self::$user->get_id());
$this->client->request('POST', '/users/rights/quotas/apply/', $params);
$response = $this->client->getResponse();
$this->assertTrue($response->isOK());
}
public function testRouteRightTime()
{
$base_id = array_pop(array_keys(self::$user->ACL()->get_granted_base()));
$params = array('base_id' => $base_id, 'users' => self::$user->get_id());
$this->client->request('POST', '/users/rights/time/', $params);
$response = $this->client->getResponse();
$this->assertTrue($response->isOK());
}
public function testRouteRightTimeApply()
{
$appbox = \appbox::get_instance(\bootstrap::getCore());
$username = uniqid('user_');
$user = User_Adapter::create($appbox, $username, "test", $username . "@email.com", false);
$base_id = self::$collection->get_base_id();
$date = new \Datetime();
$date->modify("-10 days");
$dmin = $date->format(DATE_ATOM);
$date->modify("+30 days");
$dmax = $date->format(DATE_ATOM);
$this->client->request('POST', '/users/rights/time/apply/', array('base_id' => $base_id, 'dmin' => $dmin, 'dmax' => $dmax, 'limit' => 1, 'users' => $user->get_id()));
$response = $this->client->getResponse();
$this->assertTrue($response->isOK());
// $this->assertTrue($user->ACL()->is_limited($base_id)); // $this->assertTrue($user->ACL()->is_limited($base_id));
$user->delete(); $user->delete();
}
public function testRouteRightMask()
{
$base_id = array_pop(array_keys(self::$user->ACL()->get_granted_base()));
$params = array('base_id'=>$base_id, 'users'=>self::$user->get_id());
$this->client->request('POST', '/users/rights/masks/', $params);
$response = $this->client->getResponse();
$this->assertTrue($response->isOK());
}
public function testRouteRightMaskApply()
{
$this->markTestIncomplete();
$base_id = self::$collection->get_base_id();
$username = uniqid('user_');
$user = User_Adapter::create($appbox, $username, "test", $username . "@email.com", false);
$this->client->request('POST', '/users/rights/masks/apply/', array(
'base_id' => $base_id, 'vand_and', 'vand_or', 'vxor_or', 'vxor_and'
));
$response = $this->client->getResponse();
$this->assertTrue($response->isOK());
$user->delete();
}
public function testRouteSearch()
{
$this->client->request('POST', '/users/search/');
$response = $this->client->getResponse();
$this->assertTrue($response->isOK());
}
public function testRoutesearchExport()
{
$this->client->request('POST', '/users/search/export/');
$response = $this->client->getResponse();
$this->assertTrue($response->isOK());
$this->assertEquals("text/plain; charset=UTF-8", $response->headers->get("Content-type"));
$this->assertEquals("attachment; filename=export.txt", $response->headers->get("content-disposition"));
}
public function testRouteThSearch()
{
$this->client->request('GET', '/users/typeahead/search/', array('term' => 'admin'));
$response = $this->client->getResponse();
$this->assertTrue($response->isOK());
$this->assertEquals("application/json", $response->headers->get("content-type"));
}
public function testRouteApplyTp()
{
$appbox = \appbox::get_instance(\bootstrap::getCore());
$templateName = uniqid('template_');
$template = User_Adapter::create($appbox, $templateName, "test", $templateName . "@email.com", false);
$template->set_template(self::$user);
$username = uniqid('user_');
$user = User_Adapter::create($appbox, $username, "test", $username . "@email.com", false);
$this->client->request('POST', '/users/apply_template/', array(
'template' => $template->get_id()
, 'users' => $user->get_id())
);
$response = $this->client->getResponse();
$this->assertTrue($response->isRedirect());
$template->delete();
$user->delete();
}
public function testRouteCreateException()
{
$this->client->request('POST', '/users/create/', array('value' => '', 'template' => '1'));
$response = $this->client->getResponse();
$this->assertTrue($response->isOK());
$this->assertEquals("application/json", $response->headers->get("content-type"));
$datas = json_decode($response->getContent());
$this->assertTrue(is_object($datas));
$this->assertTrue($datas->error);
}
public function testRouteCreateExceptionUser()
{
$this->client->request('POST', '/users/create/', array('value' => '', 'template' => '0'));
$response = $this->client->getResponse();
$this->assertTrue($response->isOK());
$this->assertEquals("application/json", $response->headers->get("content-type"));
$datas = json_decode($response->getContent());
$this->assertTrue(is_object($datas));
$this->assertTrue($datas->error);
}
public function testRouteCreateUser()
{
$appbox = \appbox::get_instance(\bootstrap::getCore());
$username = uniqid('user_');
$user = User_Adapter::create($appbox, $username, "test", $username . "@email.com", false);
$this->client->request('POST', '/users/create/', array('value' => $username . "@email.com", 'template' => '0'));
$response = $this->client->getResponse();
$this->assertTrue($response->isOK());
$this->assertEquals("application/json", $response->headers->get("content-type"));
$datas = json_decode($response->getContent());
$this->assertTrue(is_object($datas));
$this->assertFalse($datas->error);
try
{
$user = \User_Adapter::getInstance((int) $datas->data, $appbox);
$user->delete();
} }
catch (\Exception $e)
public function testRouteRightMask()
{ {
$this->fail("could not delete created user " . $e->getMessage()); $base_id = array_pop(array_keys(self::$user->ACL()->get_granted_base()));
$params = array('base_id' => $base_id, 'users' => self::$user->get_id());
$this->client->request('POST', '/users/rights/masks/', $params);
$response = $this->client->getResponse();
$this->assertTrue($response->isOK());
} }
}
public function testRouteRightMaskApply()
public function testRouteExportCsv()
{
$this->client->request('POST', '/users/export/csv/');
$response = $this->client->getResponse();
$this->assertTrue($response->isOK());
$this->assertRegexp("#text/csv#", $response->headers->get("content-type"));
$this->assertRegexp("#charset=UTF-8#", $response->headers->get("content-type"));
$this->assertEquals("attachment; filename=export.txt", $response->headers->get("content-disposition"));
}
public function testResetRights()
{
$appbox = \appbox::get_instance(self::$core);
$username = uniqid('user_');
$user = User_Adapter::create($appbox, $username, "test", $username . "@email.com", false);
$user->ACL()->give_access_to_sbas(array_keys($appbox->get_databoxes()));
foreach ($appbox->get_databoxes() as $databox)
{ {
$this->markTestIncomplete();
$base_id = self::$collection->get_base_id();
$username = uniqid('user_');
$user = User_Adapter::create($appbox, $username, "test", $username . "@email.com", false);
$this->client->request('POST', '/users/rights/masks/apply/', array(
'base_id' => $base_id, 'vand_and', 'vand_or', 'vxor_or', 'vxor_and'
));
$response = $this->client->getResponse();
$this->assertTrue($response->isOK());
$user->delete();
}
$rights = array( public function testRouteSearch()
'bas_manage' => '1' {
, 'bas_modify_struct' => '1' $this->client->request('POST', '/users/search/');
, 'bas_modif_th' => '1' $response = $this->client->getResponse();
, 'bas_chupub' => '1' $this->assertTrue($response->isOK());
); }
$user->ACL()->update_rights_to_sbas($databox->get_sbas_id(), $rights); public function testRoutesearchExport()
{
$this->client->request('POST', '/users/search/export/');
$response = $this->client->getResponse();
$this->assertTrue($response->isOK());
$this->assertEquals("text/plain; charset=UTF-8", $response->headers->get("Content-type"));
$this->assertEquals("attachment; filename=export.txt", $response->headers->get("content-disposition"));
}
foreach ($databox->get_collections() as $collection) public function testRouteThSearch()
{ {
$base_id = $collection->get_base_id(); $this->client->request('GET', '/users/typeahead/search/', array('term' => 'admin'));
$user->ACL()->give_access_to_base(array($base_id)); $response = $this->client->getResponse();
$this->assertTrue($response->isOK());
$this->assertEquals("application/json", $response->headers->get("content-type"));
}
$rights = array( public function testRouteApplyTp()
'canputinalbum' => '1' {
, 'candwnldhd' => '1' $appbox = \appbox::get_instance(\bootstrap::getCore());
, 'candwnldsubdef' => '1'
, 'nowatermark' => '1' $templateName = uniqid('template_');
$template = User_Adapter::create($appbox, $templateName, "test", $templateName . "@email.com", false);
$template->set_template(self::$user);
$username = uniqid('user_');
$user = User_Adapter::create($appbox, $username, "test", $username . "@email.com", false);
$this->client->request('POST', '/users/apply_template/', array(
'template' => $template->get_id()
, 'users' => $user->get_id())
); );
$user->ACL()->update_rights_to_base($collection->get_base_id(), $rights); $response = $this->client->getResponse();
break; $this->assertTrue($response->isRedirect());
}
$template->delete();
$user->delete();
} }
public function testRouteCreateException()
{
$this->client->request('POST', '/users/create/', array('value' => '', 'template' => '1'));
$response = $this->client->getResponse();
$this->assertTrue($response->isOK());
$this->assertEquals("application/json", $response->headers->get("content-type"));
$datas = json_decode($response->getContent());
$this->assertTrue(is_object($datas));
$this->assertTrue($datas->error);
}
public function testRouteCreateExceptionUser()
{
$this->client->request('POST', '/users/create/', array('value' => '', 'template' => '0'));
$response = $this->client->getResponse();
$this->assertTrue($response->isOK());
$this->assertEquals("application/json", $response->headers->get("content-type"));
$datas = json_decode($response->getContent());
$this->assertTrue(is_object($datas));
$this->assertTrue($datas->error);
}
public function testRouteCreateUser()
{
$appbox = \appbox::get_instance(\bootstrap::getCore());
$username = uniqid('user_');
$user = User_Adapter::create($appbox, $username, "test", $username . "@email.com", false);
$this->client->request('POST', '/users/create/', array('value' => $username . "@email.com", 'template' => '0'));
$response = $this->client->getResponse();
$this->assertTrue($response->isOK());
$this->assertEquals("application/json", $response->headers->get("content-type"));
$datas = json_decode($response->getContent());
$this->assertTrue(is_object($datas));
$this->assertFalse($datas->error);
try {
$user = \User_Adapter::getInstance((int) $datas->data, $appbox);
$user->delete();
} catch (\Exception $e) {
$this->fail("could not delete created user " . $e->getMessage());
}
}
public function testRouteExportCsv()
{
$this->client->request('POST', '/users/export/csv/');
$response = $this->client->getResponse();
$this->assertTrue($response->isOK());
$this->assertRegexp("#text/csv#", $response->headers->get("content-type"));
$this->assertRegexp("#charset=UTF-8#", $response->headers->get("content-type"));
$this->assertEquals("attachment; filename=export.txt", $response->headers->get("content-disposition"));
}
public function testResetRights()
{
$appbox = \appbox::get_instance(self::$core);
$username = uniqid('user_');
$user = User_Adapter::create($appbox, $username, "test", $username . "@email.com", false);
$user->ACL()->give_access_to_sbas(array_keys($appbox->get_databoxes()));
foreach ($appbox->get_databoxes() as $databox) {
$rights = array(
'bas_manage' => '1'
, 'bas_modify_struct' => '1'
, 'bas_modif_th' => '1'
, 'bas_chupub' => '1'
);
$user->ACL()->update_rights_to_sbas($databox->get_sbas_id(), $rights);
foreach ($databox->get_collections() as $collection) {
$base_id = $collection->get_base_id();
$user->ACL()->give_access_to_base(array($base_id));
$rights = array(
'canputinalbum' => '1'
, 'candwnldhd' => '1'
, 'candwnldsubdef' => '1'
, 'nowatermark' => '1'
);
$user->ACL()->update_rights_to_base($collection->get_base_id(), $rights);
break;
}
}
// //
$this->client->request('POST', '/users/rights/reset/', array('users' => $user->get_id())); $this->client->request('POST', '/users/rights/reset/', array('users' => $user->get_id()));
$response = $this->client->getResponse(); $response = $this->client->getResponse();
$this->assertTrue($response->isOK()); $this->assertTrue($response->isOK());
$this->assertEquals("application/json", $response->headers->get("content-type")); $this->assertEquals("application/json", $response->headers->get("content-type"));
$datas = json_decode($response->getContent()); $datas = json_decode($response->getContent());
$this->assertTrue(is_object($datas)); $this->assertTrue(is_object($datas));
$this->assertFalse($datas->error); $this->assertFalse($datas->error);
$this->assertFalse($user->ACL()->has_access_to_base($base_id)); $this->assertFalse($user->ACL()->has_access_to_base($base_id));
$user->delete(); $user->delete();
} }
} }

View File

@@ -21,49 +21,48 @@ use Symfony\Component\HttpFoundation\Response;
*/ */
class BoilerPlate extends \PhraseanetWebTestCaseAbstract class BoilerPlate extends \PhraseanetWebTestCaseAbstract
{ {
/**
* As controllers use WebTestCase, it requires a client
*/
protected $client;
/** /**
* As controllers use WebTestCase, it requires a client * If the controller tests require some records, specify it her
*/ *
protected $client; * For example, this will loacd 2 records
/** * (self::$record_1 and self::$record_2) :
* If the controller tests require some records, specify it her *
* * $need_records = 2;
* For example, this will loacd 2 records *
* (self::$record_1 and self::$record_2) : */
* protected static $need_records = false;
* $need_records = 2;
*
*/
protected static $need_records = false;
/** /**
* The application loader * The application loader
*/ */
public function createApplication() public function createApplication()
{ {
return require __DIR__ . '/../../../../Path/To/Application.php'; return require __DIR__ . '/../../../../Path/To/Application.php';
} }
public function setUp() public function setUp()
{ {
parent::setUp(); parent::setUp();
$this->client = $this->createClient(); $this->client = $this->createClient();
} }
public function tearDown() public function tearDown()
{ {
parent::tearDown(); parent::tearDown();
} }
/** /**
* Default route test * Default route test
*/ */
public function testRouteSlash() public function testRouteSlash()
{ {
$this->markTestIncomplete( $this->markTestIncomplete(
'This test has not been implemented yet.' 'This test has not been implemented yet.'
); );
} }
} }

File diff suppressed because it is too large Load Diff

View File

@@ -8,431 +8,398 @@ use Symfony\Component\HttpFoundation\Response;
class BridgeApplication extends PhraseanetWebTestCaseAuthenticatedAbstract class BridgeApplication extends PhraseanetWebTestCaseAuthenticatedAbstract
{ {
public static $account = null;
public static $api = null;
protected $client;
protected static $need_records = 1;
public static $account = null; public function setUp()
public static $api = null;
protected $client;
protected static $need_records = 1;
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
}
public static function tearDownAfterClass()
{
parent::tearDownAfterClass();
}
public function setUp()
{
parent::setUp();
$this->client = $this->createClient();
try
{ {
self::$api = Bridge_Api::get_by_api_name(appbox::get_instance(\bootstrap::getCore()), 'apitest'); parent::setUp();
} $this->client = $this->createClient();
catch (Bridge_Exception_ApiNotFound $e) try {
{ self::$api = Bridge_Api::get_by_api_name(appbox::get_instance(\bootstrap::getCore()), 'apitest');
self::$api = Bridge_Api::create(appbox::get_instance(\bootstrap::getCore()), 'apitest'); } catch (Bridge_Exception_ApiNotFound $e) {
self::$api = Bridge_Api::create(appbox::get_instance(\bootstrap::getCore()), 'apitest');
}
try {
self::$account = Bridge_Account::load_account_from_distant_id(appbox::get_instance(\bootstrap::getCore()), self::$api, self::$user, 'kirikoo');
} catch (Bridge_Exception_AccountNotFound $e) {
self::$account = Bridge_Account::create(appbox::get_instance(\bootstrap::getCore()), self::$api, self::$user, 'kirikoo', 'coucou');
}
} }
try public function tearDown()
{ {
self::$account = Bridge_Account::load_account_from_distant_id(appbox::get_instance(\bootstrap::getCore()), self::$api, self::$user, 'kirikoo'); if (self::$api instanceof Bridge_Api) {
self::$api->delete();
}
if (self::$account instanceof Bridge_Account) {
self::$account->delete();
}
parent::tearDown();
} }
catch (Bridge_Exception_AccountNotFound $e)
public function createApplication()
{ {
self::$account = Bridge_Account::create(appbox::get_instance(\bootstrap::getCore()), self::$api, self::$user, 'kirikoo', 'coucou'); return include realpath(__DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Prod.php');
} }
}
public function tearDown() /**
{ * @todo create a new basket dont take an existing one
parent::tearDown(); */
if (self::$api instanceof Bridge_Api) public function testManager()
self::$api->delete(); {
if (self::$account instanceof Bridge_Account) $appbox = appbox::get_instance(\bootstrap::getCore());
self::$account->delete(); $accounts = Bridge_Account::get_accounts_by_user($appbox, self::$user);
} $usr_id = self::$user->get_id();
public function createApplication() $basket = $this->insertOneBasket();
{
return include realpath(__DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Prod.php');
}
/** $crawler = $this->client->request('POST', '/bridge/manager/', array('ssel' => $basket->getId()));
* @todo create a new basket dont take an existing one $pageContent = $this->client->getResponse()->getContent();
*/ $this->assertTrue($this->client->getResponse()->isOk());
public function testManager() }
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$accounts = Bridge_Account::get_accounts_by_user($appbox, self::$user);
$usr_id = self::$user->get_id();
$basket = $this->insertOneBasket(); public function testLogin()
{
$this->client->request('GET', '/bridge/login/Apitest/');
$test = new Bridge_Api_Apitest(registry::get_instance(), new Bridge_Api_Auth_None());
$this->assertTrue($this->client->getResponse()->getStatusCode() == 302);
$this->assertTrue($this->client->getResponse()->isRedirect($test->get_auth_url()));
}
$crawler = $this->client->request('POST', '/bridge/manager/', array('ssel' => $basket->getId())); public function testCallBackFailed()
$pageContent = $this->client->getResponse()->getContent(); {
$this->assertTrue($this->client->getResponse()->isOk()); $appbox = appbox::get_instance(\bootstrap::getCore());
} $session = $appbox->get_session();
$crawler = $this->client->request('GET', '/bridge/callback/unknow_api/');
$this->assertTrue($this->client->getResponse()->isOk());
}
public function testLogin() public function testCallBackAccountAlreadyDefined()
{ {
$this->client->request('GET', '/bridge/login/Apitest/'); $appbox = appbox::get_instance(\bootstrap::getCore());
$test = new Bridge_Api_Apitest(registry::get_instance(), new Bridge_Api_Auth_None()); $crawler = $this->client->request('GET', '/bridge/callback/apitest/');
$this->assertTrue($this->client->getResponse()->getStatusCode() == 302); $this->assertTrue($this->client->getResponse()->isOk());
$this->assertTrue($this->client->getResponse()->isRedirect($test->get_auth_url())); $pageContent = $this->client->getResponse()->getContent();
} //check for errors in the crawler
$phpunit = $this;
public function testCallBackFailed() $crawler
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$session = $appbox->get_session();
$crawler = $this->client->request('GET', '/bridge/callback/unknow_api/');
$this->assertTrue($this->client->getResponse()->isOk());
}
public function testCallBackAccountAlreadyDefined()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$crawler = $this->client->request('GET', '/bridge/callback/apitest/');
$this->assertTrue($this->client->getResponse()->isOk());
$pageContent = $this->client->getResponse()->getContent();
//check for errors in the crawler
$phpunit = $this;
$crawler
->filter('div') ->filter('div')
->reduce(function ($node, $i) use ($phpunit) ->reduce(function ($node, $i) use ($phpunit) {
{ if ( ! $node->getAttribute('class')) {
if (!$node->getAttribute('class'))
{
return false; return false;
} } elseif ($node->getAttribute('class') == 'error_auth') {
elseif ($node->getAttribute('class') == 'error_auth')
{
$phpunit->fail("Erreur callback"); $phpunit->fail("Erreur callback");
} }
}); });
$settings = self::$account->get_settings(); $settings = self::$account->get_settings();
$this->assertEquals("kikoo", $settings->get("auth_token")); $this->assertEquals("kikoo", $settings->get("auth_token"));
$this->assertEquals("kooki", $settings->get("refresh_token")); $this->assertEquals("kooki", $settings->get("refresh_token"));
$this->assertEquals("biloute", $settings->get("access_token")); $this->assertEquals("biloute", $settings->get("access_token"));
$settings->delete("auth_token"); $settings->delete("auth_token");
$settings->delete("refresh_token"); $settings->delete("refresh_token");
$settings->delete("access_token"); $settings->delete("access_token");
} }
public function testCallBackAccountNoDefined() public function testCallBackAccountNoDefined()
{ {
if (self::$account instanceof Bridge_Account) if (self::$account instanceof Bridge_Account)
self::$account->delete(); self::$account->delete();
$crawler = $this->client->request('GET', '/bridge/callback/apitest/'); $crawler = $this->client->request('GET', '/bridge/callback/apitest/');
$this->assertTrue($this->client->getResponse()->isOk()); $this->assertTrue($this->client->getResponse()->isOk());
$phpunit = $this; $phpunit = $this;
$crawler $crawler
->filter('div') ->filter('div')
->reduce(function ($node, $i) use ($phpunit) ->reduce(function ($node, $i) use ($phpunit) {
{ if ( ! $node->getAttribute('class')) {
if (!$node->getAttribute('class'))
{
return false; return false;
} } elseif ($node->getAttribute('class') == 'error_auth') {
elseif ($node->getAttribute('class') == 'error_auth')
{
$phpunit->fail("Erreur callback"); $phpunit->fail("Erreur callback");
} }
}); });
try try {
{ self::$account = Bridge_Account::load_account_from_distant_id(appbox::get_instance(\bootstrap::getCore()), self::$api, self::$user, 'kirikoo');
self::$account = Bridge_Account::load_account_from_distant_id(appbox::get_instance(\bootstrap::getCore()), self::$api, self::$user, 'kirikoo'); $settings = self::$account->get_settings();
$settings = self::$account->get_settings(); $this->assertEquals("kikoo", $settings->get("auth_token"));
$this->assertEquals("kikoo", $settings->get("auth_token")); $this->assertEquals("kooki", $settings->get("refresh_token"));
$this->assertEquals("kooki", $settings->get("refresh_token")); $this->assertEquals("biloute", $settings->get("access_token"));
$this->assertEquals("biloute", $settings->get("access_token")); $settings->delete("auth_token");
$settings->delete("auth_token"); $settings->delete("refresh_token");
$settings->delete("refresh_token"); $settings->delete("access_token");
$settings->delete("access_token"); } catch (Bridge_Exception_AccountNotFound $e) {
} $this->fail("No account created after callback");
catch (Bridge_Exception_AccountNotFound $e) }
{
$this->fail("No account created after callback"); if ( ! self::$account instanceof Bridge_Account)
self::$account = Bridge_Account::create(appbox::get_instance(\bootstrap::getCore()), self::$api, self::$user, 'kirikoo', 'coucou');
} }
if (!self::$account instanceof Bridge_Account) public function testLogout()
self::$account = Bridge_Account::create(appbox::get_instance(\bootstrap::getCore()), self::$api, self::$user, 'kirikoo', 'coucou');
}
public function testLogout()
{
self::$account->get_settings()->set("auth_token", "somethingNotNull"); //connected
$url = sprintf('/bridge/adapter/%d/logout/', self::$account->get_id());
$this->client->request('GET', $url);
$redirect = sprintf("/prod/bridge/adapter/%s/load-elements/%s/", self::$account->get_id(), self::$account->get_api()->get_connector()->get_default_element_type());
$this->assertTrue($this->client->getResponse()->isRedirect($redirect));
$this->assertNull(self::$account->get_settings()->get("auth_token"));
}
public function testLoadElements()
{
self::$account->get_settings()->set("auth_token", "somethingNotNull"); //connected
$url = sprintf("/bridge/adapter/%s/load-elements/%s/", self::$account->get_id(), self::$account->get_api()->get_connector()->get_default_element_type());
$account = new Bridge_Account(appbox::get_instance(\bootstrap::getCore()), self::$api, self::$account->get_id());
$crawler = $this->client->request('GET', $url, array("page" => 1));
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertNotContains(self::$account->get_api()->generate_login_url(registry::get_instance(), self::$account->get_api()->get_connector()->get_name()), $this->client->getResponse()->getContent());
}
public function testLoadRecords()
{
self::$account->get_settings()->set("auth_token", "somethingNotNull"); //connected
$url = sprintf("/bridge/adapter/%s/load-records/", self::$account->get_id());
$crawler = $this->client->request('GET', $url, array("page" => 1));
$elements = Bridge_Element::get_elements_by_account(appbox::get_instance(\bootstrap::getCore()), self::$account);
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertEquals(sizeof($elements), $crawler->filterXPath("//table/tr")->count());
$this->assertNotContains(self::$account->get_api()->generate_login_url(registry::get_instance(), self::$account->get_api()->get_connector()->get_name()), $this->client->getResponse()->getContent());
}
public function testLoadRecordsDisconnected()
{
$this->client->followRedirects();
self::$account->get_settings()->set("auth_token", null); //deconnected
$url = sprintf("/bridge/adapter/%s/load-records/", self::$account->get_id());
$crawler = $this->client->request('GET', $url, array("page" => 1));
$pageContent = $this->client->getResponse()->getContent();
$this->assertContains($url, $pageContent);
$this->deconnected($crawler, $pageContent);
}
public function testLoadContainers()
{
self::$account->get_settings()->set("auth_token", "somethingNotNull"); //connected
$url = sprintf("/bridge/adapter/%s/load-containers/%s/", self::$account->get_id(), self::$account->get_api()->get_connector()->get_default_container_type());
$crawler = $this->client->request('GET', $url, array("page" => 1));
$elements = Bridge_Element::get_elements_by_account(appbox::get_instance(\bootstrap::getCore()), self::$account);
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertNotContains(self::$account->get_api()->generate_login_url(registry::get_instance(), self::$account->get_api()->get_connector()->get_name()), $this->client->getResponse()->getContent());
}
public function testLoadContainersDisconnected()
{
$this->client->followRedirects();
self::$account->get_settings()->set("auth_token", null); //deconnected
$url = sprintf("/bridge/adapter/%s/load-containers/%s/", self::$account->get_id(), self::$account->get_api()->get_connector()->get_default_container_type());
$crawler = $this->client->request('GET', $url, array("page" => 1));
$pageContent = $this->client->getResponse()->getContent();
$this->assertContains($url, $pageContent);
$this->deconnected($crawler, $pageContent);
}
public function testLoadElementsDisconnected()
{
$this->client->followRedirects();
self::$account->get_settings()->set("auth_token", null); //deconnected
$url = sprintf("/bridge/adapter/%s/load-elements/%s/", self::$account->get_id(), self::$account->get_api()->get_connector()->get_default_element_type());
$crawler = $this->client->request('GET', $url, array("page" => 1));
$this->assertTrue($this->client->getResponse()->isOk());
$pageContent = $this->client->getResponse()->getContent();
$this->assertContains($url, $pageContent);
$this->deconnected($crawler, $pageContent);
}
public function testLogoutDeconnected()
{
$this->client->followRedirects();
self::$account->get_settings()->set("auth_token", null); //deconnected
$url = sprintf('/bridge/adapter/%d/logout/', self::$account->get_id());
$crawler = $this->client->request('GET', $url);
$pageContent = $this->client->getResponse()->getContent();
$this->assertContains("/adapter/" . self::$account->get_id() . "/logout/", $pageContent);
$this->deconnected($crawler, $pageContent);
}
public function testActionDeconnected()
{
$this->client->followRedirects();
self::$account->get_settings()->set("auth_token", null); //deconnected
$url = sprintf("/bridge/action/%s/une action/%s/", self::$account->get_id(), self::$account->get_api()->get_connector()->get_default_element_type());
$crawler = $this->client->request('GET', $url);
$pageContent = $this->client->getResponse()->getContent();
$this->assertContains($url, $pageContent);
$this->deconnected($crawler, $pageContent);
}
public function testActionUnknow()
{
self::$account->get_settings()->set("auth_token", "somethingNotNull"); //connected
$url = sprintf("/bridge/action/%s/ajjfhfjozqd/%s/", self::$account->get_id(), self::$account->get_api()->get_connector()->get_default_element_type());
try
{ {
$crawler = $this->client->request('GET', $url, array("elements_list" => "1;2;3")); self::$account->get_settings()->set("auth_token", "somethingNotNull"); //connected
$this->fail("expected Exception here"); $url = sprintf('/bridge/adapter/%d/logout/', self::$account->get_id());
} $this->client->request('GET', $url);
catch (Exception $e) $redirect = sprintf("/prod/bridge/adapter/%s/load-elements/%s/", self::$account->get_id(), self::$account->get_api()->get_connector()->get_default_element_type());
{ $this->assertTrue($this->client->getResponse()->isRedirect($redirect));
$this->assertNull(self::$account->get_settings()->get("auth_token"));
} }
try public function testLoadElements()
{ {
$crawler = $this->client->request('POST', $url, array("elements_list" => "1;2;3")); self::$account->get_settings()->set("auth_token", "somethingNotNull"); //connected
$this->fail("expected Exception here"); $url = sprintf("/bridge/adapter/%s/load-elements/%s/", self::$account->get_id(), self::$account->get_api()->get_connector()->get_default_element_type());
$account = new Bridge_Account(appbox::get_instance(\bootstrap::getCore()), self::$api, self::$account->get_id());
$crawler = $this->client->request('GET', $url, array("page" => 1));
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertNotContains(self::$account->get_api()->generate_login_url(registry::get_instance(), self::$account->get_api()->get_connector()->get_name()), $this->client->getResponse()->getContent());
} }
catch (Exception $e)
public function testLoadRecords()
{ {
self::$account->get_settings()->set("auth_token", "somethingNotNull"); //connected
$url = sprintf("/bridge/adapter/%s/load-records/", self::$account->get_id());
$crawler = $this->client->request('GET', $url, array("page" => 1));
$elements = Bridge_Element::get_elements_by_account(appbox::get_instance(\bootstrap::getCore()), self::$account);
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertEquals(sizeof($elements), $crawler->filterXPath("//table/tr")->count());
$this->assertNotContains(self::$account->get_api()->generate_login_url(registry::get_instance(), self::$account->get_api()->get_connector()->get_name()), $this->client->getResponse()->getContent());
} }
}
public function testActionModifyTooManyElements() public function testLoadRecordsDisconnected()
{ {
self::$account->get_settings()->set("auth_token", "somethingNotNull"); //connected $this->client->followRedirects();
$url = sprintf("/bridge/action/%s/modify/%s/", self::$account->get_id(), self::$account->get_api()->get_connector()->get_default_element_type()); self::$account->get_settings()->set("auth_token", null); //deconnected
$crawler = $this->client->request('GET', $url, array("element_list" => "1_2;1_3;1_4")); $url = sprintf("/bridge/adapter/%s/load-records/", self::$account->get_id());
$redirect = sprintf("/prod/bridge/adapter/%s/load-elements/%s/", self::$account->get_id(), self::$account->get_api()->get_connector()->get_default_element_type()); $crawler = $this->client->request('GET', $url, array("page" => 1));
$this->assertTrue($this->client->getResponse()->isRedirect()); $pageContent = $this->client->getResponse()->getContent();
$this->assertContains($redirect, $this->client->getResponse()->headers->get("location")); $this->assertContains($url, $pageContent);
$this->assertContains("error=", $this->client->getResponse()->headers->get("location")); $this->deconnected($crawler, $pageContent);
$this->assertNotContains(self::$account->get_api()->generate_login_url(registry::get_instance(), self::$account->get_api()->get_connector()->get_name()), $this->client->getResponse()->getContent()); }
$this->client->request('POST', $url, array("element_list" => "1_2;1_3;1_4")); public function testLoadContainers()
$this->assertTrue($this->client->getResponse()->isRedirect()); {
} self::$account->get_settings()->set("auth_token", "somethingNotNull"); //connected
$url = sprintf("/bridge/adapter/%s/load-containers/%s/", self::$account->get_id(), self::$account->get_api()->get_connector()->get_default_container_type());
$crawler = $this->client->request('GET', $url, array("page" => 1));
$elements = Bridge_Element::get_elements_by_account(appbox::get_instance(\bootstrap::getCore()), self::$account);
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertNotContains(self::$account->get_api()->generate_login_url(registry::get_instance(), self::$account->get_api()->get_connector()->get_name()), $this->client->getResponse()->getContent());
}
public function testActionModifyElement() public function testLoadContainersDisconnected()
{ {
self::$account->get_settings()->set("auth_token", "somethingNotNull"); //connected $this->client->followRedirects();
$url = sprintf("/bridge/action/%s/modify/%s/", self::$account->get_id(), self::$account->get_api()->get_connector()->get_default_element_type()); self::$account->get_settings()->set("auth_token", null); //deconnected
$crawler = $this->client->request('GET', $url, array("elements_list" => "element123qcs789")); $url = sprintf("/bridge/adapter/%s/load-containers/%s/", self::$account->get_id(), self::$account->get_api()->get_connector()->get_default_container_type());
$this->assertTrue($this->client->getResponse()->isOk()); $crawler = $this->client->request('GET', $url, array("page" => 1));
$this->assertNotContains(self::$account->get_api()->generate_login_url(registry::get_instance(), self::$account->get_api()->get_connector()->get_name()), $this->client->getResponse()->getContent()); $pageContent = $this->client->getResponse()->getContent();
$this->assertContains($url, $pageContent);
$this->deconnected($crawler, $pageContent);
}
$this->client->request('POST', $url, array("elements_list" => "element123qcs789")); public function testLoadElementsDisconnected()
$this->assertTrue($this->client->getResponse()->isRedirect()); {
} $this->client->followRedirects();
self::$account->get_settings()->set("auth_token", null); //deconnected
$url = sprintf("/bridge/adapter/%s/load-elements/%s/", self::$account->get_id(), self::$account->get_api()->get_connector()->get_default_element_type());
$crawler = $this->client->request('GET', $url, array("page" => 1));
$this->assertTrue($this->client->getResponse()->isOk());
$pageContent = $this->client->getResponse()->getContent();
$this->assertContains($url, $pageContent);
$this->deconnected($crawler, $pageContent);
}
public function testActionModifyElementError() public function testLogoutDeconnected()
{ {
self::$account->get_settings()->set("auth_token", "somethingNotNull"); $this->client->followRedirects();
Bridge_Api_Apitest::$hasError = true; self::$account->get_settings()->set("auth_token", null); //deconnected
$url = sprintf("/bridge/action/%s/modify/%s/", self::$account->get_id(), self::$account->get_api()->get_connector()->get_default_element_type()); $url = sprintf('/bridge/adapter/%d/logout/', self::$account->get_id());
$this->client->request('POST', $url, array("elements_list" => "element123qcs789")); $crawler = $this->client->request('GET', $url);
$this->assertTrue($this->client->getResponse()->isOk()); $pageContent = $this->client->getResponse()->getContent();
} $this->assertContains("/adapter/" . self::$account->get_id() . "/logout/", $pageContent);
$this->deconnected($crawler, $pageContent);
}
public function testActionModifyElementException() public function testActionDeconnected()
{ {
self::$account->get_settings()->set("auth_token", "somethingNotNull"); $this->client->followRedirects();
Bridge_Api_Apitest::$hasException = true; self::$account->get_settings()->set("auth_token", null); //deconnected
$url = sprintf("/bridge/action/%s/modify/%s/", self::$account->get_id(), self::$account->get_api()->get_connector()->get_default_element_type()); $url = sprintf("/bridge/action/%s/une action/%s/", self::$account->get_id(), self::$account->get_api()->get_connector()->get_default_element_type());
$this->client->request('POST', $url, array("elements_list" => "element123qcs789")); $crawler = $this->client->request('GET', $url);
$this->assertTrue($this->client->getResponse()->isRedirect()); $pageContent = $this->client->getResponse()->getContent();
$this->assertRegexp('/error/', $this->client->getResponse()->headers->get('location')); $this->assertContains($url, $pageContent);
} $this->deconnected($crawler, $pageContent);
}
public function testActionDeleteElement() public function testActionUnknow()
{ {
self::$account->get_settings()->set("auth_token", "somethingNotNull"); self::$account->get_settings()->set("auth_token", "somethingNotNull"); //connected
$url = sprintf("/bridge/action/%s/deleteelement/%s/", self::$account->get_id(), self::$account->get_api()->get_connector()->get_default_element_type()); $url = sprintf("/bridge/action/%s/ajjfhfjozqd/%s/", self::$account->get_id(), self::$account->get_api()->get_connector()->get_default_element_type());
$this->client->request('GET', $url, array("elements_list" => "element123qcs789")); try {
$this->assertTrue($this->client->getResponse()->isOk()); $crawler = $this->client->request('GET', $url, array("elements_list" => "1;2;3"));
$this->fail("expected Exception here");
} catch (Exception $e) {
Bridge_Api_Apitest::$hasException = true; }
$url = sprintf("/bridge/action/%s/deleteelement/%s/", self::$account->get_id(), self::$account->get_api()->get_connector()->get_default_element_type());
$this->client->request('POST', $url, array("elements_list" => "element123qcs789"));
$this->assertTrue($this->client->getResponse()->isRedirect());
$this->assertRegexp('/error/', $this->client->getResponse()->headers->get('location'));
$url = sprintf("/bridge/action/%s/deleteelement/%s/", self::$account->get_id(), self::$account->get_api()->get_connector()->get_default_element_type()); try {
$this->client->request('POST', $url, array("elements_list" => "element123qcs789")); $crawler = $this->client->request('POST', $url, array("elements_list" => "1;2;3"));
$this->assertTrue($this->client->getResponse()->isRedirect()); $this->fail("expected Exception here");
} } catch (Exception $e) {
public function testActionCreateContainer() }
{ }
self::$account->get_settings()->set("auth_token", "somethingNotNull"); //connected
$url = sprintf("/bridge/action/%s/createcontainer/%s/", self::$account->get_id(), self::$account->get_api()->get_connector()->get_default_container_type()); public function testActionModifyTooManyElements()
$this->client->request('GET', $url); {
$this->assertTrue($this->client->getResponse()->isOk()); self::$account->get_settings()->set("auth_token", "somethingNotNull"); //connected
$url = sprintf("/bridge/action/%s/modify/%s/", self::$account->get_id(), self::$account->get_api()->get_connector()->get_default_element_type());
$crawler = $this->client->request('GET', $url, array("element_list" => "1_2;1_3;1_4"));
$redirect = sprintf("/prod/bridge/adapter/%s/load-elements/%s/", self::$account->get_id(), self::$account->get_api()->get_connector()->get_default_element_type());
$this->assertTrue($this->client->getResponse()->isRedirect());
$this->assertContains($redirect, $this->client->getResponse()->headers->get("location"));
$this->assertContains("error=", $this->client->getResponse()->headers->get("location"));
$this->assertNotContains(self::$account->get_api()->generate_login_url(registry::get_instance(), self::$account->get_api()->get_connector()->get_name()), $this->client->getResponse()->getContent());
$this->client->request('POST', $url, array("element_list" => "1_2;1_3;1_4"));
$this->assertTrue($this->client->getResponse()->isRedirect());
}
public function testActionModifyElement()
{
self::$account->get_settings()->set("auth_token", "somethingNotNull"); //connected
$url = sprintf("/bridge/action/%s/modify/%s/", self::$account->get_id(), self::$account->get_api()->get_connector()->get_default_element_type());
$crawler = $this->client->request('GET', $url, array("elements_list" => "element123qcs789"));
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertNotContains(self::$account->get_api()->generate_login_url(registry::get_instance(), self::$account->get_api()->get_connector()->get_name()), $this->client->getResponse()->getContent());
$this->client->request('POST', $url, array("elements_list" => "element123qcs789"));
$this->assertTrue($this->client->getResponse()->isRedirect());
}
public function testActionModifyElementError()
{
self::$account->get_settings()->set("auth_token", "somethingNotNull");
Bridge_Api_Apitest::$hasError = true;
$url = sprintf("/bridge/action/%s/modify/%s/", self::$account->get_id(), self::$account->get_api()->get_connector()->get_default_element_type());
$this->client->request('POST', $url, array("elements_list" => "element123qcs789"));
$this->assertTrue($this->client->getResponse()->isOk());
}
public function testActionModifyElementException()
{
self::$account->get_settings()->set("auth_token", "somethingNotNull");
Bridge_Api_Apitest::$hasException = true;
$url = sprintf("/bridge/action/%s/modify/%s/", self::$account->get_id(), self::$account->get_api()->get_connector()->get_default_element_type());
$this->client->request('POST', $url, array("elements_list" => "element123qcs789"));
$this->assertTrue($this->client->getResponse()->isRedirect());
$this->assertRegexp('/error/', $this->client->getResponse()->headers->get('location'));
}
public function testActionDeleteElement()
{
self::$account->get_settings()->set("auth_token", "somethingNotNull");
$url = sprintf("/bridge/action/%s/deleteelement/%s/", self::$account->get_id(), self::$account->get_api()->get_connector()->get_default_element_type());
$this->client->request('GET', $url, array("elements_list" => "element123qcs789"));
$this->assertTrue($this->client->getResponse()->isOk());
Bridge_Api_Apitest::$hasException = true;
$url = sprintf("/bridge/action/%s/deleteelement/%s/", self::$account->get_id(), self::$account->get_api()->get_connector()->get_default_element_type());
$this->client->request('POST', $url, array("elements_list" => "element123qcs789"));
$this->assertTrue($this->client->getResponse()->isRedirect());
$this->assertRegexp('/error/', $this->client->getResponse()->headers->get('location'));
$url = sprintf("/bridge/action/%s/deleteelement/%s/", self::$account->get_id(), self::$account->get_api()->get_connector()->get_default_element_type());
$this->client->request('POST', $url, array("elements_list" => "element123qcs789"));
$this->assertTrue($this->client->getResponse()->isRedirect());
}
public function testActionCreateContainer()
{
self::$account->get_settings()->set("auth_token", "somethingNotNull"); //connected
$url = sprintf("/bridge/action/%s/createcontainer/%s/", self::$account->get_id(), self::$account->get_api()->get_connector()->get_default_container_type());
$this->client->request('GET', $url);
$this->assertTrue($this->client->getResponse()->isOk());
Bridge_Api_Apitest::$hasException = true; Bridge_Api_Apitest::$hasException = true;
$url = sprintf("/bridge/action/%s/createcontainer/%s/", self::$account->get_id(), self::$account->get_api()->get_connector()->get_default_element_type()); $url = sprintf("/bridge/action/%s/createcontainer/%s/", self::$account->get_id(), self::$account->get_api()->get_connector()->get_default_element_type());
$this->client->request('POST', $url); $this->client->request('POST', $url);
$this->assertTrue($this->client->getResponse()->isRedirect()); $this->assertTrue($this->client->getResponse()->isRedirect());
$this->assertRegexp('/error/', $this->client->getResponse()->headers->get('location')); $this->assertRegexp('/error/', $this->client->getResponse()->headers->get('location'));
$url = sprintf("/bridge/action/%s/createcontainer/%s/", self::$account->get_id(), self::$account->get_api()->get_connector()->get_default_container_type()); $url = sprintf("/bridge/action/%s/createcontainer/%s/", self::$account->get_id(), self::$account->get_api()->get_connector()->get_default_container_type());
$this->client->request('POST', $url, array('title' => 'test', 'description' => 'description')); $this->client->request('POST', $url, array('title' => 'test', 'description' => 'description'));
$this->assertTrue($this->client->getResponse()->isRedirect()); $this->assertTrue($this->client->getResponse()->isRedirect());
$this->assertRegexp('/success/', $this->client->getResponse()->headers->get('location')); $this->assertRegexp('/success/', $this->client->getResponse()->headers->get('location'));
} }
/** /**
* @todo no templates declared for modify a container in any apis * @todo no templates declared for modify a container in any apis
*/ */
public function testActionModifyContainer() public function testActionModifyContainer()
{ {
$this->markTestSkipped("No templates declared for modify a container in any apis"); $this->markTestSkipped("No templates declared for modify a container in any apis");
self::$account->get_settings()->set("auth_token", "somethingNotNull"); //connected self::$account->get_settings()->set("auth_token", "somethingNotNull"); //connected
$url = sprintf("/bridge/action/%s/modify/%s/", self::$account->get_id(), self::$account->get_api()->get_connector()->get_default_container_type()); $url = sprintf("/bridge/action/%s/modify/%s/", self::$account->get_id(), self::$account->get_api()->get_connector()->get_default_container_type());
$crawler = $this->client->request('GET', $url, array("elements_list" => "containerudt456shn")); $crawler = $this->client->request('GET', $url, array("elements_list" => "containerudt456shn"));
$this->assertTrue($this->client->getResponse()->isOk()); $this->assertTrue($this->client->getResponse()->isOk());
$pageContent = $this->client->getResponse()->getContent(); $pageContent = $this->client->getResponse()->getContent();
$this->assertNotContains(self::$account->get_api()->generate_login_url(registry::get_instance(), self::$account->get_api()->get_connector()->get_name()), $this->client->getResponse()->getContent()); $this->assertNotContains(self::$account->get_api()->generate_login_url(registry::get_instance(), self::$account->get_api()->get_connector()->get_name()), $this->client->getResponse()->getContent());
$this->client->request('POST', $url, array("elements_list" => "containerudt456shn")); $this->client->request('POST', $url, array("elements_list" => "containerudt456shn"));
$this->assertTrue($this->client->getResponse()->isOk()); $this->assertTrue($this->client->getResponse()->isOk());
} }
public function testActionMoveInto() public function testActionMoveInto()
{ {
self::$account->get_settings()->set("auth_token", "somethingNotNull"); //connected self::$account->get_settings()->set("auth_token", "somethingNotNull"); //connected
$url = sprintf("/bridge/action/%s/moveinto/%s/", self::$account->get_id(), self::$account->get_api()->get_connector()->get_default_element_type()); $url = sprintf("/bridge/action/%s/moveinto/%s/", self::$account->get_id(), self::$account->get_api()->get_connector()->get_default_element_type());
$crawler = $this->client->request('GET', $url, array("elements_list" => "containerudt456shn", 'destination' => self::$account->get_api()->get_connector()->get_default_container_type())); $crawler = $this->client->request('GET', $url, array("elements_list" => "containerudt456shn", 'destination' => self::$account->get_api()->get_connector()->get_default_container_type()));
$this->assertNotContains("http://dev.phrasea.net/prod/bridge/login/youtube/", $this->client->getResponse()->getContent()); $this->assertNotContains("http://dev.phrasea.net/prod/bridge/login/youtube/", $this->client->getResponse()->getContent());
$this->assertTrue($this->client->getResponse()->isOk()); $this->assertTrue($this->client->getResponse()->isOk());
$this->client->request('POST', $url, array("elements_list" => "containerudt456shn", 'destination' => self::$account->get_api()->get_connector()->get_default_container_type())); $this->client->request('POST', $url, array("elements_list" => "containerudt456shn", 'destination' => self::$account->get_api()->get_connector()->get_default_container_type()));
$this->assertRegexp('/success/', $this->client->getResponse()->headers->get('location')); $this->assertRegexp('/success/', $this->client->getResponse()->headers->get('location'));
$this->assertTrue($this->client->getResponse()->isRedirect()); $this->assertTrue($this->client->getResponse()->isRedirect());
Bridge_Api_Apitest::$hasException = true; Bridge_Api_Apitest::$hasException = true;
$this->client->request('POST', $url, array("elements_list" => "containerudt456shn", 'destination' => self::$account->get_api()->get_connector()->get_default_container_type())); $this->client->request('POST', $url, array("elements_list" => "containerudt456shn", 'destination' => self::$account->get_api()->get_connector()->get_default_container_type()));
$this->assertRegexp('/error/', $this->client->getResponse()->headers->get('location')); $this->assertRegexp('/error/', $this->client->getResponse()->headers->get('location'));
$this->assertTrue($this->client->getResponse()->isRedirect()); $this->assertTrue($this->client->getResponse()->isRedirect());
} }
public function deconnected($crawler, $pageContent) public function deconnected($crawler, $pageContent)
{ {
$this->assertTrue($this->client->getResponse()->isOk()); $this->assertTrue($this->client->getResponse()->isOk());
$this->assertContains("prod/bridge/login/" . mb_strtolower(self::$account->get_api()->get_connector()->get_name()) . "/", $pageContent); $this->assertContains("prod/bridge/login/" . mb_strtolower(self::$account->get_api()->get_connector()->get_name()) . "/", $pageContent);
} }
public function testUpload() public function testUpload()
{ {
self::$account->get_settings()->set("auth_token", "somethingNotNull"); self::$account->get_settings()->set("auth_token", "somethingNotNull");
$url = "/bridge/upload/"; $url = "/bridge/upload/";
$this->client->request('GET', $url, array("account_id" => self::$account->get_id())); $this->client->request('GET', $url, array("account_id" => self::$account->get_id()));
$response = $this->client->getResponse(); $response = $this->client->getResponse();
$this->assertTrue($response->isOk()); $this->assertTrue($response->isOk());
$records = array( $records = array(
self::$record_1->get_serialize_key() self::$record_1->get_serialize_key()
); );
Bridge_Api_Apitest::$hasError = true; Bridge_Api_Apitest::$hasError = true;
$lst = implode(';', $records); $lst = implode(';', $records);
$this->client->request('POST', $url, array("account_id" => self::$account->get_id(), 'lst' => $lst)); $this->client->request('POST', $url, array("account_id" => self::$account->get_id(), 'lst' => $lst));
$response = $this->client->getResponse(); $response = $this->client->getResponse();
$this->assertTrue($response->isOk()); $this->assertTrue($response->isOk());
$this->client->request('POST', $url, array("account_id" => self::$account->get_id(), 'lst' => $lst));
$response = $this->client->getResponse();
$this->assertTrue($response->isRedirect());
}
$this->client->request('POST', $url, array("account_id" => self::$account->get_id(), 'lst' => $lst));
$response = $this->client->getResponse();
$this->assertTrue($response->isRedirect());
}
} }

View File

@@ -2,93 +2,73 @@
require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.class.inc'; require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.class.inc';
class ControllerEditTest extends \PhraseanetWebTestCaseAuthenticatedAbstract class ControllerEditTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{ {
protected $client;
protected static $need_records = 1;
/** public function createApplication()
* As controllers use WebTestCase, it requires a client {
*/ return require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Prod.php';
protected $client; }
/** public function setUp()
* If the controller tests require some records, specify it her {
* parent::setUp();
* For example, this will loacd 2 records $this->client = $this->createClient();
* (self::$record_1 and self::$record_2) : }
*
* $need_records = 2;
*
*/
protected static $need_records = 1;
/** /**
* The application loader * Default route test
*/ */
public function createApplication() public function testRouteSlash()
{ {
return require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Prod.php'; $this->client->request('POST', '/records/edit/', array('lst' => self::$record_1->get_serialize_key()));
}
public function setUp() $response = $this->client->getResponse();
{
parent::setUp();
$this->client = $this->createClient();
}
/** $this->assertTrue($response->isOk());
* Default route test }
*/
public function testRouteSlash()
{
$this->client->request('POST', '/records/edit/', array('lst' => self::$record_1->get_serialize_key()));
$response = $this->client->getResponse(); public function testApply()
{
$this->client->request('POST', '/records/edit/apply/', array('lst' => self::$record_1->get_serialize_key()));
$this->assertTrue($response->isOk()); $response = $this->client->getResponse();
}
public function testApply() $this->assertTrue($response->isOk());
{ }
$this->client->request('POST', '/records/edit/apply/', array('lst' => self::$record_1->get_serialize_key()));
$response = $this->client->getResponse(); public function testVocabulary()
{
$this->client->request('GET', '/records/edit/vocabulary/Zanzibar/');
$this->assertTrue($response->isOk()); $response = $this->client->getResponse();
} $this->assertTrue($response->isOk());
$datas = json_decode($response->getContent());
$this->assertFalse($datas->success);
$this->client->request('GET', '/records/edit/vocabulary/User/');
public function testVocabulary() $response = $this->client->getResponse();
{ $this->assertTrue($response->isOk());
$this->client->request('GET', '/records/edit/vocabulary/Zanzibar/'); $datas = json_decode($response->getContent());
$this->assertFalse($datas->success);
$response = $this->client->getResponse(); $params = array('sbas_id' => self::$collection->get_sbas_id());
$this->assertTrue($response->isOk()); $this->client->request('GET', '/records/edit/vocabulary/Zanzibar/', $params);
$datas = json_decode($response->getContent());
$this->assertFalse($datas->success);
$this->client->request('GET', '/records/edit/vocabulary/User/'); $response = $this->client->getResponse();
$this->assertTrue($response->isOk());
$datas = json_decode($response->getContent());
$this->assertFalse($datas->success);
$response = $this->client->getResponse(); $params = array('sbas_id' => self::$collection->get_sbas_id());
$this->assertTrue($response->isOk()); $this->client->request('GET', '/records/edit/vocabulary/User/', $params);
$datas = json_decode($response->getContent());
$this->assertFalse($datas->success);
$params = array('sbas_id'=>self::$collection->get_sbas_id());
$this->client->request('GET', '/records/edit/vocabulary/Zanzibar/', $params);
$response = $this->client->getResponse();
$this->assertTrue($response->isOk());
$datas = json_decode($response->getContent());
$this->assertFalse($datas->success);
$params = array('sbas_id'=>self::$collection->get_sbas_id());
$this->client->request('GET', '/records/edit/vocabulary/User/', $params);
$response = $this->client->getResponse();
$this->assertTrue($response->isOk());
$datas = json_decode($response->getContent());
$this->assertTrue($datas->success);
}
$response = $this->client->getResponse();
$this->assertTrue($response->isOk());
$datas = json_decode($response->getContent());
$this->assertTrue($datas->success);
}
} }

View File

@@ -7,467 +7,447 @@ use Symfony\Component\HttpFoundation\Response;
class ControllerFeedApp extends \PhraseanetWebTestCaseAuthenticatedAbstract class ControllerFeedApp extends \PhraseanetWebTestCaseAuthenticatedAbstract
{ {
/**
*
* @var Feed_Adapter
*/
protected $feed;
/**
*
* @var Feed_Entry_Adapter
*/
protected $entry;
/**
*
* @var Feed_Entry_Item
*/
protected $item;
/**
*
* @var Feed_Publisher_Adapter
*/
protected $publisher;
protected $client;
protected $feed_title = 'feed title';
protected $feed_subtitle = 'feed subtitle';
protected $entry_title = 'entry title';
protected $entry_subtitle = 'entry subtitle';
protected $entry_authorname = 'author name';
protected $entry_authormail = 'author.mail@example.com';
protected static $need_records = 2;
protected static $need_subdefs = false;
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
}
public static function tearDownAfterClass()
{
parent::tearDownAfterClass();
}
public function setUp()
{
parent::setUp();
$appbox = appbox::get_instance(\bootstrap::getCore());
$this->client = $this->createClient();
$this->feed = Feed_Adapter::create(
$appbox, self::$user, $this->feed_title, $this->feed_subtitle
);
$this->publisher = Feed_Publisher_Adapter::getPublisher(
$appbox, $this->feed, self::$user
);
$this->entry = Feed_Entry_Adapter::create(
$appbox
, $this->feed
, $this->publisher
, $this->entry_title
, $this->entry_subtitle
, $this->entry_authorname
, $this->entry_authormail
);
$this->item = Feed_Entry_Item::create($appbox, $this->entry, self::$record_1);
}
public function tearDown()
{
if ($this->feed instanceof Feed_Adapter)
{
$this->feed->delete();
}
else if($this->entry instanceof Feed_Entry_Adapter)
{
$this->entry->delete();
if ($this->publisher instanceof Feed_Publisher_Adapter)
{
$this->publisher->delete();
}
}
parent::tearDown();
}
public function createApplication()
{
return require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Prod.php';
}
public function testRequestAvailable()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$crawler = $this->client->request('POST', '/feeds/requestavailable/');
$this->assertTrue($this->client->getResponse()->isOk());
$feeds = Feed_Collection::load_all($appbox, self::$user);
foreach ($feeds->get_feeds() as $one_feed)
{
if ($one_feed->is_publisher(self::$user))
{
$this->assertEquals(1, $crawler->filterXPath("//input[@value='" . $one_feed->get_id() . "']")->count());
}
}
}
public function testEntryCreate()
{
$params = array(
"feed_id" => $this->feed->get_id()
, "title" => "salut"
, "subtitle" => "coucou"
, "author_name" => "robert"
, "author_email" => "robert@kikoo.mail"
, 'lst' => self::$record_1->get_serialize_key()
);
$crawler = $this->client->request('POST', '/feeds/entry/create/', $params);
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertEquals("application/json", $this->client->getResponse()->headers->get("content-type"));
$pageContent = json_decode($this->client->getResponse()->getContent());
$this->assertTrue(is_object($pageContent));
$this->assertFalse($pageContent->error);
$this->assertFalse($pageContent->message);
}
public function testEntryCreateError()
{
$params = array(
"feed_id" => 'unknow'
, "title" => "salut"
, "subtitle" => "coucou"
, "author_name" => "robert"
, "author_email" => "robert@kikoo.mail"
, 'lst' => self::$record_1->get_serialize_key()
);
$crawler = $this->client->request('POST', '/feeds/entry/create/', $params);
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertEquals("application/json", $this->client->getResponse()->headers->get("content-type"));
$pageContent = json_decode($this->client->getResponse()->getContent());
$this->assertTrue(is_object($pageContent));
$this->assertTrue($pageContent->error);
$this->assertTrue(is_string($pageContent->message));
}
public function testEntryEdit()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$crawler = $this->client->request('GET', '/feeds/entry/' . $this->entry->get_id() . '/edit/');
$pageContent = $this->client->getResponse()->getContent();
foreach ($this->entry->get_content() as $content)
{
$this->assertEquals(1, $crawler->filterXPath("//input[@value='" . $content->get_id() . "' and @name='item_id']")->count());
}
$this->assertEquals(1, $crawler->filterXPath("//form[@action='/prod/feeds/entry/" . $this->entry->get_id() . "/update/']")->count());
$this->assertEquals(1, $crawler->filterXPath("//input[@value='" . $this->entry_title . "']")->count());
$this->assertEquals($this->entry_subtitle, $crawler->filterXPath("//textarea[@id='feed_add_subtitle']")->text());
$this->assertEquals(1, $crawler->filterXPath("//input[@value='" . $this->entry_authorname . "']")->count());
$this->assertEquals(1, $crawler->filterXPath("//input[@value='" . $this->entry_authormail . "']")->count());
}
public function testEntryEditUnauthorized()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$feed = Feed_Adapter::create(
$appbox, self::$user_alt1, $this->feed_title, $this->feed_subtitle
);
$publisher = Feed_Publisher_Adapter::getPublisher(
$appbox, $feed, self::$user_alt1
);
$entry = Feed_Entry_Adapter::create(
$appbox
, $feed
, $publisher
, $this->entry_title
, $this->entry_subtitle
, $this->entry_authorname
, $this->entry_authormail
);
$crawler = $this->client->request('GET', '/feeds/entry/' . $entry->get_id() . '/edit/');
$response = $this->client->getResponse();
$this->assertFalse($response->isOk());
$feed->delete();
}
public function testEntryUpdate()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$params = array(
"feed_id" => $this->feed->get_id()
, "title" => "dog"
, "subtitle" => "cat"
, "author_name" => "bird"
, "author_email" => "mouse"
, 'lst' => self::$record_1->get_serialize_key()
);
$crawler = $this->client->request('POST', '/feeds/entry/' . $this->entry->get_id() . '/update/', $params);
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertEquals("application/json", $this->client->getResponse()->headers->get("content-type"));
$pageContent = json_decode($this->client->getResponse()->getContent());
$this->assertTrue(is_object($pageContent));
$this->assertFalse($pageContent->error);
$this->assertTrue(is_string($pageContent->message));
$this->assertTrue(is_string($pageContent->datas));
$this->assertRegExp("/entry_" . $this->entry->get_id() . "/", $pageContent->datas);
}
public function testEntryUpdateNotFound()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$params = array(
"feed_id" => 9999999
, "title" => "dog"
, "subtitle" => "cat"
, "author_name" => "bird"
, "author_email" => "mouse"
, 'lst' => self::$record_1->get_serialize_key()
);
$crawler = $this->client->request('POST', '/feeds/entry/99999999/update/', $params);
$response = $this->client->getResponse();
$pageContent = json_decode($response->getContent());
$this->assertTrue($response->isOk());
$this->assertEquals("application/json", $response->headers->get("content-type"));
$this->assertTrue(is_object($pageContent));
$this->assertTrue($pageContent->error);
$this->assertTrue(is_string($pageContent->message));
}
public function testEntryUpdateFailed()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$params = array(
"feed_id" => 9999999
, "title" => "dog"
, "subtitle" => "cat"
, "author_name" => "bird"
, "author_email" => "mouse"
, 'sorted_lst' => self::$record_1->get_serialize_key() . ";" . self::$record_2->get_serialize_key() . ";12345;" . "unknow_unknow"
);
$crawler = $this->client->request('POST', '/feeds/entry/' . $this->entry->get_id() . '/update/', $params);
$response = $this->client->getResponse();
$this->assertTrue($response->isOk());
$pageContent = json_decode($response->getContent());
$this->assertEquals("application/json", $response->headers->get("content-type"));
$this->assertTrue(is_object($pageContent));
$this->assertTrue($pageContent->error);
$this->assertTrue(is_string($pageContent->message));
}
public function testEntryUpdateUnauthorized()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
/** /**
* I CREATE A FEED THAT IS NOT MINE *
* */ * @var Feed_Adapter
$feed = Feed_Adapter::create($appbox, self::$user_alt1, "salut", 'coucou'); */
$publisher = Feed_Publisher_Adapter::getPublisher($appbox, $feed, self::$user_alt1); protected $feed;
$entry = Feed_Entry_Adapter::create($appbox, $feed, $publisher, "hello", "coucou", "salut", "bonjour@phraseanet.com");
$item = Feed_Entry_Item::create($appbox, $entry, self::$record_1);
$params = array(
"feed_id" => $feed->get_id()
, "title" => "dog"
, "subtitle" => "cat"
, "author_name" => "bird"
, "author_email" => "mouse"
, 'lst' => self::$record_1->get_serialize_key()
);
$crawler = $this->client->request('POST', '/feeds/entry/' . $entry->get_id() . '/update/', $params);
$response = $this->client->getResponse();
$this->assertTrue($response->isOk());
$pageContent = json_decode($response->getContent());
$this->assertEquals("application/json", $response->headers->get("content-type"));
$this->assertTrue(is_object($pageContent));
$this->assertTrue($pageContent->error);
$this->assertTrue(is_string($pageContent->message));
$feed->delete();
}
public function testDelete()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$crawler = $this->client->request('POST', '/feeds/entry/' . $this->entry->get_id() . '/delete/');
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertEquals("application/json", $this->client->getResponse()->headers->get("content-type"));
$pageContent = json_decode($this->client->getResponse()->getContent());
$this->assertTrue(is_object($pageContent));
$this->assertFalse($pageContent->error);
$this->assertTrue(is_string($pageContent->message));
try
{
Feed_Entry_Adapter::load_from_id($appbox, $this->entry->get_id());
$this->fail("Failed to delete entry");
}
catch (Exception $e)
{
}
}
public function testDeleteNotFound()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$crawler = $this->client->request('POST', '/feeds/entry/9999999/delete/');
$response = $this->client->getResponse();
$pageContent = json_decode($this->client->getResponse()->getContent());
$this->assertTrue($response->isOk());
$this->assertEquals("application/json", $response->headers->get("content-type"));
$this->assertTrue(is_object($pageContent));
$this->assertTrue($pageContent->error);
$this->assertTrue(is_string($pageContent->message));
}
public function testDeleteUnauthorized()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
/** /**
* I CREATE A FEED *
* */ * @var Feed_Entry_Adapter
$feed = Feed_Adapter::create($appbox, self::$user_alt1, "salut", 'coucou'); */
protected $entry;
$publisher = Feed_Publisher_Adapter::getPublisher($appbox, $feed, self::$user_alt1); /**
$entry = Feed_Entry_Adapter::create($appbox, $feed, $publisher, "hello", "coucou", "salut", "bonjour@phraseanet.com"); *
$item = Feed_Entry_Item::create($appbox, $entry, self::$record_1); * @var Feed_Entry_Item
*/
protected $item;
$crawler = $this->client->request('POST', '/feeds/entry/' . $entry->get_id() . '/delete/'); /**
*
* @var Feed_Publisher_Adapter
*/
protected $publisher;
protected $client;
protected $feed_title = 'feed title';
protected $feed_subtitle = 'feed subtitle';
protected $entry_title = 'entry title';
protected $entry_subtitle = 'entry subtitle';
protected $entry_authorname = 'author name';
protected $entry_authormail = 'author.mail@example.com';
protected static $need_records = 2;
protected static $need_subdefs = false;
$response = $this->client->getResponse(); public static function setUpBeforeClass()
$pageContent = json_decode($this->client->getResponse()->getContent());
$this->assertTrue($response->isOk());
$this->assertEquals("application/json", $response->headers->get("content-type"));
$this->assertTrue(is_object($pageContent));
$this->assertTrue($pageContent->error);
$this->assertTrue(is_string($pageContent->message));
$feed->delete();
}
public function testRoot()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$crawler = $this->client->request('GET', '/feeds/');
$pageContent = $this->client->getResponse()->getContent();
$this->assertTrue($this->client->getResponse()->isOk());
$feeds = Feed_Collection::load_all($appbox, self::$user);
foreach ($feeds->get_feeds() as $one_feed)
{ {
$path = "//div[@class='submenu']/a[@href='/prod/feeds/feed/" . $one_feed->get_id() . "/']"; parent::setUpBeforeClass();
$msg = sprintf("user %s has access to feed %s", self::$user->get_id(), $one_feed->get_id());
if ($one_feed->has_access(self::$user))
{
$this->assertEquals(1, $crawler->filterXPath($path)->count(), $msg);
}
else
{
$this->fail('Feed_collection::load_all should return feed where I got access');
}
} }
}
public function testGetFeed() public static function tearDownAfterClass()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$feeds = Feed_Collection::load_all($appbox, self::$user);
$crawler = $this->client->request('GET', '/feeds/feed/' . $this->feed->get_id() . "/");
$pageContent = $this->client->getResponse()->getContent();
foreach ($feeds->get_feeds() as $one_feed)
{ {
$path = "//div[@class='submenu']/a[@href='/prod/feeds/feed/" . $one_feed->get_id() . "/']"; parent::tearDownAfterClass();
$msg = sprintf("user %s has access to feed %s", self::$user->get_id(), $one_feed->get_id());
if ($one_feed->has_access(self::$user))
{
$this->assertEquals(1, $crawler->filterXPath($path)->count(), $msg);
}
else
{
$this->fail('Feed_collection::load_all should return feed where I got access');
}
} }
}
public function testSuscribeAggregate() public function setUp()
{ {
$appbox = appbox::get_instance(\bootstrap::getCore()); parent::setUp();
$feeds = Feed_Collection::load_all($appbox, self::$user);
$crawler = $this->client->request('GET', '/feeds/subscribe/aggregated/');
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertEquals("application/json", $this->client->getResponse()->headers->get("content-type"));
$pageContent = json_decode($this->client->getResponse()->getContent());
$this->assertTrue(is_object($pageContent));
$this->assertTrue(is_string($pageContent->texte));
$suscribe_link = $feeds->get_aggregate()->get_user_link(registry::get_instance(), self::$user, Feed_Adapter::FORMAT_RSS, null, false)->get_href();
$this->assertContains($suscribe_link, $pageContent->texte);
}
public function testSuscribe() $appbox = appbox::get_instance(\bootstrap::getCore());
{
$crawler = $this->client->request('GET', '/feeds/subscribe/' . $this->feed->get_id() . '/');
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertEquals("application/json", $this->client->getResponse()->headers->get("content-type"));
$pageContent = json_decode($this->client->getResponse()->getContent());
$this->assertTrue(is_object($pageContent));
$this->assertTrue(is_string($pageContent->texte));
$suscribe_link = $this->feed->get_user_link(registry::get_instance(), self::$user, Feed_Adapter::FORMAT_RSS, null, false)->get_href();
$this->assertContains($suscribe_link, $pageContent->texte);
}
$this->client = $this->createClient();
$this->feed = Feed_Adapter::create(
$appbox, self::$user, $this->feed_title, $this->feed_subtitle
);
$this->publisher = Feed_Publisher_Adapter::getPublisher(
$appbox, $this->feed, self::$user
);
$this->entry = Feed_Entry_Adapter::create(
$appbox
, $this->feed
, $this->publisher
, $this->entry_title
, $this->entry_subtitle
, $this->entry_authorname
, $this->entry_authormail
);
$this->item = Feed_Entry_Item::create($appbox, $this->entry, self::$record_1);
}
public function tearDown()
{
if ($this->feed instanceof Feed_Adapter) {
$this->feed->delete();
} else if ($this->entry instanceof Feed_Entry_Adapter) {
$this->entry->delete();
if ($this->publisher instanceof Feed_Publisher_Adapter) {
$this->publisher->delete();
}
}
parent::tearDown();
}
public function createApplication()
{
return require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Prod.php';
}
public function testRequestAvailable()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$crawler = $this->client->request('POST', '/feeds/requestavailable/');
$this->assertTrue($this->client->getResponse()->isOk());
$feeds = Feed_Collection::load_all($appbox, self::$user);
foreach ($feeds->get_feeds() as $one_feed) {
if ($one_feed->is_publisher(self::$user)) {
$this->assertEquals(1, $crawler->filterXPath("//input[@value='" . $one_feed->get_id() . "']")->count());
}
}
}
public function testEntryCreate()
{
$params = array(
"feed_id" => $this->feed->get_id()
, "title" => "salut"
, "subtitle" => "coucou"
, "author_name" => "robert"
, "author_email" => "robert@kikoo.mail"
, 'lst' => self::$record_1->get_serialize_key()
);
$crawler = $this->client->request('POST', '/feeds/entry/create/', $params);
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertEquals("application/json", $this->client->getResponse()->headers->get("content-type"));
$pageContent = json_decode($this->client->getResponse()->getContent());
$this->assertTrue(is_object($pageContent));
$this->assertFalse($pageContent->error);
$this->assertFalse($pageContent->message);
}
public function testEntryCreateError()
{
$params = array(
"feed_id" => 'unknow'
, "title" => "salut"
, "subtitle" => "coucou"
, "author_name" => "robert"
, "author_email" => "robert@kikoo.mail"
, 'lst' => self::$record_1->get_serialize_key()
);
$crawler = $this->client->request('POST', '/feeds/entry/create/', $params);
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertEquals("application/json", $this->client->getResponse()->headers->get("content-type"));
$pageContent = json_decode($this->client->getResponse()->getContent());
$this->assertTrue(is_object($pageContent));
$this->assertTrue($pageContent->error);
$this->assertTrue(is_string($pageContent->message));
}
public function testEntryEdit()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$crawler = $this->client->request('GET', '/feeds/entry/' . $this->entry->get_id() . '/edit/');
$pageContent = $this->client->getResponse()->getContent();
foreach ($this->entry->get_content() as $content) {
$this->assertEquals(1, $crawler->filterXPath("//input[@value='" . $content->get_id() . "' and @name='item_id']")->count());
}
$this->assertEquals(1, $crawler->filterXPath("//form[@action='/prod/feeds/entry/" . $this->entry->get_id() . "/update/']")->count());
$this->assertEquals(1, $crawler->filterXPath("//input[@value='" . $this->entry_title . "']")->count());
$this->assertEquals($this->entry_subtitle, $crawler->filterXPath("//textarea[@id='feed_add_subtitle']")->text());
$this->assertEquals(1, $crawler->filterXPath("//input[@value='" . $this->entry_authorname . "']")->count());
$this->assertEquals(1, $crawler->filterXPath("//input[@value='" . $this->entry_authormail . "']")->count());
}
public function testEntryEditUnauthorized()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$feed = Feed_Adapter::create(
$appbox, self::$user_alt1, $this->feed_title, $this->feed_subtitle
);
$publisher = Feed_Publisher_Adapter::getPublisher(
$appbox, $feed, self::$user_alt1
);
$entry = Feed_Entry_Adapter::create(
$appbox
, $feed
, $publisher
, $this->entry_title
, $this->entry_subtitle
, $this->entry_authorname
, $this->entry_authormail
);
$crawler = $this->client->request('GET', '/feeds/entry/' . $entry->get_id() . '/edit/');
$response = $this->client->getResponse();
$this->assertFalse($response->isOk());
$feed->delete();
}
public function testEntryUpdate()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$params = array(
"feed_id" => $this->feed->get_id()
, "title" => "dog"
, "subtitle" => "cat"
, "author_name" => "bird"
, "author_email" => "mouse"
, 'lst' => self::$record_1->get_serialize_key()
);
$crawler = $this->client->request('POST', '/feeds/entry/' . $this->entry->get_id() . '/update/', $params);
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertEquals("application/json", $this->client->getResponse()->headers->get("content-type"));
$pageContent = json_decode($this->client->getResponse()->getContent());
$this->assertTrue(is_object($pageContent));
$this->assertFalse($pageContent->error);
$this->assertTrue(is_string($pageContent->message));
$this->assertTrue(is_string($pageContent->datas));
$this->assertRegExp("/entry_" . $this->entry->get_id() . "/", $pageContent->datas);
}
public function testEntryUpdateNotFound()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$params = array(
"feed_id" => 9999999
, "title" => "dog"
, "subtitle" => "cat"
, "author_name" => "bird"
, "author_email" => "mouse"
, 'lst' => self::$record_1->get_serialize_key()
);
$crawler = $this->client->request('POST', '/feeds/entry/99999999/update/', $params);
$response = $this->client->getResponse();
$pageContent = json_decode($response->getContent());
$this->assertTrue($response->isOk());
$this->assertEquals("application/json", $response->headers->get("content-type"));
$this->assertTrue(is_object($pageContent));
$this->assertTrue($pageContent->error);
$this->assertTrue(is_string($pageContent->message));
}
public function testEntryUpdateFailed()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$params = array(
"feed_id" => 9999999
, "title" => "dog"
, "subtitle" => "cat"
, "author_name" => "bird"
, "author_email" => "mouse"
, 'sorted_lst' => self::$record_1->get_serialize_key() . ";" . self::$record_2->get_serialize_key() . ";12345;" . "unknow_unknow"
);
$crawler = $this->client->request('POST', '/feeds/entry/' . $this->entry->get_id() . '/update/', $params);
$response = $this->client->getResponse();
$this->assertTrue($response->isOk());
$pageContent = json_decode($response->getContent());
$this->assertEquals("application/json", $response->headers->get("content-type"));
$this->assertTrue(is_object($pageContent));
$this->assertTrue($pageContent->error);
$this->assertTrue(is_string($pageContent->message));
}
public function testEntryUpdateUnauthorized()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
/**
* I CREATE A FEED THAT IS NOT MINE
* */
$feed = Feed_Adapter::create($appbox, self::$user_alt1, "salut", 'coucou');
$publisher = Feed_Publisher_Adapter::getPublisher($appbox, $feed, self::$user_alt1);
$entry = Feed_Entry_Adapter::create($appbox, $feed, $publisher, "hello", "coucou", "salut", "bonjour@phraseanet.com");
$item = Feed_Entry_Item::create($appbox, $entry, self::$record_1);
$params = array(
"feed_id" => $feed->get_id()
, "title" => "dog"
, "subtitle" => "cat"
, "author_name" => "bird"
, "author_email" => "mouse"
, 'lst' => self::$record_1->get_serialize_key()
);
$crawler = $this->client->request('POST', '/feeds/entry/' . $entry->get_id() . '/update/', $params);
$response = $this->client->getResponse();
$this->assertTrue($response->isOk());
$pageContent = json_decode($response->getContent());
$this->assertEquals("application/json", $response->headers->get("content-type"));
$this->assertTrue(is_object($pageContent));
$this->assertTrue($pageContent->error);
$this->assertTrue(is_string($pageContent->message));
$feed->delete();
}
public function testDelete()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$crawler = $this->client->request('POST', '/feeds/entry/' . $this->entry->get_id() . '/delete/');
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertEquals("application/json", $this->client->getResponse()->headers->get("content-type"));
$pageContent = json_decode($this->client->getResponse()->getContent());
$this->assertTrue(is_object($pageContent));
$this->assertFalse($pageContent->error);
$this->assertTrue(is_string($pageContent->message));
try {
Feed_Entry_Adapter::load_from_id($appbox, $this->entry->get_id());
$this->fail("Failed to delete entry");
} catch (Exception $e) {
}
}
public function testDeleteNotFound()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$crawler = $this->client->request('POST', '/feeds/entry/9999999/delete/');
$response = $this->client->getResponse();
$pageContent = json_decode($this->client->getResponse()->getContent());
$this->assertTrue($response->isOk());
$this->assertEquals("application/json", $response->headers->get("content-type"));
$this->assertTrue(is_object($pageContent));
$this->assertTrue($pageContent->error);
$this->assertTrue(is_string($pageContent->message));
}
public function testDeleteUnauthorized()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
/**
* I CREATE A FEED
* */
$feed = Feed_Adapter::create($appbox, self::$user_alt1, "salut", 'coucou');
$publisher = Feed_Publisher_Adapter::getPublisher($appbox, $feed, self::$user_alt1);
$entry = Feed_Entry_Adapter::create($appbox, $feed, $publisher, "hello", "coucou", "salut", "bonjour@phraseanet.com");
$item = Feed_Entry_Item::create($appbox, $entry, self::$record_1);
$crawler = $this->client->request('POST', '/feeds/entry/' . $entry->get_id() . '/delete/');
$response = $this->client->getResponse();
$pageContent = json_decode($this->client->getResponse()->getContent());
$this->assertTrue($response->isOk());
$this->assertEquals("application/json", $response->headers->get("content-type"));
$this->assertTrue(is_object($pageContent));
$this->assertTrue($pageContent->error);
$this->assertTrue(is_string($pageContent->message));
$feed->delete();
}
public function testRoot()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$crawler = $this->client->request('GET', '/feeds/');
$pageContent = $this->client->getResponse()->getContent();
$this->assertTrue($this->client->getResponse()->isOk());
$feeds = Feed_Collection::load_all($appbox, self::$user);
foreach ($feeds->get_feeds() as $one_feed) {
$path = "//div[@class='submenu']/a[@href='/prod/feeds/feed/" . $one_feed->get_id() . "/']";
$msg = sprintf("user %s has access to feed %s", self::$user->get_id(), $one_feed->get_id());
if ($one_feed->has_access(self::$user)) {
$this->assertEquals(1, $crawler->filterXPath($path)->count(), $msg);
} else {
$this->fail('Feed_collection::load_all should return feed where I got access');
}
}
}
public function testGetFeed()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$feeds = Feed_Collection::load_all($appbox, self::$user);
$crawler = $this->client->request('GET', '/feeds/feed/' . $this->feed->get_id() . "/");
$pageContent = $this->client->getResponse()->getContent();
foreach ($feeds->get_feeds() as $one_feed) {
$path = "//div[@class='submenu']/a[@href='/prod/feeds/feed/" . $one_feed->get_id() . "/']";
$msg = sprintf("user %s has access to feed %s", self::$user->get_id(), $one_feed->get_id());
if ($one_feed->has_access(self::$user)) {
$this->assertEquals(1, $crawler->filterXPath($path)->count(), $msg);
} else {
$this->fail('Feed_collection::load_all should return feed where I got access');
}
}
}
public function testSuscribeAggregate()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$feeds = Feed_Collection::load_all($appbox, self::$user);
$crawler = $this->client->request('GET', '/feeds/subscribe/aggregated/');
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertEquals("application/json", $this->client->getResponse()->headers->get("content-type"));
$pageContent = json_decode($this->client->getResponse()->getContent());
$this->assertTrue(is_object($pageContent));
$this->assertTrue(is_string($pageContent->texte));
$suscribe_link = $feeds->get_aggregate()->get_user_link(registry::get_instance(), self::$user, Feed_Adapter::FORMAT_RSS, null, false)->get_href();
$this->assertContains($suscribe_link, $pageContent->texte);
}
public function testSuscribe()
{
$crawler = $this->client->request('GET', '/feeds/subscribe/' . $this->feed->get_id() . '/');
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertEquals("application/json", $this->client->getResponse()->headers->get("content-type"));
$pageContent = json_decode($this->client->getResponse()->getContent());
$this->assertTrue(is_object($pageContent));
$this->assertTrue(is_string($pageContent->texte));
$suscribe_link = $this->feed->get_user_link(registry::get_instance(), self::$user, Feed_Adapter::FORMAT_RSS, null, false)->get_href();
$this->assertContains($suscribe_link, $pageContent->texte);
}
} }

View File

@@ -1,47 +1,30 @@
<?php <?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__ . '/../../../../PhraseanetWebTestCaseAbstract.class.inc'; require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAbstract.class.inc';
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class ControllerLanguageTest extends PhraseanetWebTestCaseAbstract class ControllerLanguageTest extends PhraseanetWebTestCaseAbstract
{ {
protected $client;
protected $client; public function setUp()
{
parent::setUp();
$this->client = $this->createClient();
}
public function setUp() public function createApplication()
{ {
parent::setUp(); return require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Prod.php';
$this->client = $this->createClient(); }
}
public function createApplication() public function testRootPost()
{ {
return require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Prod.php'; $route = '/language/';
}
public function testRootPost()
{
$route = '/language/';
$this->client->request("GET", $route);
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertEquals("application/json", $this->client->getResponse()->headers->get("content-type"));
$pageContent = json_decode($this->client->getResponse()->getContent());
$this->assertTrue(is_object($pageContent));
}
$this->client->request("GET", $route);
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertEquals("application/json", $this->client->getResponse()->headers->get("content-type"));
$pageContent = json_decode($this->client->getResponse()->getContent());
$this->assertTrue(is_object($pageContent));
}
} }

View File

@@ -4,57 +4,39 @@ require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.
class ControllerMoveCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract class ControllerMoveCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{ {
protected $client;
protected static $need_records = 1;
/** public function createApplication()
* As controllers use WebTestCase, it requires a client {
*/ return require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Prod.php';
protected $client; }
/** public function setUp()
* If the controller tests require some records, specify it her {
* parent::setUp();
* For example, this will loacd 2 records $this->client = $this->createClient();
* (self::$record_1 and self::$record_2) : }
*
* $need_records = 2;
*
*/
protected static $need_records = 1;
/** /**
* The application loader * Default route test
*/ */
public function createApplication() public function testRouteSlash()
{ {
return require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Prod.php'; $this->client->request('POST', '/records/movecollection/', array('lst' => self::$record_1->get_serialize_key()));
}
public function setUp() $response = $this->client->getResponse();
{
parent::setUp();
$this->client = $this->createClient();
}
/** $this->assertTrue($response->isOk());
* Default route test }
*/
public function testRouteSlash()
{
$this->client->request('POST', '/records/movecollection/', array('lst' => self::$record_1->get_serialize_key()));
$response = $this->client->getResponse(); public function testApply()
{
$this->assertTrue($response->isOk()); $this->client->request('POST', '/records/movecollection/apply/', array('lst' => self::$record_1->get_serialize_key(), 'base_id' => self::$collection->get_base_id()));
}
public function testApply() $response = $this->client->getResponse();
{
$this->client->request('POST', '/records/movecollection/apply/', array('lst' => self::$record_1->get_serialize_key(), 'base_id' => self::$collection->get_base_id()));
$response = $this->client->getResponse();
$this->assertTrue($response->isOk());
}
$this->assertTrue($response->isOk());
}
} }

View File

@@ -4,54 +4,52 @@ require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.
class MustacheLoaderTest extends \PhraseanetWebTestCaseAuthenticatedAbstract class MustacheLoaderTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{ {
protected $client;
protected $client; public function createApplication()
{
return require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Prod.php';
}
public function createApplication() public function setUp()
{ {
return require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Prod.php'; parent::setUp();
} $this->client = $this->createClient();
}
public function setUp() public function testRouteSlash()
{ {
parent::setUp();
$this->client = $this->createClient();
}
public function testRouteSlash() $this->client->request('GET', '/MustacheLoader/');
{
$this->client->request('GET', '/MustacheLoader/'); $response = $this->client->getResponse();
/* @var $response \Symfony\Component\HttpFoundation\Response */
$response = $this->client->getResponse(); $this->assertEquals(400, $response->getStatusCode());
/* @var $response \Symfony\Component\HttpFoundation\Response */ $this->assertFalse($response->isOk());
$this->assertEquals(400, $response->getStatusCode()); $this->client->request('GET', '/MustacheLoader/', array('template' => '/../../../../config/config.yml'));
$this->assertFalse($response->isOk());
$this->client->request('GET', '/MustacheLoader/', array('template' => '/../../../../config/config.yml')); $response = $this->client->getResponse();
/* @var $response \Symfony\Component\HttpFoundation\Response */
$response = $this->client->getResponse(); $this->assertEquals(400, $response->getStatusCode());
/* @var $response \Symfony\Component\HttpFoundation\Response */ $this->assertFalse($response->isOk());
$this->assertEquals(400, $response->getStatusCode()); $this->client->request('GET', '/MustacheLoader/', array('template' => 'patator_lala'));
$this->assertFalse($response->isOk());
$this->client->request('GET', '/MustacheLoader/', array('template' => 'patator_lala')); $response = $this->client->getResponse();
/* @var $response \Symfony\Component\HttpFoundation\Response */
$response = $this->client->getResponse(); $this->assertEquals(404, $response->getStatusCode());
/* @var $response \Symfony\Component\HttpFoundation\Response */ $this->assertFalse($response->isOk());
$this->assertEquals(404, $response->getStatusCode()); $this->client->request('GET', '/MustacheLoader/', array('template' => 'Feedback-Badge'));
$this->assertFalse($response->isOk());
$this->client->request('GET', '/MustacheLoader/', array('template' => 'Feedback-Badge')); $response = $this->client->getResponse();
/* @var $response \Symfony\Component\HttpFoundation\Response */
$response = $this->client->getResponse();
/* @var $response \Symfony\Component\HttpFoundation\Response */
$this->assertEquals(200, $response->getStatusCode());
$this->assertTrue($response->isOk());
}
$this->assertEquals(200, $response->getStatusCode());
$this->assertTrue($response->isOk());
}
} }

View File

@@ -4,89 +4,70 @@ require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.
class ControllerPrinterTest extends \PhraseanetWebTestCaseAuthenticatedAbstract class ControllerPrinterTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{ {
protected $client;
protected static $need_records = 4;
/** public function createApplication()
* As controllers use WebTestCase, it requires a client
*/
protected $client;
/**
* If the controller tests require some records, specify it her
*
* For example, this will loacd 2 records
* (self::$record_1 and self::$record_2) :
*
* $need_records = 2;
*
*/
protected static $need_records = 4;
/**
* The application loader
*/
public function createApplication()
{
return require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Prod.php';
}
public function setUp()
{
parent::setUp();
$this->client = $this->createClient();
}
/**
* Default route test
*/
public function testRouteSlash()
{
$records = array(
self::$record_1->get_serialize_key(),
self::$record_2->get_serialize_key()
);
$lst = implode(';', $records);
$crawler = $this->client->request('POST', '/printer/', array('lst' => $lst));
$response = $this->client->getResponse();
$this->assertTrue($response->isOk());
}
public function testRoutePrintPdf()
{
$records = array(
self::$record_1->get_serialize_key(),
self::$record_2->get_serialize_key(),
self::$record_3->get_serialize_key(),
self::$record_4->get_serialize_key(),
);
$lst = implode(';', $records);
$layouts = array(
\Alchemy\Phrasea\Out\Module\PDF::LAYOUT_PREVIEW,
\Alchemy\Phrasea\Out\Module\PDF::LAYOUT_PREVIEWCAPTION,
\Alchemy\Phrasea\Out\Module\PDF::LAYOUT_PREVIEWCAPTIONTDM,
\Alchemy\Phrasea\Out\Module\PDF::LAYOUT_THUMBNAILLIST,
\Alchemy\Phrasea\Out\Module\PDF::LAYOUT_THUMBNAILGRID
);
foreach ($layouts as $layout)
{ {
$crawler = $this->client->request('POST', '/printer/print.pdf', array( return require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Prod.php';
'lst' => $lst,
'lay' => $layout
)
);
$response = $this->client->getResponse();
$this->assertEquals("application/pdf", $response->headers->get("content-type"));
$this->assertTrue($response->isOk());
} }
}
public function setUp()
{
parent::setUp();
$this->client = $this->createClient();
}
/**
* Default route test
*/
public function testRouteSlash()
{
$records = array(
self::$record_1->get_serialize_key(),
self::$record_2->get_serialize_key()
);
$lst = implode(';', $records);
$crawler = $this->client->request('POST', '/printer/', array('lst' => $lst));
$response = $this->client->getResponse();
$this->assertTrue($response->isOk());
}
public function testRoutePrintPdf()
{
$records = array(
self::$record_1->get_serialize_key(),
self::$record_2->get_serialize_key(),
self::$record_3->get_serialize_key(),
self::$record_4->get_serialize_key(),
);
$lst = implode(';', $records);
$layouts = array(
\Alchemy\Phrasea\Out\Module\PDF::LAYOUT_PREVIEW,
\Alchemy\Phrasea\Out\Module\PDF::LAYOUT_PREVIEWCAPTION,
\Alchemy\Phrasea\Out\Module\PDF::LAYOUT_PREVIEWCAPTIONTDM,
\Alchemy\Phrasea\Out\Module\PDF::LAYOUT_THUMBNAILLIST,
\Alchemy\Phrasea\Out\Module\PDF::LAYOUT_THUMBNAILGRID
);
foreach ($layouts as $layout) {
$crawler = $this->client->request('POST', '/printer/print.pdf', array(
'lst' => $lst,
'lay' => $layout
)
);
$response = $this->client->getResponse();
$this->assertEquals("application/pdf", $response->headers->get("content-type"));
$this->assertTrue($response->isOk());
}
}
} }

View File

@@ -4,160 +4,142 @@ require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.
class ControllerPushTest extends \PhraseanetWebTestCaseAuthenticatedAbstract class ControllerPushTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{ {
protected $client;
protected static $need_records = 2;
/** public function createApplication()
* As controllers use WebTestCase, it requires a client {
*/ return require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Prod.php';
protected $client; }
/** public function setUp()
* If the controller tests require some records, specify it her {
* parent::setUp();
* For example, this will loacd 2 records $this->client = $this->createClient();
* (self::$record_1 and self::$record_2) : }
*
* $need_records = 2;
*
*/
protected static $need_records = 2;
/** /**
* The application loader * Default route test
*/ */
public function createApplication() public function testRoutePOSTSendSlash()
{ {
return require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Prod.php'; $route = '/push/sendform/';
}
public function setUp() $this->client->request('POST', $route);
{
parent::setUp();
$this->client = $this->createClient();
}
/** $response = $this->client->getResponse();
* Default route test
*/
public function testRoutePOSTSendSlash()
{
$route = '/push/sendform/';
$this->client->request('POST', $route); $this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('UTF-8', $response->getCharset());
}
$response = $this->client->getResponse(); public function testRoutePOSTValidateSlash()
{
$route = '/push/validateform/';
$this->assertEquals(200, $response->getStatusCode()); $this->client->request('POST', $route);
$this->assertEquals('UTF-8', $response->getCharset());
}
public function testRoutePOSTValidateSlash() $response = $this->client->getResponse();
{
$route = '/push/validateform/';
$this->client->request('POST', $route); $this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('UTF-8', $response->getCharset());
}
$response = $this->client->getResponse(); public function testRoutePOSTsend()
{
$route = '/push/send/';
$this->assertEquals(200, $response->getStatusCode()); $records = array(
$this->assertEquals('UTF-8', $response->getCharset()); self::$record_1->get_serialize_key()
} , self::$record_2->get_serialize_key()
);
public function testRoutePOSTsend() $receivers = array(
{ array('usr_id' => self::$user_alt1->get_id(), 'HD' => 1)
$route = '/push/send/'; , array('usr_id' => self::$user_alt2->get_id(), 'HD' => 0)
);
$records = array( $params = array(
self::$record_1->get_serialize_key() 'lst' => implode(';', $records)
, self::$record_2->get_serialize_key() , 'participants' => $receivers
); );
$receivers = array( $this->client->request('POST', $route, $params);
array('usr_id'=>self::$user_alt1->get_id(), 'HD'=>1)
, array('usr_id'=>self::$user_alt2->get_id(), 'HD'=>0)
);
$params = array( $response = $this->client->getResponse();
'lst' => implode(';', $records)
, 'participants' => $receivers
);
$this->client->request('POST', $route, $params); $this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('UTF-8', $response->getCharset());
$response = $this->client->getResponse(); $datas = (array) json_decode($response->getContent());
$this->assertEquals(200, $response->getStatusCode()); $this->assertArrayHasKey('message', $datas);
$this->assertEquals('UTF-8', $response->getCharset()); $this->assertArrayHasKey('success', $datas);
$datas = (array) json_decode($response->getContent()); $this->assertTrue($datas['success'], 'Result is successful');
}
$this->assertArrayHasKey('message', $datas); public function testRoutePOSTvalidate()
$this->assertArrayHasKey('success', $datas); {
$route = '/push/validate/';
$this->assertTrue($datas['success'], 'Result is successful'); $records = array(
} self::$record_1->get_serialize_key()
, self::$record_2->get_serialize_key()
);
public function testRoutePOSTvalidate() $participants = array(
{ array(
$route = '/push/validate/'; 'usr_id' => self::$user_alt1->get_id(),
'agree' => 0,
'see_others' => 1,
'HD' => 0,
)
, array(
'usr_id' => self::$user_alt2->get_id(),
'agree' => 1,
'see_others' => 0,
'HD' => 1,
)
);
$records = array( $params = array(
self::$record_1->get_serialize_key() 'lst' => implode(';', $records)
, self::$record_2->get_serialize_key() , 'participants' => $participants
); );
$participants = array( $this->client->request('POST', $route, $params);
array(
'usr_id' => self::$user_alt1->get_id(),
'agree'=> 0,
'see_others'=> 1,
'HD'=> 0,
)
, array(
'usr_id' => self::$user_alt2->get_id(),
'agree'=> 1,
'see_others'=> 0,
'HD'=> 1,
)
);
$params = array( $response = $this->client->getResponse();
'lst' => implode(';', $records)
, 'participants' => $participants
);
$this->client->request('POST', $route, $params); $this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('UTF-8', $response->getCharset());
$response = $this->client->getResponse(); $datas = (array) json_decode($response->getContent());
$this->assertEquals(200, $response->getStatusCode()); $this->assertArrayHasKey('message', $datas);
$this->assertEquals('UTF-8', $response->getCharset()); $this->assertArrayHasKey('success', $datas);
$datas = (array) json_decode($response->getContent()); $this->assertTrue($datas['success'], 'Result is successful');
}
$this->assertArrayHasKey('message', $datas); public function testRouteGETsearchuser()
$this->assertArrayHasKey('success', $datas); {
$route = '/push/search-user/';
$this->assertTrue($datas['success'], 'Result is successful'); $params = array(
} 'query' => ''
);
public function testRouteGETsearchuser() $this->client->request('GET', $route, $params);
{
$route = '/push/search-user/';
$params = array( $response = $this->client->getResponse();
'query' => ''
);
$this->client->request('GET', $route, $params); $this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('UTF-8', $response->getCharset());
$response = $this->client->getResponse(); $datas = (array) json_decode($response->getContent());
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('UTF-8', $response->getCharset());
$datas = (array) json_decode($response->getContent());
$this->assertTrue(is_array($datas), 'Json is valid');
}
$this->assertTrue(is_array($datas), 'Json is valid');
}
} }

View File

@@ -4,49 +4,31 @@ require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.
class ControllerRootTest extends \PhraseanetWebTestCaseAuthenticatedAbstract class ControllerRootTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{ {
protected $client;
protected static $need_records = false;
/** public function createApplication()
* As controllers use WebTestCase, it requires a client {
*/ return require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Prod.php';
protected $client; }
/**
* If the controller tests require some records, specify it her
*
* For example, this will loacd 2 records
* (self::$record_1 and self::$record_2) :
*
* $need_records = 2;
*
*/
protected static $need_records = false;
/** public function setUp()
* The application loader {
*/ parent::setUp();
public function createApplication() $this->client = $this->createClient();
{ }
return require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Prod.php';
}
public function setUp() /**
{ * Default route test
parent::setUp(); */
$this->client = $this->createClient(); public function testRouteSlash()
} {
$crawler = $this->client->request('GET', '/');
/**
* Default route test
*/
public function testRouteSlash()
{
$crawler = $this->client->request('GET', '/');
$response = $this->client->getResponse(); $response = $this->client->getResponse();
/* @var $response \Symfony\Component\HttpFoundation\Response */ /* @var $response \Symfony\Component\HttpFoundation\Response */
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('UTF-8', $response->getCharset()); $this->assertEquals('UTF-8', $response->getCharset());
}
}
} }

View File

@@ -1,16 +1,6 @@
<?php <?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'; require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.class.inc';
require_once __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Controller/Prod/Story.php'; require_once __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Controller/Prod/Story.php';
use Doctrine\Common\DataFixtures\Loader; use Doctrine\Common\DataFixtures\Loader;
@@ -18,211 +8,199 @@ use PhraseaFixture\Basket as MyFixture;
use Alchemy\Phrasea\Helper; use Alchemy\Phrasea\Helper;
use Alchemy\Phrasea\RouteProcessor as routeProcessor; use Alchemy\Phrasea\RouteProcessor as routeProcessor;
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class ControllerStoryTest extends \PhraseanetWebTestCaseAuthenticatedAbstract class ControllerStoryTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{ {
protected $client;
protected $client; /**
*
* @var \record_adapter
*/
protected static $need_story = true;
protected static $need_records = 2;
/** public function setUp()
*
* @var \record_adapter
*/
protected static $need_story = true;
protected static $need_records = 2;
public function setUp()
{
parent::setUp();
$this->client = $this->createClient();
$this->purgeDatabase();
}
public function createApplication()
{
return require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Prod.php';
}
public function testRootPost()
{
$route = "/story/";
$collections = self::$core->getAuthenticatedUser()
->ACL()
->get_granted_base(array('canaddrecord'));
$collection = array_shift($collections);
$crawler = $this->client->request(
'POST', $route, array(
'base_id' => $collection->get_base_id(),
'name' => 'test story'
)
);
$response = $this->client->getResponse();
$this->assertEquals(302, $response->getStatusCode());
$query = self::$core->getEntityManager()->createQuery(
'SELECT COUNT(w.id) FROM \Entities\StoryWZ w'
);
$count = $query->getSingleScalarResult();
$this->assertEquals(1, $count);
}
public function testRootPostJSON()
{
$route = "/story/";
$collections = self::$core->getAuthenticatedUser()
->ACL()
->get_granted_base(array('canaddrecord'));
$collection = array_shift($collections);
$crawler = $this->client->request(
'POST', $route, array(
'base_id' => $collection->get_base_id(),
'name' => 'test story'), array(), array(
"HTTP_ACCEPT" => "application/json")
);
$response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode());
}
public function testCreateGet()
{
$route = "/story/create/";
$crawler = $this->client->request('GET', $route);
$response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode());
$filter = "form[action='/prod/story/']";
$this->assertEquals(1, $crawler->filter($filter)->count());
$filter = "form[action='/prod/story/'] input[name='name']";
$this->assertEquals(1, $crawler->filter($filter)->count());
$filter = "form[action='/prod/story/'] select[name='base_id']";
$this->assertEquals(1, $crawler->filter($filter)->count());
}
public function testByIds()
{
$story = self::$story_1;
$route = sprintf("/story/%d/%d/", $story->get_sbas_id(), $story->get_record_id());
$crawler = $this->client->request('GET', $route);
$response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode());
}
public function testAddElementsToStory()
{
$story = self::$story_1;
$route = sprintf("/story/%s/%s/addElements/", $story->get_sbas_id(), $story->get_record_id());
$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());
$this->assertEquals(2, self::$story_1->get_children()->get_count());
}
public function testAddElementsToStoryJSON()
{
$story = self::$story_1;
$route = sprintf("/story/%s/%s/addElements/", $story->get_sbas_id(), $story->get_record_id());
$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(200, $response->getStatusCode());
$this->assertEquals(2, self::$story_1->get_children()->get_count());
}
public function testRemoveElementFromStory()
{
$story = self::$story_1;
$records = array(
self::$record_1,
self::$record_2
);
$totalRecords = count($records);
$n = 0;
foreach ($records as $record)
{ {
/* @var $record \record_adapter */ parent::setUp();
$route = sprintf( $this->client = $this->createClient();
"/story/%s/%s/delete/%s/%s/" $this->purgeDatabase();
, $story->get_sbas_id() }
, $story->get_record_id()
, $record->get_sbas_id()
, $record->get_record_id()
);
if (($n % 2) === 0) public function createApplication()
{ {
$crawler = $this->client->request('POST', $route); return require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Prod.php';
}
public function testRootPost()
{
$route = "/story/";
$collections = self::$core->getAuthenticatedUser()
->ACL()
->get_granted_base(array('canaddrecord'));
$collection = array_shift($collections);
$crawler = $this->client->request(
'POST', $route, array(
'base_id' => $collection->get_base_id(),
'name' => 'test story'
)
);
$response = $this->client->getResponse(); $response = $this->client->getResponse();
$this->assertEquals(302, $response->getStatusCode()); $this->assertEquals(302, $response->getStatusCode());
}
else $query = self::$core->getEntityManager()->createQuery(
{ 'SELECT COUNT(w.id) FROM \Entities\StoryWZ w'
$crawler = $this->client->request(
'POST', $route, array(), array(), array(
"HTTP_ACCEPT" => "application/json")
); );
$response = $this->client->getResponse();
$count = $query->getSingleScalarResult();
$this->assertEquals(1, $count);
}
public function testRootPostJSON()
{
$route = "/story/";
$collections = self::$core->getAuthenticatedUser()
->ACL()
->get_granted_base(array('canaddrecord'));
$collection = array_shift($collections);
$crawler = $this->client->request(
'POST', $route, array(
'base_id' => $collection->get_base_id(),
'name' => 'test story'), array(), array(
"HTTP_ACCEPT" => "application/json")
);
$response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
}
$n++;
$this->assertEquals($totalRecords - $n, self::$story_1->get_children()->get_count());
} }
}
public function testCreateGet()
{
$route = "/story/create/";
$crawler = $this->client->request('GET', $route);
$response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode());
$filter = "form[action='/prod/story/']";
$this->assertEquals(1, $crawler->filter($filter)->count());
$filter = "form[action='/prod/story/'] input[name='name']";
$this->assertEquals(1, $crawler->filter($filter)->count());
$filter = "form[action='/prod/story/'] select[name='base_id']";
$this->assertEquals(1, $crawler->filter($filter)->count());
}
public function testByIds()
{
$story = self::$story_1;
$route = sprintf("/story/%d/%d/", $story->get_sbas_id(), $story->get_record_id());
$crawler = $this->client->request('GET', $route);
$response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode());
}
public function testAddElementsToStory()
{
$story = self::$story_1;
$route = sprintf("/story/%s/%s/addElements/", $story->get_sbas_id(), $story->get_record_id());
$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());
$this->assertEquals(2, self::$story_1->get_children()->get_count());
}
public function testAddElementsToStoryJSON()
{
$story = self::$story_1;
$route = sprintf("/story/%s/%s/addElements/", $story->get_sbas_id(), $story->get_record_id());
$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(200, $response->getStatusCode());
$this->assertEquals(2, self::$story_1->get_children()->get_count());
}
public function testRemoveElementFromStory()
{
$story = self::$story_1;
$records = array(
self::$record_1,
self::$record_2
);
$totalRecords = count($records);
$n = 0;
foreach ($records as $record) {
/* @var $record \record_adapter */
$route = sprintf(
"/story/%s/%s/delete/%s/%s/"
, $story->get_sbas_id()
, $story->get_record_id()
, $record->get_sbas_id()
, $record->get_record_id()
);
if (($n % 2) === 0) {
$crawler = $this->client->request('POST', $route);
$response = $this->client->getResponse();
$this->assertEquals(302, $response->getStatusCode());
} else {
$crawler = $this->client->request(
'POST', $route, array(), array(), array(
"HTTP_ACCEPT" => "application/json")
);
$response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode());
}
$n ++;
$this->assertEquals($totalRecords - $n, self::$story_1->get_children()->get_count());
}
}
} }

View File

@@ -9,188 +9,178 @@ use Symfony\Component\HttpFoundation\Response;
class ControllerTooltipTest extends \PhraseanetWebTestCaseAuthenticatedAbstract class ControllerTooltipTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{ {
protected $client;
protected static $need_records = 1;
protected static $need_subdefs = true;
protected static $need_story = 1;
protected $client; public function setUp()
protected static $need_records = 1; {
protected static $need_subdefs = true; parent::setUp();
protected static $need_story = 1; $this->client = $this->createClient();
}
public function setUp() public function createApplication()
{ {
parent::setUp(); return require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Prod.php';
$this->client = $this->createClient(); }
}
public function createApplication() public function testRouteBasket()
{ {
return require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Prod.php'; $appbox = appbox::get_instance(\bootstrap::getCore());
}
public function testRouteBasket() $basket = $this->insertOneBasket();
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$basket = $this->insertOneBasket(); $crawler = $this->client->request('POST', '/tooltip/basket/' . $basket->getId() . '/');
$pageContent = $this->client->getResponse()->getContent();
$this->assertTrue($this->client->getResponse()->isOk());
$crawler = $this->client->request('POST', '/tooltip/basket/' . $basket->getId() . '/'); $crawler = $this->client->request('POST', '/tootltip/basket/notanid/');
$pageContent = $this->client->getResponse()->getContent(); $pageContent = $this->client->getResponse()->getContent();
$this->assertTrue($this->client->getResponse()->isOk()); $this->assertFalse($this->client->getResponse()->isOk());
$crawler = $this->client->request('POST', '/tootltip/basket/notanid/'); $crawler = $this->client->request('POST', '/tooltip/basket/-5/');
$pageContent = $this->client->getResponse()->getContent(); $pageContent = $this->client->getResponse()->getContent();
$this->assertFalse($this->client->getResponse()->isOk()); $this->assertFalse($this->client->getResponse()->isOk());
}
$crawler = $this->client->request('POST', '/tooltip/basket/-5/'); public function testRoutePreview()
$pageContent = $this->client->getResponse()->getContent(); {
$this->assertFalse($this->client->getResponse()->isOk()); $route = '/tooltip/preview/' . self::$record_1->get_sbas_id()
}
public function testRoutePreview()
{
$route = '/tooltip/preview/' . self::$record_1->get_sbas_id()
. '/' . self::$record_1->get_record_id() . '/'; . '/' . self::$record_1->get_record_id() . '/';
$crawler = $this->client->request('POST', $route); $crawler = $this->client->request('POST', $route);
$pageContent = $this->client->getResponse()->getContent(); $pageContent = $this->client->getResponse()->getContent();
$this->assertTrue($this->client->getResponse()->isOk()); $this->assertTrue($this->client->getResponse()->isOk());
} }
public function testRouteCaption() public function testRouteCaption()
{ {
$route_base = '/tooltip/caption/' . self::$record_1->get_sbas_id() $route_base = '/tooltip/caption/' . self::$record_1->get_sbas_id()
. '/' . self::$record_1->get_record_id() . '/%s/'; . '/' . self::$record_1->get_record_id() . '/%s/';
$routes = array( $routes = array(
sprintf($route_base, 'answer') sprintf($route_base, 'answer')
, sprintf($route_base, 'lazaret') , sprintf($route_base, 'lazaret')
, sprintf($route_base, 'preview') , sprintf($route_base, 'preview')
, sprintf($route_base, 'basket') , sprintf($route_base, 'basket')
, sprintf($route_base, 'overview') , sprintf($route_base, 'overview')
); );
foreach ($routes as $route) foreach ($routes as $route) {
{ $crawler = $this->client->request('POST', $route);
$crawler = $this->client->request('POST', $route); $pageContent = $this->client->getResponse()->getContent();
$pageContent = $this->client->getResponse()->getContent(); $this->assertTrue($this->client->getResponse()->isOk());
$this->assertTrue($this->client->getResponse()->isOk()); }
} }
}
public function testRouteCaptionSearchEngine() public function testRouteCaptionSearchEngine()
{ {
$route_base = '/tooltip/caption/' . self::$record_1->get_sbas_id() $route_base = '/tooltip/caption/' . self::$record_1->get_sbas_id()
. '/' . self::$record_1->get_record_id() . '/%s/'; . '/' . self::$record_1->get_record_id() . '/%s/';
$routes = array( $routes = array(
sprintf($route_base, 'answer') sprintf($route_base, 'answer')
, sprintf($route_base, 'lazaret') , sprintf($route_base, 'lazaret')
, sprintf($route_base, 'preview') , sprintf($route_base, 'preview')
, sprintf($route_base, 'basket') , sprintf($route_base, 'basket')
, sprintf($route_base, 'overview') , sprintf($route_base, 'overview')
); );
foreach ($routes as $route) foreach ($routes as $route) {
{ $option = new \searchEngine_options();
$option = new \searchEngine_options(); $crawler = $this->client->request('POST', $route, array('options_serial' => serialize($option)));
$crawler = $this->client->request('POST', $route, array('options_serial' => serialize($option)));
$this->assertTrue($this->client->getResponse()->isOk()); $this->assertTrue($this->client->getResponse()->isOk());
}
} }
}
public function testRouteTCDatas() public function testRouteTCDatas()
{ {
$route = '/tooltip/tc_datas/' . self::$record_1->get_sbas_id() $route = '/tooltip/tc_datas/' . self::$record_1->get_sbas_id()
. '/' . self::$record_1->get_record_id() . '/'; . '/' . self::$record_1->get_record_id() . '/';
$crawler = $this->client->request('POST', $route);
$pageContent = $this->client->getResponse()->getContent();
$this->assertTrue($this->client->getResponse()->isOk());
}
public function testRouteMetasFieldInfos()
{
$databox = self::$record_1->get_databox();
foreach ($databox->get_meta_structure() as $field)
{
$route = '/tooltip/metas/FieldInfos/' . $databox->get_sbas_id()
. '/' . $field->get_id() . '/';
$crawler = $this->client->request('POST', $route);
$pageContent = $this->client->getResponse()->getContent();
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
}
}
public function testRouteMetasDCESInfos()
{
$databox = self::$record_1->get_databox();
$dces = array(
databox_field::DCES_CONTRIBUTOR => new databox_Field_DCES_Contributor()
, databox_field::DCES_COVERAGE => new databox_Field_DCES_Coverage()
, databox_field::DCES_CREATOR => new databox_Field_DCES_Creator()
, databox_field::DCES_DESCRIPTION => new databox_Field_DCES_Description()
);
foreach ($databox->get_meta_structure() as $field)
{
$dces_element = array_shift($dces);
$field->set_dces_element($dces_element);
$route = '/tooltip/DCESInfos/' . $databox->get_sbas_id()
. '/' . $field->get_id() . '/';
if ($field->get_dces_element() !== null)
{
$crawler = $this->client->request('POST', $route); $crawler = $this->client->request('POST', $route);
$this->assertGreaterThan(0, strlen($this->client->getResponse()->getContent())); $pageContent = $this->client->getResponse()->getContent();
$this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $this->assertTrue($this->client->getResponse()->isOk());
}
else
{
$crawler = $this->client->request('POST', $route);
$this->assertEquals(0, strlen($this->client->getResponse()->getContent()));
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
}
} }
}
public function testRouteMetaRestrictions() public function testRouteMetasFieldInfos()
{
$databox = self::$record_1->get_databox();
foreach ($databox->get_meta_structure() as $field)
{ {
$databox = self::$record_1->get_databox();
$route = '/tooltip/metas/restrictionsInfos/' . $databox->get_sbas_id() foreach ($databox->get_meta_structure() as $field) {
. '/' . $field->get_id() . '/'; $route = '/tooltip/metas/FieldInfos/' . $databox->get_sbas_id()
. '/' . $field->get_id() . '/';
$crawler = $this->client->request('POST', $route); $crawler = $this->client->request('POST', $route);
$this->assertGreaterThan(0, strlen($this->client->getResponse()->getContent())); $pageContent = $this->client->getResponse()->getContent();
$this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
}
} }
}
public function testRouteStory() public function testRouteMetasDCESInfos()
{ {
$databox = self::$story_1->get_databox(); $databox = self::$record_1->get_databox();
$dces = array(
databox_field::DCES_CONTRIBUTOR => new databox_Field_DCES_Contributor()
, databox_field::DCES_COVERAGE => new databox_Field_DCES_Coverage()
, databox_field::DCES_CREATOR => new databox_Field_DCES_Creator()
, databox_field::DCES_DESCRIPTION => new databox_Field_DCES_Description()
);
foreach ($databox->get_meta_structure() as $field) {
$dces_element = array_shift($dces);
$field->set_dces_element($dces_element);
$route = '/tooltip/DCESInfos/' . $databox->get_sbas_id()
. '/' . $field->get_id() . '/';
if ($field->get_dces_element() !== null) {
$crawler = $this->client->request('POST', $route);
$this->assertGreaterThan(0, strlen($this->client->getResponse()->getContent()));
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
} else {
$crawler = $this->client->request('POST', $route);
$this->assertEquals(0, strlen($this->client->getResponse()->getContent()));
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
}
}
}
public function testRouteMetaRestrictions()
{
$databox = self::$record_1->get_databox();
foreach ($databox->get_meta_structure() as $field) {
$route = '/tooltip/metas/restrictionsInfos/' . $databox->get_sbas_id()
. '/' . $field->get_id() . '/';
$crawler = $this->client->request('POST', $route);
$this->assertGreaterThan(0, strlen($this->client->getResponse()->getContent()));
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
}
}
public function testRouteStory()
{
$databox = self::$story_1->get_databox();
$route = '/tooltip/Story/' . $databox->get_sbas_id() $route = '/tooltip/Story/' . $databox->get_sbas_id()
. '/' . self::$story_1->get_record_id() . '/'; . '/' . self::$story_1->get_record_id() . '/';
$this->client->request('POST', $route); $this->client->request('POST', $route);
$this->assertTrue($this->client->getResponse()->isOk()); $this->assertTrue($this->client->getResponse()->isOk());
} }
public function testUser() public function testUser()
{ {
$route = '/tooltip/user/' . self::$user->get_id() . '/';
$this->client->request('POST', $route);
$this->assertTrue($this->client->getResponse()->isOk());
}
$route = '/tooltip/user/' . self::$user->get_id() . '/';
$this->client->request('POST', $route);
$this->assertTrue($this->client->getResponse()->isOk());
}
} }

View File

@@ -4,476 +4,456 @@ require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.
class ControllerUsrListsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract class ControllerUsrListsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{ {
protected $client;
protected static $need_records = false;
/** public function createApplication()
* As controllers use WebTestCase, it requires a client
*/
protected $client;
/**
* If the controller tests require some records, specify it her
*
* For example, this will loacd 2 records
* (self::$record_1 and self::$record_2) :
*
* $need_records = 2;
*
*/
protected static $need_records = false;
/**
* The application loader
*/
public function createApplication()
{
return require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Prod.php';
}
public function setUp()
{
parent::setUp();
$this->client = $this->createClient();
}
/**
* Default route test
*/
public function testRouteSlash()
{
$entry1 = $this->insertOneUsrListEntry(self::$user, self::$user);
$entry2 = $this->insertOneUsrListEntry(self::$user, self::$user_alt1);
$entry3 = $this->insertOneUsrListEntry(self::$user, self::$user);
$entry4 = $this->insertOneUsrListEntry(self::$user, self::$user_alt1);
$entry5 = $this->insertOneUsrListEntry(self::$user_alt1, self::$user_alt1);
$entry6 = $this->insertOneUsrListEntry(self::$user_alt1, self::$user_alt2);
$route = '/lists/all/';
$this->client->request('GET', $route, array(), array(), array("HTTP_CONTENT_TYPE" => "application/json", "HTTP_ACCEPT" => "application/json"));
$response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('UTF-8', $response->getCharset());
$datas = (array) json_decode($response->getContent());
$this->assertEquals(4, count($datas['result']));
}
protected function checkList($list, $owners = true, $users = true)
{
$this->assertInstanceOf('stdClass', $list);
$this->assertObjectHasAttribute('name', $list);
$this->assertObjectHasAttribute('created', $list);
$this->assertObjectHasAttribute('updated', $list);
$this->assertObjectHasAttribute('owners', $list);
$this->assertObjectHasAttribute('users', $list);
if ($owners)
$this->assertTrue(count($list->owners) > 0);
foreach ($list->owners as $owner)
{ {
$this->checkOwner($owner); return require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Prod.php';
} }
if ($users) public function setUp()
$this->assertTrue(count($list->users) > 0);
foreach ($list->users as $user)
{ {
$this->checkUser($user); parent::setUp();
$this->client = $this->createClient();
} }
}
public function testPostList() /**
{ * Default route test
$route = '/lists/list/'; */
public function testRouteSlash()
{
$entry1 = $this->insertOneUsrListEntry(self::$user, self::$user);
$entry2 = $this->insertOneUsrListEntry(self::$user, self::$user_alt1);
$entry3 = $this->insertOneUsrListEntry(self::$user, self::$user);
$entry4 = $this->insertOneUsrListEntry(self::$user, self::$user_alt1);
$entry5 = $this->insertOneUsrListEntry(self::$user_alt1, self::$user_alt1);
$entry6 = $this->insertOneUsrListEntry(self::$user_alt1, self::$user_alt2);
$this->client->request('POST', $route); $route = '/lists/all/';
$response = $this->client->getResponse(); $this->client->request('GET', $route, array(), array(), array("HTTP_CONTENT_TYPE" => "application/json", "HTTP_ACCEPT" => "application/json"));
$this->assertEquals(200, $response->getStatusCode()); $response = $this->client->getResponse();
$this->assertEquals('UTF-8', $response->getCharset());
$datas = (array) json_decode($response->getContent()); $this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('UTF-8', $response->getCharset());
$this->assertArrayHasKey('success', $datas); $datas = (array) json_decode($response->getContent());
$this->assertArrayHasKey('message', $datas);
$this->assertFalse($datas['success']); $this->assertEquals(4, count($datas['result']));
}
$this->client->request('POST', $route, array('name' => 'New List')); protected function checkList($list, $owners = true, $users = true)
{
$this->assertInstanceOf('stdClass', $list);
$this->assertObjectHasAttribute('name', $list);
$this->assertObjectHasAttribute('created', $list);
$this->assertObjectHasAttribute('updated', $list);
$this->assertObjectHasAttribute('owners', $list);
$this->assertObjectHasAttribute('users', $list);
$response = $this->client->getResponse(); if ($owners)
$this->assertTrue(count($list->owners) > 0);
$this->assertEquals(200, $response->getStatusCode()); foreach ($list->owners as $owner) {
$this->assertEquals('UTF-8', $response->getCharset()); $this->checkOwner($owner);
}
$datas = (array) json_decode($response->getContent()); if ($users)
$this->assertTrue(count($list->users) > 0);
$this->assertArrayHasKey('success', $datas); foreach ($list->users as $user) {
$this->assertArrayHasKey('message', $datas); $this->checkUser($user);
}
}
$this->assertTrue($datas['success']); public function testPostList()
} {
$route = '/lists/list/';
public function testGetList() $this->client->request('POST', $route);
{
$entry = $this->insertOneUsrListEntry(self::$user, self::$user_alt1);
$list_id = $entry->getList()->getId();
$route = '/lists/list/' . $list_id . '/'; $response = $this->client->getResponse();
$this->client->request('GET', $route, array(), array(), array("HTTP_CONTENT_TYPE" => "application/json", "HTTP_ACCEPT" => "application/json")); $this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('UTF-8', $response->getCharset());
$response = $this->client->getResponse(); $datas = (array) json_decode($response->getContent());
$this->assertEquals(200, $response->getStatusCode()); $this->assertArrayHasKey('success', $datas);
$this->assertEquals('UTF-8', $response->getCharset()); $this->assertArrayHasKey('message', $datas);
$this->assertFalse($datas['success']);
$this->client->request('POST', $route, array('name' => 'New List'));
$response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('UTF-8', $response->getCharset());
$datas = (array) json_decode($response->getContent());
$this->assertArrayHasKey('success', $datas);
$this->assertArrayHasKey('message', $datas);
$this->assertTrue($datas['success']);
}
public function testGetList()
{
$entry = $this->insertOneUsrListEntry(self::$user, self::$user_alt1);
$list_id = $entry->getList()->getId();
$route = '/lists/list/' . $list_id . '/';
$this->client->request('GET', $route, array(), array(), array("HTTP_CONTENT_TYPE" => "application/json", "HTTP_ACCEPT" => "application/json"));
$response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('UTF-8', $response->getCharset());
// $datas = (array) json_decode($response->getContent()); // $datas = (array) json_decode($response->getContent());
// //
// $this->assertTrue(is_array($datas)); // $this->assertTrue(is_array($datas));
// $this->assertArrayhasKey('result', $datas); // $this->assertArrayhasKey('result', $datas);
// $this->checkList($datas['result']); // $this->checkList($datas['result']);
} }
public function testPostUpdate() public function testPostUpdate()
{ {
$entry = $this->insertOneUsrListEntry(self::$user, self::$user_alt1); $entry = $this->insertOneUsrListEntry(self::$user, self::$user_alt1);
$list_id = $entry->getList()->getId(); $list_id = $entry->getList()->getId();
$route = '/lists/list/' . $list_id . '/update/'; $route = '/lists/list/' . $list_id . '/update/';
$this->client->request('POST', $route); $this->client->request('POST', $route);
$response = $this->client->getResponse(); $response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('UTF-8', $response->getCharset()); $this->assertEquals('UTF-8', $response->getCharset());
$datas = (array) json_decode($response->getContent()); $datas = (array) json_decode($response->getContent());
$this->assertArrayHasKey('success', $datas); $this->assertArrayHasKey('success', $datas);
$this->assertArrayHasKey('message', $datas); $this->assertArrayHasKey('message', $datas);
$this->assertFalse($datas['success']); $this->assertFalse($datas['success']);
$this->client->request('POST', $route, array('name' => 'New NAME')); $this->client->request('POST', $route, array('name' => 'New NAME'));
$response = $this->client->getResponse(); $response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('UTF-8', $response->getCharset()); $this->assertEquals('UTF-8', $response->getCharset());
$datas = (array) json_decode($response->getContent()); $datas = (array) json_decode($response->getContent());
$this->assertArrayHasKey('success', $datas); $this->assertArrayHasKey('success', $datas);
$this->assertArrayHasKey('message', $datas); $this->assertArrayHasKey('message', $datas);
$this->assertTrue($datas['success']); $this->assertTrue($datas['success']);
} }
public function testPostDelete() public function testPostDelete()
{ {
$entry = $this->insertOneUsrListEntry(self::$user, self::$user_alt1); $entry = $this->insertOneUsrListEntry(self::$user, self::$user_alt1);
$list_id = $entry->getList()->getId(); $list_id = $entry->getList()->getId();
$route = '/lists/list/' . $list_id . '/delete/'; $route = '/lists/list/' . $list_id . '/delete/';
$this->client->request('POST', $route); $this->client->request('POST', $route);
$response = $this->client->getResponse(); $response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('UTF-8', $response->getCharset()); $this->assertEquals('UTF-8', $response->getCharset());
$datas = (array) json_decode($response->getContent()); $datas = (array) json_decode($response->getContent());
$this->assertArrayHasKey('success', $datas); $this->assertArrayHasKey('success', $datas);
$this->assertArrayHasKey('message', $datas); $this->assertArrayHasKey('message', $datas);
$this->assertTrue($datas['success']); $this->assertTrue($datas['success']);
$repository = self::$core->getEntityManager()->getRepository('Entities\UsrList'); $repository = self::$core->getEntityManager()->getRepository('Entities\UsrList');
$this->assertNull($repository->find($list_id)); $this->assertNull($repository->find($list_id));
} }
public function testPostRemoveEntry() public function testPostRemoveEntry()
{ {
$entry = $this->insertOneUsrListEntry(self::$user, self::$user_alt1); $entry = $this->insertOneUsrListEntry(self::$user, self::$user_alt1);
$list_id = $entry->getList()->getId(); $list_id = $entry->getList()->getId();
$usr_id = $entry->getUser()->get_id(); $usr_id = $entry->getUser()->get_id();
$entry_id = $entry->getId(); $entry_id = $entry->getId();
$route = '/lists/list/' . $list_id . '/remove/' . $usr_id . '/'; $route = '/lists/list/' . $list_id . '/remove/' . $usr_id . '/';
$this->client->request('POST', $route, array(), array(), array("HTTP_CONTENT_TYPE" => "application/json", "HTTP_ACCEPT" => "application/json")); $this->client->request('POST', $route, array(), array(), array("HTTP_CONTENT_TYPE" => "application/json", "HTTP_ACCEPT" => "application/json"));
$response = $this->client->getResponse(); $response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('UTF-8', $response->getCharset()); $this->assertEquals('UTF-8', $response->getCharset());
$datas = (array) json_decode($response->getContent()); $datas = (array) json_decode($response->getContent());
$this->assertArrayHasKey('success', $datas); $this->assertArrayHasKey('success', $datas);
$this->assertArrayHasKey('message', $datas); $this->assertArrayHasKey('message', $datas);
$this->assertTrue($datas['success']); $this->assertTrue($datas['success']);
$repository = self::$core->getEntityManager()->getRepository('Entities\UsrListEntry'); $repository = self::$core->getEntityManager()->getRepository('Entities\UsrListEntry');
$this->assertNull($repository->find($entry_id)); $this->assertNull($repository->find($entry_id));
} }
public function testPostAddEntry() public function testPostAddEntry()
{ {
$list = $this->insertOneUsrList(self::$user); $list = $this->insertOneUsrList(self::$user);
$this->assertEquals(0, $list->getEntries()->count()); $this->assertEquals(0, $list->getEntries()->count());
$route = '/lists/list/' . $list->getId() . '/add/'; $route = '/lists/list/' . $list->getId() . '/add/';
$this->client->request('POST', $route, array('usr_ids' => array(self::$user->get_id())), array(), array("HTTP_CONTENT_TYPE" => "application/json", "HTTP_ACCEPT" => "application/json")); $this->client->request('POST', $route, array('usr_ids' => array(self::$user->get_id())), array(), array("HTTP_CONTENT_TYPE" => "application/json", "HTTP_ACCEPT" => "application/json"));
$response = $this->client->getResponse(); $response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('UTF-8', $response->getCharset()); $this->assertEquals('UTF-8', $response->getCharset());
$datas = (array) json_decode($response->getContent()); $datas = (array) json_decode($response->getContent());
$this->assertArrayHasKey('success', $datas); $this->assertArrayHasKey('success', $datas);
$this->assertArrayHasKey('message', $datas); $this->assertArrayHasKey('message', $datas);
$this->assertTrue($datas['success']); $this->assertTrue($datas['success']);
$repository = self::$core->getEntityManager()->getRepository('Entities\UsrList'); $repository = self::$core->getEntityManager()->getRepository('Entities\UsrList');
$list = $repository->find($list->getId()); $list = $repository->find($list->getId());
$this->assertEquals(1, $list->getEntries()->count()); $this->assertEquals(1, $list->getEntries()->count());
} }
public function testPostShareList() public function testPostShareList()
{ {
$list = $this->insertOneUsrList(self::$user); $list = $this->insertOneUsrList(self::$user);
$this->assertEquals(1, $list->getOwners()->count()); $this->assertEquals(1, $list->getOwners()->count());
$route = '/lists/list/' . $list->getId() . '/share/' . self::$user_alt1->get_id() . '/'; $route = '/lists/list/' . $list->getId() . '/share/' . self::$user_alt1->get_id() . '/';
$this->client->request('POST', $route); $this->client->request('POST', $route);
$response = $this->client->getResponse(); $response = $this->client->getResponse();
$this->assertEquals(400, $response->getStatusCode()); $this->assertEquals(400, $response->getStatusCode());
$this->assertEquals('UTF-8', $response->getCharset()); $this->assertEquals('UTF-8', $response->getCharset());
$route = '/lists/list/' . $list->getId() . '/share/' . self::$user_alt1->get_id() . '/'; $route = '/lists/list/' . $list->getId() . '/share/' . self::$user_alt1->get_id() . '/';
$this->client->request('POST', $route, array('role' => 'general')); $this->client->request('POST', $route, array('role' => 'general'));
$response = $this->client->getResponse(); $response = $this->client->getResponse();
$this->assertEquals(400, $response->getStatusCode()); $this->assertEquals(400, $response->getStatusCode());
$this->assertEquals('UTF-8', $response->getCharset()); $this->assertEquals('UTF-8', $response->getCharset());
$route = '/lists/list/' . $list->getId() . '/share/' . self::$user_alt1->get_id() . '/'; $route = '/lists/list/' . $list->getId() . '/share/' . self::$user_alt1->get_id() . '/';
$this->client->request('POST', $route, array('role' => \Entities\UsrListOwner::ROLE_ADMIN)); $this->client->request('POST', $route, array('role' => \Entities\UsrListOwner::ROLE_ADMIN));
$response = $this->client->getResponse(); $response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('UTF-8', $response->getCharset()); $this->assertEquals('UTF-8', $response->getCharset());
$datas = (array) json_decode($response->getContent()); $datas = (array) json_decode($response->getContent());
$this->assertArrayHasKey('success', $datas); $this->assertArrayHasKey('success', $datas);
$this->assertArrayHasKey('message', $datas); $this->assertArrayHasKey('message', $datas);
$this->assertTrue($datas['success']); $this->assertTrue($datas['success']);
$repository = self::$core->getEntityManager()->getRepository('Entities\UsrList'); $repository = self::$core->getEntityManager()->getRepository('Entities\UsrList');
$list = $repository->find($list->getId()); $list = $repository->find($list->getId());
$this->assertEquals(2, $list->getOwners()->count()); $this->assertEquals(2, $list->getOwners()->count());
} }
public function testPostUnShareList() public function testPostUnShareList()
{ {
$list = $this->insertOneUsrList(self::$user); $list = $this->insertOneUsrList(self::$user);
$this->assertEquals(1, $list->getOwners()->count()); $this->assertEquals(1, $list->getOwners()->count());
$route = '/lists/list/' . $list->getId() . '/share/' . self::$user_alt1->get_id() . '/'; $route = '/lists/list/' . $list->getId() . '/share/' . self::$user_alt1->get_id() . '/';
$this->client->request('POST', $route, array('role' => \Entities\UsrListOwner::ROLE_ADMIN)); $this->client->request('POST', $route, array('role' => \Entities\UsrListOwner::ROLE_ADMIN));
$response = $this->client->getResponse(); $response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('UTF-8', $response->getCharset()); $this->assertEquals('UTF-8', $response->getCharset());
$datas = (array) json_decode($response->getContent()); $datas = (array) json_decode($response->getContent());
$this->assertArrayHasKey('success', $datas); $this->assertArrayHasKey('success', $datas);
$this->assertArrayHasKey('message', $datas); $this->assertArrayHasKey('message', $datas);
$this->assertTrue($datas['success']); $this->assertTrue($datas['success']);
$repository = self::$core->getEntityManager()->getRepository('Entities\UsrList'); $repository = self::$core->getEntityManager()->getRepository('Entities\UsrList');
$list = $repository->find($list->getId()); $list = $repository->find($list->getId());
$this->assertEquals(2, $list->getOwners()->count()); $this->assertEquals(2, $list->getOwners()->count());
$route = '/lists/list/' . $list->getId() . '/unshare/' . self::$user_alt1->get_id() . '/'; $route = '/lists/list/' . $list->getId() . '/unshare/' . self::$user_alt1->get_id() . '/';
$this->client->request('POST', $route); $this->client->request('POST', $route);
$response = $this->client->getResponse(); $response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('UTF-8', $response->getCharset()); $this->assertEquals('UTF-8', $response->getCharset());
$datas = (array) json_decode($response->getContent()); $datas = (array) json_decode($response->getContent());
$this->assertTrue($datas['success']); $this->assertTrue($datas['success']);
$repository = self::$core->getEntityManager()->getRepository('Entities\UsrList'); $repository = self::$core->getEntityManager()->getRepository('Entities\UsrList');
$list = $repository->find($list->getId()); $list = $repository->find($list->getId());
self::$core->getEntityManager()->refresh($list); self::$core->getEntityManager()->refresh($list);
$this->assertEquals(1, $list->getOwners()->count()); $this->assertEquals(1, $list->getOwners()->count());
} }
public function testPostUnShareFail() public function testPostUnShareFail()
{ {
$list = $this->insertOneUsrList(self::$user); $list = $this->insertOneUsrList(self::$user);
$this->assertEquals(1, $list->getOwners()->count()); $this->assertEquals(1, $list->getOwners()->count());
$route = '/lists/list/' . $list->getId() . '/share/' . self::$user_alt1->get_id() . '/'; $route = '/lists/list/' . $list->getId() . '/share/' . self::$user_alt1->get_id() . '/';
$this->client->request('POST', $route, array('role' => \Entities\UsrListOwner::ROLE_ADMIN)); $this->client->request('POST', $route, array('role' => \Entities\UsrListOwner::ROLE_ADMIN));
$response = $this->client->getResponse(); $response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('UTF-8', $response->getCharset()); $this->assertEquals('UTF-8', $response->getCharset());
$datas = (array) json_decode($response->getContent()); $datas = (array) json_decode($response->getContent());
$this->assertArrayHasKey('success', $datas); $this->assertArrayHasKey('success', $datas);
$this->assertArrayHasKey('message', $datas); $this->assertArrayHasKey('message', $datas);
$this->assertTrue($datas['success']); $this->assertTrue($datas['success']);
$route = '/lists/list/' . $list->getId() . '/share/' . self::$user->get_id() . '/'; $route = '/lists/list/' . $list->getId() . '/share/' . self::$user->get_id() . '/';
$this->client->request('POST', $route, array('role' => \Entities\UsrListOwner::ROLE_USER)); $this->client->request('POST', $route, array('role' => \Entities\UsrListOwner::ROLE_USER));
$response = $this->client->getResponse(); $response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('UTF-8', $response->getCharset()); $this->assertEquals('UTF-8', $response->getCharset());
$datas = (array) json_decode($response->getContent()); $datas = (array) json_decode($response->getContent());
$this->assertArrayHasKey('success', $datas); $this->assertArrayHasKey('success', $datas);
$this->assertArrayHasKey('message', $datas); $this->assertArrayHasKey('message', $datas);
$this->assertFalse($datas['success']); $this->assertFalse($datas['success']);
$route = '/lists/list/' . $list->getId() . '/share/' . self::$user_alt1->get_id() . '/'; $route = '/lists/list/' . $list->getId() . '/share/' . self::$user_alt1->get_id() . '/';
$this->client->request('POST', $route, array('role' => \Entities\UsrListOwner::ROLE_USER)); $this->client->request('POST', $route, array('role' => \Entities\UsrListOwner::ROLE_USER));
$response = $this->client->getResponse(); $response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('UTF-8', $response->getCharset()); $this->assertEquals('UTF-8', $response->getCharset());
$datas = (array) json_decode($response->getContent()); $datas = (array) json_decode($response->getContent());
$this->assertArrayHasKey('success', $datas); $this->assertArrayHasKey('success', $datas);
$this->assertArrayHasKey('message', $datas); $this->assertArrayHasKey('message', $datas);
$this->assertTrue($datas['success']); $this->assertTrue($datas['success']);
$repository = self::$core->getEntityManager()->getRepository('Entities\UsrList'); $repository = self::$core->getEntityManager()->getRepository('Entities\UsrList');
$list = $repository->find($list->getId()); $list = $repository->find($list->getId());
$this->assertEquals(2, $list->getOwners()->count()); $this->assertEquals(2, $list->getOwners()->count());
$route = '/lists/list/' . $list->getId() . '/unshare/' . self::$user_alt1->get_id() . '/'; $route = '/lists/list/' . $list->getId() . '/unshare/' . self::$user_alt1->get_id() . '/';
$this->client->request('POST', $route); $this->client->request('POST', $route);
$response = $this->client->getResponse(); $response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('UTF-8', $response->getCharset()); $this->assertEquals('UTF-8', $response->getCharset());
$datas = (array) json_decode($response->getContent()); $datas = (array) json_decode($response->getContent());
$this->assertTrue($datas['success']); $this->assertTrue($datas['success']);
} }
protected function checkOwner($owner) protected function checkOwner($owner)
{ {
$this->assertInstanceOf('stdClass', $owner); $this->assertInstanceOf('stdClass', $owner);
$this->assertObjectHasAttribute('usr_id', $owner); $this->assertObjectHasAttribute('usr_id', $owner);
$this->assertObjectHasAttribute('display_name', $owner); $this->assertObjectHasAttribute('display_name', $owner);
$this->assertObjectHasAttribute('position', $owner); $this->assertObjectHasAttribute('position', $owner);
$this->assertObjectHasAttribute('job', $owner); $this->assertObjectHasAttribute('job', $owner);
$this->assertObjectHasAttribute('company', $owner); $this->assertObjectHasAttribute('company', $owner);
$this->assertObjectHasAttribute('email', $owner); $this->assertObjectHasAttribute('email', $owner);
$this->assertObjectHasAttribute('role', $owner); $this->assertObjectHasAttribute('role', $owner);
$this->assertTrue(ctype_digit($owner->role)); $this->assertTrue(ctype_digit($owner->role));
} }
protected function checkUser($user)
{
$this->assertInstanceOf('stdClass', $user);
$this->assertObjectHasAttribute('usr_id', $user);
$this->assertObjectHasAttribute('display_name', $user);
$this->assertObjectHasAttribute('position', $user);
$this->assertObjectHasAttribute('job', $user);
$this->assertObjectHasAttribute('company', $user);
$this->assertObjectHasAttribute('email', $user);
}
protected function checkUser($user)
{
$this->assertInstanceOf('stdClass', $user);
$this->assertObjectHasAttribute('usr_id', $user);
$this->assertObjectHasAttribute('display_name', $user);
$this->assertObjectHasAttribute('position', $user);
$this->assertObjectHasAttribute('job', $user);
$this->assertObjectHasAttribute('company', $user);
$this->assertObjectHasAttribute('email', $user);
}
} }

View File

@@ -1,213 +1,196 @@
<?php <?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'; require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.class.inc';
use Alchemy\Phrasea\Helper; use Alchemy\Phrasea\Helper;
use Alchemy\Phrasea\RouteProcessor as routeProcessor; use Alchemy\Phrasea\RouteProcessor as routeProcessor;
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class ControllerWorkZoneTest extends \PhraseanetWebTestCaseAuthenticatedAbstract class ControllerWorkZoneTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{ {
protected $client;
protected static $need_records = 1;
protected static $need_story = true;
protected $client; public function setUp()
protected static $need_records = 1; {
protected static $need_story = true; parent::setUp();
$this->client = $this->createClient();
$this->purgeDatabase();
}
public function setUp() public function createApplication()
{ {
parent::setUp(); return require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Prod.php';
$this->client = $this->createClient(); }
$this->purgeDatabase();
}
public function createApplication() public function testRootGet()
{ {
return require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Prod.php';
}
public function testRootGet() $this->insertOneWZ();
{
$this->insertOneWZ(); $route = "/WorkZone/";
$route = "/WorkZone/"; $this->client->request('GET', $route);
$this->client->request('GET', $route); $response = $this->client->getResponse();
$response = $this->client->getResponse(); $this->assertEquals(200, $response->getStatusCode());
}
$this->assertEquals(200, $response->getStatusCode()); public function testAttachStoryToWZ()
} {
$story = self::$story_1;
/* @var $story \Record_Adapter */
$route = sprintf("/WorkZone/attachStories/");
public function testAttachStoryToWZ() $this->client->request('POST', $route);
{ $response = $this->client->getResponse();
$story = self::$story_1;
/* @var $story \Record_Adapter */
$route = sprintf("/WorkZone/attachStories/");
$this->client->request('POST', $route); $this->assertEquals(400, $response->getStatusCode());
$response = $this->client->getResponse(); $this->assertFalse($response->isOk());
$this->assertEquals(400, $response->getStatusCode()); $this->client->request('POST', $route, array('stories' => array($story->get_serialize_key())));
$this->assertFalse($response->isOk()); $response = $this->client->getResponse();
$this->client->request('POST', $route, array('stories' => array($story->get_serialize_key()))); $this->assertEquals(302, $response->getStatusCode());
$response = $this->client->getResponse();
$this->assertEquals(302, $response->getStatusCode()); $em = self::$core->getEntityManager();
/* @var $em \Doctrine\ORM\EntityManager */
$em = self::$core->getEntityManager(); $query = $em->createQuery(
/* @var $em \Doctrine\ORM\EntityManager */
$query = $em->createQuery(
'SELECT COUNT(w.id) FROM \Entities\StoryWZ w' 'SELECT COUNT(w.id) FROM \Entities\StoryWZ w'
); );
$count = $query->getSingleScalarResult(); $count = $query->getSingleScalarResult();
$this->assertEquals(1, $count); $this->assertEquals(1, $count);
$story2 = self::$story_2; $story2 = self::$story_2;
$stories = array($story->get_serialize_key(), $story2->get_serialize_key()); $stories = array($story->get_serialize_key(), $story2->get_serialize_key());
$this->client->request('POST', $route, array('stories' => $stories)); $this->client->request('POST', $route, array('stories' => $stories));
$response = $this->client->getResponse(); $response = $this->client->getResponse();
$this->assertEquals(302, $response->getStatusCode()); $this->assertEquals(302, $response->getStatusCode());
$em = self::$core->getEntityManager(); $em = self::$core->getEntityManager();
/* @var $em \Doctrine\ORM\EntityManager */ /* @var $em \Doctrine\ORM\EntityManager */
$query = $em->createQuery( $query = $em->createQuery(
'SELECT COUNT(w.id) FROM \Entities\StoryWZ w' 'SELECT COUNT(w.id) FROM \Entities\StoryWZ w'
); );
$count = $query->getSingleScalarResult(); $count = $query->getSingleScalarResult();
$this->assertEquals(2, $count); $this->assertEquals(2, $count);
$query = $em->createQuery( $query = $em->createQuery(
'SELECT w FROM \Entities\StoryWZ w' 'SELECT w FROM \Entities\StoryWZ w'
); );
$storyWZ = $query->getResult(); $storyWZ = $query->getResult();
$em->remove(array_shift($storyWZ)); $em->remove(array_shift($storyWZ));
$em->flush(); $em->flush();
//attach JSON //attach JSON
$this->client->request('POST', $route, array('stories' => $story->get_serialize_key()), array(), array( $this->client->request('POST', $route, array('stories' => $story->get_serialize_key()), array(), array(
"HTTP_ACCEPT" => "application/json") "HTTP_ACCEPT" => "application/json")
); );
$response = $this->client->getResponse(); $response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
//test already attached //test already attached
$this->client->request('POST', $route, array('stories' => $story->get_serialize_key()), array(), array( $this->client->request('POST', $route, array('stories' => $story->get_serialize_key()), array(), array(
"HTTP_ACCEPT" => "application/json") "HTTP_ACCEPT" => "application/json")
); );
$response = $this->client->getResponse(); $response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
} }
public function testDetachStoryFromWZ() public function testDetachStoryFromWZ()
{ {
$story = self::$story_1; $story = self::$story_1;
$route = sprintf("/WorkZone/detachStory/%s/%s/", $story->get_sbas_id(), $story->get_record_id()); $route = sprintf("/WorkZone/detachStory/%s/%s/", $story->get_sbas_id(), $story->get_record_id());
//story not yet Attched //story not yet Attched
$this->client->request('POST', $route); $this->client->request('POST', $route);
$response = $this->client->getResponse(); $response = $this->client->getResponse();
$this->assertEquals(404, $response->getStatusCode()); $this->assertEquals(404, $response->getStatusCode());
$this->assertFalse($response->isOk()); $this->assertFalse($response->isOk());
//attach //attach
$attachRoute = sprintf("/WorkZone/attachStories/"); $attachRoute = sprintf("/WorkZone/attachStories/");
$this->client->request('POST', $attachRoute, array('stories' => array($story->get_serialize_key()))); $this->client->request('POST', $attachRoute, array('stories' => array($story->get_serialize_key())));
$query = self::$core->getEntityManager()->createQuery( $query = self::$core->getEntityManager()->createQuery(
'SELECT COUNT(w.id) FROM \Entities\StoryWZ w' 'SELECT COUNT(w.id) FROM \Entities\StoryWZ w'
); );
$count = $query->getSingleScalarResult(); $count = $query->getSingleScalarResult();
$this->assertEquals(1, $count); $this->assertEquals(1, $count);
//detach //detach
$this->client->request('POST', $route); $this->client->request('POST', $route);
$response = $this->client->getResponse(); $response = $this->client->getResponse();
$this->assertEquals(302, $response->getStatusCode()); $this->assertEquals(302, $response->getStatusCode());
$query = self::$core->getEntityManager()->createQuery( $query = self::$core->getEntityManager()->createQuery(
'SELECT COUNT(w.id) FROM \Entities\StoryWZ w' 'SELECT COUNT(w.id) FROM \Entities\StoryWZ w'
); );
$count = $query->getSingleScalarResult(); $count = $query->getSingleScalarResult();
$this->assertEquals(0, $count); $this->assertEquals(0, $count);
//attach //attach
$this->client->request('POST', $attachRoute, array('stories' => array($story->get_serialize_key()))); $this->client->request('POST', $attachRoute, array('stories' => array($story->get_serialize_key())));
//detach JSON //detach JSON
$this->client->request('POST', $route, array(), array(), array( $this->client->request('POST', $route, array(), array(), array(
"HTTP_ACCEPT" => "application/json") "HTTP_ACCEPT" => "application/json")
); );
$response = $this->client->getResponse(); $response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
} }
public function testBrowse() public function testBrowse()
{ {
$this->client->request("GET", "/WorkZone/Browse/"); $this->client->request("GET", "/WorkZone/Browse/");
$response = $this->client->getResponse(); $response = $this->client->getResponse();
$this->assertTrue($response->isOk()); $this->assertTrue($response->isOk());
} }
public function testBrowseSearch() public function testBrowseSearch()
{ {
$this->client->request("GET", "/WorkZone/Browse/Search/"); $this->client->request("GET", "/WorkZone/Browse/Search/");
$response = $this->client->getResponse(); $response = $this->client->getResponse();
$this->assertTrue($response->isOk()); $this->assertTrue($response->isOk());
} }
public function testBrowseBasket() public function testBrowseBasket()
{ {
$basket = $this->insertOneBasket(); $basket = $this->insertOneBasket();
$this->client->request("GET", "/WorkZone/Browse/Basket/" . $basket->getId() . "/"); $this->client->request("GET", "/WorkZone/Browse/Basket/" . $basket->getId() . "/");
$response = $this->client->getResponse(); $response = $this->client->getResponse();
$this->assertTrue($response->isOk()); $this->assertTrue($response->isOk());
} }
public function testDetachStoryFromWZNotFound() public function testDetachStoryFromWZNotFound()
{ {
$story = self::$story_1; $story = self::$story_1;
$route = sprintf("/WorkZone/detachStory/%s/%s/", $story->get_sbas_id(), 'unknow');
//story not yet Attched
}
$route = sprintf("/WorkZone/detachStory/%s/%s/", $story->get_sbas_id(), 'unknow');
//story not yet Attched
}
} }

File diff suppressed because it is too large Load Diff

View File

@@ -7,28 +7,25 @@ use Symfony\Component\HttpFoundation\Request;
use Alchemy\Phrasea\Controller\Setup as Controller; use Alchemy\Phrasea\Controller\Setup as Controller;
use Alchemy\Phrasea\Controller\Utils as ControllerUtils; use Alchemy\Phrasea\Controller\Utils as ControllerUtils;
return call_user_func(function() {
$app = new \Silex\Application();
return call_user_func(function() $app['Core'] = \bootstrap::getCore();
{
$app = new \Silex\Application();
$app['Core'] = \bootstrap::getCore(); $app['install'] = true;
$app['install'] = true; $app->get('/', function() use ($app) {
return $app->redirect('/setup/installer/');
});
$app->get('/', function() use ($app) $app->mount('/installer/', new Controller\Installer());
{ $app->mount('/test', new ControllerUtils\PathFileTest());
return $app->redirect('/setup/installer/'); $app->mount('/connection_test', new ControllerUtils\ConnectionTest());
$app->error(function($e) {
});
return $app;
}); });
$app->mount('/installer/', new Controller\Installer());
$app->mount('/test', new ControllerUtils\PathFileTest());
$app->mount('/connection_test', new ControllerUtils\ConnectionTest());
$app->error(function($e){
});
return $app;
});

View File

@@ -7,28 +7,26 @@ use Symfony\Component\HttpFoundation\Request;
use Alchemy\Phrasea\Controller\Setup as Controller; use Alchemy\Phrasea\Controller\Setup as Controller;
use Alchemy\Phrasea\Controller\Utils as ControllerUtils; use Alchemy\Phrasea\Controller\Utils as ControllerUtils;
return call_user_func(function() {
$app = new \Silex\Application();
return call_user_func(function() $app['Core'] = \bootstrap::getCore();
{
$app = new \Silex\Application();
$app['Core'] = \bootstrap::getCore(); $app['upgrade'] = true;
$app['upgrade'] = true; $app->get('/', function() use ($app) {
return $app->redirect('/setup/upgrader/');
});
$app->get('/', function() use ($app) $app->mount('/upgrader/', new Controller\Upgrader());
{ $app->mount('/test', new ControllerUtils\PathFileTest());
return $app->redirect('/setup/upgrader/'); $app->mount('/connection_test', new ControllerUtils\ConnectionTest());
$app->error(function($e) {
});
return $app;
}); });
$app->mount('/upgrader/', new Controller\Upgrader());
$app->mount('/test', new ControllerUtils\PathFileTest());
$app->mount('/connection_test', new ControllerUtils\ConnectionTest());
$app->error(function($e){
});
return $app;
});

View File

@@ -4,70 +4,69 @@ require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAbstract.class.inc';
class ControllerInstallerTest extends \PhraseanetWebTestCaseAbstract class ControllerInstallerTest extends \PhraseanetWebTestCaseAbstract
{ {
/**
* As controllers use WebTestCase, it requires a client
*/
protected $client;
/** /**
* As controllers use WebTestCase, it requires a client * If the controller tests require some records, specify it her
*/ *
protected $client; * For example, this will loacd 2 records
/** * (self::$record_1 and self::$record_2) :
* If the controller tests require some records, specify it her *
* * $need_records = 2;
* For example, this will loacd 2 records *
* (self::$record_1 and self::$record_2) : */
* protected static $need_records = false;
* $need_records = 2;
*
*/
protected static $need_records = false;
/** /**
* The application loader * The application loader
*/ */
public function createApplication() public function createApplication()
{ {
return require __DIR__ . '/FakeSetupApplication.inc'; return require __DIR__ . '/FakeSetupApplication.inc';
} }
public function setUp() public function setUp()
{ {
parent::setUp(); parent::setUp();
$this->client = $this->createClient(); $this->client = $this->createClient();
} }
/** /**
* Default route test * Default route test
*/ */
public function testRouteSlash() public function testRouteSlash()
{ {
$this->client->request('GET', '/'); $this->client->request('GET', '/');
$response = $this->client->getResponse(); $response = $this->client->getResponse();
/* @var $response \Symfony\Component\HttpFoundation\Response */ /* @var $response \Symfony\Component\HttpFoundation\Response */
$this->assertEquals(302, $response->getStatusCode()); $this->assertEquals(302, $response->getStatusCode());
$this->assertEquals('/setup/installer/', $response->headers->get('location')); $this->assertEquals('/setup/installer/', $response->headers->get('location'));
} }
public function testRouteInstaller() public function testRouteInstaller()
{ {
$this->client->request('GET', '/installer/'); $this->client->request('GET', '/installer/');
$response = $this->client->getResponse(); $response = $this->client->getResponse();
/* @var $response \Symfony\Component\HttpFoundation\Response */ /* @var $response \Symfony\Component\HttpFoundation\Response */
$this->assertEquals(302, $response->getStatusCode(), "test that response is a redirection " . $this->client->getResponse()->getContent()); $this->assertEquals(302, $response->getStatusCode(), "test that response is a redirection " . $this->client->getResponse()->getContent());
$this->assertEquals('/setup/installer/step2/', $response->headers->get('location')); $this->assertEquals('/setup/installer/step2/', $response->headers->get('location'));
} }
public function testRouteInstallerStep2() public function testRouteInstallerStep2()
{ {
$this->client->request('GET', '/installer/step2/'); $this->client->request('GET', '/installer/step2/');
$response = $this->client->getResponse(); $response = $this->client->getResponse();
/* @var $response \Symfony\Component\HttpFoundation\Response */ /* @var $response \Symfony\Component\HttpFoundation\Response */
$this->assertEquals(200, $response->getStatusCode());
$this->assertTrue($response->isOk());
}
$this->assertEquals(200, $response->getStatusCode());
$this->assertTrue($response->isOk());
}
} }

View File

@@ -4,85 +4,86 @@ require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAbstract.class.inc';
class ControllerUpgraderTest extends \PhraseanetWebTestCaseAbstract class ControllerUpgraderTest extends \PhraseanetWebTestCaseAbstract
{ {
/**
* As controllers use WebTestCase, it requires a client
*/
protected $client;
/** /**
* As controllers use WebTestCase, it requires a client * If the controller tests require some records, specify it her
*/ *
protected $client; * For example, this will loacd 2 records
/** * (self::$record_1 and self::$record_2) :
* If the controller tests require some records, specify it her *
* * $need_records = 2;
* For example, this will loacd 2 records *
* (self::$record_1 and self::$record_2) : */
* protected static $need_records = false;
* $need_records = 2;
*
*/
protected static $need_records = false;
/** /**
* The application loader * The application loader
*/ */
public function createApplication() public function createApplication()
{ {
return require __DIR__ . '/FakeUpgradeApplication.inc'; return require __DIR__ . '/FakeUpgradeApplication.inc';
} }
public function setUp() public function setUp()
{ {
parent::setUp(); parent::setUp();
$this->client = $this->createClient(); $this->client = $this->createClient();
} }
/** /**
* Default route test * Default route test
*/ */
public function testRouteSlash() public function testRouteSlash()
{ {
$this->client->request('GET', '/'); $this->client->request('GET', '/');
$response = $this->client->getResponse(); $response = $this->client->getResponse();
/* @var $response \Symfony\Component\HttpFoundation\Response */ /* @var $response \Symfony\Component\HttpFoundation\Response */
$this->assertEquals(302, $response->getStatusCode()); $this->assertEquals(302, $response->getStatusCode());
$this->assertEquals('/setup/upgrader/', $response->headers->get('location')); $this->assertEquals('/setup/upgrader/', $response->headers->get('location'));
} }
/** /**
* Default route test * Default route test
*/ */
public function testRouteUpgrader() public function testRouteUpgrader()
{ {
$this->client->request('GET', '/upgrader/'); $this->client->request('GET', '/upgrader/');
$response = $this->client->getResponse(); $response = $this->client->getResponse();
/* @var $response \Symfony\Component\HttpFoundation\Response */ /* @var $response \Symfony\Component\HttpFoundation\Response */
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
} }
/**
* Default route test
*/
public function testRouteStatus()
{
$this->client->request('GET', '/upgrader/status/');
$response = $this->client->getResponse(); /**
/* @var $response \Symfony\Component\HttpFoundation\Response */ * Default route test
*/
public function testRouteStatus()
{
$this->client->request('GET', '/upgrader/status/');
$this->assertEquals(200, $response->getStatusCode()); $response = $this->client->getResponse();
} /* @var $response \Symfony\Component\HttpFoundation\Response */
/**
* Default route test
*/
public function testRouteExecute()
{
$this->client->request('POST', '/upgrader/execute/');
$response = $this->client->getResponse(); $this->assertEquals(200, $response->getStatusCode());
/* @var $response \Symfony\Component\HttpFoundation\Response */ }
$this->assertEquals(302, $response->getStatusCode());
$this->assertEquals('/', $response->headers->get('location'));
}
/**
* Default route test
*/
public function testRouteExecute()
{
$this->client->request('POST', '/upgrader/execute/');
$response = $this->client->getResponse();
/* @var $response \Symfony\Component\HttpFoundation\Response */
$this->assertEquals(302, $response->getStatusCode());
$this->assertEquals('/', $response->headers->get('location'));
}
} }

View File

@@ -4,120 +4,118 @@ require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAbstract.class.inc';
class ControllerConnectionTestTest extends \PhraseanetWebTestCaseAbstract class ControllerConnectionTestTest extends \PhraseanetWebTestCaseAbstract
{ {
/**
* As controllers use WebTestCase, it requires a client
*/
protected $client;
/** /**
* As controllers use WebTestCase, it requires a client * If the controller tests require some records, specify it her
*/ *
protected $client; * For example, this will loacd 2 records
* (self::$record_1 and self::$record_2) :
*
* $need_records = 2;
*
*/
protected static $need_records = false;
/** /**
* If the controller tests require some records, specify it her * The application loader
* */
* For example, this will loacd 2 records public function createApplication()
* (self::$record_1 and self::$record_2) : {
* return require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Admin.php';
* $need_records = 2; }
*
*/
protected static $need_records = false;
/** public function setUp()
* The application loader {
*/ parent::setUp();
public function createApplication() $this->client = $this->createClient();
{ }
return require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Admin.php';
}
public function setUp() /**
{ * Default route test
parent::setUp(); */
$this->client = $this->createClient(); public function testRouteMysql()
} {
$configuration = \Alchemy\Phrasea\Core\Configuration::build();
/** $chooseConnexion = $configuration->getPhraseanet()->get('database');
* Default route test
*/
public function testRouteMysql()
{
$configuration = \Alchemy\Phrasea\Core\Configuration::build();
$chooseConnexion = $configuration->getPhraseanet()->get('database'); $connexion = $configuration->getConnexion($chooseConnexion);
$connexion = $configuration->getConnexion($chooseConnexion); $params = array(
"hostname" => $connexion->get('host'),
"port" => $connexion->get('port'),
"user" => $connexion->get('user'),
"password" => $connexion->get('password'),
"dbname" => $connexion->get('dbname')
);
$params = array( $this->client->request("GET", "/tests/connection/mysql/", $params);
"hostname" => $connexion->get('host'), $response = $this->client->getResponse();
"port" => $connexion->get('port'), $this->assertTrue($response->isOk());
"user" => $connexion->get('user'), }
"password" => $connexion->get('password'),
"dbname" => $connexion->get('dbname')
);
$this->client->request("GET", "/tests/connection/mysql/", $params); public function testRouteMysqlFailed()
$response = $this->client->getResponse(); {
$this->assertTrue($response->isOk()); $configuration = \Alchemy\Phrasea\Core\Configuration::build();
}
public function testRouteMysqlFailed() $chooseConnexion = $configuration->getPhraseanet()->get('database');
{
$configuration = \Alchemy\Phrasea\Core\Configuration::build();
$chooseConnexion = $configuration->getPhraseanet()->get('database'); $connexion = $configuration->getConnexion($chooseConnexion);
$connexion = $configuration->getConnexion($chooseConnexion); $params = array(
"hostname" => $connexion->get('host'),
"port" => $connexion->get('port'),
"user" => $connexion->get('user'),
"password" => "fakepassword",
"dbname" => $connexion->get('dbname')
);
$params = array( $this->client->request("GET", "/tests/connection/mysql/", $params);
"hostname" => $connexion->get('host'), $response = $this->client->getResponse();
"port" => $connexion->get('port'), $content = json_decode($this->client->getResponse()->getContent());
"user" => $connexion->get('user'), $this->assertEquals("application/json", $this->client->getResponse()->headers->get("content-type"));
"password" => "fakepassword", $this->assertTrue($response->isOk());
"dbname" => $connexion->get('dbname') $this->assertTrue(is_object($content));
); $this->assertObjectHasAttribute('connection', $content);
$this->assertObjectHasAttribute('database', $content);
$this->client->request("GET", "/tests/connection/mysql/", $params); $this->assertObjectHasAttribute('is_empty', $content);
$response = $this->client->getResponse(); $this->assertObjectHasAttribute('is_appbox', $content);
$content = json_decode($this->client->getResponse()->getContent()); $this->assertObjectHasAttribute('is_databox', $content);
$this->assertEquals("application/json", $this->client->getResponse()->headers->get("content-type")); $this->assertFalse($content->connection);
$this->assertTrue($response->isOk()); }
$this->assertTrue(is_object($content));
$this->assertObjectHasAttribute('connection', $content);
$this->assertObjectHasAttribute('database', $content);
$this->assertObjectHasAttribute('is_empty', $content);
$this->assertObjectHasAttribute('is_appbox', $content);
$this->assertObjectHasAttribute('is_databox', $content);
$this->assertFalse($content->connection);
}
public function testRouteMysqlDbFailed() public function testRouteMysqlDbFailed()
{ {
$configuration = \Alchemy\Phrasea\Core\Configuration::build(); $configuration = \Alchemy\Phrasea\Core\Configuration::build();
$chooseConnexion = $configuration->getPhraseanet()->get('database'); $chooseConnexion = $configuration->getPhraseanet()->get('database');
$connexion = $configuration->getConnexion($chooseConnexion); $connexion = $configuration->getConnexion($chooseConnexion);
$params = array( $params = array(
"hostname" => $connexion->get('host'), "hostname" => $connexion->get('host'),
"port" => $connexion->get('port'), "port" => $connexion->get('port'),
"user" => $connexion->get('user'), "user" => $connexion->get('user'),
"password" => $connexion->get('password'), "password" => $connexion->get('password'),
"dbname" => "fake-DTABASE-name" "dbname" => "fake-DTABASE-name"
); );
$this->client->request("GET", "/tests/connection/mysql/", $params);
$response = $this->client->getResponse();
$content = json_decode($this->client->getResponse()->getContent());
$this->assertEquals("application/json", $this->client->getResponse()->headers->get("content-type"));
$this->assertTrue($response->isOk());
$this->assertTrue(is_object($content));
$this->assertObjectHasAttribute('connection', $content);
$this->assertObjectHasAttribute('database', $content);
$this->assertObjectHasAttribute('is_empty', $content);
$this->assertObjectHasAttribute('is_appbox', $content);
$this->assertObjectHasAttribute('is_databox', $content);
$this->assertFalse($content->database);
}
$this->client->request("GET", "/tests/connection/mysql/", $params);
$response = $this->client->getResponse();
$content = json_decode($this->client->getResponse()->getContent());
$this->assertEquals("application/json", $this->client->getResponse()->headers->get("content-type"));
$this->assertTrue($response->isOk());
$this->assertTrue(is_object($content));
$this->assertObjectHasAttribute('connection', $content);
$this->assertObjectHasAttribute('database', $content);
$this->assertObjectHasAttribute('is_empty', $content);
$this->assertObjectHasAttribute('is_appbox', $content);
$this->assertObjectHasAttribute('is_databox', $content);
$this->assertFalse($content->database);
}
} }

View File

@@ -4,66 +4,64 @@ require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAbstract.class.inc';
class ControllerPathFileTestTest extends \PhraseanetWebTestCaseAbstract class ControllerPathFileTestTest extends \PhraseanetWebTestCaseAbstract
{ {
/**
* As controllers use WebTestCase, it requires a client
*/
protected $client;
/** /**
* As controllers use WebTestCase, it requires a client * If the controller tests require some records, specify it her
*/ *
protected $client; * For example, this will loacd 2 records
* (self::$record_1 and self::$record_2) :
*
* $need_records = 2;
*
*/
protected static $need_records = false;
/** /**
* If the controller tests require some records, specify it her * The application loader
* */
* For example, this will loacd 2 records public function createApplication()
* (self::$record_1 and self::$record_2) : {
* return require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Admin.php';
* $need_records = 2; }
*
*/
protected static $need_records = false;
/** public function setUp()
* The application loader {
*/ parent::setUp();
public function createApplication() $this->client = $this->createClient();
{ }
return require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Admin.php';
}
public function setUp() /**
{ * Default route test
parent::setUp(); */
$this->client = $this->createClient(); public function testRoutePath()
} {
$file = new \SplFileObject(__DIR__ . '/../../../../testfiles/cestlafete.jpg');
$this->client->request("GET", "/tests/pathurl/path/", array('path' => $file->getPathname()));
/** $response = $this->client->getResponse();
* Default route test $this->assertTrue($response->isOk());
*/ $this->assertEquals("application/json", $this->client->getResponse()->headers->get("content-type"));
public function testRoutePath() $content = json_decode($this->client->getResponse()->getContent());
{ $this->assertTrue(is_object($content));
$file = new \SplFileObject(__DIR__ . '/../../../../testfiles/cestlafete.jpg'); $this->assertObjectHasAttribute('exists', $content);
$this->client->request("GET", "/tests/pathurl/path/", array('path' => $file->getPathname())); $this->assertObjectHasAttribute('file', $content);
$this->assertObjectHasAttribute('dir', $content);
$this->assertObjectHasAttribute('readable', $content);
$this->assertObjectHasAttribute('executable', $content);
}
$response = $this->client->getResponse(); public function testRouteUrl()
$this->assertTrue($response->isOk()); {
$this->assertEquals("application/json", $this->client->getResponse()->headers->get("content-type")); $this->client->request("GET", "/tests/pathurl/url/", array('url' => "www.google.com"));
$content = json_decode($this->client->getResponse()->getContent());
$this->assertTrue(is_object($content));
$this->assertObjectHasAttribute('exists', $content);
$this->assertObjectHasAttribute('file', $content);
$this->assertObjectHasAttribute('dir', $content);
$this->assertObjectHasAttribute('readable', $content);
$this->assertObjectHasAttribute('executable', $content);
}
public function testRouteUrl()
{
$this->client->request("GET", "/tests/pathurl/url/", array('url' => "www.google.com"));
$response = $this->client->getResponse();
$this->assertTrue($response->isOk());
$this->assertEquals("application/json", $this->client->getResponse()->headers->get("content-type"));
$content = json_decode($this->client->getResponse()->getContent());
$this->assertTrue(is_object($content));
}
$response = $this->client->getResponse();
$this->assertTrue($response->isOk());
$this->assertEquals("application/json", $this->client->getResponse()->headers->get("content-type"));
$content = json_decode($this->client->getResponse()->getContent());
$this->assertTrue(is_object($content));
}
} }

View File

@@ -1,500 +1,453 @@
<?php <?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__ . '/../../../../PhraseanetPHPUnitAbstract.class.inc'; require_once __DIR__ . '/../../../../PhraseanetPHPUnitAbstract.class.inc';
use Alchemy\Phrasea\Core as PhraseaCore; use Alchemy\Phrasea\Core as PhraseaCore;
use Alchemy\Phrasea\Core\Configuration; use Alchemy\Phrasea\Core\Configuration;
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class ConfigurationTest extends \PhraseanetPHPUnitAbstract class ConfigurationTest extends \PhraseanetPHPUnitAbstract
{ {
/**
*
* @var \Alchemy\Phrasea\Core\Configuration
*/
protected $confProd;
/** /**
* *
* @var \Alchemy\Phrasea\Core\Configuration * @var \Alchemy\Phrasea\Core\Configuration
*/ */
protected $confProd; protected $confDev;
/** /**
* *
* @var \Alchemy\Phrasea\Core\Configuration * @var \Alchemy\Phrasea\Core\Configuration
*/ */
protected $confDev; protected $confTest;
/** /**
* *
* @var \Alchemy\Phrasea\Core\Configuration * @var \Alchemy\Phrasea\Core\Configuration
*/ */
protected $confTest; protected $confNotInstalled;
/** /**
* *
* @var \Alchemy\Phrasea\Core\Configuration * @var \Alchemy\Phrasea\Core\Configuration
*/ */
protected $confNotInstalled; protected $confExperience;
/** /**
* *
* @var \Alchemy\Phrasea\Core\Configuration * @var \Alchemy\Phrasea\Core\Configuration
*/ */
protected $confExperience; protected $object;
/** public function setUp()
*
* @var \Alchemy\Phrasea\Core\Configuration
*/
protected $object;
public function setUp()
{
$this->markTestSkipped('To rewrite');
parent::setUp();
$specNotInstalled = $this->getMock(
'\Alchemy\Phrasea\Core\Configuration\Application'
, array('getConfigurationsFile')
);
$specNotInstalled->expects($this->any())
->method('getConfigurationsFile')
->will(
$this->throwException(new Exception)
);
$specExperience = $this->getMock(
'\Alchemy\Phrasea\Core\Configuration\Application'
, array('getConfigurationsFile')
);
$specExperience->expects($this->any())
->method('getConfigurationsFile')
->will(
$this->returnValue(
new \SplFileObject(__DIR__ . '/confTestFiles/config.yml')
)
);
$handler = new Configuration\Handler($specNotInstalled);
$this->confNotInstalled = new PhraseaCore\Configuration($handler);
$handler = new Configuration\Handler($specExperience);
$this->object = new PhraseaCore\Configuration($handler);
}
public function testGetEnvironment()
{
$this->assertEquals("dev", $this->object->getEnvironnement());
$this->assertEquals(null, $this->confNotInstalled->getEnvironnement());
}
public function testSetEnvironment()
{
$this->object->setEnvironnement("test");
$this->assertEquals("test", $this->object->getEnvironnement());
$this->confNotInstalled->setEnvironnement("prod");
$this->assertEquals("prod", $this->confNotInstalled->getEnvironnement());
try
{
$this->object->setEnvironnement("unknow");
$this->fail("should raise exception");
}
catch (\Exception $e)
{ {
$this->markTestSkipped('To rewrite');
parent::setUp();
} $specNotInstalled = $this->getMock(
} '\Alchemy\Phrasea\Core\Configuration\Application'
, array('getConfigurationsFile')
);
public function testIsDebug() $specNotInstalled->expects($this->any())
{ ->method('getConfigurationsFile')
$this->object->setEnvironnement("test"); ->will(
$this->assertTrue($this->object->isDebug()); $this->throwException(new Exception)
$this->object->setEnvironnement("dev"); );
$this->assertTrue($this->object->isDebug());
$this->object->setEnvironnement("prod");
$this->assertFalse($this->object->isDebug());
$this->object->setEnvironnement("no_debug");
$this->assertFalse($this->object->isDebug());
}
public function testIsMaintened() $specExperience = $this->getMock(
{ '\Alchemy\Phrasea\Core\Configuration\Application'
$this->object->setEnvironnement("test"); , array('getConfigurationsFile')
$this->assertFalse($this->object->isMaintained()); );
$this->object->setEnvironnement("dev");
$this->assertFalse($this->object->isMaintained());
$this->object->setEnvironnement("prod");
$this->assertFalse($this->object->isMaintained());
$this->object->setEnvironnement("no_maintenance");
$this->assertFalse($this->object->isMaintained());
}
public function testIsDisplayingErrors() $specExperience->expects($this->any())
{ ->method('getConfigurationsFile')
$this->object->setEnvironnement("test"); ->will(
$this->assertTrue($this->object->isDisplayingErrors()); $this->returnValue(
$this->object->setEnvironnement("dev"); new \SplFileObject(__DIR__ . '/confTestFiles/config.yml')
$this->assertTrue($this->object->isDisplayingErrors()); )
$this->object->setEnvironnement("prod"); );
$this->assertFalse($this->object->isDisplayingErrors());
$this->object->setEnvironnement("no_display_errors");
$this->assertFalse($this->object->isDisplayingErrors());
}
public function testGetPhraseanet() $handler = new Configuration\Handler($specNotInstalled);
{ $this->confNotInstalled = new PhraseaCore\Configuration($handler);
$this->object->setEnvironnement("test");
$this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag", $this->object->getPhraseanet());
$this->object->setEnvironnement("dev");
$this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag", $this->object->getPhraseanet());
$this->object->setEnvironnement("prod");
$this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag", $this->object->getPhraseanet());
$this->object->setEnvironnement("missing_phraseanet");
try
{
$this->object->getPhraseanet();
$this->fail("should raise an exeception");
}
catch (\Exception $e)
{
}
}
public function testisInstalled()
{
$this->assertFalse($this->confNotInstalled->isInstalled());
$this->assertTrue($this->object->isInstalled());
}
public function testGetConfiguration()
{
$config = $this->object->getConfiguration();
$this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag", $config);
$this->assertNotEmpty($config->all());
$config = $this->confNotInstalled->getConfiguration();
$this->assertEmpty($config->all());
}
public function testGetConnexions()
{
$connexions = $this->object->getConnexions();
$this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag", $connexions);
$this->assertGreaterThan(0, sizeof($connexions->all()));
}
public function testGetConnexion()
{
$connexion = $this->object->getConnexion();
$this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag", $connexion);
$this->assertGreaterThan(0, sizeof($connexion->all()));
}
public function testGetConnexionException()
{
try
{
$this->object->getConnexion('unknow_connexion');
$this->fail('should raise an exception');
}
catch (\Exception $e)
{
}
}
public function testGetFile()
{
$this->assertInstanceOf("\SplFileObject", $this->object->getFile());
}
public function testGetFileExeption()
{
try
{
$this->assertInstanceOf("\SplFileObject", $this->confNotInstalled->getFile());
$this->fail("should raise an excpetion");
}
catch (\Exception $e)
{
}
}
public function testAll()
{
$all = $this->object->all();
$this->assertTrue(is_array($all));
$this->assertArrayHasKey("test", $all);
$this->assertArrayHasKey("dev", $all);
$this->assertArrayHasKey("prod", $all);
$this->assertArrayHasKey("environment", $all);
}
public function testGetServices()
{
$services = $this->object->getServices();
$this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag", $services);
$this->assertGreaterThan(0, sizeof($services->all()));
}
public function testGetService()
{
$services = $this->object->getService('TemplateEngine\Twig');
$this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag", $services);
$this->assertGreaterThan(0, sizeof($services->all()));
}
public function testGetServiceException()
{
try
{
$this->object->getService('unknow_service');
$this->fail('should raise an exception');
}
catch (\Exception $e)
{
}
}
public function testWrite()
{
touch(__DIR__ . "/confTestFiles/yamlWriteTest.yml");
$stub = $this->getMock(
'\Alchemy\Phrasea\Core\Configuration\Application'
, array('getConfigurationPathName')
);
$file = new \SplFileObject(__DIR__ . "/confTestFiles/yamlWriteTest.yml");
$stub->expects($this->any())
->method('getConfigurationPathName')
->will(
$this->returnValue($file->getPathname())
);
$handler = new Configuration\Handler($stub);
$configuration = new PhraseaCore\Configuration($handler);
$arrayToBeWritten = array(
'hello' => 'world'
, 'key' => array(
'keyone' => 'valueone'
, 'keytwo' => 'valuetwo'
)
);
$configuration->write($arrayToBeWritten, 0, true);
$all = $configuration->all();
$this->assertArrayHasKey("hello", $all);
$this->assertArrayHasKey("key", $all);
$this->assertTrue(is_array($all["key"]));
}
public function testWriteException()
{
touch(__DIR__ . "/confTestFiles/yamlWriteTest.yml");
$stub = $this->getMock(
'\Alchemy\Phrasea\Core\Configuration\Application'
, array('getConfigurationPathName')
);
$file = new \SplFileObject(__DIR__ . "/confTestFiles/yamlWriteTest.yml");
$stub->expects($this->any())
->method('getConfigurationPathName')
->will(
$this->returnValue("unknow_path")
);
$handler = new Configuration\Handler($stub);
$configuration = new PhraseaCore\Configuration($handler);
$arrayToBeWritten = array(
'hello' => 'world'
, 'key' => array(
'keyone' => 'valueone'
, 'keytwo' => 'valuetwo'
)
);
try
{
$configuration->write($arrayToBeWritten);
$this->fail("should raise an exception");
}
catch (\exception $e)
{
}
}
public function testDelete()
{
touch(__DIR__ . "/confTestFiles/yamlWriteTest.yml");
$stub = $this->getMock(
'\Alchemy\Phrasea\Core\Configuration\Application'
, array('getConfigurationPathName')
);
$file = new \SplFileObject(__DIR__ . "/confTestFiles/yamlWriteTest.yml");
$stub->expects($this->any())
->method('getConfigurationPathName')
->will(
$this->returnValue($file->getPathname())
);
$handler = new Configuration\Handler($stub);
$configuration = new PhraseaCore\Configuration($handler);
$configuration->delete();
$this->assertFileNotExists($file->getPathname());
}
public function testDeleteException()
{
touch(__DIR__ . "/confTestFiles/yamlWriteTest.yml");
$stub = $this->getMock(
'\Alchemy\Phrasea\Core\Configuration\Application'
, array('getConfigurationPathName')
);
$file = new \SplFileObject(__DIR__ . "/confTestFiles/yamlWriteTest.yml");
$stub->expects($this->any())
->method('getConfigurationPathName')
->will(
$this->returnValue("unknow_path")
);
$handler = new Configuration\Handler($stub);
$configuration = new PhraseaCore\Configuration($handler);
try
{
$configuration->delete();
$this->fail("should raise an exception");
}
catch (\Exception $e)
{
$handler = new Configuration\Handler($specExperience);
$this->object = new PhraseaCore\Configuration($handler);
} }
$this->assertFileExists($file->getPathname()); public function testGetEnvironment()
unlink(__DIR__ . "/confTestFiles/yamlWriteTest.yml");
}
public function testGetTemplating()
{
try
{ {
$templating = $this->object->getTemplating(); $this->assertEquals("dev", $this->object->getEnvironnement());
} $this->assertEquals(null, $this->confNotInstalled->getEnvironnement());
catch (\Exception $e)
{
$this->fail("not template_engine provided");
}
$this->assertTrue(is_string($templating));
}
public function testGetOrm()
{
try
{
$orm = $this->object->getOrm();
}
catch (\Exception $e)
{
$this->fail("not template_engine provided");
}
$this->assertTrue(is_string($orm));
}
public function testGetServiceFile()
{
$this->assertInstanceOf("\SplFileObject", $this->object->getServiceFile());
}
public function testGetConnexionFile()
{
$this->assertInstanceOf("\SplFileObject", $this->object->getConnexionFile());
}
public function testRefresh()
{
$this->confNotInstalled->refresh();
$this->assertFalse($this->confNotInstalled->isInstalled());
$this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag", $this->confNotInstalled->getConfiguration());
touch(__DIR__ . "/confTestFiles/yamlWriteTest.yml");
$stub = $this->getMock(
'\Alchemy\Phrasea\Core\Configuration\Application'
, array('getConfigurationPathName')
);
$file = new \SplFileObject(__DIR__ . "/confTestFiles/yamlWriteTest.yml");
$stub->expects($this->any())
->method('getConfigurationPathName')
->will(
$this->returnValue($file->getPathname())
);
$handler = new Configuration\Handler($stub);
$configuration = new PhraseaCore\Configuration($handler);
$newScope = array("prod" => array('key' => 'value', 'key2' => 'value2'));
//append new conf
$configuration->write($newScope, FILE_APPEND);
try
{
$configuration->getConfiguration(); //it is not loaded
$this->fail("should raise an exception");
}
catch (\Exception $e)
{
} }
$configuration->refresh(); //reload conf public function testSetEnvironment()
$prod = $configuration->getConfiguration(); {
$this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag", $prod); $this->object->setEnvironnement("test");
$this->assertEquals("test", $this->object->getEnvironnement());
$this->confNotInstalled->setEnvironnement("prod");
$this->assertEquals("prod", $this->confNotInstalled->getEnvironnement());
unlink(__DIR__ . "/confTestFiles/yamlWriteTest.yml"); try {
} $this->object->setEnvironnement("unknow");
$this->fail("should raise exception");
} catch (\Exception $e) {
}
}
public function testIsDebug()
{
$this->object->setEnvironnement("test");
$this->assertTrue($this->object->isDebug());
$this->object->setEnvironnement("dev");
$this->assertTrue($this->object->isDebug());
$this->object->setEnvironnement("prod");
$this->assertFalse($this->object->isDebug());
$this->object->setEnvironnement("no_debug");
$this->assertFalse($this->object->isDebug());
}
public function testIsMaintened()
{
$this->object->setEnvironnement("test");
$this->assertFalse($this->object->isMaintained());
$this->object->setEnvironnement("dev");
$this->assertFalse($this->object->isMaintained());
$this->object->setEnvironnement("prod");
$this->assertFalse($this->object->isMaintained());
$this->object->setEnvironnement("no_maintenance");
$this->assertFalse($this->object->isMaintained());
}
public function testIsDisplayingErrors()
{
$this->object->setEnvironnement("test");
$this->assertTrue($this->object->isDisplayingErrors());
$this->object->setEnvironnement("dev");
$this->assertTrue($this->object->isDisplayingErrors());
$this->object->setEnvironnement("prod");
$this->assertFalse($this->object->isDisplayingErrors());
$this->object->setEnvironnement("no_display_errors");
$this->assertFalse($this->object->isDisplayingErrors());
}
public function testGetPhraseanet()
{
$this->object->setEnvironnement("test");
$this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag", $this->object->getPhraseanet());
$this->object->setEnvironnement("dev");
$this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag", $this->object->getPhraseanet());
$this->object->setEnvironnement("prod");
$this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag", $this->object->getPhraseanet());
$this->object->setEnvironnement("missing_phraseanet");
try {
$this->object->getPhraseanet();
$this->fail("should raise an exeception");
} catch (\Exception $e) {
}
}
public function testisInstalled()
{
$this->assertFalse($this->confNotInstalled->isInstalled());
$this->assertTrue($this->object->isInstalled());
}
public function testGetConfiguration()
{
$config = $this->object->getConfiguration();
$this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag", $config);
$this->assertNotEmpty($config->all());
$config = $this->confNotInstalled->getConfiguration();
$this->assertEmpty($config->all());
}
public function testGetConnexions()
{
$connexions = $this->object->getConnexions();
$this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag", $connexions);
$this->assertGreaterThan(0, sizeof($connexions->all()));
}
public function testGetConnexion()
{
$connexion = $this->object->getConnexion();
$this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag", $connexion);
$this->assertGreaterThan(0, sizeof($connexion->all()));
}
public function testGetConnexionException()
{
try {
$this->object->getConnexion('unknow_connexion');
$this->fail('should raise an exception');
} catch (\Exception $e) {
}
}
public function testGetFile()
{
$this->assertInstanceOf("\SplFileObject", $this->object->getFile());
}
public function testGetFileExeption()
{
try {
$this->assertInstanceOf("\SplFileObject", $this->confNotInstalled->getFile());
$this->fail("should raise an excpetion");
} catch (\Exception $e) {
}
}
public function testAll()
{
$all = $this->object->all();
$this->assertTrue(is_array($all));
$this->assertArrayHasKey("test", $all);
$this->assertArrayHasKey("dev", $all);
$this->assertArrayHasKey("prod", $all);
$this->assertArrayHasKey("environment", $all);
}
public function testGetServices()
{
$services = $this->object->getServices();
$this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag", $services);
$this->assertGreaterThan(0, sizeof($services->all()));
}
public function testGetService()
{
$services = $this->object->getService('TemplateEngine\Twig');
$this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag", $services);
$this->assertGreaterThan(0, sizeof($services->all()));
}
public function testGetServiceException()
{
try {
$this->object->getService('unknow_service');
$this->fail('should raise an exception');
} catch (\Exception $e) {
}
}
public function testWrite()
{
touch(__DIR__ . "/confTestFiles/yamlWriteTest.yml");
$stub = $this->getMock(
'\Alchemy\Phrasea\Core\Configuration\Application'
, array('getConfigurationPathName')
);
$file = new \SplFileObject(__DIR__ . "/confTestFiles/yamlWriteTest.yml");
$stub->expects($this->any())
->method('getConfigurationPathName')
->will(
$this->returnValue($file->getPathname())
);
$handler = new Configuration\Handler($stub);
$configuration = new PhraseaCore\Configuration($handler);
$arrayToBeWritten = array(
'hello' => 'world'
, 'key' => array(
'keyone' => 'valueone'
, 'keytwo' => 'valuetwo'
)
);
$configuration->write($arrayToBeWritten, 0, true);
$all = $configuration->all();
$this->assertArrayHasKey("hello", $all);
$this->assertArrayHasKey("key", $all);
$this->assertTrue(is_array($all["key"]));
}
public function testWriteException()
{
touch(__DIR__ . "/confTestFiles/yamlWriteTest.yml");
$stub = $this->getMock(
'\Alchemy\Phrasea\Core\Configuration\Application'
, array('getConfigurationPathName')
);
$file = new \SplFileObject(__DIR__ . "/confTestFiles/yamlWriteTest.yml");
$stub->expects($this->any())
->method('getConfigurationPathName')
->will(
$this->returnValue("unknow_path")
);
$handler = new Configuration\Handler($stub);
$configuration = new PhraseaCore\Configuration($handler);
$arrayToBeWritten = array(
'hello' => 'world'
, 'key' => array(
'keyone' => 'valueone'
, 'keytwo' => 'valuetwo'
)
);
try {
$configuration->write($arrayToBeWritten);
$this->fail("should raise an exception");
} catch (\exception $e) {
}
}
public function testDelete()
{
touch(__DIR__ . "/confTestFiles/yamlWriteTest.yml");
$stub = $this->getMock(
'\Alchemy\Phrasea\Core\Configuration\Application'
, array('getConfigurationPathName')
);
$file = new \SplFileObject(__DIR__ . "/confTestFiles/yamlWriteTest.yml");
$stub->expects($this->any())
->method('getConfigurationPathName')
->will(
$this->returnValue($file->getPathname())
);
$handler = new Configuration\Handler($stub);
$configuration = new PhraseaCore\Configuration($handler);
$configuration->delete();
$this->assertFileNotExists($file->getPathname());
}
public function testDeleteException()
{
touch(__DIR__ . "/confTestFiles/yamlWriteTest.yml");
$stub = $this->getMock(
'\Alchemy\Phrasea\Core\Configuration\Application'
, array('getConfigurationPathName')
);
$file = new \SplFileObject(__DIR__ . "/confTestFiles/yamlWriteTest.yml");
$stub->expects($this->any())
->method('getConfigurationPathName')
->will(
$this->returnValue("unknow_path")
);
$handler = new Configuration\Handler($stub);
$configuration = new PhraseaCore\Configuration($handler);
try {
$configuration->delete();
$this->fail("should raise an exception");
} catch (\Exception $e) {
}
$this->assertFileExists($file->getPathname());
unlink(__DIR__ . "/confTestFiles/yamlWriteTest.yml");
}
public function testGetTemplating()
{
try {
$templating = $this->object->getTemplating();
} catch (\Exception $e) {
$this->fail("not template_engine provided");
}
$this->assertTrue(is_string($templating));
}
public function testGetOrm()
{
try {
$orm = $this->object->getOrm();
} catch (\Exception $e) {
$this->fail("not template_engine provided");
}
$this->assertTrue(is_string($orm));
}
public function testGetServiceFile()
{
$this->assertInstanceOf("\SplFileObject", $this->object->getServiceFile());
}
public function testGetConnexionFile()
{
$this->assertInstanceOf("\SplFileObject", $this->object->getConnexionFile());
}
public function testRefresh()
{
$this->confNotInstalled->refresh();
$this->assertFalse($this->confNotInstalled->isInstalled());
$this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag", $this->confNotInstalled->getConfiguration());
touch(__DIR__ . "/confTestFiles/yamlWriteTest.yml");
$stub = $this->getMock(
'\Alchemy\Phrasea\Core\Configuration\Application'
, array('getConfigurationPathName')
);
$file = new \SplFileObject(__DIR__ . "/confTestFiles/yamlWriteTest.yml");
$stub->expects($this->any())
->method('getConfigurationPathName')
->will(
$this->returnValue($file->getPathname())
);
$handler = new Configuration\Handler($stub);
$configuration = new PhraseaCore\Configuration($handler);
$newScope = array("prod" => array('key' => 'value', 'key2' => 'value2'));
//append new conf
$configuration->write($newScope, FILE_APPEND);
try {
$configuration->getConfiguration(); //it is not loaded
$this->fail("should raise an exception");
} catch (\Exception $e) {
}
$configuration->refresh(); //reload conf
$prod = $configuration->getConfiguration();
$this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag", $prod);
unlink(__DIR__ . "/confTestFiles/yamlWriteTest.yml");
}
} }

View File

@@ -1,74 +1,49 @@
<?php <?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__ . '/../../../../../PhraseanetPHPUnitAbstract.class.inc'; require_once __DIR__ . '/../../../../../PhraseanetPHPUnitAbstract.class.inc';
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class ServiceApcCacheTest extends PhraseanetPHPUnitAbstract class ServiceApcCacheTest extends PhraseanetPHPUnitAbstract
{ {
public function testService() public function testService()
{
$cache = new \Alchemy\Phrasea\Core\Service\Cache\ApcCache(
self::$core, array()
);
if (extension_loaded('apc'))
{ {
$service = $cache->getDriver(); $cache = new \Alchemy\Phrasea\Core\Service\Cache\ApcCache(
$this->assertTrue($service instanceof \Doctrine\Common\Cache\CacheProvider); self::$core, array()
);
if (extension_loaded('apc')) {
$service = $cache->getDriver();
$this->assertTrue($service instanceof \Doctrine\Common\Cache\CacheProvider);
} else {
try {
$cache->getDriver();
$this->fail("should raise an exception");
} catch (\Exception $e) {
}
}
} }
else
public function testServiceException()
{ {
try $cache = new \Alchemy\Phrasea\Core\Service\Cache\ApcCache(
{ self::$core, array()
$cache->getDriver(); );
$this->fail("should raise an exception");
}
catch (\Exception $e)
{
} try {
$cache->getDriver();
$this->fail("should raise an exception");
} catch (\Exception $e) {
}
} }
}
public function testServiceException() public function testType()
{
$cache = new \Alchemy\Phrasea\Core\Service\Cache\ApcCache(
self::$core, array()
);
try
{ {
$cache->getDriver(); $cache = new \Alchemy\Phrasea\Core\Service\Cache\ApcCache(
$this->fail("should raise an exception"); self::$core, array()
);
$this->assertEquals("apc", $cache->getType());
} }
catch (\Exception $e)
{
}
}
public function testType()
{
$cache = new \Alchemy\Phrasea\Core\Service\Cache\ApcCache(
self::$core, array()
);
$this->assertEquals("apc", $cache->getType());
}
} }

View File

@@ -1,59 +1,40 @@
<?php <?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__ . '/../../../../../PhraseanetPHPUnitAbstract.class.inc'; require_once __DIR__ . '/../../../../../PhraseanetPHPUnitAbstract.class.inc';
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class ServiceArrayCacheTest extends PhraseanetPHPUnitAbstract class ServiceArrayCacheTest extends PhraseanetPHPUnitAbstract
{ {
public function testService() public function testService()
{
$cache = new \Alchemy\Phrasea\Core\Service\Cache\ArrayCache(
self::$core, array()
);
$service = $cache->getDriver();
$this->assertTrue($service instanceof \Doctrine\Common\Cache\CacheProvider);
}
public function testServiceException()
{
$cache = new \Alchemy\Phrasea\Core\Service\Cache\ArrayCache(
self::$core, array()
);
try
{ {
$cache->getDriver(); $cache = new \Alchemy\Phrasea\Core\Service\Cache\ArrayCache(
$this->fail("should raise an exception"); self::$core, array()
);
$service = $cache->getDriver();
$this->assertTrue($service instanceof \Doctrine\Common\Cache\CacheProvider);
} }
catch (\Exception $e)
public function testServiceException()
{ {
$cache = new \Alchemy\Phrasea\Core\Service\Cache\ArrayCache(
self::$core, array()
);
try {
$cache->getDriver();
$this->fail("should raise an exception");
} catch (\Exception $e) {
}
} }
}
public function testType() public function testType()
{ {
$cache = new \Alchemy\Phrasea\Core\Service\Cache\ArrayCache( $cache = new \Alchemy\Phrasea\Core\Service\Cache\ArrayCache(
self::$core, array() self::$core, array()
); );
$this->assertEquals("array", $cache->getType());
}
$this->assertEquals("array", $cache->getType());
}
} }

View File

@@ -1,92 +1,67 @@
<?php <?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__ . '/../../../../../PhraseanetPHPUnitAbstract.class.inc'; require_once __DIR__ . '/../../../../../PhraseanetPHPUnitAbstract.class.inc';
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class ServiceMemcacheCacheTest extends PhraseanetPHPUnitAbstract class ServiceMemcacheCacheTest extends PhraseanetPHPUnitAbstract
{ {
public function testService() public function testService()
{
$cache = new \Alchemy\Phrasea\Core\Service\Cache\MemcacheCache(
self::$core, array()
);
if (extension_loaded('memcache'))
{ {
$service = $cache->getDriver(); $cache = new \Alchemy\Phrasea\Core\Service\Cache\MemcacheCache(
$this->assertTrue($service instanceof \Doctrine\Common\Cache\CacheProvider); self::$core, array()
);
if (extension_loaded('memcache')) {
$service = $cache->getDriver();
$this->assertTrue($service instanceof \Doctrine\Common\Cache\CacheProvider);
} else {
try {
$cache->getDriver();
$this->fail("should raise an exception");
} catch (\Exception $e) {
}
}
} }
else
public function testServiceException()
{ {
try $cache = new \Alchemy\Phrasea\Core\Service\Cache\MemcacheCache(
{ self::$core, array()
$cache->getDriver(); );
$this->fail("should raise an exception");
}
catch (\Exception $e)
{
} try {
$cache->getDriver();
$this->fail("should raise an exception");
} catch (\Exception $e) {
}
} }
}
public function testServiceException() public function testType()
{
$cache = new \Alchemy\Phrasea\Core\Service\Cache\MemcacheCache(
self::$core, array()
);
try
{ {
$cache->getDriver(); $cache = new \Alchemy\Phrasea\Core\Service\Cache\MemcacheCache(
$this->fail("should raise an exception"); self::$core, array()
);
$this->assertEquals("memcache", $cache->getType());
} }
catch (\Exception $e)
public function testHost()
{ {
$cache = new \Alchemy\Phrasea\Core\Service\Cache\MemcacheCache(
self::$core, array()
);
$this->assertEquals(\Alchemy\Phrasea\Core\Service\Cache\MemcacheCache::DEFAULT_HOST, $cache->getHost());
} }
}
public function testType() public function testPort()
{ {
$cache = new \Alchemy\Phrasea\Core\Service\Cache\MemcacheCache( $cache = new \Alchemy\Phrasea\Core\Service\Cache\MemcacheCache(
self::$core, array() self::$core, array()
); );
$this->assertEquals("memcache", $cache->getType());
}
public function testHost()
{
$cache = new \Alchemy\Phrasea\Core\Service\Cache\MemcacheCache(
self::$core, array()
);
$this->assertEquals(\Alchemy\Phrasea\Core\Service\Cache\MemcacheCache::DEFAULT_HOST, $cache->getHost());
}
public function testPort()
{
$cache = new \Alchemy\Phrasea\Core\Service\Cache\MemcacheCache(
self::$core, array()
);
$this->assertEquals(\Alchemy\Phrasea\Core\Service\Cache\MemcacheCache::DEFAULT_PORT, $cache->getPort());
}
$this->assertEquals(\Alchemy\Phrasea\Core\Service\Cache\MemcacheCache::DEFAULT_PORT, $cache->getPort());
}
} }

View File

@@ -1,74 +1,49 @@
<?php <?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__ . '/../../../../../PhraseanetPHPUnitAbstract.class.inc'; require_once __DIR__ . '/../../../../../PhraseanetPHPUnitAbstract.class.inc';
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class ServiceXcacheCacheTest extends PhraseanetPHPUnitAbstract class ServiceXcacheCacheTest extends PhraseanetPHPUnitAbstract
{ {
public function testService() public function testService()
{
$cache = new \Alchemy\Phrasea\Core\Service\Cache\XcacheCache(
self::$core, array()
);
if (extension_loaded('xcache'))
{ {
$service = $cache->getDriver(); $cache = new \Alchemy\Phrasea\Core\Service\Cache\XcacheCache(
$this->assertTrue($service instanceof \Doctrine\Common\Cache\CacheProvider); self::$core, array()
);
if (extension_loaded('xcache')) {
$service = $cache->getDriver();
$this->assertTrue($service instanceof \Doctrine\Common\Cache\CacheProvider);
} else {
try {
$cache->getDriver();
$this->fail("should raise an exception");
} catch (\Exception $e) {
}
}
} }
else
public function testServiceException()
{ {
try $cache = new \Alchemy\Phrasea\Core\Service\Cache\XcacheCache(
{ self::$core, array()
$cache->getDriver(); );
$this->fail("should raise an exception");
}
catch(\Exception $e)
{
} try {
$cache->getDriver();
$this->fail("should raise an exception");
} catch (\Exception $e) {
}
} }
}
public function testServiceException() public function testType()
{
$cache = new \Alchemy\Phrasea\Core\Service\Cache\XcacheCache(
self::$core, array()
);
try
{ {
$cache->getDriver(); $cache = new \Alchemy\Phrasea\Core\Service\Cache\XcacheCache(
$this->fail("should raise an exception"); self::$core, array()
);
$this->assertEquals("xcache", $cache->getType());
} }
catch (\Exception $e)
{
}
}
public function testType()
{
$cache = new \Alchemy\Phrasea\Core\Service\Cache\XcacheCache(
self::$core, array()
);
$this->assertEquals("xcache", $cache->getType());
}
} }

View File

@@ -1,71 +1,46 @@
<?php <?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__ . '/../../../../../../PhraseanetPHPUnitAbstract.class.inc'; require_once __DIR__ . '/../../../../../../PhraseanetPHPUnitAbstract.class.inc';
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class DoctrineMonologTest extends PhraseanetPHPUnitAbstract class DoctrineMonologTest extends PhraseanetPHPUnitAbstract
{ {
protected $options = array(
protected $options = array( "handler" => "rotate"
"handler" => "rotate" , "filename" => "test"
, "filename" => "test" , 'output' => 'json'
, 'output' => 'json' , 'channel' => 'test'
, 'channel' => 'test'
); );
public function setUp() public function testService()
{
parent::setUp();
}
public function testService()
{
$log = new \Alchemy\Phrasea\Core\Service\Log\Doctrine\Monolog(
self::$core, $this->options
);
$this->assertInstanceOf("\Doctrine\Logger\MonologSQLLogger", $log->getDriver());
}
public function testType()
{
$log = new \Alchemy\Phrasea\Core\Service\Log\Doctrine\Monolog(
self::$core, $this->options
);
$this->assertEquals("doctrine_monolog", $log->getType());
}
public function testExceptionBadOutput()
{
try
{
$this->options["output"] = "unknowOutput";
$log = new \Alchemy\Phrasea\Core\Service\Log\Doctrine\Monolog(
self::$core, $this->options
);
$log->getDriver();
$this->fail("should raise an exception");
}
catch (\Exception $e)
{ {
} $log = new \Alchemy\Phrasea\Core\Service\Log\Doctrine\Monolog(
} self::$core, $this->options
);
$this->assertInstanceOf("\Doctrine\Logger\MonologSQLLogger", $log->getDriver());
}
public function testType()
{
$log = new \Alchemy\Phrasea\Core\Service\Log\Doctrine\Monolog(
self::$core, $this->options
);
$this->assertEquals("doctrine_monolog", $log->getType());
}
public function testExceptionBadOutput()
{
try {
$this->options["output"] = "unknowOutput";
$log = new \Alchemy\Phrasea\Core\Service\Log\Doctrine\Monolog(
self::$core, $this->options
);
$log->getDriver();
$this->fail("should raise an exception");
} catch (\Exception $e) {
}
}
} }

View File

@@ -1,42 +1,25 @@
<?php <?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__ . '/../../../../../../PhraseanetPHPUnitAbstract.class.inc'; require_once __DIR__ . '/../../../../../../PhraseanetPHPUnitAbstract.class.inc';
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class DoctrinePhpechoTest extends PhraseanetPHPUnitAbstract class DoctrinePhpechoTest extends PhraseanetPHPUnitAbstract
{ {
public function testService() public function testService()
{ {
$log = new \Alchemy\Phrasea\Core\Service\Log\Doctrine\Phpecho(
self::$core, array()
);
$log = new \Alchemy\Phrasea\Core\Service\Log\Doctrine\Phpecho( $this->assertInstanceOf("\Doctrine\DBAL\Logging\EchoSQLLogger", $log->getDriver());
self::$core, array() }
);
$this->assertInstanceOf("\Doctrine\DBAL\Logging\EchoSQLLogger", $log->getDriver()); public function testType()
} {
$log = new \Alchemy\Phrasea\Core\Service\Log\Doctrine\Phpecho(
public function testType() self::$core, array()
{ );
$log = new \Alchemy\Phrasea\Core\Service\Log\Doctrine\Phpecho(
self::$core, array()
);
$this->assertEquals("phpecho", $log->getType());
}
$this->assertEquals("phpecho", $log->getType());
}
} }

View File

@@ -1,127 +1,97 @@
<?php <?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__ . '/../../../../../PhraseanetPHPUnitAbstract.class.inc'; require_once __DIR__ . '/../../../../../PhraseanetPHPUnitAbstract.class.inc';
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class MonologTest extends PhraseanetPHPUnitAbstract class MonologTest extends PhraseanetPHPUnitAbstract
{ {
protected $options;
protected $options; public function setUp()
public function setUp()
{
parent::setUp();
$this->options = array(
"handler" => "rotate"
, "filename" => "test"
, "channel" => "test"
);
}
public function testService()
{
$log = new \Alchemy\Phrasea\Core\Service\Log\Monolog(
self::$core, $this->options
);
$this->assertInstanceOf("\Monolog\Logger", $log->getDriver());
}
public function testType()
{
$log = new \Alchemy\Phrasea\Core\Service\Log\Monolog(
self::$core, $this->options
);
$this->assertEquals("monolog", $log->getType());
}
public function testExceptionMissingOptions()
{
try
{ {
$log = new \Alchemy\Phrasea\Core\Service\Log\Monolog( parent::setUp();
self::$core, $this->options $this->options = array(
); "handler" => "rotate"
$this->fail("should raise an exception"); , "filename" => "test"
, "channel" => "test"
);
} }
catch (\Exception $e)
public function testService()
{
$log = new \Alchemy\Phrasea\Core\Service\Log\Monolog(
self::$core, $this->options
);
$this->assertInstanceOf("\Monolog\Logger", $log->getDriver());
}
public function testType()
{
$log = new \Alchemy\Phrasea\Core\Service\Log\Monolog(
self::$core, $this->options
);
$this->assertEquals("monolog", $log->getType());
}
public function testExceptionMissingOptions()
{
try {
$log = new \Alchemy\Phrasea\Core\Service\Log\Monolog(
self::$core, $this->options
);
$this->fail("should raise an exception");
} catch (\Exception $e) {
}
}
public function testExceptionMissingHandler()
{
try {
unset($this->options["handler"]);
$log = new \Alchemy\Phrasea\Core\Service\Log\Monolog(
self::$core, $this->options
);
$this->fail("should raise an exception");
} catch (\Exception $e) {
}
}
public function testExceptionUnknowHandler()
{
try {
$this->options["handler"] = "unknowHandler";
$log = new \Alchemy\Phrasea\Core\Service\Log\Monolog(
self::$core, $this->options
);
$this->fail("should raise an exception");
} catch (\Exception $e) {
}
}
public function testMissingFile()
{
try {
unset($this->options["filename"]);
$log = new \Alchemy\Phrasea\Core\Service\Log\Monolog(
self::$core, $this->options
);
$this->fail("should raise an exception");
} catch (\Exception $e) {
}
}
public function testStreamLogger()
{ {
$this->options["handler"] = "stream";
$log = new \Alchemy\Phrasea\Core\Service\Log\Monolog(
self::$core, $this->options
);
$this->assertInstanceOf("\Monolog\Logger", $log->getDriver());
} }
}
public function testExceptionMissingHandler()
{
try
{
unset($this->options["handler"]);
$log = new \Alchemy\Phrasea\Core\Service\Log\Monolog(
self::$core, $this->options
);
$this->fail("should raise an exception");
}
catch (\Exception $e)
{
}
}
public function testExceptionUnknowHandler()
{
try
{
$this->options["handler"] = "unknowHandler";
$log = new \Alchemy\Phrasea\Core\Service\Log\Monolog(
self::$core, $this->options
);
$this->fail("should raise an exception");
}
catch (\Exception $e)
{
}
}
public function testMissingFile()
{
try
{
unset($this->options["filename"]);
$log = new \Alchemy\Phrasea\Core\Service\Log\Monolog(
self::$core, $this->options
);
$this->fail("should raise an exception");
}
catch (\Exception $e)
{
}
}
public function testStreamLogger()
{
$this->options["handler"] = "stream";
$log = new \Alchemy\Phrasea\Core\Service\Log\Monolog(
self::$core, $this->options
);
$this->assertInstanceOf("\Monolog\Logger", $log->getDriver());
}
} }

View File

@@ -1,222 +1,182 @@
<?php <?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__ . '/../../../../../PhraseanetPHPUnitAbstract.class.inc'; require_once __DIR__ . '/../../../../../PhraseanetPHPUnitAbstract.class.inc';
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class DoctrineTest extends PhraseanetPHPUnitAbstract class DoctrineTest extends PhraseanetPHPUnitAbstract
{ {
protected $options;
protected $options; public function setUp()
public function setUp()
{
parent::setUp();
$this->options = array(
"debug" => false
, "log" => array('service' => "Log\\sql_logger")
, "dbal" => "main_connexion"
, "cache" => array(
"metadata" => array('service' => "Cache\\array_cache")
, "query" => array('service' => "Cache\\array_cache")
, "result" => array('service' => "Cache\\array_cache")
)
);
}
public function testService()
{
$doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine(
self::$core, $this->options
);
$this->assertInstanceOf("\Doctrine\ORM\EntityManager", $doctrine->getDriver());
}
public function testType()
{
$doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine(
self::$core, $this->options
);
$this->assertEquals("doctrine", $doctrine->getType());
}
public function testExceptionMissingOptions()
{
try
{ {
$doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine( parent::setUp();
self::$core, $this->options $this->options = array(
); "debug" => false
$this->fail("should raise an exception"); , "log" => array('service' => "Log\\sql_logger")
} , "dbal" => "main_connexion"
catch (\Exception $e) , "cache" => array(
{ "metadata" => array('service' => "Cache\\array_cache")
, "query" => array('service' => "Cache\\array_cache")
} , "result" => array('service' => "Cache\\array_cache")
} )
public function testNoCacheInOptions()
{
$this->markTestSkipped('To rewrite');
unset($this->options["cache"]);
$doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine(
self::$core, $this->options
);
foreach ($doctrine->getCacheServices()->all() as $service)
{
$this->assertEquals("array", $service->getType());
}
}
public function testUnknowCache()
{
$this->options["cache"]["result"] = "unknowCache";
try
{
$doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine(
self::$core, $this->options
);
$this->fail("An exception should be raised");
}
catch (\Exception $e)
{
}
}
public function testIsDebug()
{
$doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine(
self::$core, $this->options
);
$this->assertFalse($doctrine->isDebug());
$this->options['debug'] = true;
$doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine(
self::$core, $this->options
);
$this->assertTrue($doctrine->isDebug());
}
public function testGetCacheServices()
{
$this->markTestSkipped('To rewrite');
$doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine(
self::$core, $this->options
);
$this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag"
, $doctrine->getCacheServices());
foreach ($doctrine->getCacheServices()->all() as $service)
{
$this->assertEquals("array", $service->getType());
}
$this->options['orm']["cache"] = array(
"metadata" => "array_cache"
, "query" => "apc_cache"
, "result" => "xcache_cache"
);
if (extension_loaded("apc") && extension_loaded("xcache"))
{
$doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine(
self::$core, $this->options
);
$this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag"
, $doctrine->getCacheServices());
foreach ($doctrine->getCacheServices()->all() as $key => $service)
{
if ($key === "metadata")
$this->assertEquals("array", $service->getType());
elseif ($key === "query")
$this->assertEquals("apc", $service->getType());
elseif ($key === "result")
$this->assertEquals("xcache", $service->getType());
}
}
else
{
try
{
$doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine(
self::$core, $this->options
); );
$this->fail("An exception should be raised");
}
catch (\Exception $e)
{
}
} }
}
public function testExceptionUnknowLogService() public function testService()
{
try
{ {
$this->options["log"] = "unknowLogger"; $doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine(
$doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine( self::$core, $this->options
self::$core, $this->options );
);
$this->fail("should raise an exception"); $this->assertInstanceOf("\Doctrine\ORM\EntityManager", $doctrine->getDriver());
} }
catch (\Exception $e)
public function testType()
{ {
$doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine(
self::$core, $this->options
);
$this->assertEquals("doctrine", $doctrine->getType());
} }
}
public function testExceptionMissingDbal() public function testExceptionMissingOptions()
{
try
{ {
unset($this->options["dbal"]); try {
$doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine( $doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine(
self::$core, $this->options self::$core, $this->options
); );
$this->fail("should raise an exception"); $this->fail("should raise an exception");
} catch (\Exception $e) {
}
} }
catch (\Exception $e)
public function testNoCacheInOptions()
{ {
$this->markTestSkipped('To rewrite');
unset($this->options["cache"]);
$doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine(
self::$core, $this->options
);
foreach ($doctrine->getCacheServices()->all() as $service) {
$this->assertEquals("array", $service->getType());
}
} }
}
public function testExceptionUnknowDbal() public function testUnknowCache()
{
try
{ {
$this->options["dbal"] = "unknowDbal"; $this->options["cache"]["result"] = "unknowCache";
$doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine(
self::$core, $this->options try {
); $doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine(
$this->fail("should raise an exception"); self::$core, $this->options
);
$this->fail("An exception should be raised");
} catch (\Exception $e) {
}
} }
catch (\Exception $e)
public function testIsDebug()
{ {
$doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine(
self::$core, $this->options
);
$this->assertFalse($doctrine->isDebug());
$this->options['debug'] = true;
$doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine(
self::$core, $this->options
);
$this->assertTrue($doctrine->isDebug());
} }
}
public function testGetCacheServices()
{
$this->markTestSkipped('To rewrite');
$doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine(
self::$core, $this->options
);
$this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag"
, $doctrine->getCacheServices());
foreach ($doctrine->getCacheServices()->all() as $service) {
$this->assertEquals("array", $service->getType());
}
$this->options['orm']["cache"] = array(
"metadata" => "array_cache"
, "query" => "apc_cache"
, "result" => "xcache_cache"
);
if (extension_loaded("apc") && extension_loaded("xcache")) {
$doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine(
self::$core, $this->options
);
$this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag"
, $doctrine->getCacheServices());
foreach ($doctrine->getCacheServices()->all() as $key => $service) {
if ($key === "metadata")
$this->assertEquals("array", $service->getType());
elseif ($key === "query")
$this->assertEquals("apc", $service->getType());
elseif ($key === "result")
$this->assertEquals("xcache", $service->getType());
}
}
else {
try {
$doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine(
self::$core, $this->options
);
$this->fail("An exception should be raised");
} catch (\Exception $e) {
}
}
}
public function testExceptionUnknowLogService()
{
try {
$this->options["log"] = "unknowLogger";
$doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine(
self::$core, $this->options
);
$this->fail("should raise an exception");
} catch (\Exception $e) {
}
}
public function testExceptionMissingDbal()
{
try {
unset($this->options["dbal"]);
$doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine(
self::$core, $this->options
);
$this->fail("should raise an exception");
} catch (\Exception $e) {
}
}
public function testExceptionUnknowDbal()
{
try {
$this->options["dbal"] = "unknowDbal";
$doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine(
self::$core, $this->options
);
$this->fail("should raise an exception");
} catch (\Exception $e) {
}
}
} }

View File

@@ -1,49 +1,32 @@
<?php <?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__ . '/../../../../PhraseanetPHPUnitAbstract.class.inc'; require_once __DIR__ . '/../../../../PhraseanetPHPUnitAbstract.class.inc';
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class ServiceAbstractTest extends PhraseanetPHPUnitAbstract class ServiceAbstractTest extends PhraseanetPHPUnitAbstract
{ {
/**
*
* @var \Alchemy\Phrasea\Core\Service\ServiceAbstract
*/
protected $object;
/** public function setUp()
* {
* @var \Alchemy\Phrasea\Core\Service\ServiceAbstract parent::setUp();
*/ $stub = $this->getMockForAbstractClass(
protected $object;
public function setUp()
{
parent::setUp();
$stub = $this->getMockForAbstractClass(
"\Alchemy\Phrasea\Core\Service\ServiceAbstract" "\Alchemy\Phrasea\Core\Service\ServiceAbstract"
, array( , array(
self::$core self::$core
, array('option' => 'my_options') , array('option' => 'my_options')
) )
); );
$this->object = $stub; $this->object = $stub;
} }
public function testGetOptions()
{
$this->assertTrue(is_array($this->object->getOptions()));
$this->assertEquals(array('option' => 'my_options'), $this->object->getOptions());
}
public function testGetOptions()
{
$this->assertTrue(is_array($this->object->getOptions()));
$this->assertEquals(array('option' => 'my_options'), $this->object->getOptions());
}
} }

View File

@@ -1,64 +1,47 @@
<?php <?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__ . '/../../../../../PhraseanetPHPUnitAbstract.class.inc'; require_once __DIR__ . '/../../../../../PhraseanetPHPUnitAbstract.class.inc';
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class TwigTest extends PhraseanetPHPUnitAbstract class TwigTest extends PhraseanetPHPUnitAbstract
{ {
protected $options;
protected $options; public function setUp()
{
parent::setUp();
$this->options = array(
'debug' => true
, 'charset' => 'utf-8'
, 'strict_variables' => true
, 'autoescape' => true
, 'optimizer' => true
);
}
public function setUp() public function testService()
{ {
parent::setUp(); $doctrine = new \Alchemy\Phrasea\Core\Service\TemplateEngine\Twig(
$this->options = array( self::$core, $this->options
'debug' => true );
,'charset' => 'utf-8'
,'strict_variables' => true
,'autoescape' => true
,'optimizer' => true
);
}
public function testService() $this->assertInstanceOf("\Twig_Environment", $doctrine->getDriver());
{ }
$doctrine = new \Alchemy\Phrasea\Core\Service\TemplateEngine\Twig(
self::$core, $this->options
);
$this->assertInstanceOf("\Twig_Environment", $doctrine->getDriver()); public function testServiceExcpetion()
} {
$doctrine = new \Alchemy\Phrasea\Core\Service\TemplateEngine\Twig(
self::$core, $this->options
);
public function testServiceExcpetion() $this->assertInstanceOf("\Twig_Environment", $doctrine->getDriver());
{ }
$doctrine = new \Alchemy\Phrasea\Core\Service\TemplateEngine\Twig(
self::$core, $this->options
);
$this->assertInstanceOf("\Twig_Environment", $doctrine->getDriver()); public function testType()
} {
$doctrine = new \Alchemy\Phrasea\Core\Service\TemplateEngine\Twig(
public function testType() self::$core, $this->options
{ );
$doctrine = new \Alchemy\Phrasea\Core\Service\TemplateEngine\Twig(
self::$core, $this->options
);
$this->assertEquals("twig", $doctrine->getType());
}
$this->assertEquals("twig", $doctrine->getType());
}
} }

View File

@@ -1,63 +1,41 @@
<?php <?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__ . '/../../../../PhraseanetPHPUnitAbstract.class.inc'; require_once __DIR__ . '/../../../../PhraseanetPHPUnitAbstract.class.inc';
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class AbstractBuilderTest extends PhraseanetPHPUnitAbstract class AbstractBuilderTest extends PhraseanetPHPUnitAbstract
{ {
public function testConstructExceptionNameEmpty() public function testConstructExceptionNameEmpty()
{
try
{ {
$stub = $this->getMock( try {
"\Alchemy\Phrasea\Core\Service\Builder" $stub = $this->getMock(
, array( "\Alchemy\Phrasea\Core\Service\Builder"
self::$core , array(
, '' self::$core
, new \Symfony\Component\DependencyInjection\ParameterBag\ParameterBag() , ''
) , new \Symfony\Component\DependencyInjection\ParameterBag\ParameterBag()
); )
$this->fail("should raise an exception"); );
$this->fail("should raise an exception");
} catch (\Exception $e) {
}
} }
catch (\Exception $e)
public function testConstructExceptionCreate()
{ {
try {
$stub = $this->getMock(
"\\Alchemy\\Phrasea\\Core\\Service\\Builder"
, array(
self::$core,
'test',
new \Symfony\Component\DependencyInjection\ParameterBag\ParameterBag(),
)
);
$this->fail("should raise an exception");
} catch (\Exception $e) {
}
} }
}
public function testConstructExceptionCreate()
{
try
{
$stub = $this->getMock(
"\\Alchemy\\Phrasea\\Core\\Service\\Builder"
, array(
self::$core,
'test',
new \Symfony\Component\DependencyInjection\ParameterBag\ParameterBag(),
)
);
$this->fail("should raise an exception");
}
catch (\Exception $e)
{
}
}
} }

View File

@@ -1,50 +1,31 @@
<?php <?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__ . '/../../../../PhraseanetPHPUnitAbstract.class.inc'; require_once __DIR__ . '/../../../../PhraseanetPHPUnitAbstract.class.inc';
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class CacheBuilderTest extends PhraseanetPHPUnitAbstract class CacheBuilderTest extends PhraseanetPHPUnitAbstract
{ {
public function testCreateException() public function testCreateException()
{
$configuration = new Symfony\Component\DependencyInjection\ParameterBag\ParameterBag(
array("type" => "unknow")
);
try
{ {
$service = Alchemy\Phrasea\Core\Service\Builder::create(self::$core, $configuration); $configuration = new Symfony\Component\DependencyInjection\ParameterBag\ParameterBag(
$this->fail("An exception should be raised"); array("type" => "unknow")
);
try {
$service = Alchemy\Phrasea\Core\Service\Builder::create(self::$core, $configuration);
$this->fail("An exception should be raised");
} catch (\Exception $e) {
}
} }
catch (\Exception $e)
public function testCreate()
{ {
$configuration = new Symfony\Component\DependencyInjection\ParameterBag\ParameterBag(
array("type" => "Cache\\ArrayCache")
);
$service = Alchemy\Phrasea\Core\Service\Builder::create(self::$core, $configuration);
$this->assertInstanceOf("\Alchemy\Phrasea\Core\Service\ServiceAbstract", $service);
} }
}
public function testCreate()
{
$configuration = new Symfony\Component\DependencyInjection\ParameterBag\ParameterBag(
array("type" => "Cache\\ArrayCache")
);
$service = Alchemy\Phrasea\Core\Service\Builder::create(self::$core, $configuration);
$this->assertInstanceOf("\Alchemy\Phrasea\Core\Service\ServiceAbstract", $service);
}
} }

View File

@@ -1,67 +1,48 @@
<?php <?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__ . '/../../../../PhraseanetPHPUnitAbstract.class.inc'; require_once __DIR__ . '/../../../../PhraseanetPHPUnitAbstract.class.inc';
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class LogBuilderTest extends PhraseanetPHPUnitAbstract class LogBuilderTest extends PhraseanetPHPUnitAbstract
{ {
public function testCreateException() public function testCreateException()
{
$configuration = new Symfony\Component\DependencyInjection\ParameterBag\ParameterBag(
array("type" => "unknow", "options" => array())
);
try
{ {
$service = Alchemy\Phrasea\Core\Service\Builder::create(self::$core, $configuration); $configuration = new Symfony\Component\DependencyInjection\ParameterBag\ParameterBag(
$this->fail("An exception should be raised"); array("type" => "unknow", "options" => array())
);
try {
$service = Alchemy\Phrasea\Core\Service\Builder::create(self::$core, $configuration);
$this->fail("An exception should be raised");
} catch (\Exception $e) {
}
} }
catch (\Exception $e)
public function testCreate()
{ {
$configuration = new Symfony\Component\DependencyInjection\ParameterBag\ParameterBag(
array("type" => "Log\\Doctrine\\Monolog", "options" => array(
"handler" => "rotate"
, "filename" => "test"
, 'channel' => 'Test'
, 'output' => 'json'
, 'max_day' => '1'
)
)
);
$service = Alchemy\Phrasea\Core\Service\Builder::create(self::$core, $configuration);
$this->assertInstanceOf("\Alchemy\Phrasea\Core\Service\ServiceAbstract", $service);
} }
}
public function testCreate() public function testCreateNamespace()
{ {
$configuration = new Symfony\Component\DependencyInjection\ParameterBag\ParameterBag( $configuration = new Symfony\Component\DependencyInjection\ParameterBag\ParameterBag(
array("type" => "Log\\Doctrine\\Monolog", "options" => array( array("type" => "Log\\Doctrine\\Phpecho", "options" => array())
"handler" => "rotate" );
, "filename" => "test"
, 'channel' => 'Test'
, 'output' => 'json'
, 'max_day' => '1'
)
)
);
$service = Alchemy\Phrasea\Core\Service\Builder::create(self::$core, $configuration);
$this->assertInstanceOf("\Alchemy\Phrasea\Core\Service\ServiceAbstract", $service);
}
public function testCreateNamespace()
{
$configuration = new Symfony\Component\DependencyInjection\ParameterBag\ParameterBag(
array("type" => "Log\\Doctrine\\Phpecho", "options" => array())
);
$service = Alchemy\Phrasea\Core\Service\Builder::create(self::$core, $configuration);
$this->assertInstanceOf("\Alchemy\Phrasea\Core\Service\ServiceAbstract", $service);
}
$service = Alchemy\Phrasea\Core\Service\Builder::create(self::$core, $configuration);
$this->assertInstanceOf("\Alchemy\Phrasea\Core\Service\ServiceAbstract", $service);
}
} }

View File

@@ -1,62 +1,43 @@
<?php <?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__ . '/../../../../PhraseanetPHPUnitAbstract.class.inc'; require_once __DIR__ . '/../../../../PhraseanetPHPUnitAbstract.class.inc';
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class OrmBuilderTest extends PhraseanetPHPUnitAbstract class OrmBuilderTest extends PhraseanetPHPUnitAbstract
{ {
public function testCreateException() public function testCreateException()
{
$configuration = new Symfony\Component\DependencyInjection\ParameterBag\ParameterBag(
array("type" => "unknow", "options" => array())
);
try
{ {
$service = Alchemy\Phrasea\Core\Service\Builder::create(self::$core, $configuration); $configuration = new Symfony\Component\DependencyInjection\ParameterBag\ParameterBag(
$this->fail("An exception should be raised"); array("type" => "unknow", "options" => array())
);
try {
$service = Alchemy\Phrasea\Core\Service\Builder::create(self::$core, $configuration);
$this->fail("An exception should be raised");
} catch (\Exception $e) {
}
} }
catch (\Exception $e)
public function testCreate()
{ {
$registry = $this->getMock("\RegistryInterface");
$configuration = new Symfony\Component\DependencyInjection\ParameterBag\ParameterBag(
array("type" => "Orm\\Doctrine", "options" => array(
"debug" => false
, "log" => array('service' => "Log\\query_logger")
, "dbal" => "main_connexion"
, "cache" => array(
"metadata" => "Cache\\array_cache"
, "query" => "Cache\\array_cache"
, "result" => "Cache\\array_cache"
)
)
)
);
$service = Alchemy\Phrasea\Core\Service\Builder::create(self::$core, $configuration);
$this->assertInstanceOf("\Alchemy\Phrasea\Core\Service\ServiceAbstract", $service);
} }
}
public function testCreate()
{
$registry = $this->getMock("\RegistryInterface");
$configuration = new Symfony\Component\DependencyInjection\ParameterBag\ParameterBag(
array("type" => "Orm\\Doctrine", "options" => array(
"debug" => false
, "log" => array('service'=>"Log\\query_logger")
, "dbal" => "main_connexion"
, "cache" => array(
"metadata" => "Cache\\array_cache"
, "query" => "Cache\\array_cache"
, "result" => "Cache\\array_cache"
)
)
)
);
$service = Alchemy\Phrasea\Core\Service\Builder::create(self::$core, $configuration);
$this->assertInstanceOf("\Alchemy\Phrasea\Core\Service\ServiceAbstract", $service);
}
} }

View File

@@ -1,58 +1,39 @@
<?php <?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__ . '/../../../../PhraseanetPHPUnitAbstract.class.inc'; require_once __DIR__ . '/../../../../PhraseanetPHPUnitAbstract.class.inc';
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class TemplateBuilderTest extends PhraseanetPHPUnitAbstract class TemplateBuilderTest extends PhraseanetPHPUnitAbstract
{ {
public function testCreateException() public function testCreateException()
{
$configuration = new Symfony\Component\DependencyInjection\ParameterBag\ParameterBag(
array("type" => "unknow", "options" => array())
);
try
{ {
$service = Alchemy\Phrasea\Core\Service\Builder::create(self::$core, $configuration); $configuration = new Symfony\Component\DependencyInjection\ParameterBag\ParameterBag(
$this->fail("An exception should be raised"); array("type" => "unknow", "options" => array())
);
try {
$service = Alchemy\Phrasea\Core\Service\Builder::create(self::$core, $configuration);
$this->fail("An exception should be raised");
} catch (\Exception $e) {
}
} }
catch (\Exception $e)
public function testCreate()
{ {
$configuration = new Symfony\Component\DependencyInjection\ParameterBag\ParameterBag(
array(
"type" => "TemplateEngine\\Twig"
, "options" => array(
'debug' => 'true'
, 'charset' => 'UTF-8'
, 'strict_variables' => 'true'
, 'autoescape' => 'true'
, 'optimizer' => 'true'
))
);
$service = Alchemy\Phrasea\Core\Service\Builder::create(self::$core, $configuration);
$this->assertInstanceOf("\Alchemy\Phrasea\Core\Service\ServiceAbstract", $service);
} }
}
public function testCreate()
{
$configuration = new Symfony\Component\DependencyInjection\ParameterBag\ParameterBag(
array(
"type" => "TemplateEngine\\Twig"
, "options" => array(
'debug' => 'true'
, 'charset' => 'UTF-8'
, 'strict_variables' => 'true'
, 'autoescape' => 'true'
, 'optimizer' => 'true'
))
);
$service = Alchemy\Phrasea\Core\Service\Builder::create(self::$core, $configuration);
$this->assertInstanceOf("\Alchemy\Phrasea\Core\Service\ServiceAbstract", $service);
}
} }

View File

@@ -1,36 +1,21 @@
<?php <?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__ . '/../../../PhraseanetPHPUnitAbstract.class.inc'; require_once __DIR__ . '/../../../PhraseanetPHPUnitAbstract.class.inc';
use Alchemy\Phrasea\Core\Version; use Alchemy\Phrasea\Core\Version;
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class VersionTest extends \PhraseanetPHPUnitAbstract class VersionTest extends \PhraseanetPHPUnitAbstract
{ {
public function testGetNumber() public function testGetNumber()
{ {
$this->assertTrue(is_string(Version::getNumber())); $this->assertTrue(is_string(Version::getNumber()));
$this->assertRegExp('/[\d]{1}\.[\d]{1,2}\.[\d]{1,2}/', Version::getNumber()); $this->assertRegExp('/[\d]{1}\.[\d]{1,2}\.[\d]{1,2}/', Version::getNumber());
} }
public function testGetName() public function testGetName()
{ {
$this->assertTrue(is_string(Version::getName())); $this->assertTrue(is_string(Version::getName()));
$this->assertTrue(strlen(Version::getName()) > 3); $this->assertTrue(strlen(Version::getName()) > 3);
} }
} }

View File

@@ -1,146 +1,128 @@
<?php <?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__ . '/../../PhraseanetPHPUnitAbstract.class.inc'; require_once __DIR__ . '/../../PhraseanetPHPUnitAbstract.class.inc';
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class CoreTest extends PhraseanetPHPUnitAbstract class CoreTest extends PhraseanetPHPUnitAbstract
{ {
public function testCoreVersion() public function testCoreVersion()
{
$this->assertInstanceOf('\Alchemy\Phrasea\Core\Version', self::$core->getVersion());
}
public function testCoreRegistry()
{
$this->assertInstanceOf('\registryInterface', self::$core->getRegistry());
}
public function testCoreEntityManager()
{
$this->assertInstanceOf('\Doctrine\ORM\EntityManager', self::$core->getEntityManager());
}
public function testCoreTemplateEngine()
{
$this->assertInstanceOf('\Twig_Environment', self::$core->getTwig());
}
public function testCoreSerializer()
{
$this->assertInstanceOf('\Symfony\Component\Serializer\Serializer', self::$core->getSerializer());
}
public function testCoreConfiguration()
{
$this->assertInstanceOf('\Alchemy\Phrasea\Core\Configuration', self::$core->getConfiguration());
}
public function testIsAuthenticathed()
{
$this->assertFalse(self::$core->isAuthenticated());
$appbox = appbox::get_instance(\bootstrap::getCore());
$session = $appbox->get_session();
$auth = new Session_Authentication_None(self::$user);
$session->authenticate($auth);
$this->assertTrue(self::$core->isAuthenticated());
$session->logout();
}
public function testGetAuthenticathed()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$session = $appbox->get_session();
$auth = new Session_Authentication_None(self::$user);
$session->authenticate($auth);
$this->assertInstanceOf("\User_Adapter", self::$core->getAuthenticatedUser());
$session->logout();
}
public function testGetAvailableLanguages()
{
$languages = \Alchemy\Phrasea\Core::getAvailableLanguages();
$this->assertTrue(is_array($languages));
$this->assertEquals(5, count($languages));
$this->assertTrue(array_key_exists("ar_SA", $languages));
$this->assertTrue(array_key_exists("de_DE", $languages));
$this->assertTrue(array_key_exists("en_GB", $languages));
$this->assertTrue(array_key_exists("es_ES", $languages));
$this->assertTrue(array_key_exists("fr_FR", $languages));
}
public function testGetPhpConf()
{
\Alchemy\Phrasea\Core::initPHPConf();
// $this->assertEquals("4096", ini_get('output_buffering'));
$this->assertGreaterThanOrEqual(2048, (int) ini_get('memory_limit'));
$this->assertEquals("6143", ini_get('error_reporting'));
$this->assertEquals("UTF-8", ini_get('default_charset'));
$this->assertEquals("1", ini_get('session.use_cookies'));
$this->assertEquals("1", ini_get('session.use_only_cookies'));
$this->assertEquals("0", ini_get('session.auto_start'));
$this->assertEquals("1", ini_get('session.hash_function'));
$this->assertEquals("6", ini_get('session.hash_bits_per_character'));
$this->assertEquals("1", ini_get('allow_url_fopen'));
}
public function testGetEnv()
{
$core = new \Alchemy\Phrasea\Core("test");
$this->assertEquals("test", $core->getEnv());
}
public function testNotInstalled()
{
if (!extension_loaded('test_helpers'))
{ {
$this->markTestSkipped("test_helpers extension required"); $this->assertInstanceOf('\Alchemy\Phrasea\Core\Version', self::$core->getVersion());
} }
set_new_overload(array($this, 'newCallback')); public function testCoreRegistry()
{
$this->assertInstanceOf('\registryInterface', self::$core->getRegistry());
}
$specification = new \Alchemy\Phrasea\Core\Configuration\ApplicationSpecification(); public function testCoreEntityManager()
{
$this->assertInstanceOf('\Doctrine\ORM\EntityManager', self::$core->getEntityManager());
}
$class = $this->getMock( public function testCoreTemplateEngine()
{
$this->assertInstanceOf('\Twig_Environment', self::$core->getTwig());
}
public function testCoreSerializer()
{
$this->assertInstanceOf('\Symfony\Component\Serializer\Serializer', self::$core->getSerializer());
}
public function testCoreConfiguration()
{
$this->assertInstanceOf('\Alchemy\Phrasea\Core\Configuration', self::$core->getConfiguration());
}
public function testIsAuthenticathed()
{
$this->assertFalse(self::$core->isAuthenticated());
$appbox = appbox::get_instance(\bootstrap::getCore());
$session = $appbox->get_session();
$auth = new Session_Authentication_None(self::$user);
$session->authenticate($auth);
$this->assertTrue(self::$core->isAuthenticated());
$session->logout();
}
public function testGetAuthenticathed()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$session = $appbox->get_session();
$auth = new Session_Authentication_None(self::$user);
$session->authenticate($auth);
$this->assertInstanceOf("\User_Adapter", self::$core->getAuthenticatedUser());
$session->logout();
}
public function testGetAvailableLanguages()
{
$languages = \Alchemy\Phrasea\Core::getAvailableLanguages();
$this->assertTrue(is_array($languages));
$this->assertEquals(5, count($languages));
$this->assertTrue(array_key_exists("ar_SA", $languages));
$this->assertTrue(array_key_exists("de_DE", $languages));
$this->assertTrue(array_key_exists("en_GB", $languages));
$this->assertTrue(array_key_exists("es_ES", $languages));
$this->assertTrue(array_key_exists("fr_FR", $languages));
}
public function testGetPhpConf()
{
\Alchemy\Phrasea\Core::initPHPConf();
// $this->assertEquals("4096", ini_get('output_buffering'));
$this->assertGreaterThanOrEqual(2048, (int) ini_get('memory_limit'));
$this->assertEquals("6143", ini_get('error_reporting'));
$this->assertEquals("UTF-8", ini_get('default_charset'));
$this->assertEquals("1", ini_get('session.use_cookies'));
$this->assertEquals("1", ini_get('session.use_only_cookies'));
$this->assertEquals("0", ini_get('session.auto_start'));
$this->assertEquals("1", ini_get('session.hash_function'));
$this->assertEquals("6", ini_get('session.hash_bits_per_character'));
$this->assertEquals("1", ini_get('allow_url_fopen'));
}
public function testGetEnv()
{
$core = new \Alchemy\Phrasea\Core("test");
$this->assertEquals("test", $core->getEnv());
}
public function testNotInstalled()
{
if ( ! extension_loaded('test_helpers')) {
$this->markTestSkipped("test_helpers extension required");
}
set_new_overload(array($this, 'newCallback'));
$specification = new \Alchemy\Phrasea\Core\Configuration\ApplicationSpecification();
$class = $this->getMock(
'\Alchemy\Phrasea\Core\Configuration' '\Alchemy\Phrasea\Core\Configuration'
, array('isInstalled') , array('isInstalled')
, array($specification) , array($specification)
, 'ConfMock' , 'ConfMock'
); );
$class->expects($this->any()) $class->expects($this->any())
->method('isInstalled') ->method('isInstalled')
->will($this->returnValue(false)); ->will($this->returnValue(false));
$core = new \Alchemy\Phrasea\Core("test"); $core = new \Alchemy\Phrasea\Core("test");
$this->assertInstanceOf("\Setup_Registry", $core->getRegistry()); $this->assertInstanceOf("\Setup_Registry", $core->getRegistry());
unset_new_overload(); unset_new_overload();
}
protected function newCallback($className)
{
switch ($className)
{
case 'Alchemy\Phrasea\Core\Configuration': return 'ConfMock';
default: return $className;
} }
}
protected function newCallback($className)
{
switch ($className) {
case 'Alchemy\Phrasea\Core\Configuration': return 'ConfMock';
default: return $className;
}
}
} }

View File

@@ -1,26 +0,0 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetPHPUnitAuthenticatedAbstract.class.inc';
class HelperBridgeTest extends \PhraseanetPHPUnitAuthenticatedAbstract
{
/**
* @var Bridge
*/
protected $object;
public function setUp()
{
parent::setUp();
}
public function testFooBar()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
}

View File

@@ -1,138 +0,0 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetPHPUnitAuthenticatedAbstract.class.inc';
class HelperEditTest extends \PhraseanetPHPUnitAuthenticatedAbstract
{
/**
* @var Edit
*/
protected $object;
public function setUp()
{
parent::setUp();
}
/**
*
* @todo Implement testPropose_editing().
*/
public function testPropose_editing()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
*
* @todo Implement testHas_thesaurus().
*/
public function testHas_thesaurus()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
*
* @todo Implement testGet_javascript_elements_ids().
*/
public function testGet_javascript_elements_ids()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
*
* @todo Implement testGet_javascript_elements().
*/
public function testGet_javascript_elements()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
*
* @todo Implement testGet_javascript_sugg_values().
*/
public function testGet_javascript_sugg_values()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
*
* @todo Implement testGet_javascript_status().
*/
public function testGet_javascript_status()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
*
* @todo Implement testGet_javascript_fields().
*/
public function testGet_javascript_fields()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
*
* @todo Implement testGet_status().
*/
public function testGet_status()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
*
* @todo Implement testGet_fields().
*/
public function testGet_fields()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
*
* @todo Implement testExecute().
*/
public function testExecute()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
}

View File

@@ -1,26 +0,0 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetPHPUnitAuthenticatedAbstract.class.inc';
class HelperFeedTest extends \PhraseanetPHPUnitAuthenticatedAbstract
{
/**
* @var Feed
*/
protected $object;
public function setUp()
{
parent::setUp();
}
public function testFooBar()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
}

View File

@@ -1,186 +0,0 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetPHPUnitAuthenticatedAbstract.class.inc';
class HelperHelperTest extends \PhraseanetPHPUnitAuthenticatedAbstract
{
/**
* @var Helper
*/
protected $object;
public function setUp()
{
parent::setUp();
}
/**
*
* @todo Implement testIs_basket().
*/
public function testIs_basket()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
*
* @todo Implement testGet_original_basket().
*/
public function testGet_original_basket()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
*
* @todo Implement testIs_single_grouping().
*/
public function testIs_single_grouping()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
*
* @todo Implement testGet_grouping_head().
*/
public function testGet_grouping_head()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
*
* @todo Implement testGet_elements().
*/
public function testGet_elements()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
*
* @todo Implement testHas_many_sbas().
*/
public function testHas_many_sbas()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
*
* @todo Implement testIs_possible().
*/
public function testIs_possible()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
*
* @todo Implement testGet_count_not_actionable().
*/
public function testGet_count_not_actionable()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
*
* @todo Implement testGet_count_actionable().
*/
public function testGet_count_actionable()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
*
* @todo Implement testGet_count_actionable_groupings().
*/
public function testGet_count_actionable_groupings()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
*
* @todo Implement testGet_count_element_received().
*/
public function testGet_count_element_received()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
*
* @todo Implement testGet_sbas_id().
*/
public function testGet_sbas_id()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
*
* @todo Implement testGet_serialize_list().
*/
public function testGet_serialize_list()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
*
* @todo Implement testGrep_records().
*/
public function testGrep_records()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
}

View File

@@ -1,54 +0,0 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetPHPUnitAuthenticatedAbstract.class.inc';
class HelperMoveCollectionTest extends \PhraseanetPHPUnitAuthenticatedAbstract
{
/**
* @var MoveCollection
*/
protected $object;
public function setUp()
{
parent::setUp();
}
/**
*
* @todo Implement testAvailable_destination().
*/
public function testAvailable_destination()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
*
* @todo Implement testPropose().
*/
public function testPropose()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
*
* @todo Implement testExecute().
*/
public function testExecute()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
}

View File

@@ -1,42 +0,0 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetPHPUnitAuthenticatedAbstract.class.inc';
class HelperPrinterTest extends \PhraseanetPHPUnitAuthenticatedAbstract
{
/**
* @var Printer
*/
protected $object;
public function setUp()
{
parent::setUp();
}
/**
*
* @todo Implement testGet_count_preview().
*/
public function testGet_count_preview()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
*
* @todo Implement testGet_count_thumbnail().
*/
public function testGet_count_thumbnail()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
}

View File

@@ -1,31 +0,0 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetPHPUnitAuthenticatedAbstract.class.inc';
class HelperPushTest extends \PhraseanetPHPUnitAuthenticatedAbstract
{
/**
* @var Push
*/
protected $object;
public function setUp()
{
parent::setUp();
}
/**
*
* @todo Implement testSearch().
*/
public function testSearch()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
}

View File

@@ -1,26 +0,0 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetPHPUnitAuthenticatedAbstract.class.inc';
class HelperTooltipTest extends \PhraseanetPHPUnitAuthenticatedAbstract
{
/**
* @var Tooltip
*/
protected $object;
public function setUp()
{
parent::setUp();
}
public function testFooBar()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
}

View File

@@ -11,7 +11,7 @@ class AutoloaderTest extends \PhraseanetPHPUnitAbstract
public function testFindFile() public function testFindFile()
{ {
$testClassName = 'Test_Hello'; $testClassName = 'Test_Hello';
$autoloader = new Alchemy\Phrasea\Loader\Autoloader(); $autoloader = new Alchemy\Phrasea\Loader\Autoloader();
$autoloader->addPath('fixture', __DIR__ . '/Fixtures'); $autoloader->addPath('fixture', __DIR__ . '/Fixtures');
$autoloader->loadClass($testClassName); $autoloader->loadClass($testClassName);
$this->assertTrue(class_exists($testClassName)); $this->assertTrue(class_exists($testClassName));
@@ -23,7 +23,7 @@ class AutoloaderTest extends \PhraseanetPHPUnitAbstract
public function testAddPath() public function testAddPath()
{ {
$autoloader = new Alchemy\Phrasea\Loader\Autoloader(); $autoloader = new Alchemy\Phrasea\Loader\Autoloader();
$pathNb = count($autoloader->getPaths()); $pathNb = count($autoloader->getPaths());
$autoloader->addPath('fixture', __DIR__ . '/Fixtures'); $autoloader->addPath('fixture', __DIR__ . '/Fixtures');
$this->assertGreaterThan($pathNb, count($autoloader->getPaths())); $this->assertGreaterThan($pathNb, count($autoloader->getPaths()));
$this->assertArrayHasKey('fixture', $autoloader->getPaths()); $this->assertArrayHasKey('fixture', $autoloader->getPaths());
@@ -40,5 +40,4 @@ class AutoloaderTest extends \PhraseanetPHPUnitAbstract
$this->assertArrayHasKey('config', $autoloader->getPaths()); $this->assertArrayHasKey('config', $autoloader->getPaths());
$this->assertArrayHasKey('library', $autoloader->getPaths()); $this->assertArrayHasKey('library', $autoloader->getPaths());
} }
} }

View File

@@ -1,121 +1,87 @@
<?php <?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
*/
require_once __DIR__ . '/../../../PhraseanetPHPUnitAbstract.class.inc'; require_once __DIR__ . '/../../../PhraseanetPHPUnitAbstract.class.inc';
class CacheAutoloaderTest extends \PhraseanetPHPUnitAbstract class CacheAutoloaderTest extends \PhraseanetPHPUnitAbstract
{ {
private $apc = false;
private $xcache = false;
private $apc = false; public function setUp()
private $xcache = false;
public function setUp()
{
parent::setUp();
if (extension_loaded('apc'))
{ {
$this->apc = true; parent::setUp();
if (extension_loaded('apc')) {
$this->apc = true;
}
if (extension_loaded('xcache')) {
$this->xcache = true;
}
} }
if (extension_loaded('xcache')) public function testConstruct()
{ {
$this->xcache = true; if ( ! $this->apc && ! $this->xcache) {
} try {
} $autoloader = new Alchemy\Phrasea\Loader\CacheAutoloader('test_prefix_');
$this->fail("should raise an exception");
} catch (\Exception $e) {
public function testConstruct() }
{ }
if (!$this->apc && !$this->xcache) }
public function testFindFileApc()
{ {
try if ($this->apc) {
{ if ( ! (ini_get('apc.enabled') && ini_get('apc.enable_cli'))) {
$autoloader = new Alchemy\Phrasea\Loader\CacheAutoloader('test_prefix_'); $this->markTestSkipped('The apc extension is available, but not enabled.');
$this->fail("should raise an exception"); } else {
} apc_clear_cache('user');
catch(\Exception $e) }
{
} $autoloader = new Alchemy\Phrasea\Loader\CacheAutoloader('test_prefix_');
$cacheAdapter = $autoloader->getAdapter();
$this->assertEquals($autoloader->findFile('Test_HelloCache'), $cacheAdapter->fetch('test_prefix_Test_Hello'));
}
} }
}
public function testFindFileApc() public function testGetPrefix()
{
if ($this->apc)
{ {
if (!(ini_get('apc.enabled') && ini_get('apc.enable_cli'))) if ($this->apc) {
{ $autoloader = new Alchemy\Phrasea\Loader\CacheAutoloader('test_prefix_');
$this->markTestSkipped('The apc extension is available, but not enabled.'); $this->assertEquals('test_prefix_', $autoloader->getPrefix());
} }
else
{
apc_clear_cache('user');
}
$autoloader = new Alchemy\Phrasea\Loader\CacheAutoloader('test_prefix_');
$cacheAdapter = $autoloader->getAdapter();
$this->assertEquals($autoloader->findFile('Test_HelloCache'), $cacheAdapter->fetch('test_prefix_Test_Hello'));
} }
}
public function testGetPrefix() public function testRegister()
{
if ($this->apc)
{ {
$autoloader = new Alchemy\Phrasea\Loader\CacheAutoloader('test_prefix_'); if ($this->apc) {
$this->assertEquals('test_prefix_', $autoloader->getPrefix()); if ( ! (ini_get('apc.enabled') && ini_get('apc.enable_cli'))) {
$this->markTestSkipped('The apc extension is available, but not enabled.');
} else {
apc_clear_cache('user');
}
$autoloader = new Alchemy\Phrasea\Loader\CacheAutoloader('test_prefix_');
$autoloader->addPath('fixture', __DIR__ . '/Fixtures');
$autoloader->register();
$this->assertTrue(class_exists("Test_test"));
}
} }
}
public function testRegister() public function testFindFileXcache()
{
if ($this->apc)
{ {
if (!(ini_get('apc.enabled') && ini_get('apc.enable_cli'))) if ($this->xcache) {
{ $this->marktestSkipped("can't use xcache in cli mode");
$this->markTestSkipped('The apc extension is available, but not enabled.'); }
}
else
{
apc_clear_cache('user');
}
$autoloader = new Alchemy\Phrasea\Loader\CacheAutoloader('test_prefix_');
$autoloader->addPath('fixture', __DIR__ . '/Fixtures');
$autoloader->register();
$this->assertTrue(class_exists("Test_test"));
} }
}
public function testFindFileXcache() public function tearDown()
{
if ($this->xcache)
{ {
$this->marktestSkipped("can't use xcache in cli mode"); if (ini_get('apc.enabled') && ini_get('apc.enable_cli')) {
apc_clear_cache('user');
}
parent::tearDown();
} }
}
public function tearDown()
{
if (ini_get('apc.enabled') && ini_get('apc.enable_cli'))
{
apc_clear_cache('user');
}
parent::tearDown();
}
} }

View File

@@ -1,21 +1,5 @@
<?php <?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
*/
class Test_hello class Test_hello
{ {

View File

@@ -1,21 +1,5 @@
<?php <?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
*/
class HelloCache class HelloCache
{ {

View File

@@ -1,21 +1,5 @@
<?php <?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
*/
class Test_test class Test_test
{ {

View File

@@ -4,7 +4,6 @@ namespace Alchemy\Phrasea\Media\Subdef;
class AudioTest extends \PHPUnit_Framework_TestCase class AudioTest extends \PHPUnit_Framework_TestCase
{ {
/** /**
* @var Audio * @var Audio
*/ */
@@ -38,5 +37,4 @@ class AudioTest extends \PHPUnit_Framework_TestCase
{ {
$this->assertInstanceOf('\\MediaAlchemyst\\Specification\\Audio', $this->object->getMediaAlchemystSpec()); $this->assertInstanceOf('\\MediaAlchemyst\\Specification\\Audio', $this->object->getMediaAlchemystSpec());
} }
} }

View File

@@ -4,7 +4,6 @@ namespace Alchemy\Phrasea\Media\Subdef;
class FlexPaperTest extends \PHPUnit_Framework_TestCase class FlexPaperTest extends \PHPUnit_Framework_TestCase
{ {
/** /**
* @var FlexPaper * @var FlexPaper
*/ */
@@ -38,5 +37,4 @@ class FlexPaperTest extends \PHPUnit_Framework_TestCase
{ {
$this->assertInstanceOf('\\MediaAlchemyst\\Specification\\Flash', $this->object->getMediaAlchemystSpec()); $this->assertInstanceOf('\\MediaAlchemyst\\Specification\\Flash', $this->object->getMediaAlchemystSpec());
} }
} }

View File

@@ -4,7 +4,6 @@ namespace Alchemy\Phrasea\Media\Subdef;
class GifTest extends \PHPUnit_Framework_TestCase class GifTest extends \PHPUnit_Framework_TestCase
{ {
/** /**
* @var Gif * @var Gif
*/ */
@@ -38,5 +37,4 @@ class GifTest extends \PHPUnit_Framework_TestCase
{ {
$this->assertInstanceOf('\\MediaAlchemyst\\Specification\\Animation', $this->object->getMediaAlchemystSpec()); $this->assertInstanceOf('\\MediaAlchemyst\\Specification\\Animation', $this->object->getMediaAlchemystSpec());
} }
} }

View File

@@ -4,7 +4,6 @@ namespace Alchemy\Phrasea\Media\Subdef;
class ImageTest extends \PHPUnit_Framework_TestCase class ImageTest extends \PHPUnit_Framework_TestCase
{ {
/** /**
* @var Image * @var Image
*/ */
@@ -38,5 +37,4 @@ class ImageTest extends \PHPUnit_Framework_TestCase
{ {
$this->assertInstanceOf('\\MediaAlchemyst\\Specification\\Image', $this->object->getMediaAlchemystSpec()); $this->assertInstanceOf('\\MediaAlchemyst\\Specification\\Image', $this->object->getMediaAlchemystSpec());
} }
} }

View File

@@ -4,7 +4,6 @@ namespace Alchemy\Phrasea\Media\Subdef\OptionType;
class BooleanTest extends \PHPUnit_Framework_TestCase class BooleanTest extends \PHPUnit_Framework_TestCase
{ {
/** /**
* @var Boolean * @var Boolean
*/ */
@@ -49,5 +48,4 @@ class BooleanTest extends \PHPUnit_Framework_TestCase
{ {
$this->assertEquals('Booleen', $this->object->getDisplayName()); $this->assertEquals('Booleen', $this->object->getDisplayName());
} }
} }

View File

@@ -4,7 +4,6 @@ namespace Alchemy\Phrasea\Media\Subdef\OptionType;
class EnumTest extends \PHPUnit_Framework_TestCase class EnumTest extends \PHPUnit_Framework_TestCase
{ {
/** /**
* @var Enum * @var Enum
*/ */
@@ -68,5 +67,4 @@ class EnumTest extends \PHPUnit_Framework_TestCase
{ {
$this->assertEquals('Numo', $this->object->getDisplayName()); $this->assertEquals('Numo', $this->object->getDisplayName());
} }
} }

View File

@@ -4,7 +4,6 @@ namespace Alchemy\Phrasea\Media\Subdef\OptionType;
class RangeTest extends \PHPUnit_Framework_TestCase class RangeTest extends \PHPUnit_Framework_TestCase
{ {
/** /**
* @var Range * @var Range
*/ */
@@ -88,5 +87,4 @@ class RangeTest extends \PHPUnit_Framework_TestCase
{ {
$this->assertEquals('Rangers', $this->object->getDisplayName()); $this->assertEquals('Rangers', $this->object->getDisplayName());
} }
} }

View File

@@ -4,7 +4,6 @@ namespace Alchemy\Phrasea\Media\Subdef;
class ProviderTest extends \PHPUnit_Framework_TestCase class ProviderTest extends \PHPUnit_Framework_TestCase
{ {
/** /**
* @var Provider * @var Provider
*/ */
@@ -22,8 +21,7 @@ class ProviderTest extends \PHPUnit_Framework_TestCase
{ {
$this->assertTrue(is_array($this->object->getOptions())); $this->assertTrue(is_array($this->object->getOptions()));
foreach ($this->object->getOptions() as $option) foreach ($this->object->getOptions() as $option) {
{
$this->assertInstanceOf('\\Alchemy\\Phrasea\\Media\\Subdef\\OptionType\\OptionType', $option); $this->assertInstanceOf('\\Alchemy\\Phrasea\\Media\\Subdef\\OptionType\\OptionType', $option);
} }
} }
@@ -48,5 +46,4 @@ class ProviderTest extends \PHPUnit_Framework_TestCase
$option = $this->object->getOption(Image::OPTION_SIZE); $option = $this->object->getOption(Image::OPTION_SIZE);
$this->assertEquals(300, $option->getValue()); $this->assertEquals(300, $option->getValue());
} }
} }

View File

@@ -4,7 +4,6 @@ namespace Alchemy\Phrasea\Media\Subdef;
class VideoTest extends \PHPUnit_Framework_TestCase class VideoTest extends \PHPUnit_Framework_TestCase
{ {
/** /**
* @var Video * @var Video
*/ */
@@ -38,5 +37,4 @@ class VideoTest extends \PHPUnit_Framework_TestCase
{ {
$this->assertInstanceOf('\\MediaAlchemyst\\Specification\\Video', $this->object->getMediaAlchemystSpec()); $this->assertInstanceOf('\\MediaAlchemyst\\Specification\\Video', $this->object->getMediaAlchemystSpec());
} }
} }

View File

@@ -4,88 +4,81 @@ require_once __DIR__ . '/../../../../PhraseanetPHPUnitAbstract.class.inc';
class UserProviderTest extends \PhraseanetPHPUnitAbstract class UserProviderTest extends \PhraseanetPHPUnitAbstract
{ {
/**
* @var UserProvider
*/
protected $object;
/** public function setUp()
* @var UserProvider
*/
protected $object;
public function setUp()
{
$this->object = new \Alchemy\Phrasea\Vocabulary\ControlProvider\UserProvider();
}
/**
* Verify that Type is scalar and that the classname is like {Type}Provider
*/
public function testGetType()
{
$type = $this->object->getType();
$this->assertTrue(is_scalar($type));
$classname = array_pop(explode('\\', get_class($this->object)));
$this->assertEquals($classname, $type . 'Provider');
}
public function testGetName()
{
$this->assertTrue(is_scalar($this->object->getName()));
}
public function testFind()
{
$results = $this->object->find('BABE', self::$user, self::$collection->get_databox());
$this->assertInstanceOf('\\Doctrine\\Common\\Collections\\ArrayCollection', $results);
$results = $this->object->find(self::$user->get_email(), self::$user, self::$collection->get_databox());
$this->assertInstanceOf('\\Doctrine\\Common\\Collections\\ArrayCollection', $results);
$this->assertTrue($results->count() > 0);
$results = $this->object->find(self::$user->get_firstname(), self::$user, self::$collection->get_databox());
$this->assertInstanceOf('\\Doctrine\\Common\\Collections\\ArrayCollection', $results);
$this->assertTrue($results->count() > 0);
$results = $this->object->find(self::$user->get_lastname(), self::$user, self::$collection->get_databox());
$this->assertInstanceOf('\\Doctrine\\Common\\Collections\\ArrayCollection', $results);
$this->assertTrue($results->count() > 0);
}
public function testValidate()
{
$this->assertFalse($this->object->validate(-200));
$this->assertFalse($this->object->validate('A'));
$this->assertTrue($this->object->validate(self::$user->get_id()));
}
public function testGetValue()
{
try
{ {
$this->object->getValue(-200); parent::setUp();
$this->fail('Should raise an exception'); $this->object = new \Alchemy\Phrasea\Vocabulary\ControlProvider\UserProvider();
}
catch(\Exception $e)
{
} }
try /**
{ * Verify that Type is scalar and that the classname is like {Type}Provider
$this->object->getValue('A'); */
$this->fail('Should raise an exception'); public function testGetType()
}
catch(\Exception $e)
{ {
$type = $this->object->getType();
$this->assertTrue(is_scalar($type));
$classname = array_pop(explode('\\', get_class($this->object)));
$this->assertEquals($classname, $type . 'Provider');
} }
$this->assertEquals(self::$user->get_display_name(), $this->object->getValue(self::$user->get_id())); public function testGetName()
} {
$this->assertTrue(is_scalar($this->object->getName()));
}
public function testFind()
{
$results = $this->object->find('BABE', self::$user, self::$collection->get_databox());
$this->assertInstanceOf('\\Doctrine\\Common\\Collections\\ArrayCollection', $results);
$results = $this->object->find(self::$user->get_email(), self::$user, self::$collection->get_databox());
$this->assertInstanceOf('\\Doctrine\\Common\\Collections\\ArrayCollection', $results);
$this->assertTrue($results->count() > 0);
$results = $this->object->find(self::$user->get_firstname(), self::$user, self::$collection->get_databox());
$this->assertInstanceOf('\\Doctrine\\Common\\Collections\\ArrayCollection', $results);
$this->assertTrue($results->count() > 0);
$results = $this->object->find(self::$user->get_lastname(), self::$user, self::$collection->get_databox());
$this->assertInstanceOf('\\Doctrine\\Common\\Collections\\ArrayCollection', $results);
$this->assertTrue($results->count() > 0);
}
public function testValidate()
{
$this->assertFalse($this->object->validate(-200));
$this->assertFalse($this->object->validate('A'));
$this->assertTrue($this->object->validate(self::$user->get_id()));
}
public function testGetValue()
{
try {
$this->object->getValue(-200);
$this->fail('Should raise an exception');
} catch (\Exception $e) {
}
try {
$this->object->getValue('A');
$this->fail('Should raise an exception');
} catch (\Exception $e) {
}
$this->assertEquals(self::$user->get_display_name(), $this->object->getValue(self::$user->get_id()));
}
} }

View File

@@ -5,33 +5,28 @@ require_once __DIR__ . '/../../../PhraseanetPHPUnitAbstract.class.inc';
class ControllerTest extends \PhraseanetPHPUnitAbstract class ControllerTest extends \PhraseanetPHPUnitAbstract
{ {
public function testGet() public function testGet()
{
$provider = \Alchemy\Phrasea\Vocabulary\Controller::get('User');
$this->assertInstanceOf('\\Alchemy\\Phrasea\\Vocabulary\\ControlProvider\\UserProvider', $provider);
try
{ {
$provider = \Alchemy\Phrasea\Vocabulary\Controller::get('Zebulon'); $provider = \Alchemy\Phrasea\Vocabulary\Controller::get('User');
$this->fail('Should raise an exception');
$this->assertInstanceOf('\\Alchemy\\Phrasea\\Vocabulary\\ControlProvider\\UserProvider', $provider);
try {
$provider = \Alchemy\Phrasea\Vocabulary\Controller::get('Zebulon');
$this->fail('Should raise an exception');
} catch (\Exception $e) {
}
} }
catch(\Exception $e)
public function testGetAvailable()
{ {
$available = \Alchemy\Phrasea\Vocabulary\Controller::getAvailable();
$this->assertTrue(is_array($available));
foreach ($available as $controller) {
$this->assertInstanceOf('\\Alchemy\\Phrasea\\Vocabulary\\ControlProvider\\ControlProviderInterface', $controller);
}
} }
}
public function testGetAvailable()
{
$available = \Alchemy\Phrasea\Vocabulary\Controller::getAvailable();
$this->assertTrue(is_array($available));
foreach($available as $controller)
{
$this->assertInstanceOf('\\Alchemy\\Phrasea\\Vocabulary\\ControlProvider\\ControlProviderInterface', $controller);
}
}
} }

View File

@@ -6,65 +6,64 @@ use \Alchemy\Phrasea\Vocabulary\Term;
class TermTest extends \PhraseanetPHPUnitAbstract class TermTest extends \PhraseanetPHPUnitAbstract
{ {
/**
* @var Term
*/
protected $object;
/** /**
* @var Term * @var Term
*/ */
protected $object; protected $basicObject;
/** /**
* @var Term * @var Term
*/ */
protected $basicObject; protected $objectWithControl;
protected $value2 = 'Supa valu&é"\'(§è!)';
/** protected $context2 = 'context
* @var Term
*/
protected $objectWithControl;
protected $value2 = 'Supa valu&é"\'(§è!)';
protected $context2 = 'context
oualibi'; oualibi';
protected $basicValue = 'Joli chien'; protected $basicValue = 'Joli chien';
protected $value = 'One value'; protected $value = 'One value';
protected $context = 'Another context'; protected $context = 'Another context';
protected $control; protected $control;
protected $id = 25; protected $id = 25;
public function setUp() public function setUp()
{ {
$this->control = new Alchemy\Phrasea\Vocabulary\ControlProvider\UserProvider(); parent::setUp();
$this->control = new Alchemy\Phrasea\Vocabulary\ControlProvider\UserProvider();
$this->object = new Term($this->value, $this->context); $this->object = new Term($this->value, $this->context);
$this->basicObject = new Term($this->basicValue); $this->basicObject = new Term($this->basicValue);
$this->objectWithControl = new Term($this->value2, $this->context2, $this->control, $this->id); $this->objectWithControl = new Term($this->value2, $this->context2, $this->control, $this->id);
} }
public function testGetValue() public function testGetValue()
{ {
$this->assertEquals($this->basicValue, $this->basicObject->getValue()); $this->assertEquals($this->basicValue, $this->basicObject->getValue());
$this->assertEquals($this->value, $this->object->getValue()); $this->assertEquals($this->value, $this->object->getValue());
$this->assertEquals($this->value2, $this->objectWithControl->getValue()); $this->assertEquals($this->value2, $this->objectWithControl->getValue());
} }
public function testGetContext() public function testGetContext()
{ {
$this->assertEquals(null, $this->basicObject->getContext()); $this->assertEquals(null, $this->basicObject->getContext());
$this->assertEquals($this->context, $this->object->getContext()); $this->assertEquals($this->context, $this->object->getContext());
$this->assertEquals($this->context2, $this->objectWithControl->getContext()); $this->assertEquals($this->context2, $this->objectWithControl->getContext());
} }
public function testGetType() public function testGetType()
{ {
$this->assertEquals(null, $this->basicObject->getType()); $this->assertEquals(null, $this->basicObject->getType());
$this->assertEquals(null, $this->object->getType()); $this->assertEquals(null, $this->object->getType());
$this->assertEquals($this->control, $this->objectWithControl->getType()); $this->assertEquals($this->control, $this->objectWithControl->getType());
} }
public function testGetId()
{
$this->assertEquals(null, $this->basicObject->getId());
$this->assertEquals(null, $this->object->getId());
$this->assertEquals($this->id, $this->objectWithControl->getId());
}
public function testGetId()
{
$this->assertEquals(null, $this->basicObject->getId());
$this->assertEquals(null, $this->object->getId());
$this->assertEquals($this->id, $this->objectWithControl->getId());
}
} }

View File

@@ -6,12 +6,11 @@ require_once __DIR__ . '/../../Bridge_datas.inc';
class Bridge_Api_Auth_AbstractTest extends PHPUnit_Framework_TestCase class Bridge_Api_Auth_AbstractTest extends PHPUnit_Framework_TestCase
{ {
public function testSet_settings() public function testSet_settings()
{ {
$stub = $this->getMockForAbstractClass('Bridge_Api_Auth_Abstract'); $stub = $this->getMockForAbstractClass('Bridge_Api_Auth_Abstract');
$setting = $this->getMock("Bridge_AccountSettings", array(), array(), '' , false); $setting = $this->getMock("Bridge_AccountSettings", array(), array(), '', false);
$return = $stub->set_settings($setting); $return = $stub->set_settings($setting);
$this->assertEquals($stub, $return); $this->assertEquals($stub, $return);
} }
} }

View File

@@ -5,172 +5,170 @@ require_once __DIR__ . '/../../Bridge_datas.inc';
class Bridge_Api_Auth_FlickrTest extends PHPUnit_Framework_TestCase class Bridge_Api_Auth_FlickrTest extends PHPUnit_Framework_TestCase
{ {
/**
* @var Bridge_Api_Auth_Flickr
*/
protected $object;
/** public function setUp()
* @var Bridge_Api_Auth_Flickr {
*/ $this->object = new Bridge_Api_Auth_Flickr();
protected $object; }
public function setUp() public function testParse_request_token()
{ {
$this->object = new Bridge_Api_Auth_Flickr(); $this->assertNull($this->object->parse_request_token());
} $_GET["frob"] = "123";
$this->assertEquals("123", $this->object->parse_request_token());
unset($_GET["frob"]);
$this->assertNull($this->object->parse_request_token());
}
public function testParse_request_token() public function testConnect()
{ {
$this->assertNull($this->object->parse_request_token()); $api = $this->getMock("Phlickr_Api", array(), array(), "", false);
$_GET["frob"] = "123"; //mock api method
$this->assertEquals("123", $this->object->parse_request_token()); $api->expects($this->once())
unset($_GET["frob"]);
$this->assertNull($this->object->parse_request_token());
}
public function testConnect()
{
$api = $this->getMock("Phlickr_Api", array(), array(), "", false);
//mock api method
$api->expects($this->once())
->method("setAuthTokenFromFrob") ->method("setAuthTokenFromFrob")
->will($this->returnValue("un_token")); ->will($this->returnValue("un_token"));
$api->expects($this->once()) $api->expects($this->once())
->method("setAuthToken") ->method("setAuthToken")
->with($this->equalTo("un_token")); ->with($this->equalTo("un_token"));
$api->expects($this->once()) $api->expects($this->once())
->method("isAuthValid") ->method("isAuthValid")
->will($this->returnValue(true)); ->will($this->returnValue(true));
$stub = $this->getMock("Bridge_Api_Auth_Flickr", array("get_api")); $stub = $this->getMock("Bridge_Api_Auth_Flickr", array("get_api"));
$stub->expects($this->any()) $stub->expects($this->any())
->method("get_api") ->method("get_api")
->will($this->returnValue($api)); ->will($this->returnValue($api));
$return = $stub->connect("123"); $return = $stub->connect("123");
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY, $return); $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY, $return);
$this->assertArrayHasKey("auth_token", $return); $this->assertArrayHasKey("auth_token", $return);
$this->assertEquals("un_token", $return["auth_token"]); $this->assertEquals("un_token", $return["auth_token"]);
} }
public function testBadConnect() public function testBadConnect()
{ {
$api = $this->getMock("Phlickr_Api", array(), array(), "", false); $api = $this->getMock("Phlickr_Api", array(), array(), "", false);
//mock api method //mock api method
$api->expects($this->once()) $api->expects($this->once())
->method("setAuthTokenFromFrob") ->method("setAuthTokenFromFrob")
->will($this->returnValue("un_token")); ->will($this->returnValue("un_token"));
$api->expects($this->once()) $api->expects($this->once())
->method("isAuthValid") ->method("isAuthValid")
->will($this->returnValue(false)); ->will($this->returnValue(false));
$stub = $this->getMock("Bridge_Api_Auth_Flickr", array("get_api")); $stub = $this->getMock("Bridge_Api_Auth_Flickr", array("get_api"));
$stub->expects($this->any()) $stub->expects($this->any())
->method("get_api") ->method("get_api")
->will($this->returnValue($api)); ->will($this->returnValue($api));
$this->setExpectedException("Bridge_Exception_ApiConnectorAccessTokenFailed"); $this->setExpectedException("Bridge_Exception_ApiConnectorAccessTokenFailed");
$return = $stub->connect("123"); $return = $stub->connect("123");
} }
public function testReconnect() public function testReconnect()
{ {
$this->assertEquals($this->object, $this->object->reconnect()); $this->assertEquals($this->object, $this->object->reconnect());
} }
public function testDisconnect() public function testDisconnect()
{ {
$setting = $this->getMock("Bridge_AccountSettings", array("set"), array(), "", false); $setting = $this->getMock("Bridge_AccountSettings", array("set"), array(), "", false);
$setting->expects($this->once()) $setting->expects($this->once())
->method("set") ->method("set")
->with($this->equalTo("auth_token"), $this->isNull()); ->with($this->equalTo("auth_token"), $this->isNull());
$this->object->set_settings($setting); $this->object->set_settings($setting);
$return = $this->object->disconnect(); $return = $this->object->disconnect();
$this->assertEquals($this->object, $return); $this->assertEquals($this->object, $return);
} }
public function testIs_connected() public function testIs_connected()
{ {
$setting = $this->getMock("Bridge_AccountSettings", array("get"), array(), "", false); $setting = $this->getMock("Bridge_AccountSettings", array("get"), array(), "", false);
$setting->expects($this->any()) $setting->expects($this->any())
->method("get") ->method("get")
->with($this->equalTo("auth_token")) ->with($this->equalTo("auth_token"))
->will($this->onConsecutiveCalls("123456", 123456, null)); ->will($this->onConsecutiveCalls("123456", 123456, null));
$this->object->set_settings($setting); $this->object->set_settings($setting);
$this->assertTrue($this->object->is_connected()); $this->assertTrue($this->object->is_connected());
$this->assertTrue($this->object->is_connected()); $this->assertTrue($this->object->is_connected());
$this->assertFalse($this->object->is_connected()); $this->assertFalse($this->object->is_connected());
} }
public function testGet_auth_signatures() public function testGet_auth_signatures()
{ {
$setting = $this->getMock("Bridge_AccountSettings", array("get"), array(), "", false); $setting = $this->getMock("Bridge_AccountSettings", array("get"), array(), "", false);
$setting->expects($this->once()) $setting->expects($this->once())
->method("get") ->method("get")
->with($this->equalTo("auth_token")) ->with($this->equalTo("auth_token"))
->will($this->returnValue("123")); ->will($this->returnValue("123"));
$this->object->set_settings($setting); $this->object->set_settings($setting);
$return = $this->object->get_auth_signatures(); $return = $this->object->get_auth_signatures();
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY, $return); $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY, $return);
$this->assertArrayHasKey("auth_token", $return); $this->assertArrayHasKey("auth_token", $return);
$this->assertEquals("123", $return["auth_token"]); $this->assertEquals("123", $return["auth_token"]);
} }
public function testSet_parameters() public function testSet_parameters()
{ {
$parameters = array( $parameters = array(
"caca" => "boudain" "caca" => "boudain"
, "sirop" => "fraise" , "sirop" => "fraise"
, "choco" => "banane" , "choco" => "banane"
, "pirouette" => "cacahuete" , "pirouette" => "cacahuete"
); );
$return = $this->object->set_parameters($parameters); $return = $this->object->set_parameters($parameters);
$this->assertEquals(0, sizeof(get_object_vars($this->object))); $this->assertEquals(0, sizeof(get_object_vars($this->object)));
$this->assertEquals($return, $this->object); $this->assertEquals($return, $this->object);
} }
public function testGet_auth_url() public function testGet_auth_url()
{ {
$api = $this->getMock("Phlickr_Api", array(), array(), "", false); $api = $this->getMock("Phlickr_Api", array(), array(), "", false);
//mock api method //mock api method
$api->expects($this->any()) $api->expects($this->any())
->method("requestFrob") ->method("requestFrob")
->will($this->returnValue("un_token")); ->will($this->returnValue("un_token"));
$api->expects($this->any()) $api->expects($this->any())
->method("buildAuthUrl") ->method("buildAuthUrl")
->with($this->equalTo("write"), $this->equalTo("un_token")) ->with($this->equalTo("write"), $this->equalTo("un_token"))
->will($this->returnValue("une_super_url")); ->will($this->returnValue("une_super_url"));
$stub = $this->getMock("Bridge_Api_Auth_Flickr", array("get_api")); $stub = $this->getMock("Bridge_Api_Auth_Flickr", array("get_api"));
$stub->expects($this->any()) $stub->expects($this->any())
->method("get_api") ->method("get_api")
->will($this->returnValue($api)); ->will($this->returnValue($api));
$params = array("permissions" => "write"); $params = array("permissions" => "write");
$stub->set_parameters($params); $stub->set_parameters($params);
$this->assertEquals("une_super_url", $stub->get_auth_url());
$this->assertEquals("une_super_url", $stub->get_auth_url($params));
}
$this->assertEquals("une_super_url", $stub->get_auth_url());
$this->assertEquals("une_super_url", $stub->get_auth_url($params));
}
} }

View File

@@ -5,138 +5,135 @@ require_once __DIR__ . '/../../Bridge_datas.inc';
class Bridge_Api_Auth_OAuth2Test extends PHPUnit_Framework_TestCase class Bridge_Api_Auth_OAuth2Test extends PHPUnit_Framework_TestCase
{ {
/**
* @var Bridge_Api_Auth_OAuth2
*/
protected $object;
protected $parameters;
/** public function setUp()
* @var Bridge_Api_Auth_OAuth2 {
*/ $this->object = new Bridge_Api_Auth_OAuth2();
protected $object;
protected $parameters;
public function setUp() $this->parameters = array(
{ 'client_id' => "client_id"
$this->object = new Bridge_Api_Auth_OAuth2(); , 'client_secret' => "client_secret"
, 'redirect_uri' => "redirect_uri"
, 'scope' => 'super_scope'
, 'response_type' => 'code'
, 'token_endpoint' => "one_token_endpoint"
, 'auth_endpoint' => "one_auth_endpoint"
);
}
$this->parameters = array( public function testParse_request_token()
'client_id' => "client_id" {
, 'client_secret' => "client_secret" $this->object->set_parameters($this->parameters);
, 'redirect_uri' => "redirect_uri" $_GET = array("code" => "12345");
, 'scope' => 'super_scope' $token = $this->object->parse_request_token();
, 'response_type' => 'code' $this->assertEquals("12345", $token);
, 'token_endpoint' => "one_token_endpoint" $this->parameters["response_type"] = "blabla";
, 'auth_endpoint' => "one_auth_endpoint" $this->object->set_parameters($this->parameters);
); $this->assertNull($this->object->parse_request_token());
} }
public function testConnect()
{
$this->setExpectedException("Bridge_Exception_ApiConnectorAccessTokenFailed");
public function testParse_request_token() $this->object->connect("123");
{ }
$this->object->set_parameters($this->parameters);
$_GET = array("code" => "12345");
$token = $this->object->parse_request_token();
$this->assertEquals("12345", $token);
$this->parameters["response_type"] = "blabla";
$this->object->set_parameters($this->parameters);
$this->assertNull($this->object->parse_request_token());
}
public function testConnect() public function testReconnect()
{ {
$this->setExpectedException("Bridge_Exception_ApiConnectorAccessTokenFailed"); $setting = $this->getMock("Bridge_AccountSettings", array("get"), array(), "", false);
$this->object->connect("123"); $setting->expects($this->once())
}
public function testReconnect()
{
$setting = $this->getMock("Bridge_AccountSettings", array("get"), array(), "", false);
$setting->expects($this->once())
->method("get") ->method("get")
->with($this->equalTo("refresh_token")) ->with($this->equalTo("refresh_token"))
->will($this->returnValue("123")); ->will($this->returnValue("123"));
$this->object->set_settings($setting); $this->object->set_settings($setting);
$this->setExpectedException("Bridge_Exception_ApiConnectorAccessTokenFailed"); $this->setExpectedException("Bridge_Exception_ApiConnectorAccessTokenFailed");
$this->object->reconnect(); $this->object->reconnect();
} }
public function testDisconnect() public function testDisconnect()
{ {
$setting = $this->getMock("Bridge_AccountSettings", array("set"), array(), "", false); $setting = $this->getMock("Bridge_AccountSettings", array("set"), array(), "", false);
$setting->expects($this->once()) $setting->expects($this->once())
->method("set") ->method("set")
->with($this->equalTo("auth_token"), $this->isNull()); ->with($this->equalTo("auth_token"), $this->isNull());
$this->object->set_settings($setting); $this->object->set_settings($setting);
$return = $this->object->disconnect(); $return = $this->object->disconnect();
$this->assertEquals($this->object, $return); $this->assertEquals($this->object, $return);
} }
public function testIs_connected() public function testIs_connected()
{ {
$setting = $this->getMock("Bridge_AccountSettings", array("get"), array(), "", false); $setting = $this->getMock("Bridge_AccountSettings", array("get"), array(), "", false);
$setting->expects($this->any()) $setting->expects($this->any())
->method("get") ->method("get")
->with($this->equalTo("auth_token")) ->with($this->equalTo("auth_token"))
->will($this->onConsecutiveCalls("123456",123456, null)); ->will($this->onConsecutiveCalls("123456", 123456, null));
$this->object->set_settings($setting); $this->object->set_settings($setting);
$this->assertTrue($this->object->is_connected()); $this->assertTrue($this->object->is_connected());
$this->assertTrue($this->object->is_connected()); $this->assertTrue($this->object->is_connected());
$this->assertFalse($this->object->is_connected()); $this->assertFalse($this->object->is_connected());
} }
public function testGet_auth_signatures() public function testGet_auth_signatures()
{ {
$setting = $this->getMock("Bridge_AccountSettings", array("get"), array(), "", false); $setting = $this->getMock("Bridge_AccountSettings", array("get"), array(), "", false);
$setting->expects($this->once()) $setting->expects($this->once())
->method("get") ->method("get")
->with($this->equalTo("auth_token")) ->with($this->equalTo("auth_token"))
->will($this->returnValue("123")); ->will($this->returnValue("123"));
$this->object->set_settings($setting); $this->object->set_settings($setting);
$return = $this->object->get_auth_signatures(); $return = $this->object->get_auth_signatures();
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY, $return); $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY, $return);
$this->assertArrayHasKey("auth_token", $return); $this->assertArrayHasKey("auth_token", $return);
$this->assertEquals("123" , $return["auth_token"]); $this->assertEquals("123", $return["auth_token"]);
} }
public function testSet_parameters() public function testSet_parameters()
{ {
$parameters = array( $parameters = array(
"client_id" => "cid" "client_id" => "cid"
,"allo"=>"hello" , "allo" => "hello"
,"yo" => "coucou" , "yo" => "coucou"
,"response_type" => "hihi" , "response_type" => "hihi"
); );
$return = $this->object->set_parameters($parameters); $return = $this->object->set_parameters($parameters);
$this->assertEquals(0 , sizeof(get_object_vars($this->object))); $this->assertEquals(0, sizeof(get_object_vars($this->object)));
$this->assertEquals($return, $this->object); $this->assertEquals($return, $this->object);
} }
public function testGet_auth_url() public function testGet_auth_url()
{ {
$this->object->set_parameters($this->parameters); $this->object->set_parameters($this->parameters);
$expected_url = "one_auth_endpoint?response_type=code&client_id=client_id&redirect_uri=redirect_uri&scope=super_scope"; $expected_url = "one_auth_endpoint?response_type=code&client_id=client_id&redirect_uri=redirect_uri&scope=super_scope";
$this->assertEquals($expected_url, $this->object->get_auth_url()); $this->assertEquals($expected_url, $this->object->get_auth_url());
$more_params = array("test" => "test"); $more_params = array("test" => "test");
$this->assertEquals($expected_url."&test=test", $this->object->get_auth_url($more_params)); $this->assertEquals($expected_url . "&test=test", $this->object->get_auth_url($more_params));
$more_params = array("response_type" => "test");
$this->assertNotEquals($expected_url, $this->object->get_auth_url($more_params));
}
$more_params = array("response_type" => "test");
$this->assertNotEquals($expected_url, $this->object->get_auth_url($more_params));
}
} }

View File

@@ -5,175 +5,123 @@ require_once __DIR__ . '/../Bridge_datas.inc';
class Bridge_Api_AbstractCollectionTest extends PHPUnit_Framework_TestCase class Bridge_Api_AbstractCollectionTest extends PHPUnit_Framework_TestCase
{ {
/**
* @var Bridge_Api_AbstractCollection
*/
protected $object;
/** public function testGet_total_items()
* @var Bridge_Api_AbstractCollection {
*/ $stub = $this->getMockForAbstractClass('Bridge_Api_AbstractCollection');
protected $object; $this->assertNull($stub->get_total_items());
$stub->set_total_items("3");
$this->assertEquals(3, $stub->get_total_items());
}
public function setUp() public function testSet_total_items()
{ {
$stub = $this->getMockForAbstractClass('Bridge_Api_AbstractCollection');
$return = $stub->set_total_items("3");
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_INT, $stub->get_total_items());
$this->assertEquals(3, $stub->get_total_items());
$this->assertEquals($return, $stub);
}
} public function testGet_items_per_page()
{
$stub = $this->getMockForAbstractClass('Bridge_Api_AbstractCollection');
$this->assertNull($stub->get_items_per_page());
$stub->set_items_per_page("3");
$this->assertEquals(3, $stub->get_items_per_page());
}
/** public function testSet_items_per_page()
* Tears down the fixture, for example, closes a network connection. {
* This method is called after a test is executed. $stub = $this->getMockForAbstractClass('Bridge_Api_AbstractCollection');
*/ $return = $stub->set_items_per_page("3");
public function tearDown() $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_INT, $stub->get_items_per_page());
{ $this->assertEquals(3, $stub->get_items_per_page());
$this->assertEquals($return, $stub);
}
} public function testGet_current_page()
{
$stub = $this->getMockForAbstractClass('Bridge_Api_AbstractCollection');
$this->assertEquals(1, $stub->get_current_page());
$stub->set_current_page("3");
$this->assertEquals(3, $stub->get_current_page());
}
/** public function testSet_current_page()
* @todo Implement testGet_total_items(). {
*/ $stub = $this->getMockForAbstractClass('Bridge_Api_AbstractCollection');
public function testGet_total_items() $return = $stub->set_current_page("3");
{ $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_INT, $stub->get_current_page());
$stub = $this->getMockForAbstractClass('Bridge_Api_AbstractCollection'); $this->assertEquals(3, $stub->get_current_page());
$this->assertNull($stub->get_total_items()); $this->assertEquals($return, $stub);
$stub->set_total_items("3"); $return = $stub->set_current_page(-4);
$this->assertEquals(3, $stub->get_total_items()); $this->assertEquals(3, $stub->get_current_page());
} }
/** public function testGet_total_page()
* @todo Implement testSet_total_items(). {
*/ $stub = $this->getMockForAbstractClass('Bridge_Api_AbstractCollection');
public function testSet_total_items() $this->assertEquals(1, $stub->get_total_page());
{ $stub->set_total_page("3");
$stub = $this->getMockForAbstractClass('Bridge_Api_AbstractCollection'); $this->assertEquals(3, $stub->get_total_page());
$return = $stub->set_total_items("3"); }
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_INT, $stub->get_total_items());
$this->assertEquals(3, $stub->get_total_items());
$this->assertEquals($return, $stub);
}
/** public function testSet_total_page()
* @todo Implement testGet_items_per_page(). {
*/ $stub = $this->getMockForAbstractClass('Bridge_Api_AbstractCollection');
public function testGet_items_per_page() $return = $stub->set_total_page("3");
{ $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_INT, $stub->get_total_page());
$stub = $this->getMockForAbstractClass('Bridge_Api_AbstractCollection'); $this->assertEquals(3, $stub->get_total_page());
$this->assertNull($stub->get_items_per_page()); $this->assertEquals($return, $stub);
$stub->set_items_per_page("3"); $return = $stub->set_total_page(-4);
$this->assertEquals(3, $stub->get_items_per_page()); $this->assertEquals(3, $stub->get_total_page());
} }
/** public function testHas_next_page()
* @todo Implement testSet_items_per_page(). {
*/ $stub = $this->getMockForAbstractClass('Bridge_Api_AbstractCollection');
public function testSet_items_per_page() $stub->set_current_page(2);
{ $stub->set_total_page(2);
$stub = $this->getMockForAbstractClass('Bridge_Api_AbstractCollection'); $this->assertFalse($stub->has_next_page());
$return = $stub->set_items_per_page("3"); $stub->set_current_page(1);
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_INT, $stub->get_items_per_page()); $stub->set_total_page(2);
$this->assertEquals(3, $stub->get_items_per_page()); $this->assertTrue($stub->has_next_page());
$this->assertEquals($return, $stub); $stub->set_current_page(3);
} $stub->set_total_page(2);
$this->assertFalse($stub->has_next_page());
}
/** public function testHas_previous_page()
* @todo Implement testGet_current_page(). {
*/ $stub = $this->getMockForAbstractClass('Bridge_Api_AbstractCollection');
public function testGet_current_page() $stub->set_current_page(2);
{ $this->assertTrue($stub->has_previous_page());
$stub = $this->getMockForAbstractClass('Bridge_Api_AbstractCollection'); $stub->set_current_page(1);
$this->assertEquals(1, $stub->get_current_page()); $this->assertFalse($stub->has_previous_page());
$stub->set_current_page("3"); $stub->set_current_page(0);
$this->assertEquals(3, $stub->get_current_page()); $this->assertFalse($stub->has_previous_page());
} }
/** public function testHas_more_than_one_page()
* @todo Implement testSet_current_page(). {
*/ $stub = $this->getMockForAbstractClass('Bridge_Api_AbstractCollection');
public function testSet_current_page() $stub->set_total_page(2);
{ $this->assertTrue($stub->has_more_than_one_page());
$stub = $this->getMockForAbstractClass('Bridge_Api_AbstractCollection'); $stub->set_total_page(1);
$return = $stub->set_current_page("3"); $this->assertFalse($stub->has_more_than_one_page());
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_INT, $stub->get_current_page()); $stub->set_total_page(0);
$this->assertEquals(3, $stub->get_current_page()); $this->assertFalse($stub->has_more_than_one_page());
$this->assertEquals($return, $stub); }
$return = $stub->set_current_page(-4);
$this->assertEquals(3, $stub->get_current_page());
}
/**
* @todo Implement testGet_total_page().
*/
public function testGet_total_page()
{
$stub = $this->getMockForAbstractClass('Bridge_Api_AbstractCollection');
$this->assertEquals(1, $stub->get_total_page());
$stub->set_total_page("3");
$this->assertEquals(3, $stub->get_total_page());
}
/**
* @todo Implement testSet_total_page().
*/
public function testSet_total_page()
{
$stub = $this->getMockForAbstractClass('Bridge_Api_AbstractCollection');
$return = $stub->set_total_page("3");
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_INT, $stub->get_total_page());
$this->assertEquals(3, $stub->get_total_page());
$this->assertEquals($return, $stub);
$return = $stub->set_total_page(-4);
$this->assertEquals(3, $stub->get_total_page());
}
/**
* @todo Implement testHas_next_page().
*/
public function testHas_next_page()
{
$stub = $this->getMockForAbstractClass('Bridge_Api_AbstractCollection');
$stub->set_current_page(2);
$stub->set_total_page(2);
$this->assertFalse($stub->has_next_page());
$stub->set_current_page(1);
$stub->set_total_page(2);
$this->assertTrue($stub->has_next_page());
$stub->set_current_page(3);
$stub->set_total_page(2);
$this->assertFalse($stub->has_next_page());
}
/**
* @todo Implement testHas_previous_page().
*/
public function testHas_previous_page()
{
$stub = $this->getMockForAbstractClass('Bridge_Api_AbstractCollection');
$stub->set_current_page(2);
$this->assertTrue($stub->has_previous_page());
$stub->set_current_page(1);
$this->assertFalse($stub->has_previous_page());
$stub->set_current_page(0);
$this->assertFalse($stub->has_previous_page());
}
/**
* @todo Implement testHas_more_than_one_page().
*/
public function testHas_more_than_one_page()
{
$stub = $this->getMockForAbstractClass('Bridge_Api_AbstractCollection');
$stub->set_total_page(2);
$this->assertTrue($stub->has_more_than_one_page());
$stub->set_total_page(1);
$this->assertFalse($stub->has_more_than_one_page());
$stub->set_total_page(0);
$this->assertFalse($stub->has_more_than_one_page());
}
/**
* @todo Implement testGet_elements().
*/
public function testGet_elements()
{
$stub = $this->getMockForAbstractClass('Bridge_Api_AbstractCollection');
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY, $stub->get_elements());
$this->assertEquals(array(), $stub->get_elements());
}
public function testGet_elements()
{
$stub = $this->getMockForAbstractClass('Bridge_Api_AbstractCollection');
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY, $stub->get_elements());
$this->assertEquals(array(), $stub->get_elements());
}
} }

View File

@@ -5,250 +5,202 @@ require_once __DIR__ . '/../Bridge_datas.inc';
class Bridge_Api_AbstractTest extends PhraseanetWebTestCaseAuthenticatedAbstract class Bridge_Api_AbstractTest extends PhraseanetWebTestCaseAuthenticatedAbstract
{ {
public static $account = null;
public static $api = null;
public static $account = null; /**
public static $api = null; * @var Bridge_Api_Abstract
*/
protected $auth;
/** public function setUp()
* @var Bridge_Api_Abstract
*/
protected $auth;
public function setUp()
{
$this->auth = $this->getMock("Bridge_Api_Auth_Interface");
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
public function tearDown()
{
}
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
try
{ {
self::$api = Bridge_Api::get_by_api_name(appbox::get_instance(\bootstrap::getCore()), 'apitest'); parent::setUp();
} $this->auth = $this->getMock("Bridge_Api_Auth_Interface");
catch (Bridge_Exception_ApiNotFound $e)
{
self::$api = Bridge_Api::create(appbox::get_instance(\bootstrap::getCore()), 'apitest');
} }
try public static function setUpBeforeClass()
{ {
self::$account = Bridge_Account::load_account_from_distant_id(appbox::get_instance(\bootstrap::getCore()), self::$api, self::$user, 'kirikoo'); parent::setUpBeforeClass();
try {
self::$api = Bridge_Api::get_by_api_name(appbox::get_instance(\bootstrap::getCore()), 'apitest');
} catch (Bridge_Exception_ApiNotFound $e) {
self::$api = Bridge_Api::create(appbox::get_instance(\bootstrap::getCore()), 'apitest');
}
try {
self::$account = Bridge_Account::load_account_from_distant_id(appbox::get_instance(\bootstrap::getCore()), self::$api, self::$user, 'kirikoo');
} catch (Bridge_Exception_AccountNotFound $e) {
self::$account = Bridge_Account::create(appbox::get_instance(\bootstrap::getCore()), self::$api, self::$user, 'kirikoo', 'coucou');
}
} }
catch (Bridge_Exception_AccountNotFound $e)
public static function tearDownAfterClass()
{ {
self::$account = Bridge_Account::create(appbox::get_instance(\bootstrap::getCore()), self::$api, self::$user, 'kirikoo', 'coucou'); self::$api->delete();
if (self::$account instanceof Bridge_Account) {
self::$account->delete();
}
parent::tearDownAfterClass();
} }
}
public static function tearDownAfterClass() public function testSet_auth_settings()
{ {
parent::tearDownAfterClass(); $stub = $this->getMockForAbstractClass('Bridge_Api_Abstract', array(registry::get_instance(), $this->auth, "Mock_Bridge_Api_Abstract"));
self::$api->delete();
if (self::$account instanceof Bridge_Account)
self::$account->delete();
}
/** $settings = self::$account->get_settings();
* @todo Implement testSet_auth_settings().
*/
public function testSet_auth_settings()
{
$stub = $this->getMockForAbstractClass('Bridge_Api_Abstract', array(registry::get_instance(), $this->auth, "Mock_Bridge_Api_Abstract"));
$settings = self::$account->get_settings(); $stub->expects($this->once())
$stub->expects($this->once())
->method('set_transport_authentication_params'); ->method('set_transport_authentication_params');
$return = $stub->set_auth_settings($settings); $return = $stub->set_auth_settings($settings);
$this->assertEquals($stub, $return); $this->assertEquals($stub, $return);
} }
/** public function testConnectGood()
* @todo Implement testConnect(). {
*/ $stub = $this->getMock('Bridge_Api_Abstract', array("is_configured", "initialize_transport", "set_auth_params", "set_transport_authentication_params"), array(registry::get_instance(), $this->auth, "Mock_Bridge_Api_Abstract"));
public function testConnectGood()
{
$stub = $this->getMock('Bridge_Api_Abstract', array("is_configured", "initialize_transport", "set_auth_params", "set_transport_authentication_params"), array(registry::get_instance(), $this->auth, "Mock_Bridge_Api_Abstract"));
$stub->expects($this->once()) $stub->expects($this->once())
->method('is_configured') ->method('is_configured')
->will($this->returnValue(TRUE)); ->will($this->returnValue(TRUE));
$this->auth->expects($this->once()) $this->auth->expects($this->once())
->method('parse_request_token') ->method('parse_request_token')
->will($this->returnValue("token")); ->will($this->returnValue("token"));
$this->auth->expects($this->once()) $this->auth->expects($this->once())
->method('connect') ->method('connect')
->will($this->returnValue(array("coucou"))); ->will($this->returnValue(array("coucou")));
$return = $stub->connect(); $return = $stub->connect();
$this->assertEquals(array("coucou"), $return); $this->assertEquals(array("coucou"), $return);
} }
public function testConnectBad() public function testConnectBad()
{ {
$stub = $this->getMock('Bridge_Api_Abstract', array("is_configured", "initialize_transport", "set_auth_params", "set_transport_authentication_params"), array(registry::get_instance(), $this->auth, "Mock_Bridge_Api_Abstract")); $stub = $this->getMock('Bridge_Api_Abstract', array("is_configured", "initialize_transport", "set_auth_params", "set_transport_authentication_params"), array(registry::get_instance(), $this->auth, "Mock_Bridge_Api_Abstract"));
$stub->expects($this->once()) $stub->expects($this->once())
->method('is_configured') ->method('is_configured')
->will($this->returnValue(FALSE)); ->will($this->returnValue(FALSE));
$this->setExpectedException("Bridge_Exception_ApiConnectorNotConfigured"); $this->setExpectedException("Bridge_Exception_ApiConnectorNotConfigured");
$stub->connect(); $stub->connect();
} }
/** public function testReconnect()
* @todo Implement testReconnect(). {
*/ $stub = $this->getMock('Bridge_Api_Abstract', array("is_configured", "initialize_transport", "set_auth_params", "set_transport_authentication_params"), array(registry::get_instance(), $this->auth, "Mock_Bridge_Api_Abstract"));
public function testReconnect()
{
$stub = $this->getMock('Bridge_Api_Abstract', array("is_configured", "initialize_transport", "set_auth_params", "set_transport_authentication_params"), array(registry::get_instance(), $this->auth, "Mock_Bridge_Api_Abstract"));
$stub->expects($this->once()) $stub->expects($this->once())
->method('is_configured') ->method('is_configured')
->will($this->returnValue(TRUE)); ->will($this->returnValue(TRUE));
$this->auth->expects($this->once()) $this->auth->expects($this->once())
->method('reconnect'); ->method('reconnect');
$return = $stub->reconnect(); $return = $stub->reconnect();
$this->assertEquals($stub, $return); $this->assertEquals($stub, $return);
} }
/** public function testReconnectBad()
* @todo Implement testReconnect(). {
*/ $stub = $this->getMock('Bridge_Api_Abstract', array("is_configured", "initialize_transport", "set_auth_params", "set_transport_authentication_params"), array(registry::get_instance(), $this->auth, "Mock_Bridge_Api_Abstract"));
public function testReconnectBad()
{
$stub = $this->getMock('Bridge_Api_Abstract', array("is_configured", "initialize_transport", "set_auth_params", "set_transport_authentication_params"), array(registry::get_instance(), $this->auth, "Mock_Bridge_Api_Abstract"));
$stub->expects($this->once()) $stub->expects($this->once())
->method('is_configured') ->method('is_configured')
->will($this->returnValue(FALSE)); ->will($this->returnValue(FALSE));
$this->setExpectedException("Bridge_Exception_ApiConnectorNotConfigured"); $this->setExpectedException("Bridge_Exception_ApiConnectorNotConfigured");
$stub->reconnect(); $stub->reconnect();
} }
/** public function testDisconnect()
* @todo Implement testDisconnect(). {
*/ $stub = $this->getMock('Bridge_Api_Abstract', array("is_configured", "initialize_transport", "set_auth_params", "set_transport_authentication_params"), array(registry::get_instance(), $this->auth, "Mock_Bridge_Api_Abstract"));
public function testDisconnect()
{
$stub = $this->getMock('Bridge_Api_Abstract', array("is_configured", "initialize_transport", "set_auth_params", "set_transport_authentication_params"), array(registry::get_instance(), $this->auth, "Mock_Bridge_Api_Abstract"));
$stub->expects($this->once()) $stub->expects($this->once())
->method('is_configured') ->method('is_configured')
->will($this->returnValue(TRUE)); ->will($this->returnValue(TRUE));
$this->auth->expects($this->once()) $this->auth->expects($this->once())
->method('disconnect'); ->method('disconnect');
$return = $stub->disconnect(); $return = $stub->disconnect();
$this->assertEquals($stub, $return); $this->assertEquals($stub, $return);
} }
/** public function testDisconnectBad()
* @todo Implement testDisconnect(). {
*/ $stub = $this->getMock('Bridge_Api_Abstract', array("is_configured", "initialize_transport", "set_auth_params", "set_transport_authentication_params"), array(registry::get_instance(), $this->auth, "Mock_Bridge_Api_Abstract"));
public function testDisconnectBad()
{
$stub = $this->getMock('Bridge_Api_Abstract', array("is_configured", "initialize_transport", "set_auth_params", "set_transport_authentication_params"), array(registry::get_instance(), $this->auth, "Mock_Bridge_Api_Abstract"));
$stub->expects($this->once()) $stub->expects($this->once())
->method('is_configured') ->method('is_configured')
->will($this->returnValue(FALSE)); ->will($this->returnValue(FALSE));
$this->setExpectedException("Bridge_Exception_ApiConnectorNotConfigured"); $this->setExpectedException("Bridge_Exception_ApiConnectorNotConfigured");
$stub->disconnect(); $stub->disconnect();
} }
/** public function testIs_connected()
* @todo Implement testIs_connected(). {
*/ $stub = $this->getMockForAbstractClass('Bridge_Api_Abstract', array(registry::get_instance(), $this->auth, "Mock_Bridge_Api_Abstract"));
public function testIs_connected()
{
$stub = $this->getMockForAbstractClass('Bridge_Api_Abstract', array(registry::get_instance(), $this->auth, "Mock_Bridge_Api_Abstract"));
$this->auth->expects($this->once()) $this->auth->expects($this->once())
->method('is_connected') ->method('is_connected')
->will($this->returnValue(TRUE)); ->will($this->returnValue(TRUE));
$return = $stub->is_connected(); $return = $stub->is_connected();
$this->assertEquals(TRUE, $return); $this->assertEquals(TRUE, $return);
} }
/** public function testGet_auth_url()
* @todo Implement testGet_auth_url(). {
*/ $stub = $this->getMockForAbstractClass('Bridge_Api_Abstract', array(registry::get_instance(), $this->auth, "Mock_Bridge_Api_Abstract"));
public function testGet_auth_url()
{
$stub = $this->getMockForAbstractClass('Bridge_Api_Abstract', array(registry::get_instance(), $this->auth, "Mock_Bridge_Api_Abstract"));
$this->auth->expects($this->once()) $this->auth->expects($this->once())
->method('get_auth_url') ->method('get_auth_url')
->with($this->isType(PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY)) ->with($this->isType(PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY))
->will($this->returnValue("une url")); ->will($this->returnValue("une url"));
$return = $stub->get_auth_url(); $return = $stub->get_auth_url();
$this->assertEquals("une url", $return); $this->assertEquals("une url", $return);
} }
/** public function testSet_locale()
* @todo Implement testSet_locale(). {
*/ $stub = $this->getMockForAbstractClass('Bridge_Api_Abstract', array(registry::get_instance(), $this->auth, "Mock_Bridge_Api_Abstract"));
public function testSet_locale()
{
$stub = $this->getMockForAbstractClass('Bridge_Api_Abstract', array(registry::get_instance(), $this->auth, "Mock_Bridge_Api_Abstract"));
$stub->set_locale("fr"); $stub->set_locale("fr");
$this->assertEquals("fr", $stub->get_locale()); $this->assertEquals("fr", $stub->get_locale());
} }
/** public function testIs_valid_object_id()
* @todo Implement testIs_valid_object_id(). {
*/ $stub = $this->getMockForAbstractClass('Bridge_Api_Abstract', array(registry::get_instance(), $this->auth, "Mock_Bridge_Api_Abstract"));
public function testIs_valid_object_id()
{
$stub = $this->getMockForAbstractClass('Bridge_Api_Abstract', array(registry::get_instance(), $this->auth, "Mock_Bridge_Api_Abstract"));
$this->assertTrue($stub->is_valid_object_id("abc")); $this->assertTrue($stub->is_valid_object_id("abc"));
$this->assertTrue($stub->is_valid_object_id(123)); $this->assertTrue($stub->is_valid_object_id(123));
$this->assertTrue($stub->is_valid_object_id(12.25)); $this->assertTrue($stub->is_valid_object_id(12.25));
$this->assertFalse($stub->is_valid_object_id(array())); $this->assertFalse($stub->is_valid_object_id(array()));
$this->assertFalse($stub->is_valid_object_id(true)); $this->assertFalse($stub->is_valid_object_id(true));
} }
/**
* @todo Implement testHandle_exception().
*/
public function testHandle_exception()
{
$stub = $this->getMockForAbstractClass('Bridge_Api_Abstract', array(registry::get_instance(), $this->auth, "Mock_Bridge_Api_Abstract"));
$e = new Exception("hihi");
$void = $stub->handle_exception($e);
$this->assertNull($void);
}
public function testHandle_exception()
{
$stub = $this->getMockForAbstractClass('Bridge_Api_Abstract', array(registry::get_instance(), $this->auth, "Mock_Bridge_Api_Abstract"));
$e = new Exception("hihi");
$void = $stub->handle_exception($e);
$this->assertNull($void);
}
} }

View File

@@ -5,17 +5,16 @@ require_once __DIR__ . '/../Bridge_datas.inc';
class Bridge_Api_ContainerCollectionTest extends PHPUnit_Framework_TestCase class Bridge_Api_ContainerCollectionTest extends PHPUnit_Framework_TestCase
{ {
public function testAdd_element()
{
$collection = new Bridge_Api_ContainerCollection();
$i = 0;
while($i < 5)
{
$container = $this->getMock("Bridge_Api_ContainerInterface");
$collection->add_element(new $container);
$i++;
}
$this->assertEquals(5, sizeof($collection->get_elements()));
}
public function testAdd_element()
{
$collection = new Bridge_Api_ContainerCollection();
$i = 0;
while ($i < 5) {
$container = $this->getMock("Bridge_Api_ContainerInterface");
$collection->add_element(new $container);
$i ++;
}
$this->assertEquals(5, sizeof($collection->get_elements()));
}
} }

View File

@@ -1,348 +0,0 @@
<?php
require_once __DIR__ . '/../../PhraseanetPHPUnitAuthenticatedAbstract.class.inc';
require_once __DIR__ . '/../Bridge_datas.inc';
require_once __DIR__ . '/../../../lib/classes/Bridge/Api/Dailymotion.class.php';
class Bridge_Api_DailymotionTest extends PHPUnit_Framework_TestCase
{
/**
* @var Bridge_Api_Dailymotion
*/
protected $object;
protected function setUp()
{
$this->object = $this->getMock("Bridge_Api_Dailymotion", array("initialize_transport", "set_auth_params"), array(registry::get_instance(), $this->getMock("Bridge_Api_Auth_Interface")));
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
}
/**
* @todo Implement testConnect().
*/
public function testConnect()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testReconnect().
*/
public function testReconnect()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_user_id().
*/
public function testGet_user_id()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_user_name().
*/
public function testGet_user_name()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_name().
*/
public function testGet_name()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_icon_url().
*/
public function testGet_icon_url()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_image_url().
*/
public function testGet_image_url()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_url().
*/
public function testGet_url()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_infos().
*/
public function testGet_infos()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_default_element_type().
*/
public function testGet_default_element_type()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_default_container_type().
*/
public function testGet_default_container_type()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_element_types().
*/
public function testGet_element_types()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_container_types().
*/
public function testGet_container_types()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_object_class_from_type().
*/
public function testGet_object_class_from_type()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testList_elements().
*/
public function testList_elements()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testList_containers().
*/
public function testList_containers()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testUpdate_element().
*/
public function testUpdate_element()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testCreate_container().
*/
public function testCreate_container()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testAdd_element_to_container().
*/
public function testAdd_element_to_container()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testDelete_object().
*/
public function testDelete_object()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testAcceptable_records().
*/
public function testAcceptable_records()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_element_status().
*/
public function testGet_element_status()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testMap_connector_to_element_status().
*/
public function testMap_connector_to_element_status()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_error_message_from_status().
*/
public function testGet_error_message_from_status()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testHandle_exception().
*/
public function testHandle_exception()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testUpload().
*/
public function testUpload()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_element_from_id().
*/
public function testGet_element_from_id()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_container_from_id().
*/
public function testGet_container_from_id()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_category_list().
*/
public function testGet_category_list()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
}

View File

@@ -6,17 +6,15 @@ require_once __DIR__ . '/../Bridge_datas.inc';
class Bridge_Api_ElementCollectionTest extends PHPUnit_Framework_TestCase class Bridge_Api_ElementCollectionTest extends PHPUnit_Framework_TestCase
{ {
public function testAdd_element() public function testAdd_element()
{
$collection = new Bridge_Api_ElementCollection();
$i = 0;
while($i < 5)
{ {
$element = $this->getMock("Bridge_Api_ElementInterface"); $collection = new Bridge_Api_ElementCollection();
$collection->add_element(new $element); $i = 0;
$i++; while ($i < 5) {
$element = $this->getMock("Bridge_Api_ElementInterface");
$collection->add_element(new $element);
$i ++;
}
$this->assertEquals(5, sizeof($collection->get_elements()));
} }
$this->assertEquals(5, sizeof($collection->get_elements()));
}
} }

View File

@@ -1,336 +0,0 @@
<?php
require_once __DIR__ . '/../../PhraseanetPHPUnitAuthenticatedAbstract.class.inc';
require_once __DIR__ . '/../Bridge_datas.inc';
class Bridge_Api_FlickrTest extends PHPUnit_Framework_TestCase
{
/**
* @var Bridge_Api_Flickr
*/
protected $object;
public function setUp()
{
$this->object = $this->getMock("Bridge_Api_Flickr", array("initialize_transport", "set_auth_params"), array(registry::get_instance(), $this->getMock("Bridge_Api_Auth_Interface")));
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
public function tearDown()
{
}
/**
* @todo Implement testConnect().
*/
public function testConnect()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testDisconnect().
*/
public function testDisconnect()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_user_name().
*/
public function testGet_user_name()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_user_id().
*/
public function testGet_user_id()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_name().
*/
public function testGet_name()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_icon_url().
*/
public function testGet_icon_url()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_image_url().
*/
public function testGet_image_url()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_url().
*/
public function testGet_url()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_infos().
*/
public function testGet_infos()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_default_element_type().
*/
public function testGet_default_element_type()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_default_container_type().
*/
public function testGet_default_container_type()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_element_from_id().
*/
public function testGet_element_from_id()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_container_from_id().
*/
public function testGet_container_from_id()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testList_containers().
*/
public function testList_containers()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testUpdate_element().
*/
public function testUpdate_element()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testCreate_container().
*/
public function testCreate_container()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testAdd_element_to_container().
*/
public function testAdd_element_to_container()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testDelete_object().
*/
public function testDelete_object()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testList_elements().
*/
public function testList_elements()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_element_status().
*/
public function testGet_element_status()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testMap_connector_to_element_status().
*/
public function testMap_connector_to_element_status()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_error_message_from_status().
*/
public function testGet_error_message_from_status()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testUpload().
*/
public function testUpload()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testAcceptable_records().
*/
public function testAcceptable_records()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_object_class_from_type().
*/
public function testGet_object_class_from_type()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_element_types().
*/
public function testGet_element_types()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_container_types().
*/
public function testGet_container_types()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_category_list().
*/
public function testGet_category_list()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
}

View File

@@ -1,339 +0,0 @@
<?php
require_once __DIR__ . '/../../PhraseanetPHPUnitAuthenticatedAbstract.class.inc';
require_once __DIR__ . '/../Bridge_datas.inc';
class Bridge_Api_YoutubeTest extends PHPUnit_Framework_TestCase
{
/**
* @var Bridge_Api_Youtube
*/
protected $object;
public function setUp()
{
$this->object = $this->getMock("Bridge_Api_Youtube", array("initialize_transport", "set_auth_params"), array(registry::get_instance(), $this->getMock("Bridge_Api_Auth_Interface")));
}
/**
* @todo Implement testConnect().
*/
public function testConnect()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testReconnect().
*/
public function testReconnect()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_user_id().
*/
public function testGet_user_id()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_user_name().
*/
public function testGet_user_name()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_name().
*/
public function testGet_name()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_icon_url().
*/
public function testGet_icon_url()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_image_url().
*/
public function testGet_image_url()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_url().
*/
public function testGet_url()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_infos().
*/
public function testGet_infos()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_default_element_type().
*/
public function testGet_default_element_type()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_default_container_type().
*/
public function testGet_default_container_type()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_element_types().
*/
public function testGet_element_types()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_container_types().
*/
public function testGet_container_types()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_object_class_from_type().
*/
public function testGet_object_class_from_type()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testList_elements().
*/
public function testList_elements()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testList_containers().
*/
public function testList_containers()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testUpdate_element().
*/
public function testUpdate_element()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testCreate_container().
*/
public function testCreate_container()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testAdd_element_to_container().
*/
public function testAdd_element_to_container()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testDelete_object().
*/
public function testDelete_object()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testAcceptable_records().
*/
public function testAcceptable_records()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_element_status().
*/
public function testGet_element_status()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testMap_connector_to_element_status().
*/
public function testMap_connector_to_element_status()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_error_message_from_status().
*/
public function testGet_error_message_from_status()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testHandle_exception().
*/
public function testHandle_exception()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testUpload().
*/
public function testUpload()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_element_from_id().
*/
public function testGet_element_from_id()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_category_list().
*/
public function testGet_category_list()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @todo Implement testGet_container_from_id().
*/
public function testGet_container_from_id()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
}

View File

@@ -1,107 +1,82 @@
<?php <?php
require_once __DIR__ . '/../../../PhraseanetPHPUnitAuthenticatedAbstract.class.inc'; require_once __DIR__ . '/../../../PhraseanetPHPUnitAuthenticatedAbstract.class.inc';
require_once __DIR__ . '/../../Bridge_datas.inc'; require_once __DIR__ . '/../../Bridge_datas.inc';
require_once __DIR__ . '/../../../../lib/classes/Bridge/Api/Dailymotion/Container.class.php'; require_once __DIR__ . '/../../../../lib/classes/Bridge/Api/Dailymotion/Container.class.php';
class Bridge_Api_Dailymotion_ContainerTest extends PHPUnit_Framework_TestCase class Bridge_Api_Dailymotion_ContainerTest extends PHPUnit_Framework_TestCase
{ {
/**
* @var Bridge_Api_Dailymotion_Container
*/
protected $object;
/** protected function setUp()
* @var Bridge_Api_Dailymotion_Container {
*/ $this->test = array(
protected $object; 'id' => '01234567'
, 'description' => 'one description'
, 'name' => 'hello container'
);
}
protected function setUp() public function testGet_created_on()
{ {
$this->test = array( $this->object = new Bridge_Api_Dailymotion_Container($this->test, 'playlist', 'thumb', 'url');
'id' => '01234567' $this->assertNull($this->object->get_created_on());
,'description' => 'one description' }
, 'name' => 'hello container'
);
}
/** public function testGet_description()
* @todo Implement testGet_created_on(). {
*/ $this->object = new Bridge_Api_Dailymotion_Container($this->test, 'playlist', 'thumb', 'url');
public function testGet_created_on() $this->assertEquals($this->test['description'], $this->object->get_description());
{ unset($this->test["description"]);
$this->object = new Bridge_Api_Dailymotion_Container($this->test, 'playlist', 'thumb', 'url'); $this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla');
$this->assertNull($this->object->get_created_on()); $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_description());
} $this->assertEmpty($this->object->get_description());
}
/** public function testGet_id()
* @todo Implement testGet_description(). {
*/ $this->object = new Bridge_Api_Dailymotion_Container($this->test, 'playlist', 'thumb', 'url');
public function testGet_description() $this->assertEquals($this->test['id'], $this->object->get_id());
{ unset($this->test["id"]);
$this->object = new Bridge_Api_Dailymotion_Container($this->test, 'playlist', 'thumb', 'url'); $this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla');
$this->assertEquals($this->test['description'], $this->object->get_description()); $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_id());
unset($this->test["description"]); $this->assertEmpty($this->object->get_id());
$this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla'); }
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_description());
$this->assertEmpty($this->object->get_description());
}
/** public function testGet_thumbnail()
* @todo Implement testGet_id(). {
*/ $this->object = new Bridge_Api_Dailymotion_Container($this->test, 'playlist', 'thumb', 'url');
public function testGet_id() $this->assertEquals('thumb', $this->object->get_thumbnail());
{ }
$this->object = new Bridge_Api_Dailymotion_Container($this->test, 'playlist', 'thumb', 'url');
$this->assertEquals($this->test['id'], $this->object->get_id());
unset($this->test["id"]);
$this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla');
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_id());
$this->assertEmpty($this->object->get_id());
}
/** public function testGet_title()
* @todo Implement testGet_thumbnail(). {
*/ $this->object = new Bridge_Api_Dailymotion_Container($this->test, 'playlist', 'thumb', 'url');
public function testGet_thumbnail() $this->assertEquals($this->test['name'], $this->object->get_title());
{ unset($this->test["name"]);
$this->object = new Bridge_Api_Dailymotion_Container($this->test, 'playlist', 'thumb', 'url'); $this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla');
$this->assertEquals('thumb', $this->object->get_thumbnail()); $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_title());
} $this->assertEmpty($this->object->get_title());
}
/** public function testGet_type()
* @todo Implement testGet_title(). {
*/ $this->object = new Bridge_Api_Dailymotion_Container($this->test, 'playlist', 'thumb', 'url');
public function testGet_title() $this->assertEquals('playlist', $this->object->get_type());
{ }
$this->object = new Bridge_Api_Dailymotion_Container($this->test, 'playlist', 'thumb', 'url');
$this->assertEquals($this->test['name'], $this->object->get_title());
unset($this->test["name"]);
$this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla');
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_title());
$this->assertEmpty($this->object->get_title());
}
/** public function testGet_updated_on()
* @todo Implement testGet_type(). {
*/ $this->object = new Bridge_Api_Dailymotion_Container($this->test, 'playlist', 'thumb', 'url');
public function testGet_type() $this->assertNull($this->object->get_updated_on());
{ }
$this->object = new Bridge_Api_Dailymotion_Container($this->test, 'playlist', 'thumb', 'url');
$this->assertEquals('playlist', $this->object->get_type());
}
/**
* @todo Implement testGet_updated_on().
*/
public function testGet_updated_on()
{
$this->object = new Bridge_Api_Dailymotion_Container($this->test, 'playlist', 'thumb', 'url');
$this->assertNull($this->object->get_updated_on());
}
/**
* @todo Implement testGet_url().
*/
public function testGet_url()
{
$this->object = new Bridge_Api_Dailymotion_Container($this->test, 'playlist', 'thumb', 'url');
$this->assertEquals('url', $this->object->get_url());
}
public function testGet_url()
{
$this->object = new Bridge_Api_Dailymotion_Container($this->test, 'playlist', 'thumb', 'url');
$this->assertEquals('url', $this->object->get_url());
}
} }

View File

@@ -6,155 +6,153 @@ require_once __DIR__ . '/../../../../lib/classes/Bridge/Api/Dailymotion/Element.
class Bridge_Api_Dailymotion_ElementTest extends PHPUnit_Framework_TestCase class Bridge_Api_Dailymotion_ElementTest extends PHPUnit_Framework_TestCase
{ {
/**
* @var Bridge_Api_Dailymotion_Element
*/
protected $object;
protected $test;
/** public function setUp()
* @var Bridge_Api_Dailymotion_Element {
*/ $this->test = array(
protected $object; 'created_time' => time()
protected $test; , 'description' => 'Description of a dailymotion element'
, 'id' => "1"
, 'thumbnail_medium_url' => 'thumbnail_medium_url'
, 'title' => 'title of dailymotion lement'
, 'modified_time' => time()
, 'url' => 'www.my.element/url'
, 'private' => 1
, 'views_total' => '34'
, 'ratings_total' => '4'
, 'duration' => 80
, 'channel' => 'animation'
);
}
public function setUp() public function testGet_created_on()
{ {
$this->test = array( $this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla');
'created_time' => time() $this->assertEquals(DateTime::createFromFormat('U', $this->test['created_time']), $this->object->get_created_on());
, 'description' => 'Description of a dailymotion element' }
, 'id' => "1"
, 'thumbnail_medium_url' => 'thumbnail_medium_url'
, 'title' => 'title of dailymotion lement'
, 'modified_time' => time()
, 'url' => 'www.my.element/url'
, 'private' => 1
, 'views_total' => '34'
, 'ratings_total' => '4'
, 'duration' => 80
, 'channel' => 'animation'
);
}
public function testGet_created_on() public function testGet_description()
{ {
$this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla'); $this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla');
$this->assertEquals(DateTime::createFromFormat('U', $this->test['created_time']), $this->object->get_created_on()); $this->assertEquals($this->test['description'], $this->object->get_description());
} unset($this->test["description"]);
$this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla');
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_description());
$this->assertEmpty($this->object->get_description());
}
public function testGet_description() public function testGet_id()
{ {
$this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla'); $this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla');
$this->assertEquals($this->test['description'], $this->object->get_description()); $this->assertEquals($this->test['id'], $this->object->get_id());
unset($this->test["description"]); unset($this->test["id"]);
$this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla'); $this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla');
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_description()); $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_description());
$this->assertEmpty($this->object->get_description()); $this->assertEmpty($this->object->get_id());
} }
public function testGet_id() public function testGet_thumbnail()
{ {
$this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla'); $this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla');
$this->assertEquals($this->test['id'], $this->object->get_id()); $this->assertEquals($this->test['thumbnail_medium_url'], $this->object->get_thumbnail());
unset($this->test["id"]); unset($this->test["thumbnail_medium_url"]);
$this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla'); $this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla');
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_description()); $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_thumbnail());
$this->assertEmpty($this->object->get_id()); $this->assertEmpty($this->object->get_thumbnail());
} }
public function testGet_thumbnail() public function testGet_title()
{ {
$this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla'); $this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla');
$this->assertEquals($this->test['thumbnail_medium_url'], $this->object->get_thumbnail()); $this->assertEquals($this->test['title'], $this->object->get_title());
unset($this->test["thumbnail_medium_url"]); unset($this->test["title"]);
$this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla'); $this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla');
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_thumbnail()); $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_title());
$this->assertEmpty($this->object->get_thumbnail()); $this->assertEmpty($this->object->get_title());
} }
public function testGet_title() public function testGet_type()
{ {
$this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla'); $type = 'kikoo';
$this->assertEquals($this->test['title'], $this->object->get_title()); $this->object = new Bridge_Api_Dailymotion_Element($this->test, $type);
unset($this->test["title"]); $this->assertEquals($type, $this->object->get_type());
$this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla'); $type = 'kooki';
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_title()); $this->object = new Bridge_Api_Dailymotion_Element($this->test, $type);
$this->assertEmpty($this->object->get_title()); $this->assertEquals($type, $this->object->get_type());
} }
public function testGet_type() public function testGet_updated_on()
{ {
$type = 'kikoo'; $this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla');
$this->object = new Bridge_Api_Dailymotion_Element($this->test, $type); $this->assertEquals(DateTime::createFromFormat('U', $this->test['modified_time']), $this->object->get_updated_on());
$this->assertEquals($type, $this->object->get_type()); }
$type = 'kooki';
$this->object = new Bridge_Api_Dailymotion_Element($this->test, $type);
$this->assertEquals($type, $this->object->get_type());
}
public function testGet_updated_on() public function testGet_url()
{ {
$this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla'); $this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla');
$this->assertEquals(DateTime::createFromFormat('U', $this->test['modified_time']), $this->object->get_updated_on()); $this->assertEquals($this->test['url'], $this->object->get_url());
} unset($this->test["url"]);
$this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla');
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_url());
$this->assertEmpty($this->object->get_url());
}
public function testGet_url() public function testIs_private()
{ {
$this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla'); $this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla');
$this->assertEquals($this->test['url'], $this->object->get_url()); $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_BOOL, $this->object->is_private());
unset($this->test["url"]); $this->assertTrue($this->object->is_private());
$this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla'); unset($this->test["private"]);
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_url()); $this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla');
$this->assertEmpty($this->object->get_url()); $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_BOOL, $this->object->is_private());
} $this->assertFalse($this->object->is_private());
}
public function testIs_private() public function testGet_duration()
{ {
$this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla'); $this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla');
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_BOOL, $this->object->is_private()); $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_duration());
$this->assertTrue($this->object->is_private()); $this->assertEquals("01:20", $this->object->get_duration());
unset($this->test["private"]); unset($this->test["duration"]);
$this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla'); $this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla');
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_BOOL, $this->object->is_private()); $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_duration());
$this->assertFalse($this->object->is_private()); $this->assertEquals("00:00", $this->object->get_duration());
} }
public function testGet_duration() public function testGet_view_count()
{ {
$this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla'); $this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla');
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_duration()); $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_INT, $this->object->get_view_count());
$this->assertEquals("01:20", $this->object->get_duration()); $this->assertEquals($this->test['views_total'], $this->object->get_view_count());
unset($this->test["duration"]); unset($this->test["views_total"]);
$this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla'); $this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla');
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_duration()); $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_INT, $this->object->get_view_count());
$this->assertEquals("00:00", $this->object->get_duration()); $this->assertEquals(0, $this->object->get_view_count());
} }
public function testGet_view_count() public function testGet_rating()
{ {
$this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla'); $this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla');
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_INT, $this->object->get_view_count()); $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_INT, $this->object->get_rating());
$this->assertEquals($this->test['views_total'], $this->object->get_view_count()); $this->assertEquals($this->test['ratings_total'], $this->object->get_rating());
unset($this->test["views_total"]); unset($this->test["ratings_total"]);
$this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla'); $this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla');
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_INT, $this->object->get_view_count()); $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_INT, $this->object->get_rating());
$this->assertEquals(0 , $this->object->get_view_count()); $this->assertEquals(0, $this->object->get_rating());
} }
public function testGet_rating()
{
$this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla');
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_INT, $this->object->get_rating());
$this->assertEquals($this->test['ratings_total'], $this->object->get_rating());
unset($this->test["ratings_total"]);
$this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla');
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_INT, $this->object->get_rating());
$this->assertEquals(0 , $this->object->get_rating());
}
public function testGet_category()
{
$this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla');
$this->assertEquals($this->test['channel'], $this->object->get_category());
unset($this->test["channel"]);
$this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla');
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_category());
$this->assertEmpty($this->object->get_category());
}
public function testGet_category()
{
$this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla');
$this->assertEquals($this->test['channel'], $this->object->get_category());
unset($this->test["channel"]);
$this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla');
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_category());
$this->assertEmpty($this->object->get_category());
}
} }

View File

@@ -5,72 +5,70 @@ require_once __DIR__ . '/../../Bridge_datas.inc';
class Bridge_Api_Flickr_ContainerTest extends PHPUnit_Framework_TestCase class Bridge_Api_Flickr_ContainerTest extends PHPUnit_Framework_TestCase
{ {
/**
* @var Bridge_Api_Flickr_Container
*/
protected $object;
/** public function setUp()
* @var Bridge_Api_Flickr_Container {
*/ $string = '
protected $object;
public function setUp()
{
$string = '
<photoset id="72157626216528324" primary="5504567858" secret="017804c585" server="5174" farm="6" photos="22" videos="0" count_views="137" count_comments="0" can_comment="1" date_create="1299514498" date_update="1300335009"> <photoset id="72157626216528324" primary="5504567858" secret="017804c585" server="5174" farm="6" photos="22" videos="0" count_views="137" count_comments="0" can_comment="1" date_create="1299514498" date_update="1300335009">
<title>Avis Blanche</title> <title>Avis Blanche</title>
<description>My Grandma\'s Recipe File.</description> <description>My Grandma\'s Recipe File.</description>
</photoset> </photoset>
'; ';
$xml = simplexml_load_string($string); $xml = simplexml_load_string($string);
$this->object = new Bridge_Api_Flickr_Container($xml, 'userid123', "photoset", "my_humbnail"); $this->object = new Bridge_Api_Flickr_Container($xml, 'userid123', "photoset", "my_humbnail");
} }
public function testGet_id() public function testGet_id()
{ {
$this->assertEquals("72157626216528324", $this->object->get_id()); $this->assertEquals("72157626216528324", $this->object->get_id());
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_id()); $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_id());
} }
public function testGet_thumbnail() public function testGet_thumbnail()
{ {
$this->assertEquals("my_humbnail", $this->object->get_thumbnail()); $this->assertEquals("my_humbnail", $this->object->get_thumbnail());
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_thumbnail()); $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_thumbnail());
} }
public function testGet_url() public function testGet_url()
{ {
$this->assertRegExp("/https:\/\/secure.flickr.com\/photos/", $this->object->get_url()); $this->assertRegExp("/https:\/\/secure.flickr.com\/photos/", $this->object->get_url());
$this->assertRegExp("/userid123/", $this->object->get_url()); $this->assertRegExp("/userid123/", $this->object->get_url());
$this->assertRegExp("/72157626216528324/", $this->object->get_url()); $this->assertRegExp("/72157626216528324/", $this->object->get_url());
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_thumbnail()); $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_thumbnail());
} }
public function testGet_title() public function testGet_title()
{ {
$this->assertEquals("My Grandma's Recipe File.", $this->object->get_description()); $this->assertEquals("My Grandma's Recipe File.", $this->object->get_description());
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_description()); $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_description());
} }
public function testGet_description() public function testGet_description()
{ {
$this->assertEquals("Avis Blanche", $this->object->get_title()); $this->assertEquals("Avis Blanche", $this->object->get_title());
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_title()); $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_title());
} }
public function testGet_updated_on() public function testGet_updated_on()
{ {
$this->assertInstanceOf('DateTime', $this->object->get_updated_on()); $this->assertInstanceOf('DateTime', $this->object->get_updated_on());
$this->assertEquals(DateTime::createFromFormat('U', '1300335009'), $this->object->get_updated_on()); $this->assertEquals(DateTime::createFromFormat('U', '1300335009'), $this->object->get_updated_on());
} }
public function testGet_created_on() public function testGet_created_on()
{ {
$this->assertInstanceOf('DateTime', $this->object->get_created_on()); $this->assertInstanceOf('DateTime', $this->object->get_created_on());
$this->assertEquals(DateTime::createFromFormat('U', '1299514498'), $this->object->get_created_on()); $this->assertEquals(DateTime::createFromFormat('U', '1299514498'), $this->object->get_created_on());
} }
public function testGet_type()
{
$this->assertEquals("photoset", $this->object->get_type());
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_type());
}
public function testGet_type()
{
$this->assertEquals("photoset", $this->object->get_type());
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_type());
}
} }

View File

@@ -5,27 +5,26 @@ require_once __DIR__ . '/../../Bridge_datas.inc';
class Bridge_Api_Flickr_ElementTest extends PHPUnit_Framework_TestCase class Bridge_Api_Flickr_ElementTest extends PHPUnit_Framework_TestCase
{ {
/**
* @var Bridge_Api_Flickr_Element
*/
protected $object_list;
/** /**
* @var Bridge_Api_Flickr_Element * @var Bridge_Api_Flickr_Element
*/ */
protected $object_list; protected $object_alone;
protected $xml_list;
protected $xml_alone;
/** public function setUp()
* @var Bridge_Api_Flickr_Element {
*/ $str = '
protected $object_alone;
protected $xml_list;
protected $xml_alone;
public function setUp()
{
$str = '
<photo id="6263188755" width_t="100" height_t="67" url_t="http://farm7.static.flickr.com/6034/6263188755_2dca715798_t.jpg" width_sq="75" height_sq="75" url_sq="http://farm7.static.flickr.com/6034/6263188755_2dca715798_s.jpg" views="1" tags="" lastupdate="1319126343" ownername="Boontyp4" datetakengranularity="0" datetaken="2008-09-28 20:26:00" dateupload="1319117962" license="0" isfamily="0" isfriend="0" ispublic="1" title="un titre" farm="7" server="6034" secret="2dca715798" owner="60578095@N05"> <photo id="6263188755" width_t="100" height_t="67" url_t="http://farm7.static.flickr.com/6034/6263188755_2dca715798_t.jpg" width_sq="75" height_sq="75" url_sq="http://farm7.static.flickr.com/6034/6263188755_2dca715798_s.jpg" views="1" tags="" lastupdate="1319126343" ownername="Boontyp4" datetakengranularity="0" datetaken="2008-09-28 20:26:00" dateupload="1319117962" license="0" isfamily="0" isfriend="0" ispublic="1" title="un titre" farm="7" server="6034" secret="2dca715798" owner="60578095@N05">
<description>une description</description> <description>une description</description>
</photo> </photo>
'; ';
$string = ' $string = '
<rsp stat="ok"> <rsp stat="ok">
<photo id="5930279108" media="photo" views="1" rotation="0" safety_level="0" license="0" isfavorite="0" dateuploaded="1310477820" farm="7" server="6135" secret="c06196fbd8"> <photo id="5930279108" media="photo" views="1" rotation="0" safety_level="0" license="0" isfavorite="0" dateuploaded="1310477820" farm="7" server="6135" secret="c06196fbd8">
<owner iconfarm="0" iconserver="0" location="" realname="" username="Boontyp4" nsid="60578095@N05"></owner> <owner iconfarm="0" iconserver="0" location="" realname="" username="Boontyp4" nsid="60578095@N05"></owner>
@@ -49,114 +48,113 @@ class Bridge_Api_Flickr_ElementTest extends PHPUnit_Framework_TestCase
</photo> </photo>
</rsp> </rsp>
'; ';
$this->xml_alone = simplexml_load_string($string); $this->xml_alone = simplexml_load_string($string);
$this->object_alone = new Bridge_Api_Flickr_Element($this->xml_alone, '12037949754@N01', 'album', false); $this->object_alone = new Bridge_Api_Flickr_Element($this->xml_alone, '12037949754@N01', 'album', false);
$this->xml_list = simplexml_load_string($str); $this->xml_list = simplexml_load_string($str);
$this->object_list = new Bridge_Api_Flickr_Element($this->xml_list, '12037949754@N01', 'album', true); $this->object_list = new Bridge_Api_Flickr_Element($this->xml_list, '12037949754@N01', 'album', true);
} }
public function testGet_id() public function testGet_id()
{ {
$this->assertEquals("5930279108", $this->object_alone->get_id()); $this->assertEquals("5930279108", $this->object_alone->get_id());
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object_alone->get_id()); $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object_alone->get_id());
$this->assertEquals("6263188755", $this->object_list->get_id()); $this->assertEquals("6263188755", $this->object_list->get_id());
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object_list->get_id()); $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object_list->get_id());
} }
public function testGet_url() public function testGet_url()
{ {
$this->assertRegExp("/6263188755/", $this->object_list->get_url()); $this->assertRegExp("/6263188755/", $this->object_list->get_url());
$this->assertRegExp("/album/", $this->object_list->get_url()); $this->assertRegExp("/album/", $this->object_list->get_url());
$this->assertRegExp("/60578095@N05/", $this->object_list->get_url()); $this->assertRegExp("/60578095@N05/", $this->object_list->get_url());
$this->assertRegExp("/http:\/\/www.flickr.com\//", $this->object_list->get_url()); $this->assertRegExp("/http:\/\/www.flickr.com\//", $this->object_list->get_url());
$this->assertEquals("http://www.flickr.com/photos/bees/2733/", $this->object_alone->get_url()); $this->assertEquals("http://www.flickr.com/photos/bees/2733/", $this->object_alone->get_url());
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object_alone->get_url()); $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object_alone->get_url());
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object_list->get_url()); $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object_list->get_url());
} }
public function testGet_thumbnail() public function testGet_thumbnail()
{ {
$this->assertEquals("http://farm7.static.flickr.com/6034/6263188755_2dca715798_t.jpg", $this->object_list->get_thumbnail()); $this->assertEquals("http://farm7.static.flickr.com/6034/6263188755_2dca715798_t.jpg", $this->object_list->get_thumbnail());
$this->assertRegExp("/https:\/\/farm7.static.flickr.com/", $this->object_alone->get_thumbnail()); $this->assertRegExp("/https:\/\/farm7.static.flickr.com/", $this->object_alone->get_thumbnail());
$this->assertRegExp("/6135/", $this->object_alone->get_thumbnail()); $this->assertRegExp("/6135/", $this->object_alone->get_thumbnail());
$this->assertRegExp("/c06196fbd8/", $this->object_alone->get_thumbnail()); $this->assertRegExp("/c06196fbd8/", $this->object_alone->get_thumbnail());
$this->assertRegExp("/5930279108/", $this->object_alone->get_thumbnail()); $this->assertRegExp("/5930279108/", $this->object_alone->get_thumbnail());
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object_alone->get_thumbnail()); $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object_alone->get_thumbnail());
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object_list->get_thumbnail()); $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object_list->get_thumbnail());
} }
public function testGet_title() public function testGet_title()
{ {
$this->assertEquals("un titre", $this->object_list->get_title()); $this->assertEquals("un titre", $this->object_list->get_title());
$this->assertEquals("Australia.gif", $this->object_alone->get_title()); $this->assertEquals("Australia.gif", $this->object_alone->get_title());
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object_alone->get_title()); $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object_alone->get_title());
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object_list->get_title()); $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object_list->get_title());
} }
public function testGet_description() public function testGet_description()
{ {
$this->assertEquals("une description", $this->object_list->get_description()); $this->assertEquals("une description", $this->object_list->get_description());
$this->assertEquals("drapeau de l'australie", $this->object_alone->get_description()); $this->assertEquals("drapeau de l'australie", $this->object_alone->get_description());
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object_alone->get_description()); $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object_alone->get_description());
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object_list->get_description()); $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object_list->get_description());
} }
public function testGet_updated_on() public function testGet_updated_on()
{ {
$this->assertInstanceOf('DateTime', $this->object_list->get_updated_on()); $this->assertInstanceOf('DateTime', $this->object_list->get_updated_on());
$this->assertInstanceOf('DateTime', $this->object_alone->get_updated_on()); $this->assertInstanceOf('DateTime', $this->object_alone->get_updated_on());
$this->assertEquals(DateTime::createFromFormat('U', '1319126343'), $this->object_list->get_updated_on()); $this->assertEquals(DateTime::createFromFormat('U', '1319126343'), $this->object_list->get_updated_on());
$this->assertEquals(DateTime::createFromFormat('U', '1314975347'), $this->object_alone->get_updated_on()); $this->assertEquals(DateTime::createFromFormat('U', '1314975347'), $this->object_alone->get_updated_on());
} }
public function testGet_category() public function testGet_category()
{ {
$this->assertEmpty($this->object_list->get_category()); $this->assertEmpty($this->object_list->get_category());
$this->assertEmpty($this->object_alone->get_category()); $this->assertEmpty($this->object_alone->get_category());
} }
public function testGet_duration() public function testGet_duration()
{ {
$this->assertEmpty($this->object_list->get_duration()); $this->assertEmpty($this->object_list->get_duration());
$this->assertEmpty($this->object_alone->get_duration()); $this->assertEmpty($this->object_alone->get_duration());
} }
public function testGet_view_count() public function testGet_view_count()
{ {
$this->assertEquals(1, $this->object_list->get_view_count()); $this->assertEquals(1, $this->object_list->get_view_count());
$this->assertEquals(1, $this->object_alone->get_view_count()); $this->assertEquals(1, $this->object_alone->get_view_count());
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_INT, $this->object_alone->get_view_count()); $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_INT, $this->object_alone->get_view_count());
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_INT, $this->object_list->get_view_count()); $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_INT, $this->object_list->get_view_count());
} }
public function testGet_rating() public function testGet_rating()
{ {
$this->assertNull($this->object_list->get_rating()); $this->assertNull($this->object_list->get_rating());
$this->assertNull($this->object_alone->get_rating()); $this->assertNull($this->object_alone->get_rating());
} }
public function testGet_created_on() public function testGet_created_on()
{ {
$this->assertInstanceOf('DateTime', $this->object_list->get_created_on()); $this->assertInstanceOf('DateTime', $this->object_list->get_created_on());
$this->assertInstanceOf('DateTime', $this->object_alone->get_created_on()); $this->assertInstanceOf('DateTime', $this->object_alone->get_created_on());
$this->assertEquals(DateTime::createFromFormat('U', '1319117962'), $this->object_list->get_created_on()); $this->assertEquals(DateTime::createFromFormat('U', '1319117962'), $this->object_list->get_created_on());
$this->assertEquals(DateTime::createFromFormat('U', '1310477820'), $this->object_alone->get_created_on()); $this->assertEquals(DateTime::createFromFormat('U', '1310477820'), $this->object_alone->get_created_on());
} }
public function testIs_private() public function testIs_private()
{ {
$this->assertFalse($this->object_list->is_private()); $this->assertFalse($this->object_list->is_private());
$this->assertTrue($this->object_alone->is_private()); $this->assertTrue($this->object_alone->is_private());
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_BOOL, $this->object_alone->is_private()); $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_BOOL, $this->object_alone->is_private());
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_BOOL, $this->object_list->is_private()); $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_BOOL, $this->object_list->is_private());
} }
public function testGet_type()
{
$this->assertEquals('album', $this->object_list->get_type());
$this->assertEquals('album', $this->object_alone->get_type());
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object_alone->get_type());
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object_list->get_type());
}
public function testGet_type()
{
$this->assertEquals('album', $this->object_list->get_type());
$this->assertEquals('album', $this->object_alone->get_type());
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object_alone->get_type());
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object_list->get_type());
}
} }

View File

@@ -5,77 +5,69 @@ require_once __DIR__ . '/../../Bridge_datas.inc';
class Bridge_Api_Youtube_ContainerTest extends PHPUnit_Framework_TestCase class Bridge_Api_Youtube_ContainerTest extends PHPUnit_Framework_TestCase
{ {
/**
* @var Bridge_Api_Youtube_Container
*/
protected $object;
/** public function setUp()
* @var Bridge_Api_Youtube_Container {
*/ $published = new Zend_Gdata_App_Extension_Published("2011-10-21 12:00:00");
protected $object; $updated = new Zend_Gdata_App_Extension_Updated("2011-10-21 12:20:00");
$id = new Zend_Gdata_App_Extension_Id("Az2cv12");
$entry = new Zend_Gdata_YouTube_PlaylistListEntry();
$entry->setMajorProtocolVersion(2);
$entry->setId($id);
$entry->setTitle(new Zend_Gdata_App_Extension_Title("one title"));
$entry->setUpdated($updated);
$entry->setPublished($published);
$entry->setLink(array(new Zend_Gdata_App_Extension_link("one url", "alternate")));
$entry->setDescription(new Zend_Gdata_App_Extension_Summary("one description"));
$this->object = new Bridge_Api_Youtube_Container($entry, 'playlist', 'my_thumbnail');
}
public function setUp() /**
{ * @todo find a way to test getPlaylistId
$published = new Zend_Gdata_App_Extension_Published("2011-10-21 12:00:00"); */
$updated = new Zend_Gdata_App_Extension_Updated("2011-10-21 12:20:00"); public function testGet_thumbnail()
$id = new Zend_Gdata_App_Extension_Id("Az2cv12"); {
$entry = new Zend_Gdata_YouTube_PlaylistListEntry(); $this->assertEquals("my_thumbnail", $this->object->get_thumbnail());
$entry->setMajorProtocolVersion(2); $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_thumbnail());
$entry->setId($id); }
$entry->setTitle(new Zend_Gdata_App_Extension_Title("one title"));
$entry->setUpdated($updated);
$entry->setPublished($published);
$entry->setLink(array(new Zend_Gdata_App_Extension_link("one url", "alternate")));
$entry->setDescription(new Zend_Gdata_App_Extension_Summary("one description"));
$this->object = new Bridge_Api_Youtube_Container($entry, 'playlist', 'my_thumbnail');
}
public function testGet_url()
{
$this->assertEquals("one url", $this->object->get_url());
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_url());
}
public function testGet_title()
{
$this->assertEquals("one title", $this->object->get_title());
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_title());
}
/** public function testGet_description()
* @todo fin a way to test getPlaylistId {
*/ $this->assertEquals("one description", $this->object->get_description());
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_description());
}
public function testGet_updated_on()
{
$this->assertInstanceOf('DateTime', $this->object->get_updated_on());
$this->assertEquals(new DateTime("2011-10-21 12:20:00"), $this->object->get_updated_on());
}
public function testGet_created_on()
{
$this->assertInstanceOf('DateTime', $this->object->get_created_on());
$this->assertEquals(new DateTime("2011-10-21 12:00:00"), $this->object->get_created_on());
}
public function testGet_type()
public function testGet_thumbnail() {
{ $this->assertEquals("playlist", $this->object->get_type());
$this->assertEquals("my_thumbnail", $this->object->get_thumbnail()); $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_type());
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_thumbnail()); }
}
public function testGet_url()
{
$this->assertEquals("one url", $this->object->get_url());
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_url());
}
public function testGet_title()
{
$this->assertEquals("one title", $this->object->get_title());
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_title());
}
public function testGet_description()
{
$this->assertEquals("one description", $this->object->get_description());
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_description());
}
public function testGet_updated_on()
{
$this->assertInstanceOf('DateTime', $this->object->get_updated_on());
$this->assertEquals(new DateTime("2011-10-21 12:20:00"), $this->object->get_updated_on());
}
public function testGet_created_on()
{
$this->assertInstanceOf('DateTime', $this->object->get_created_on());
$this->assertEquals(new DateTime("2011-10-21 12:00:00"), $this->object->get_created_on());
}
public function testGet_type()
{
$this->assertEquals("playlist", $this->object->get_type());
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_type());
}
} }

Some files were not shown because too many files have changed in this diff Show More