Move tests at root

This commit is contained in:
Romain Neutron
2012-04-14 12:07:49 +02:00
parent 855bb0d635
commit 855fd91081
260 changed files with 47666 additions and 0 deletions

755
tests/ACLTest.php Normal file
View File

@@ -0,0 +1,755 @@
<?php
require_once __DIR__ . '/PhraseanetPHPUnitAuthenticatedAbstract.class.inc';
class ACLTest extends PhraseanetPHPUnitAuthenticatedAbstract
{
/**
* @var ACL
*/
protected static $object;
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
self::$object = self::$user->ACL();
}
public static function tearDownAfterClass()
{
/**
* In case first test fails
*/
$usr_id = User_Adapter::get_usr_id_from_login('test_phpunit2');
try
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$template = User_Adapter::getInstance($usr_id, $appbox);
$template->delete();
}
catch (Exception $e)
{
}
$usr_id = User_Adapter::get_usr_id_from_login('test_phpunit3');
try
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$cobaye = User_Adapter::getInstance($usr_id, $appbox);
$cobaye->delete();
}
catch (Exception $e)
{
}
parent::tearDownAfterClass();
}
public function testApply_model()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$template = User_Adapter::create($appbox, 'test_phpunit2', 'blabla2', 'test2@example.com', false);
$template->set_template(self::$user);
$base_ids = array();
foreach ($appbox->get_databoxes() as $databox)
{
foreach ($databox->get_collections() as $collection)
{
$base_id = $collection->get_base_id();
$base_ids[] = $base_id;
}
}
$template->ACL()->give_access_to_base($base_ids);
$cobaye = User_Adapter::create($appbox, 'test_phpunit3', 'blabla3', 'test3@example.com', false);
$cobaye->ACL()->apply_model($template, $base_ids);
foreach ($appbox->get_databoxes() as $databox)
{
foreach ($databox->get_collections() as $collection)
{
$base_id = $collection->get_base_id();
$this->assertTrue($cobaye->ACL()->has_access_to_base($base_id));
}
}
$template->delete();
$cobaye->delete();
}
public function testRevoke_access_from_bases()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$base_ids = array();
foreach ($appbox->get_databoxes() as $databox)
{
foreach ($databox->get_collections() as $collection)
{
$base_id = $collection->get_base_id();
self::$user->ACL()->revoke_access_from_bases(array($base_id));
$this->assertFalse(self::$user->ACL()->has_access_to_base($base_id));
self::$user->ACL()->give_access_to_base(array($base_id));
$this->assertTrue(self::$user->ACL()->has_access_to_base($base_id));
$base_ids[] = $base_id;
}
}
self::$user->ACL()->revoke_access_from_bases($base_ids);
foreach ($base_ids as $base_id)
{
$this->assertFalse(self::$user->ACL()->has_access_to_base($base_id));
}
}
public function testGive_access_to_base()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
foreach ($appbox->get_databoxes() as $databox)
{
foreach ($databox->get_collections() as $collection)
{
$base_id = $collection->get_base_id();
$this->assertFalse(self::$user->ACL()->has_access_to_base($base_id));
self::$user->ACL()->give_access_to_base(array($base_id));
$this->assertTrue(self::$user->ACL()->has_access_to_base($base_id));
}
}
}
public function testGive_access_to_sbas()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
foreach ($appbox->get_databoxes() as $databox)
{
$sbas_id = $databox->get_sbas_id();
$base_ids = array();
foreach ($databox->get_collections() as $collection)
{
$base_ids[] = $collection->get_base_id();
}
self::$user->ACL()->revoke_access_from_bases($base_ids);
self::$user->ACL()->revoke_unused_sbas_rights();
$this->assertFalse(self::$user->ACL()->has_access_to_sbas($sbas_id));
self::$user->ACL()->give_access_to_sbas(array($sbas_id));
$this->assertTrue(self::$user->ACL()->has_access_to_sbas($sbas_id));
}
}
public function testRevoke_unused_sbas_rights()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
foreach ($appbox->get_databoxes() as $databox)
{
$sbas_id = $databox->get_sbas_id();
$base_ids = array();
foreach ($databox->get_collections() as $collection)
{
$base_ids[] = $collection->get_base_id();
}
self::$user->ACL()->revoke_access_from_bases($base_ids);
self::$user->ACL()->give_access_to_sbas(array($sbas_id));
$this->assertTrue(self::$user->ACL()->has_access_to_sbas($sbas_id));
self::$user->ACL()->revoke_unused_sbas_rights();
$this->assertFalse(self::$user->ACL()->has_access_to_sbas($sbas_id));
}
}
public function testRemove_quotas_on_base()
{
$this->testSet_quotas_on_base();
}
public function testSet_quotas_on_base()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
foreach ($appbox->get_databoxes() as $databox)
{
foreach ($databox->get_collections() as $collection)
{
$base_id = $collection->get_base_id();
$droits = 50;
$restes = 40;
self::$user->ACL()->give_access_to_base(array($base_id));
self::$user->ACL()->set_quotas_on_base($base_id, $droits, $restes);
$this->assertTrue(self::$user->ACL()->is_restricted_download($base_id));
self::$user->ACL()->remove_quotas_on_base($base_id);
$this->assertFalse(self::$user->ACL()->is_restricted_download($base_id));
return;
}
}
}
public function testDuplicate_right_from_bas()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$first = true;
$base_ref = null;
foreach ($appbox->get_databoxes() as $databox)
{
foreach ($databox->get_collections() as $collection)
{
$base_id = $collection->get_base_id();
self::$user->ACL()->give_access_to_base(array($base_id));
if ($first)
{
self::$user->ACL()->update_rights_to_base($base_id, array('imgtools' => true, 'chgstatus' => true, 'canaddrecord' => true, 'canputinalbum' => true));
$base_ref = $base_id;
}
else
{
self::$user->ACL()->duplicate_right_from_bas($base_ref, $base_id);
}
$this->assertTrue(self::$user->ACL()->has_right_on_base($base_id, 'imgtools'));
$this->assertTrue(self::$user->ACL()->has_right_on_base($base_id, 'chgstatus'));
$this->assertTrue(self::$user->ACL()->has_right_on_base($base_id, 'canaddrecord'));
$this->assertTrue(self::$user->ACL()->has_right_on_base($base_id, 'canputinalbum'));
$first = false;
}
}
}
public function testHas_hd_grant()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
public function testHas_right_on_base()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$rights_false = array(
'imgtools' => false
, 'chgstatus' => false
, 'canaddrecord' => false
, 'canputinalbum' => false
);
$rights_true = array(
'imgtools' => true
, 'chgstatus' => true
, 'canaddrecord' => true
);
foreach ($appbox->get_databoxes() as $databox)
{
foreach ($databox->get_collections() as $collection)
{
$base_id = $collection->get_base_id();
self::$user->ACL()->give_access_to_base(array($base_id));
self::$user->ACL()->update_rights_to_base($base_id, $rights_false);
$this->assertFalse(self::$user->ACL()->has_right_on_base($base_id, 'imgtools'));
$this->assertFalse(self::$user->ACL()->has_right_on_base($base_id, 'chgstatus'));
$this->assertFalse(self::$user->ACL()->has_right_on_base($base_id, 'canaddrecord'));
$this->assertFalse(self::$user->ACL()->has_right_on_base($base_id, 'canputinalbum'));
self::$user->ACL()->update_rights_to_base($base_id, $rights_true);
$this->assertTrue(self::$user->ACL()->has_right_on_base($base_id, 'imgtools'));
$this->assertTrue(self::$user->ACL()->has_right_on_base($base_id, 'chgstatus'));
$this->assertTrue(self::$user->ACL()->has_right_on_base($base_id, 'canaddrecord'));
$this->assertFalse(self::$user->ACL()->has_right_on_base($base_id, 'canputinalbum'));
self::$user->ACL()->update_rights_to_base($base_id, $rights_false);
$this->assertFalse(self::$user->ACL()->has_right_on_base($base_id, 'imgtools'));
$this->assertFalse(self::$user->ACL()->has_right_on_base($base_id, 'chgstatus'));
$this->assertFalse(self::$user->ACL()->has_right_on_base($base_id, 'canaddrecord'));
$this->assertFalse(self::$user->ACL()->has_right_on_base($base_id, 'canputinalbum'));
}
}
}
public function testIs_restricted_download()
{
$this->testSet_quotas_on_base();
}
public function testRemaining_download()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
foreach ($appbox->get_databoxes() as $databox)
{
foreach ($databox->get_collections() as $collection)
{
$base_id = $collection->get_base_id();
$droits = 50;
$restes = 40;
self::$user->ACL()->give_access_to_base(array($base_id));
self::$user->ACL()->set_quotas_on_base($base_id, $droits, $restes);
$this->assertEquals(40, self::$user->ACL()->remaining_download($base_id));
self::$user->ACL()->remove_quotas_on_base($base_id);
$this->assertFalse(self::$user->ACL()->is_restricted_download($base_id));
return;
}
}
}
public function testRemove_remaining()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
foreach ($appbox->get_databoxes() as $databox)
{
foreach ($databox->get_collections() as $collection)
{
$base_id = $collection->get_base_id();
$droits = 50;
$restes = 40;
self::$user->ACL()->give_access_to_base(array($base_id));
self::$user->ACL()->set_quotas_on_base($base_id, $droits, $restes);
$this->assertEquals(40, self::$user->ACL()->remaining_download($base_id));
self::$user->ACL()->remove_remaining($base_id, 1);
$this->assertEquals(39, self::$user->ACL()->remaining_download($base_id));
self::$user->ACL()->remove_remaining($base_id, 10);
$this->assertEquals(29, self::$user->ACL()->remaining_download($base_id));
self::$user->ACL()->remove_remaining($base_id, 100);
$this->assertEquals(0, self::$user->ACL()->remaining_download($base_id));
self::$user->ACL()->remove_quotas_on_base($base_id);
$this->assertFalse(self::$user->ACL()->is_restricted_download($base_id));
return;
}
}
}
public function testHas_right()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$rights = array(
'bas_modify_struct' => true
);
$this->assertFalse(self::$user->ACL()->has_right('bas_modify_struct'));
$this->assertFalse(self::$user->ACL()->has_right('bas_modif_th'));
foreach ($appbox->get_databoxes() as $databox)
{
self::$user->ACL()->give_access_to_sbas(array($databox->get_sbas_id()));
self::$user->ACL()->update_rights_to_sbas($databox->get_sbas_id(), $rights);
break;
}
$this->assertTrue(self::$user->ACL()->has_right('bas_modify_struct'));
$this->assertFalse(self::$user->ACL()->has_right('bas_modif_th'));
}
public function testHas_right_on_sbas()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$rights_false = array(
'bas_modify_struct' => false
, 'bas_manage' => false
, 'bas_chupub' => false
, 'bas_modif_th' => false
);
$rights_true = array(
'bas_modify_struct' => true
, 'bas_manage' => true
, 'bas_chupub' => true
, 'bas_modif_th' => true
);
foreach ($appbox->get_databoxes() as $databox)
{
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);
$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_manage'));
$this->assertFalse(self::$user->ACL()->has_right_on_sbas($databox->get_sbas_id(), 'bas_chupub'));
$this->assertFalse(self::$user->ACL()->has_right_on_sbas($databox->get_sbas_id(), 'bas_modif_th'));
self::$user->ACL()->update_rights_to_sbas($databox->get_sbas_id(), $rights_true);
$this->assertTrue(self::$user->ACL()->has_right_on_sbas($databox->get_sbas_id(), 'bas_modify_struct'));
$this->assertTrue(self::$user->ACL()->has_right_on_sbas($databox->get_sbas_id(), 'bas_manage'));
$this->assertTrue(self::$user->ACL()->has_right_on_sbas($databox->get_sbas_id(), 'bas_chupub'));
$this->assertTrue(self::$user->ACL()->has_right_on_sbas($databox->get_sbas_id(), 'bas_modif_th'));
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_manage'));
$this->assertFalse(self::$user->ACL()->has_right_on_sbas($databox->get_sbas_id(), 'bas_chupub'));
$this->assertFalse(self::$user->ACL()->has_right_on_sbas($databox->get_sbas_id(), 'bas_modif_th'));
}
}
public function testGet_mask_and()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
foreach ($appbox->get_databoxes() as $databox)
{
foreach ($databox->get_collections() as $collection)
{
$base_id = $collection->get_base_id();
self::$user->ACL()->give_access_to_base(array($base_id));
self::$user->ACL()->update_rights_to_base($base_id, array('actif' => false));
$this->assertFalse(self::$user->ACL()->get_mask_and($base_id));
self::$user->ACL()->update_rights_to_base($base_id, array('actif' => true));
$this->assertEquals('0', self::$user->ACL()->get_mask_and($base_id));
self::$user->ACL()->update_rights_to_base($base_id, array('mask_and' => 42));
$this->assertEquals('42', self::$user->ACL()->get_mask_and($base_id));
self::$user->ACL()->update_rights_to_base($base_id, array('mask_and' => 1));
$this->assertEquals('1', self::$user->ACL()->get_mask_and($base_id));
self::$user->ACL()->update_rights_to_base($base_id, array('mask_and' => 0));
$this->assertEquals('0', self::$user->ACL()->get_mask_and($base_id));
}
}
}
public function testGet_mask_xor()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
foreach ($appbox->get_databoxes() as $databox)
{
foreach ($databox->get_collections() as $collection)
{
$base_id = $collection->get_base_id();
self::$user->ACL()->give_access_to_base(array($base_id));
self::$user->ACL()->update_rights_to_base($base_id, array('actif' => false));
$this->assertFalse(self::$user->ACL()->get_mask_xor($base_id));
self::$user->ACL()->update_rights_to_base($base_id, array('actif' => true));
$this->assertEquals('0', self::$user->ACL()->get_mask_xor($base_id));
self::$user->ACL()->update_rights_to_base($base_id, array('mask_xor' => 42));
$this->assertEquals('42', self::$user->ACL()->get_mask_xor($base_id));
self::$user->ACL()->update_rights_to_base($base_id, array('mask_xor' => 1));
$this->assertEquals('1', self::$user->ACL()->get_mask_xor($base_id));
self::$user->ACL()->update_rights_to_base($base_id, array('mask_xor' => 0));
$this->assertEquals('0', self::$user->ACL()->get_mask_xor($base_id));
}
}
}
public function testHas_access_to_base()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$base_ids = array();
$n = 0;
foreach ($appbox->get_databoxes() as $databox)
{
foreach ($databox->get_collections() as $collection)
{
$base_ids[] = $collection->get_base_id();
$n ++;
}
self::$user->ACL()->give_access_to_sbas(array($databox->get_sbas_id()));
}
if ($n === 0)
$this->fail('Not enough collection to test');
self::$user->ACL()->give_access_to_base($base_ids);
$bases = array_keys(self::$user->ACL()->get_granted_base());
$this->assertEquals(count($base_ids), count($bases));
$sql = 'SELECT actif FROM basusr WHERE usr_id = :usr_id AND base_id = :base_id';
$stmt = $appbox->get_connection()->prepare($sql);
foreach ($bases as $base_id)
{
$stmt->execute(array(':usr_id' => $appbox->get_session()->get_usr_id(), ':base_id' => $base_id));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$this->assertEquals(1, $row['actif']);
$this->assertTrue(self::$user->ACL()->has_access_to_base($base_id));
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));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$this->assertEquals(0, $row['actif']);
$this->assertFalse(self::$user->ACL()->has_access_to_base($base_id));
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));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$this->assertEquals(1, $row['actif']);
$this->assertTrue(self::$user->ACL()->has_access_to_base($base_id));
self::$user->ACL()->update_rights_to_base($base_id, array('actif' => false));
$this->assertFalse(self::$user->ACL()->has_access_to_base($base_id));
}
self::$user->ACL()->give_access_to_base($base_ids);
foreach ($bases as $base_id)
{
$this->assertTrue(self::$user->ACL()->has_access_to_base($base_id));
}
$stmt->closeCursor();
}
public function testGet_granted_base()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$base_ids = array();
$n = 0;
foreach ($appbox->get_databoxes() as $databox)
{
foreach ($databox->get_collections() as $collection)
{
$base_ids[] = $collection->get_base_id();
$n ++;
}
}
if ($n === 0)
$this->fail('Not enough collection to test');
self::$user->ACL()->give_access_to_base($base_ids);
$bases = array_keys(self::$user->ACL()->get_granted_base());
$this->assertEquals(count($bases), count($base_ids));
$this->assertEquals($n, count($base_ids));
foreach ($bases as $base_id)
{
try
{
$collection = collection::get_from_base_id($base_id);
$this->assertTrue($collection instanceof collection);
$this->assertEquals($base_id, $collection->get_base_id());
unset($collection);
}
catch (Exception $e)
{
$this->fail('get granted base should returned OK collection');
}
}
}
public function testGet_granted_sbas()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$sbas_ids = array();
$n = 0;
foreach ($appbox->get_databoxes() as $databox)
{
$sbas_ids[] = $databox->get_sbas_id();
$n ++;
}
self::$user->ACL()->give_access_to_sbas($sbas_ids);
$sbas = self::$user->ACL()->get_granted_sbas();
$this->assertEquals(count($sbas), count($sbas_ids));
$this->assertEquals($n, count($sbas_ids));
foreach ($sbas as $sbas_id => $databox)
{
try
{
$this->assertTrue($databox instanceof databox);
$this->assertEquals($sbas_id, $databox->get_sbas_id());
unset($databox);
}
catch (Exception $e)
{
$this->fail('get granted sbas should returned OK collection');
}
}
}
public function testHas_access_to_module()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
foreach ($appbox->get_databoxes() as $databox)
{
$base_ids = array();
foreach ($databox->get_collections() as $collection)
{
$base_id = $collection->get_base_id();
$base_ids[] = $base_id;
}
self::$user->ACL()->revoke_access_from_bases($base_ids);
self::$user->ACL()->revoke_unused_sbas_rights();
}
if (self::$user->is_admin())
$this->assertTrue(self::$user->ACL()->has_access_to_module('admin'));
else
$this->assertFalse(self::$user->ACL()->has_access_to_module('admin'));
$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('report'));
$found = false;
foreach ($appbox->get_databoxes() as $databox)
{
foreach ($databox->get_collections() as $collection)
{
$base_id = $collection->get_base_id();
$base_ids[] = $base_id;
self::$user->ACL()->update_rights_to_base($base_id, array('canreport' => true));
$found = true;
break;
}
if ($found)
break;
}
$this->assertTrue(self::$user->ACL()->has_access_to_module('report'));
$this->assertFalse(self::$user->ACL()->has_access_to_module('thesaurus'));
$this->assertFalse(self::$user->ACL()->has_access_to_module('upload'));
foreach ($appbox->get_databoxes() as $databox)
{
self::$user->ACL()->update_rights_to_sbas($databox->get_sbas_id(), array('bas_modif_th' => true));
$found = true;
}
$this->assertTrue(self::$user->ACL()->has_access_to_module('report'));
$this->assertTrue(self::$user->ACL()->has_access_to_module('thesaurus'));
$this->assertFalse(self::$user->ACL()->has_access_to_module('upload'));
$found = false;
foreach ($appbox->get_databoxes() as $databox)
{
foreach ($databox->get_collections() as $collection)
{
$base_id = $collection->get_base_id();
$base_ids[] = $base_id;
self::$user->ACL()->update_rights_to_base($base_id, array('canaddrecord' => true));
$found = true;
break;
}
if ($found)
break;
}
$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('upload'));
}
public function testis_limited()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$found = false;
foreach ($appbox->get_databoxes() as $databox)
{
foreach ($databox->get_collections() as $collection)
{
$base_id = $collection->get_base_id();
if ( ! self::$user->ACL()->has_access_to_base($base_id))
continue;
$this->assertFalse(self::$user->ACL()->is_limited($base_id));
self::$user->ACL()->set_limits($base_id, true, new DateTime('-1 day'), new DateTime('+1 day'));
$this->assertFalse(self::$user->ACL()->is_limited($base_id));
self::$user->ACL()->set_limits($base_id, false, new DateTime('-1 day'), new DateTime('+1 day'));
$this->assertFalse(self::$user->ACL()->is_limited($base_id));
self::$user->ACL()->set_limits($base_id, true, new DateTime('+1 day'), new DateTime('+2 day'));
$this->assertTrue(self::$user->ACL()->is_limited($base_id));
self::$user->ACL()->set_limits($base_id, true, new DateTime('-2 day'), new DateTime('-1 day'));
$this->assertTrue(self::$user->ACL()->is_limited($base_id));
self::$user->ACL()->set_limits($base_id, true, new DateTime('-2 day'), new DateTime('+2 day'));
$this->assertFalse(self::$user->ACL()->is_limited($base_id));
self::$user->ACL()->set_limits($base_id, false, new DateTime('-2 day'), new DateTime('+2 day'));
$this->assertFalse(self::$user->ACL()->is_limited($base_id));
$found = true;
}
}
if ( ! $found)
$this->fail('Unable to test');
}
public function testget_limits()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$found = false;
foreach ($appbox->get_databoxes() as $databox)
{
foreach ($databox->get_collections() as $collection)
{
$base_id = $collection->get_base_id();
if ( ! self::$user->ACL()->has_access_to_base($base_id))
continue;
$minusone = new DateTime('-1 day');
$plusone = new DateTime('+1 day');
self::$user->ACL()->set_limits($base_id, true, $minusone, $plusone);
$limits = self::$user->ACL()->get_limits($base_id);
$this->assertEquals($limits['dmin'], $minusone);
$this->assertEquals($limits['dmax'], $plusone);
$minustwo = new DateTime('-2 day');
$plustwo = new DateTime('-2 day');
self::$user->ACL()->set_limits($base_id, true, $minustwo, $plustwo);
$limits = self::$user->ACL()->get_limits($base_id);
$this->assertEquals($limits['dmin'], $minustwo);
$this->assertEquals($limits['dmax'], $plustwo);
self::$user->ACL()->set_limits($base_id, false);
$this->assertNull(self::$user->ACL()->get_limits($base_id));
$found = true;
}
}
if ( ! $found)
$this->fail('Unable to test');
}
public function testset_limits()
{
$this->testget_limits();
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,327 @@
<?php
require_once __DIR__ . '/../../../PhraseanetWebTestCaseAuthenticatedAbstract.class.inc';
use Silex\WebTestCase;
use Symfony\Component\HttpFoundation\Response;
class ApplicationLightboxTest extends PhraseanetWebTestCaseAuthenticatedAbstract
{
protected $client;
protected $feed;
protected $entry;
protected $item;
protected $validation_basket;
protected static $need_records = 1;
// protected static $need_subdefs = true;
public function setUp()
{
parent::setUp();
$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()
{
if($this->feed instanceof Feed_Adapter)
$this->feed->delete();
parent::tearDown();
}
public function createApplication()
{
return require __DIR__ . '/../../../../lib/Alchemy/Phrasea/Application/Lightbox.php';
}
public function testRouteSlash()
{
$baskets = $this->insertFiveBasket();
$this->set_user_agent(self::USER_AGENT_FIREFOX8MAC);
$crawler = $this->client->request('GET', '/');
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$this->assertEquals('UTF-8', $this->client->getResponse()->getCharset());
$this->assertEquals(5, $crawler->filter('div.basket_wrapper')->count());
$this->set_user_agent(self::USER_AGENT_IE6);
$crawler = $this->client->request('GET', '/');
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$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);
$crawler = $this->client->request('GET', '/');
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$this->assertEquals('UTF-8', $this->client->getResponse()->getCharset());
}
public function testAjaxNoteForm()
{
$basket = $this->insertOneValidationBasket();
$basket_element = $basket->getELements()->first();
$this->set_user_agent(self::USER_AGENT_FIREFOX8MAC);
$crawler = $this->client->request('GET', '/ajax/NOTE_FORM/' . $basket_element->getId() . '/');
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$this->assertEquals('', trim($this->client->getResponse()->getContent()));
$this->set_user_agent(self::USER_AGENT_IE6);
$crawler = $this->client->request('GET', '/ajax/NOTE_FORM/' . $basket_element->getId() . '/');
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$this->assertEquals('', trim($this->client->getResponse()->getContent()));
$this->set_user_agent(self::USER_AGENT_IPHONE);
$crawler = $this->client->request('GET', '/ajax/NOTE_FORM/' . $basket_element->getId() . '/');
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$this->assertNotEquals('', trim($this->client->getResponse()->getContent()));
}
public function testAjaxElement()
{
$basket_element = $this->insertOneBasketElement();
$this->set_user_agent(self::USER_AGENT_FIREFOX8MAC);
$crawler = $this->client->request('GET', '/ajax/LOAD_BASKET_ELEMENT/' . $basket_element->getId() . '/');
$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);
$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);
$this->set_user_agent(self::USER_AGENT_IE6);
$crawler = $this->client->request('GET', '/ajax/LOAD_BASKET_ELEMENT/' . $basket_element->getId() . '/');
$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);
$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);
$this->set_user_agent(self::USER_AGENT_IPHONE);
$crawler = $this->client->request('GET', '/ajax/LOAD_BASKET_ELEMENT/' . $basket_element->getId() . '/');
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$this->assertNotEquals('application/json', $this->client->getResponse()->headers->get('Content-type'));
}
public function testAjaxFeedItem()
{
$this->set_user_agent(self::USER_AGENT_FIREFOX8MAC);
$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('application/json', $this->client->getResponse()->headers->get('Content-type'));
$datas = json_decode($this->client->getResponse()->getContent());
$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);
$this->set_user_agent(self::USER_AGENT_IE6);
$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('application/json', $this->client->getResponse()->headers->get('Content-type'));
$datas = json_decode($this->client->getResponse()->getContent());
$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);
$this->set_user_agent(self::USER_AGENT_IPHONE);
$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->assertNotEquals('application/json', $this->client->getResponse()->headers->get('Content-type'));
}
public function testValidate()
{
$basket = $this->insertOneValidationBasket();
$this->set_user_agent(self::USER_AGENT_FIREFOX8MAC);
$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_IE6);
$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_IPHONE);
$crawler = $this->client->request('GET', '/validate/' . $basket->getId() . '/');
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$this->assertEquals('UTF-8', $this->client->getResponse()->getCharset());
}
public function testCompare()
{
$basket = $this->insertOneBasket();
$this->set_user_agent(self::USER_AGENT_FIREFOX8MAC);
$crawler = $this->client->request('GET', '/compare/' . $basket->getId() . '/');
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$this->assertEquals('UTF-8', $this->client->getResponse()->getCharset());
$this->set_user_agent(self::USER_AGENT_IE6);
$crawler = $this->client->request('GET', '/compare/' . $basket->getId() . '/');
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$this->assertEquals('UTF-8', $this->client->getResponse()->getCharset());
$this->set_user_agent(self::USER_AGENT_IPHONE);
$crawler = $this->client->request('GET', '/compare/' . $basket->getId() . '/');
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$this->assertEquals('UTF-8', $this->client->getResponse()->getCharset());
}
public function testFeedEntry()
{
$this->set_user_agent(self::USER_AGENT_FIREFOX8MAC);
$crawler = $this->client->request('GET', '/feeds/entry/' . $this->entry->get_id() . '/');
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$this->assertEquals('UTF-8', $this->client->getResponse()->getCharset());
$this->set_user_agent(self::USER_AGENT_IE6);
$crawler = $this->client->request('GET', '/feeds/entry/' . $this->entry->get_id() . '/');
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$this->assertEquals('UTF-8', $this->client->getResponse()->getCharset());
$this->set_user_agent(self::USER_AGENT_IPHONE);
$crawler = $this->client->request('GET', '/feeds/entry/' . $this->entry->get_id() . '/');
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$this->assertEquals('UTF-8', $this->client->getResponse()->getCharset());
}
public function testAjaxReport()
{
$validationBasket = $this->insertOneValidationBasket();
$this->set_user_agent(self::USER_AGENT_FIREFOX8MAC);
$crawler = $this->client->request('GET', '/ajax/LOAD_REPORT/' . $validationBasket->getId() . '/');
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$this->assertEquals('UTF-8', $this->client->getResponse()->getCharset());
}
public function testAjaxSetNote()
{
$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'
, '/ajax/SET_NOTE/' . $validationBasketElement->getId() . '/'
, array('note' => 'une jolie note')
);
$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'));
$datas = json_decode($this->client->getResponse()->getContent());
$this->assertTrue(is_object($datas), 'asserting good json datas');
$this->assertObjectHasAttribute('datas', $datas);
$this->assertObjectHasAttribute('error', $datas);
}
public function testAjaxSetAgreement()
{
$validationBasket = $this->insertOneValidationBasket();
$validationBasketElement = $validationBasket->getElements()->first();
$crawler = $this->client->request(
'POST'
, '/ajax/SET_ELEMENT_AGREEMENT/' . $validationBasketElement->getId() . '/'
);
$this->assertEquals(400, $this->client->getResponse()->getStatusCode());
$crawler = $this->client->request(
'POST'
, '/ajax/SET_ELEMENT_AGREEMENT/' . $validationBasketElement->getId() . '/'
, array('agreement' => 1)
);
$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'));
$datas = json_decode($this->client->getResponse()->getContent());
$this->assertTrue(is_object($datas), 'asserting good json datas');
$this->assertObjectHasAttribute('datas', $datas);
$this->assertObjectHasAttribute('error', $datas);
}
public function testAjaxSetRelease()
{
$basket = $this->insertOneBasket();
$crawler = $this->client->request('POST', '/ajax/SET_RELEASE/' . $basket->getId() . '/');
$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->assertTrue(is_object($datas), 'asserting good json datas');
$this->assertTrue($datas->error);
$validationBasket = $this->insertOneValidationBasket();
$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('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);
}
}

View File

@@ -0,0 +1,161 @@
<?php
require_once __DIR__ . '/../../../PhraseanetWebTestCaseAuthenticatedAbstract.class.inc';
use Symfony\Component\HttpFoundation\Response;
use Silex\WebTestCase;
/**
* Test oauthv2 flow based on ietf authv2 spec
* @link http://tools.ietf.org/html/draft-ietf-oauth-v2-18
*/
/**
*
*
*/
class oauthv2_application_test extends \PhraseanetWebTestCaseAuthenticatedAbstract
{
/**
*
* @var API_OAuth2_Application
*/
public static $appli;
public static $account_id;
public static $account;
public $oauth;
protected $client;
protected $queryParameters;
public static function 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->set_description('une description')
->set_redirect_uri('http://callback.com/callback/')
->set_website('http://website.com/')
->set_type(API_OAuth2_Application::WEB_TYPE);
}
public static function tearDownAfterClass()
{
parent::tearDownAfterClass();
if (self::$appli !== false)
self::deleteInsertedRow(appbox::get_instance(\bootstrap::getCore()), self::$appli);
}
public function setUp()
{
parent::setUp();
$this->client = $this->createClient();
$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
WHERE application_id = :id
';
$t = array(':id' => $app->get_id());
$stmt = $conn->prepare($sql);
$stmt->execute($t);
$sql = '
DELETE FROM api_accounts
WHERE api_account_id = :id
';
$acc = self::getAccount();
$t = array(':id' => $acc->get_id());
$stmt = $conn->prepare($sql);
$stmt->execute($t);
}
public static function getApp($rowId)
{
$sql = "SELECT * FROM api_applications WHERE application_id = :app_id";
$t = array(":app_id" => $rowId);
$appbox = appbox::get_instance(\bootstrap::getCore());
$conn = $appbox->get_connection();
$stmt = $conn->prepare($sql);
$stmt->execute($t);
$result = $stmt->fetch(PDO::FETCH_ASSOC);
return $result;
}
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())
{
$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

@@ -0,0 +1,131 @@
<?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';
use Silex\WebTestCase;
use Symfony\Component\HttpKernel\Client;
use Symfony\Component\HttpFoundation\Response;
class ApplicationOverviewTest extends PhraseanetWebTestCaseAuthenticatedAbstract
{
protected static $need_records = 1;
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());
$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

@@ -0,0 +1,63 @@
<?php
require_once __DIR__ . '/../../../PhraseanetWebTestCaseAuthenticatedAbstract.class.inc';
use Silex\WebTestCase;
use Symfony\Component\HttpFoundation\Response;
class ApplicationRootTest extends PhraseanetWebTestCaseAuthenticatedAbstract
{
protected $client;
protected static $need_records = false;
public function createApplication()
{
return require __DIR__ . '/../../../../lib/Alchemy/Phrasea/Application/Root.php';
}
public function setUp()
{
parent::setUp();
$this->client = $this->createClient();
}
public function testRouteSlash()
{
$crawler = $this->client->request('GET', '/');
$response = $this->client->getResponse();
$this->assertEquals(302, $response->getStatusCode());
$this->assertRegExp('/^\/login\/\?redirect=[\/a-zA-Z]+/', $response->headers->get('location'));
}
public function testRouteRobots()
{
$registry = \registry::get_instance();
$original_value = $registry->get('GV_allow_search_engine');
$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());
$this->assertRegExp('/^Disallow: \/$/m', $response->getContent());
$registry = \registry::get_instance();
$registry->set('GV_allow_search_engine', true, \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());
$this->assertRegExp('/^Allow: \/$/m', $response->getContent());
$registry->set('GV_allow_search_engine', $original_value, \registry::TYPE_BOOLEAN);
}
}

View File

@@ -0,0 +1,33 @@
<?php
require_once __DIR__ . '/../../../PhraseanetWebTestCaseAuthenticatedAbstract.class.inc';
use Silex\WebTestCase;
use Symfony\Component\HttpFoundation\Response;
class ApplicationSetupTest extends PhraseanetWebTestCaseAuthenticatedAbstract
{
protected $client;
protected static $need_records = false;
public function createApplication()
{
return require __DIR__ . '/../../../../lib/Alchemy/Phrasea/Application/Setup.php';
}
public function setUp()
{
parent::setUp();
$this->client = $this->createClient();
}
public function testRouteSlash()
{
$crawler = $this->client->request('GET', '/');
$response = $this->client->getResponse();
$this->assertEquals(302, $response->getStatusCode());
$this->assertEquals('/login/', $response->headers->get('location'));
}
}

View File

@@ -0,0 +1,53 @@
<?php
require_once __DIR__ . '/../../../PhraseanetPHPUnitAbstract.class.inc';
/**
* Test class for ApcCache.
* Generated by PHPUnit on 2012-02-21 at 16:39:56.
*/
class ApcCacheTest extends \PHPUnit_Framework_TestCase
{
/**
* @var ApcCache
*/
protected $object;
public function setUp()
{
if (!extension_loaded('apc'))
{
$this->markTestSkipped('Apc is not installed');
}
$this->object = new \Alchemy\Phrasea\Cache\ApcCache;
}
public function testIsServer()
{
$this->assertTrue(is_bool($this->object->isServer()));
}
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.'
);
}
}

View File

@@ -0,0 +1,53 @@
<?php
require_once __DIR__ . '/../../../PhraseanetPHPUnitAbstract.class.inc';
/**
* Test class for ArrayCache.
* Generated by PHPUnit on 2012-02-21 at 16:37:10.
*/
class ArrayCacheTest extends \PHPUnit_Framework_TestCase
{
/**
* @var ArrayCache
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
public function setUp()
{
$this->object = new \Alchemy\Phrasea\Cache\ArrayCache;
}
public function testIsServer()
{
$this->assertTrue(is_bool($this->object->isServer()));
}
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.'
);
}
}

View File

@@ -0,0 +1,51 @@
<?php
require_once __DIR__ . '/../../../PhraseanetPHPUnitAbstract.class.inc';
/**
* Test class for Manager.
* Generated by PHPUnit on 2012-02-21 at 16:37:11.
*/
class ManagerTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Manager
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
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

@@ -0,0 +1,66 @@
<?php
require_once __DIR__ . '/../../../PhraseanetPHPUnitAbstract.class.inc';
/**
* Test class for MemcacheCache.
* Generated by PHPUnit on 2012-02-21 at 16:37:11.
*/
class MemcacheCacheTest extends \PHPUnit_Framework_TestCase
{
/**
* @var MemcacheCache
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
public function setUp()
{
$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);
}
public function testIsServer()
{
$this->assertTrue(is_bool($this->object->isServer()));
}
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.'
);
}
}

View File

@@ -0,0 +1,70 @@
<?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';
class RedisTest extends \PhraseanetPHPUnitAbstract
{
public function testBasics()
{
if (extension_loaded('Redis'))
{
$redis = new Redis();
try
{
$ok = @$redis->connect('127.0.0.1', 6379);
}
catch(\Exception $e)
{
$ok = false;
}
if (!$ok)
{
$this->markTestSkipped('The ' . __CLASS__ . ' requires the use of redis');
}
}
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

@@ -0,0 +1,58 @@
<?php
require_once __DIR__ . '/../../../PhraseanetPHPUnitAbstract.class.inc';
/**
* Test class for XcacheCache.
* Generated by PHPUnit on 2012-02-21 at 16:39:57.
*/
class XcacheCacheTest extends \PHPUnit_Framework_TestCase
{
/**
* @var XcacheCache
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
public function setUp()
{
if(!function_exists('xcache_info'))
{
$this->markTestSkipped('Xcache not loaded');
}
$this->object = new \Alchemy\Phrasea\Cache\XcacheCache;
}
public function testIsServer()
{
$this->assertTrue(is_bool($this->object->isServer()));
}
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.'
);
}
}

View File

@@ -0,0 +1,270 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.class.inc';
/**
* Test class for Subdefs.
* Generated by PHPUnit on 2012-01-11 at 18:25:04.
*/
class DescriptionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{
/**
* 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);
$field->delete();
$this->fail("should raise an exception");
}
catch (\Exception $e)
{
}
}
public function testPostCreate()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$databox = array_shift($appbox->get_databoxes());
$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))
{
$field->delete();
$find = true;
}
}
if (!$find)
{
$this->fail("should have create a new field");
}
}
public function testPostDescriptionException()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$databox = array_shift($appbox->get_databoxes());
$this->client->request("POST", "/description/" . $databox->get_sbas_id() . "/", array(
'todelete_ids' => array('unknow_id')
));
$this->assertTrue($this->client->getResponse()->isRedirect());
$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();
$field = \databox_field::create($databox, $name);
$id = $field->get_id();
$this->client->request("POST", "/description/" . $databox->get_sbas_id() . "/", array(
'field_ids' => array('unknow_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();
}
public function testPostDescriptionRights()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$session = $appbox->get_session();
$auth = new Session_Authentication_None(self::$user_alt1);
$session->authenticate($auth);
$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(
'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->assertFalse($this->client->getResponse()->isOk());
$this->assertEquals("You are not allowed to access this zone", $this->client->getResponse()->getContent());
$field->delete();
}
public function testGetDescriptionException()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$session = $appbox->get_session();
$auth = new Session_Authentication_None(self::$user_alt1);
$session->authenticate($auth);
$databox = array_shift($appbox->get_databoxes());
$this->client->request("GET", "/description/" . $databox->get_sbas_id() . "/");
$this->assertFalse($this->client->getResponse()->isOk());
$this->assertEquals("You are not allowed to access this zone", $this->client->getResponse()->getContent());
}
public function testGetDescription()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$databox = array_shift($appbox->get_databoxes());
$this->client->request("GET", "/description/" . $databox->get_sbas_id() . "/");
$this->assertTrue($this->client->getResponse()->isOk());
}
}

View File

@@ -0,0 +1,86 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.class.inc';
/**
* Test class for Fields.
* Generated by PHPUnit on 2012-01-11 at 18:25:03.
*/
class ControllerFieldsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{
/**
* 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 testCheckMulti()
{
$appbox = \appbox::get_instance(\bootstrap::getCore());
$databox = array_shift($appbox->get_databoxes());
$field = \databox_field::create($databox, "test" . time());
$source = $field->get_source();
$this->client->request("GET", "/fields/checkmulti/", array(
'souce' => $source, 'multi' => 'false'));
$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_multi(), !!$datas->is_multi);
$field->delete();
}
public function testCheckReadOnly()
{
$appbox = \appbox::get_instance(\bootstrap::getCore());
$databox = array_shift($appbox->get_databoxes());
$field = \databox_field::create($databox, "test" . time());
$source = $field->get_source();
$this->client->request("GET", "/fields/checkreadonly/", array(
'souce' => $source, 'readonly' => 'false'));
$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();
}
}

View File

@@ -0,0 +1,445 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.class.inc';
use Silex\WebTestCase;
use Symfony\Component\HttpFoundation\Response;
class Module_Admin_Route_PublicationTest extends PhraseanetWebTestCaseAuthenticatedAbstract
{
public static $account = null;
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);
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());
}
}
public function testCreate()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
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());
$crawler = $this->client->request('POST', '/publications/create/', array("title" => "hello", "subtitle" => "coucou", "base_id" => $base_id));
$this->assertTrue($this->client->getResponse()->isRedirect('/admin/publications/list/'));
$feeds = Feed_Collection::load_all(appbox::get_instance(\bootstrap::getCore()), self::$user);
$count_after = sizeof($feeds->get_feeds());
$this->assertGreaterThan($count, $count_after);
$feed = array_pop($feeds->get_feeds());
$feed->delete();
}
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(
$this->client->getResponse()->headers->get('Location')
, '/admin/publications/feed/' . $feed->get_id() . '/?'
) === 0);
$feed->delete();
}
public function testUpdatedFeedException()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$feed = Feed_Adapter::create($appbox, self::$user, "salut", 'coucou');
$this->client->request("POST", "/publications/feed/" . $feed->get_id() . "/update/", array(
'title' => 'test'
, 'subtitle' => 'test'
, 'public' => '1'
));
$feed = new Feed_Adapter($appbox, $feed->get_id());
$this->assertTrue(
strpos(
$this->client->getResponse()->headers->get('Location')
, '/admin/publications/list/'
) === 0);
$this->assertEquals('test', $feed->get_title());
$this->assertEquals('test', $feed->get_subtitle());
$this->assertTrue($feed->is_public());
$this->assertNull($feed->get_collection());
$feed->delete();
}
public function testUpdatedFeedOwner()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$feed = Feed_Adapter::create($appbox, self::$user, "salut", 'coucou');
$this->client->request("POST", "/publications/feed/" . $feed->get_id() . "/update/", array(
'title' => 'test'
, 'subtitle' => 'test'
, 'public' => '1'
, 'base_id' => self::$collection->get_base_id()
));
$this->assertTrue(
strpos(
$this->client->getResponse()->headers->get('Location')
, '/admin/publications/list/'
) === 0);
$feed = new Feed_Adapter($appbox, $feed->get_id());
$collection = $feed->get_collection();
$this->assertEquals('test', $feed->get_title());
$this->assertEquals('test', $feed->get_subtitle());
$this->assertFalse($feed->is_public());
$this->assertEquals(self::$collection->get_base_id(), $collection->get_base_id());
$this->assertTrue(
strpos(
$this->client->getResponse()->headers->get('Location')
, '/admin/publications/list/'
) === 0);
$feed->delete();
}
public function testIconUploadErrorOwner()
{
$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() . "/iconupload/", array(), array());
$response = $this->client->getResponse();
$this->assertTrue($response->isOk());
$this->assertRegexp("/ERROR:you are not allowed/", $response->getContent());
$feed->delete();
}
public function testIconUploadErrorFileData()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$feed = Feed_Adapter::create($appbox, self::$user, "salut", 'coucou');
$this->client->request(
"POST"
, "/publications/feed/" . $feed->get_id() . "/iconupload/"
, array()
, array('Filedata' => array('error' => 1))
);
$response = $this->client->getResponse();
$this->assertTrue($response->isOk());
$this->assertRegexp("/ERROR:error while upload/", $response->getContent());
$feed->delete();
}
public function testIconUploadErrorFileType()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$feed = Feed_Adapter::create($appbox, self::$user, "salut", 'coucou');
$this->client->request(
"POST"
, "/publications/feed/" . $feed->get_id() . "/iconupload/"
, array()
, array('Filedata' => array('error' => 0, 'tmp_name' => __DIR__ . '/../../../../testfiles/test013.ai'))
);
$response = $this->client->getResponse();
$this->assertTrue($response->isOk());
$this->assertRegexp("/ERROR:bad filetype/", $response->getContent());
$feed->delete();
}
public function testIconUploadErrorTooLarge()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$feed = Feed_Adapter::create($appbox, self::$user, "salut", 'coucou');
$this->client->request(
"POST"
, "/publications/feed/" . $feed->get_id() . "/iconupload/"
, array()
, array('Filedata' => array('error' => 0, 'tmp_name' => __DIR__ . '/../../../../testfiles/heavy500.jpg'))
);
$response = $this->client->getResponse();
$this->assertTrue($response->isOk());
$this->assertRegexp("/ERROR:file too large/", $response->getContent());
$feed->delete();
}
public function testIconUploadErrorNotSquareA()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$feed = Feed_Adapter::create($appbox, self::$user, "salut", 'coucou');
$this->client->request(
"POST"
, "/publications/feed/" . $feed->get_id() . "/iconupload/"
, array()
, array('Filedata' => array('error' => 0, 'tmp_name' => __DIR__ . '/../../../../testfiles/recta_logo.gif'))
);
$response = $this->client->getResponse();
$this->assertTrue($response->isOk());
$this->assertRegexp("/ERROR:file is not square/", $response->getContent());
$feed->delete();
}
public function testIconUploadErrorNotSquareB()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$feed = Feed_Adapter::create($appbox, self::$user, "salut", 'coucou');
$this->client->request(
"POST"
, "/publications/feed/" . $feed->get_id() . "/iconupload/"
, array()
, array('Filedata' => array('error' => 0, 'tmp_name' => __DIR__ . '/../../../../testfiles/rectb_logo.gif'))
);
$response = $this->client->getResponse();
$this->assertTrue($response->isOk());
$this->assertRegexp("/ERROR:file is not square/", $response->getContent());
$feed->delete();
}
public function testIconUpload()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$feed = Feed_Adapter::create($appbox, self::$user, "salut", 'coucou');
copy(__DIR__ . '/../../../../testfiles/logocoll.gif', __DIR__ . '/../../../../testfiles/logocoll1.gif');
$this->client->request(
"POST"
, "/publications/feed/" . $feed->get_id() . "/iconupload/"
, array()
, array('Filedata' => array('error' => 0, 'tmp_name' => __DIR__ . '/../../../../testfiles/logocoll1.gif'))
);
$response = $this->client->getResponse();
$this->assertTrue($response->isOk());
$feed = new Feed_Adapter($appbox, $feed->get_id());
try
{
$file = new SplFileObject(__DIR__ . '/../../../../testfiles/logocoll1.gif');
$this->fail('logo not deleted');
}
catch (\Exception $e)
{
}
$this->assertRegexp("#FILEHREF:/custom/feed_" . $feed->get_id() . ".jpg?[0-9]*#", $response->getContent());
$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)
{
}
}
}

View File

@@ -0,0 +1,54 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.class.inc';
/**
* Test class for Subdefs.
* Generated by PHPUnit on 2012-01-11 at 18:25:04.
*/
class RootTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{
/**
* 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 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());
}
}

View File

@@ -0,0 +1,118 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.class.inc';
/**
* Test class for Subdefs.
* Generated by PHPUnit on 2012-01-11 at 18:25:04.
*/
class ControllerSubdefsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{
/**
* 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 testRouteGetSubdef()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$databox = array_shift($appbox->get_databoxes());
$this->client->request("GET", "/subdefs/" . $databox->get_sbas_id() . "/");
$this->assertTrue($this->client->getResponse()->isOk());
}
public function testPostRouteAddSubdef()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$databox = array_shift($appbox->get_databoxes());
$this->client->request("POST", "/subdefs/" . $databox->get_sbas_id() . "/", array('add_subdef' => array(
'class' => 'thumbnail',
'name' => 'aname',
'group' => 'image'
)));
$this->assertTrue($this->client->getResponse()->isRedirect());
$subdefs = $databox->get_subdef_structure();
$subdefs->get_subdef("image", "aname");
$subdefs->delete_subdef('image', 'aname');
}
public function testPostRouteDeleteSubdef()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$databox = array_shift($appbox->get_databoxes());
$subdefs = $databox->get_subdef_structure();
$subdefs->add_subdef("image", "name", "class");
$this->client->request("POST", "/subdefs/" . $databox->get_sbas_id() . "/", array('delete_subdef' => 'group_name'));
$this->assertTrue($this->client->getResponse()->isRedirect());
try
{
$subdefs->get_subdef("image", "name");
$this->fail("should raise an exception");
}
catch (\Exception $e)
{
}
}
public function testPostRouteAddSubdefWithNoParams()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$databox = array_shift($appbox->get_databoxes());
$subdefs = $databox->get_subdef_structure();
$subdefs->add_subdef("image", "name", "class");
$this->client->request("POST", "/subdefs/" . $databox->get_sbas_id() . "/", array('subdefs' => array(
'image_name'
)
, 'image_name_class' => 'class'
, 'image_name_downloadable' => 0
, 'image_name_mediatype' => 'image'
, 'image_name_image' => array(
'size' => 400
, 'resolution' => 83
, 'strip' => 0
, 'quality' => 90
))
);
$this->assertTrue($this->client->getResponse()->isRedirect());
$subdef = $subdefs->get_subdef("image", "name");
/* @var $subdef \databox_subdefAbstract */
$this->assertFalse($subdef->is_downloadable());
$options = $subdef->get_options();
$this->assertEquals(400, $options["size"]);
$this->assertEquals(83, $options["resolution"]);
$this->assertEquals(90, $options["quality"]);
$this->assertFalse($options["strip"]);
$subdefs->delete_subdef("image", "name");
}
}

View File

@@ -0,0 +1,366 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.class.inc';
/**
* Test class for Users.
* Generated by PHPUnit on 2012-01-11 at 18:25:04.
*/
class ControllerUsersTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{
/**
* 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;
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);
$user->delete();
$this->fail("user not deleted");
}
catch (\Exception $e)
{
}
}
public function testRouteRightsApply()
{
$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));
$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->markTestIncomplete();
$_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();
}
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);
$response = $this->client->getResponse();
$this->assertTrue($response->isOK());
}
public function testRouteQuotaAdd()
{
$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 = 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));
$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)
{
$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()));
$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);
$this->assertFalse($user->ACL()->has_access_to_base($base_id));
$user->delete();
}
}

View File

@@ -0,0 +1,69 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAbstract.class.inc';
/**
* Always load the controller file for CodeCoverage
*/
require_once __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Controller/My/Controller.php';
use Silex\WebTestCase;
use Symfony\Component\HttpFoundation\Response;
/**
*
* This class is a BoilerPlate for a Controller Test
*
* - You should extends PhraseanetWebTestCaseAuthenticatedAbstract if the
* controller required authentication
*
* - The Class Name should end with "Test" to be detected by
*
*/
class BoilerPlate extends \PhraseanetWebTestCaseAbstract
{
/**
* 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__ . '/../../../../Path/To/Application.php';
}
public function setUp()
{
parent::setUp();
$this->client = $this->createClient();
}
public function tearDown()
{
parent::tearDown();
}
/**
* Default route test
*/
public function testRouteSlash()
{
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
}

View File

@@ -0,0 +1,694 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.class.inc';
use Alchemy\Phrasea\Helper;
use Alchemy\Phrasea\RouteProcessor as routeProcessor;
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class ControllerBasketTest extends PhraseanetWebTestCaseAuthenticatedAbstract
{
protected $client;
protected static $need_records = 2;
public function setUp()
{
parent::setUp();
$this->client = $this->createClient();
}
public function createApplication()
{
return require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Prod.php';
}
public function testRootPost()
{
$route = '/baskets/';
$records = array(
self::$record_1->get_serialize_key(),
self::$record_2->get_serialize_key(),
' ',
'42',
self::$record_no_access->get_serialize_key()
);
$lst = implode(';', $records);
$this->client->request(
'POST', $route, array(
'name' => 'panier',
'desc' => 'mon beau panier',
'lst' => $lst)
);
$response = $this->client->getResponse();
$query = self::$core->getEntityManager()->createQuery(
'SELECT COUNT(b.id) FROM \Entities\Basket b'
);
$count = $query->getSingleScalarResult();
$this->assertEquals(1, $count);
$this->assertEquals(302, $response->getStatusCode());
$query = self::$core->getEntityManager()->createQuery(
'SELECT b FROM \Entities\Basket b'
);
$basket = array_shift($query->getResult());
/* @var $basket \Entities\Basket */
$this->assertEquals(2, $basket->getElements()->count());
}
public function testRootPostJSON()
{
$route = '/baskets/';
$this->client->request(
'POST'
, $route
, array(
'name' => 'panier',
'desc' => 'mon beau panier',
)
, array()
, array(
"HTTP_ACCEPT" => "application/json"
)
);
$response = $this->client->getResponse();
$query = self::$core->getEntityManager()->createQuery(
'SELECT COUNT(b.id) FROM \Entities\Basket b'
);
$count = $query->getSingleScalarResult();
$this->assertEquals(1, $count);
$this->assertEquals(200, $response->getStatusCode());
}
public function testCreateGet()
{
$route = '/baskets/create/';
$crawler = $this->client->request('GET', $route);
$response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode());
$filter = "form[action='/prod/baskets/']";
$this->assertEquals(1, $crawler->filter($filter)->count());
$filter = "form[action='/prod/baskets/'] input[name='name']";
$this->assertEquals(1, $crawler->filter($filter)->count());
$filter = "form[action='/prod/baskets/'] textarea[name='description']";
$this->assertEquals(1, $crawler->filter($filter)->count());
}
public function testBasketGet()
{
$basket = $this->insertOneBasket();
$route = sprintf('/baskets/%s/', $basket->getId());
$crawler = $this->client->request('GET', $route);
$response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode());
}
public function testBasketDeleteElementPost()
{
/* @var $em \Doctrine\ORM\EntityManager */
$em = self::$core->getEntityManager();
$basket = $this->insertOneBasket();
$record = self::$record_1;
$basket_element = new \Entities\BasketElement();
$basket_element->setBasket($basket);
$basket_element->setRecord($record);
$basket_element->setLastInBasket();
$basket->addBasketElement($basket_element);
$em->persist($basket);
$em->flush();
$route = sprintf(
"/baskets/%s/delete/%s/", $basket->getId(), $basket_element->getId()
);
$crawler = $this->client->request('POST', $route);
$response = $this->client->getResponse();
$em = self::$core->getEntityManager();
/* @var $em \Doctrine\ORM\EntityManager */
$em->refresh($basket);
$this->assertEquals(302, $response->getStatusCode());
$this->assertEquals(0, $basket->getElements()->count());
}
public function testBasketDeleteElementPostJSON()
{
/* @var $em \Doctrine\ORM\EntityManager */
$em = self::$core->getEntityManager();
$basket = $this->insertOneBasket();
$record = self::$record_1;
$basket_element = new \Entities\BasketElement();
$basket_element->setBasket($basket);
$basket_element->setRecord($record);
$basket_element->setLastInBasket();
$basket->addBasketElement($basket_element);
$em->persist($basket);
$em->flush();
$route = sprintf(
"/baskets/%s/delete/%s/", $basket->getId(), $basket_element->getId()
);
$crawler = $this->client->request(
'POST', $route, array(), array(), array(
"HTTP_ACCEPT" => "application/json")
);
$response = $this->client->getResponse();
$em->refresh($basket);
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals(0, $basket->getElements()->count());
}
public function testBasketDeletePost()
{
$basket = $this->insertOneBasket();
$route = sprintf('/baskets/%s/delete/', $basket->getId());
$crawler = $this->client->request('POST', $route);
$response = $this->client->getResponse();
$query = self::$core->getEntityManager()->createQuery(
'SELECT COUNT(b.id) FROM \Entities\Basket b'
);
$count = $query->getSingleScalarResult();
$this->assertEquals(0, $count);
$this->assertEquals(302, $response->getStatusCode());
}
public function testBasketDeletePostJSON()
{
$basket = $this->insertOneBasket();
$route = sprintf('/baskets/%s/delete/', $basket->getId());
$crawler = $this->client->request(
'POST', $route, array(), array(), array(
"HTTP_ACCEPT" => "application/json")
);
$this->client->getRequest()->setRequestFormat('json');
$response = $this->client->getResponse();
$query = self::$core->getEntityManager()->createQuery(
'SELECT COUNT(b.id) FROM \Entities\Basket b'
);
$count = $query->getSingleScalarResult();
$this->assertEquals(0, $count);
$this->assertEquals(200, $response->getStatusCode());
}
public function testBasketUpdatePost()
{
$basket = $this->insertOneBasket();
$route = sprintf('/baskets/%s/update/', $basket->getId());
$crawler = $this->client->request(
'POST', $route, array(
'name' => 'new_name',
'description' => 'new_desc')
);
$response = $this->client->getResponse();
$em = self::$core->getEntityManager();
/* @var $em \Doctrine\ORM\EntityManager */
$basket = $em->getRepository('Entities\Basket')->find($basket->getId());
$this->assertEquals('new_name', $basket->getName());
$this->assertEquals('new_desc', $basket->getDescription());
$this->assertEquals(302, $response->getStatusCode());
}
public function testBasketUpdatePostJSON()
{
$basket = $this->insertOneBasket();
$route = sprintf('/baskets/%s/update/', $basket->getId());
$crawler = $this->client->request(
'POST', $route, array(
'name' => 'new_name',
'description' => 'new_desc'
), array(), array(
"HTTP_ACCEPT" => "application/json")
);
$response = $this->client->getResponse();
$em = self::$core->getEntityManager();
/* @var $em \Doctrine\ORM\EntityManager */
$basket = $em->getRepository('Entities\Basket')->find($basket->getId());
$this->assertEquals('new_name', $basket->getName());
$this->assertEquals('new_desc', $basket->getDescription());
$this->assertEquals(200, $response->getStatusCode());
}
public function testReorderGet()
{
$basket = $this->insertOneBasketEnv();
$route = sprintf("/baskets/%s/reorder/", $basket->getId());
$crawler = $this->client->request("GET", $route);
$response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode());
foreach ($basket->getElements() as $elements)
{
$filter = sprintf("form[action='/prod/baskets/%s/reorder/']", $elements->getId());
$this->assertEquals(1, $crawler->filter($filter)->count());
}
}
public function testBasketUpdateGet()
{
$basket = $this->insertOneBasket();
$route = sprintf('/baskets/%s/update/', $basket->getId());
$crawler = $this->client->request(
'GET', $route, array(
'name' => 'new_name',
'description' => 'new_desc')
);
$response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode());
$filter = "form[action='/prod/baskets/" . $basket->getId() . "/update/']";
$this->assertEquals($crawler->filter($filter)->count(), 1);
$node = $crawler
->filter('input[name=name]');
$this->assertEquals($basket->getName(), $node->attr('value'));
$node = $crawler
->filter('textarea[name=description]');
$this->assertEquals($basket->getDescription(), $node->text());
}
public function testBasketArchivedPost()
{
$basket = $this->insertOneBasket();
$route = sprintf('/baskets/%s/archive/', $basket->getId());
$crawler = $this->client->request('POST', $route, array('archive' => '1'));
$response = $this->client->getResponse();
$em = self::$core->getEntityManager();
/* @var $em \Doctrine\ORM\EntityManager */
$basket = $em->getRepository('Entities\Basket')->find($basket->getId());
$this->assertTrue($basket->getArchived());
$crawler = $this->client->request('POST', $route, array('archive' => '0'));
$response = $this->client->getResponse();
$em->refresh($basket);
$this->assertFalse($basket->getArchived());
$this->assertEquals(302, $response->getStatusCode());
}
public function testBasketArchivedPostJSON()
{
$basket = $this->insertOneBasket();
$route = sprintf('/baskets/%s/archive/', $basket->getId());
$crawler = $this->client->request(
'POST', $route, array(
'archive' => '1'
), array(), array(
"HTTP_ACCEPT" => "application/json"
)
);
$response = $this->client->getResponse();
$em = self::$core->getEntityManager();
/* @var $em \Doctrine\ORM\EntityManager */
$basket = $em->getRepository('Entities\Basket')->find($basket->getId());
$this->assertTrue($basket->getArchived());
$crawler = $this->client->request(
'POST', $route, array(
'archive' => '0'
), array(), array(
"HTTP_ACCEPT" => "application/json"
)
);
$response = $this->client->getResponse();
$em->refresh($basket);
$this->assertFalse($basket->getArchived());
$this->assertEquals(200, $response->getStatusCode());
}
public function testAddElementPost()
{
$basket = $this->insertOneBasket();
$route = sprintf('/baskets/%s/addElements/', $basket->getId());
$records = array(
self::$record_1->get_serialize_key(),
self::$record_2->get_serialize_key(),
' ',
'42',
'abhak',
self::$record_no_access->get_serialize_key(),
);
$lst = implode(';', $records);
$crawler = $this->client->request('POST', $route, array('lst' => $lst));
$response = $this->client->getResponse();
$this->assertEquals(302, $response->getStatusCode());
$em = self::$core->getEntityManager();
/* @var $em \Doctrine\ORM\EntityManager */
$basket = $em->getRepository('Entities\Basket')->find($basket->getId());
$this->assertEquals(2, $basket->getElements()->count());
}
public function testAddElementToValidationPost()
{
$em = self::$core->getEntityManager();
$datas = $em->getRepository('Entities\ValidationData')->findAll();
$countDatas = count($datas);
$basket = $this->insertOneBasket();
$validationSession = new \Entities\ValidationSession();
$validationSession->setDescription('Une description au hasard');
$validationSession->setName('Un nom de validation');
$expires = new \DateTime();
$expires->modify('+1 week');
$validationSession->setExpires($expires);
$validationSession->setInitiator(self::$user);
$em->persist($validationSession);
$basket->setValidation($validationSession);
$validationSession->setBasket($basket);
$validationParticipant = new \Entities\ValidationParticipant();
$validationParticipant->setSession($validationSession);
$validationParticipant->setUser(self::$user_alt1);
$em->persist($validationParticipant);
$validationSession->addValidationParticipant($validationParticipant);
$em->flush();
$route = sprintf('/baskets/%s/addElements/', $basket->getId());
$records = array(
self::$record_1->get_serialize_key(),
self::$record_2->get_serialize_key(),
' ',
'42',
'abhak',
self::$record_no_access->get_serialize_key(),
);
$lst = implode(';', $records);
$this->client->request('POST', $route, array('lst' => $lst));
$response = $this->client->getResponse();
$this->assertEquals(302, $response->getStatusCode());
$em = self::$core->getEntityManager();
/* @var $em \Doctrine\ORM\EntityManager */
$basket = $em->getRepository('Entities\Basket')->find($basket->getId());
$this->assertEquals(2, $basket->getElements()->count());
$datas = $em->getRepository('Entities\ValidationData')->findAll();
$this->assertTrue($countDatas < count($datas), 'assert that '.count($datas).' > '.$countDatas );
}
public function testAddElementPostJSON()
{
$basket = $this->insertOneBasket();
$route = sprintf('/baskets/%s/addElements/', $basket->getId());
$records = array(
self::$record_1->get_serialize_key(),
self::$record_2->get_serialize_key()
);
$lst = implode(';', $records);
$crawler = $this->client->request(
'POST', $route, array(
'lst' => $lst
), array(), array(
"HTTP_ACCEPT" => "application/json"
)
);
$response = $this->client->getResponse();
$em = self::$core->getEntityManager();
/* @var $em \Doctrine\ORM\EntityManager */
$basket = $em->getRepository('Entities\Basket')->find($basket->getId());
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals(2, $basket->getElements()->count());
}
public function testRouteStealElements()
{
$em = self::$core->getEntityManager();
$BasketElement = $this->insertOneBasketElement();
$Basket_1 = $BasketElement->getBasket();
$Basket_2 = $this->insertOneBasket();
$route = sprintf('/baskets/%s/stealElements/', $Basket_2->getId());
$this->client->request(
'POST', $route, array(
'elements' => array($BasketElement->getId(), 'ufdsd')
), array()
);
$response = $this->client->getResponse();
$this->assertTrue($response->isRedirect());
$em = self::$core->getEntityManager();
/* @var $em \Doctrine\ORM\EntityManager */
$basket = $em->getRepository('Entities\Basket')->find($Basket_1->getId());
$this->assertInstanceOf('\Entities\Basket', $basket);
$this->assertEquals(0, $basket->getElements()->count());
$basket = $em->getRepository('Entities\Basket')->find($Basket_2->getId());
$this->assertInstanceOf('\Entities\Basket', $basket);
$this->assertEquals(1, $basket->getElements()->count());
}
public function testRouteStealElementsJson()
{
$em = self::$core->getEntityManager();
$BasketElement = $this->insertOneBasketElement();
$Basket_1 = $BasketElement->getBasket();
$Basket_2 = $this->insertOneBasket();
$route = sprintf('/baskets/%s/stealElements/', $Basket_2->getId());
$this->client->request(
'POST', $route, array(
'elements' => array($BasketElement->getId())
), array()
, array(
"HTTP_ACCEPT" => "application/json"
)
);
$response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode());
$datas = (array) json_decode($response->getContent());
$this->assertArrayHasKey('message', $datas);
$this->assertArrayHasKey('success', $datas);
$this->assertTrue($datas['success']);
$basket = $em->getRepository('Entities\Basket')->find($Basket_1->getId());
$this->assertInstanceOf('\Entities\Basket', $basket);
$this->assertEquals(0, $basket->getElements()->count());
$basket = $em->getRepository('Entities\Basket')->find($Basket_2->getId());
$this->assertInstanceOf('\Entities\Basket', $basket);
$this->assertEquals(1, $basket->getElements()->count());
}
/**
* Test when i remove a basket, all relations are removed too :
* - basket elements
* - validations sessions
* - validation participants
*/
public function testRemoveBasket()
{
$basket = $this->insertOneBasketEnv();
$em = self::$core->getEntityManager();
/* @var $em \Doctrine\ORM\EntityManager */
$basket = $em->find("Entities\Basket", $basket->getId());
$em->remove($basket);
$em->flush();
$query = $em->createQuery(
'SELECT COUNT(v.id) FROM \Entities\ValidationParticipant v'
);
$count = $query->getSingleScalarResult();
$this->assertEquals(0, $count);
$query = $em->createQuery(
'SELECT COUNT(b.id) FROM \Entities\BasketElement b'
);
$count = $query->getSingleScalarResult();
$this->assertEquals(0, $count);
$query = $em->createQuery(
'SELECT COUNT(v.id) FROM \Entities\ValidationSession v'
);
$count = $query->getSingleScalarResult();
$this->assertEquals(0, $count);
$query = $em->createQuery(
'SELECT COUNT(b.id) FROM \Entities\Basket b'
);
$count = $query->getSingleScalarResult();
$this->assertEquals(0, $count);
}
}

View File

@@ -0,0 +1,438 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.class.inc';
require_once __DIR__ . '/../../../../Bridge/Bridge_datas.inc';
use Silex\WebTestCase;
use Symfony\Component\HttpFoundation\Response;
class BridgeApplication extends PhraseanetWebTestCaseAuthenticatedAbstract
{
public static $account = null;
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');
}
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');
}
}
public function tearDown()
{
parent::tearDown();
if (self::$api instanceof Bridge_Api)
self::$api->delete();
if (self::$account instanceof Bridge_Account)
self::$account->delete();
}
public function createApplication()
{
return include realpath(__DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Prod.php');
}
/**
* @todo create a new basket dont take an existing one
*/
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();
$crawler = $this->client->request('POST', '/bridge/manager/', array('ssel' => $basket->getId()));
$pageContent = $this->client->getResponse()->getContent();
$this->assertTrue($this->client->getResponse()->isOk());
}
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()));
}
public function testCallBackFailed()
{
$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')
->reduce(function ($node, $i) use ($phpunit)
{
if (!$node->getAttribute('class'))
{
return false;
}
elseif ($node->getAttribute('class') == 'error_auth')
{
$phpunit->fail("Erreur callback");
}
});
$settings = self::$account->get_settings();
$this->assertEquals("kikoo", $settings->get("auth_token"));
$this->assertEquals("kooki", $settings->get("refresh_token"));
$this->assertEquals("biloute", $settings->get("access_token"));
$settings->delete("auth_token");
$settings->delete("refresh_token");
$settings->delete("access_token");
}
public function testCallBackAccountNoDefined()
{
if (self::$account instanceof Bridge_Account)
self::$account->delete();
$crawler = $this->client->request('GET', '/bridge/callback/apitest/');
$this->assertTrue($this->client->getResponse()->isOk());
$phpunit = $this;
$crawler
->filter('div')
->reduce(function ($node, $i) use ($phpunit)
{
if (!$node->getAttribute('class'))
{
return false;
}
elseif ($node->getAttribute('class') == 'error_auth')
{
$phpunit->fail("Erreur callback");
}
});
try
{
self::$account = Bridge_Account::load_account_from_distant_id(appbox::get_instance(\bootstrap::getCore()), self::$api, self::$user, 'kirikoo');
$settings = self::$account->get_settings();
$this->assertEquals("kikoo", $settings->get("auth_token"));
$this->assertEquals("kooki", $settings->get("refresh_token"));
$this->assertEquals("biloute", $settings->get("access_token"));
$settings->delete("auth_token");
$settings->delete("refresh_token");
$settings->delete("access_token");
}
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');
}
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"));
$this->fail("expected Exception here");
}
catch (Exception $e)
{
}
try
{
$crawler = $this->client->request('POST', $url, array("elements_list" => "1;2;3"));
$this->fail("expected Exception here");
}
catch (Exception $e)
{
}
}
public function testActionModifyTooManyElements()
{
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;
$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->assertTrue($this->client->getResponse()->isRedirect());
$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());
$this->client->request('POST', $url, array('title' => 'test', 'description' => 'description'));
$this->assertTrue($this->client->getResponse()->isRedirect());
$this->assertRegexp('/success/', $this->client->getResponse()->headers->get('location'));
}
/**
* @todo no templates declared for modify a container in any apis
*/
public function testActionModifyContainer()
{
$this->markTestSkipped("No templates declared for modify a container in any apis");
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());
$crawler = $this->client->request('GET', $url, array("elements_list" => "containerudt456shn"));
$this->assertTrue($this->client->getResponse()->isOk());
$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->client->request('POST', $url, array("elements_list" => "containerudt456shn"));
$this->assertTrue($this->client->getResponse()->isOk());
}
public function testActionMoveInto()
{
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());
$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->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->assertRegexp('/success/', $this->client->getResponse()->headers->get('location'));
$this->assertTrue($this->client->getResponse()->isRedirect());
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->assertRegexp('/error/', $this->client->getResponse()->headers->get('location'));
$this->assertTrue($this->client->getResponse()->isRedirect());
}
public function deconnected($crawler, $pageContent)
{
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertContains("prod/bridge/login/" . mb_strtolower(self::$account->get_api()->get_connector()->get_name()) . "/", $pageContent);
}
public function testUpload()
{
self::$account->get_settings()->set("auth_token", "somethingNotNull");
$url = "/bridge/upload/";
$this->client->request('GET', $url, array("account_id" => self::$account->get_id()));
$response = $this->client->getResponse();
$this->assertTrue($response->isOk());
$records = array(
self::$record_1->get_serialize_key()
);
Bridge_Api_Apitest::$hasError = true;
$lst = implode(';', $records);
$this->client->request('POST', $url, array("account_id" => self::$account->get_id(), 'lst' => $lst));
$response = $this->client->getResponse();
$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());
}
}

View File

@@ -0,0 +1,98 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.class.inc';
/**
* Test class for Edit.
* Generated by PHPUnit on 2012-01-11 at 18:24:28.
*/
class ControllerEditTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{
/**
* 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 = 1;
/**
* 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()
{
$this->client->request('POST', '/records/edit/', array('lst' => self::$record_1->get_serialize_key()));
$response = $this->client->getResponse();
$this->assertTrue($response->isOk());
}
public function testApply()
{
$this->client->request('POST', '/records/edit/apply/', array('lst' => self::$record_1->get_serialize_key()));
$response = $this->client->getResponse();
$this->assertTrue($response->isOk());
}
public function testVocabulary()
{
$this->client->request('GET', '/records/edit/vocabulary/Zanzibar/');
$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/');
$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/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);
}
}

View File

@@ -0,0 +1,473 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.class.inc';
use Silex\WebTestCase;
use Symfony\Component\HttpFoundation\Response;
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
* */
$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");
$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");
$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

@@ -0,0 +1,47 @@
<?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';
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class ControllerLanguageTest extends PhraseanetWebTestCaseAbstract
{
protected $client;
public function setUp()
{
parent::setUp();
$this->client = $this->createClient();
}
public function createApplication()
{
return require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Prod.php';
}
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));
}
}

View File

@@ -0,0 +1,64 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.class.inc';
/**
* Test class for MoveCollection.
* Generated by PHPUnit on 2012-01-11 at 18:24:28.
*/
class ControllerMoveCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{
/**
* 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 = 1;
/**
* 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()
{
$this->client->request('POST', '/records/movecollection/', array('lst' => self::$record_1->get_serialize_key()));
$response = $this->client->getResponse();
$this->assertTrue($response->isOk());
}
public function testApply()
{
$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());
}
}

View File

@@ -0,0 +1,61 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.class.inc';
/**
* Test class for MustacheLoader.
* Generated by PHPUnit on 2012-01-26 at 14:04:04.
*/
class MustacheLoaderTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{
protected $client;
public function createApplication()
{
return require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Prod.php';
}
public function setUp()
{
parent::setUp();
$this->client = $this->createClient();
}
public function testRouteSlash()
{
$this->client->request('GET', '/MustacheLoader/');
$response = $this->client->getResponse();
/* @var $response \Symfony\Component\HttpFoundation\Response */
$this->assertEquals(400, $response->getStatusCode());
$this->assertFalse($response->isOk());
$this->client->request('GET', '/MustacheLoader/', array('template' => '/../../../../config/config.yml'));
$response = $this->client->getResponse();
/* @var $response \Symfony\Component\HttpFoundation\Response */
$this->assertEquals(400, $response->getStatusCode());
$this->assertFalse($response->isOk());
$this->client->request('GET', '/MustacheLoader/', array('template' => 'patator_lala'));
$response = $this->client->getResponse();
/* @var $response \Symfony\Component\HttpFoundation\Response */
$this->assertEquals(404, $response->getStatusCode());
$this->assertFalse($response->isOk());
$this->client->request('GET', '/MustacheLoader/', array('template' => 'Feedback-Badge'));
$response = $this->client->getResponse();
/* @var $response \Symfony\Component\HttpFoundation\Response */
$this->assertEquals(200, $response->getStatusCode());
$this->assertTrue($response->isOk());
}
}

View File

@@ -0,0 +1,96 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.class.inc';
/**
* Test class for Printer.
* Generated by PHPUnit on 2012-01-11 at 18:24:29.
*/
class ControllerPrinterTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{
/**
* 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(
'lst' => $lst,
'lay' => $layout
)
);
$response = $this->client->getResponse();
$this->assertEquals("application/pdf", $response->headers->get("content-type"));
$this->assertTrue($response->isOk());
}
}
}

View File

@@ -0,0 +1,167 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.class.inc';
/**
* Test class for Push.
* Generated by PHPUnit on 2012-01-11 at 18:24:29.
*/
class ControllerPushTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{
/**
* 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 = 2;
/**
* 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 testRoutePOSTSendSlash()
{
$route = '/push/sendform/';
$this->client->request('POST', $route);
$response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('UTF-8', $response->getCharset());
}
public function testRoutePOSTValidateSlash()
{
$route = '/push/validateform/';
$this->client->request('POST', $route);
$response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('UTF-8', $response->getCharset());
}
public function testRoutePOSTsend()
{
$route = '/push/send/';
$records = array(
self::$record_1->get_serialize_key()
, self::$record_2->get_serialize_key()
);
$receivers = array(
array('usr_id'=>self::$user_alt1->get_id(), 'HD'=>1)
, array('usr_id'=>self::$user_alt2->get_id(), 'HD'=>0)
);
$params = array(
'lst' => implode(';', $records)
, 'participants' => $receivers
);
$this->client->request('POST', $route, $params);
$response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('UTF-8', $response->getCharset());
$datas = (array) json_decode($response->getContent());
$this->assertArrayHasKey('message', $datas);
$this->assertArrayHasKey('success', $datas);
$this->assertTrue($datas['success'], 'Result is successful');
}
public function testRoutePOSTvalidate()
{
$route = '/push/validate/';
$records = array(
self::$record_1->get_serialize_key()
, self::$record_2->get_serialize_key()
);
$participants = array(
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(
'lst' => implode(';', $records)
, 'participants' => $participants
);
$this->client->request('POST', $route, $params);
$response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('UTF-8', $response->getCharset());
$datas = (array) json_decode($response->getContent());
$this->assertArrayHasKey('message', $datas);
$this->assertArrayHasKey('success', $datas);
$this->assertTrue($datas['success'], 'Result is successful');
}
public function testRouteGETsearchuser()
{
$route = '/push/search-user/';
$params = array(
'query' => ''
);
$this->client->request('GET', $route, $params);
$response = $this->client->getResponse();
$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');
}
}

View File

@@ -0,0 +1,56 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.class.inc';
/**
* Test class for Root.
* Generated by PHPUnit on 2012-01-11 at 18:24:30.
*/
class ControllerRootTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{
/**
* 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()
{
$crawler = $this->client->request('GET', '/');
$response = $this->client->getResponse();
/* @var $response \Symfony\Component\HttpFoundation\Response */
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('UTF-8', $response->getCharset());
}
}

View File

@@ -0,0 +1,228 @@
<?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__ . '/../../../../../lib/Alchemy/Phrasea/Controller/Prod/Story.php';
use Doctrine\Common\DataFixtures\Loader;
use PhraseaFixture\Basket as MyFixture;
use Alchemy\Phrasea\Helper;
use Alchemy\Phrasea\RouteProcessor as routeProcessor;
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class ControllerStoryTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{
protected $client;
/**
*
* @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 */
$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

@@ -0,0 +1,196 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.class.inc';
require_once __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Controller/Prod/UsrLists.php';
use Silex\WebTestCase;
use Symfony\Component\HttpFoundation\Response;
class ControllerTooltipTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{
protected $client;
protected static $need_records = 1;
protected static $need_subdefs = true;
protected static $need_story = 1;
public function setUp()
{
parent::setUp();
$this->client = $this->createClient();
}
public function createApplication()
{
return require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Prod.php';
}
public function testRouteBasket()
{
$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', '/tootltip/basket/notanid/');
$pageContent = $this->client->getResponse()->getContent();
$this->assertFalse($this->client->getResponse()->isOk());
$crawler = $this->client->request('POST', '/tooltip/basket/-5/');
$pageContent = $this->client->getResponse()->getContent();
$this->assertFalse($this->client->getResponse()->isOk());
}
public function testRoutePreview()
{
$route = '/tooltip/preview/' . self::$record_1->get_sbas_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 testRouteCaption()
{
$route_base = '/tooltip/caption/' . self::$record_1->get_sbas_id()
. '/' . self::$record_1->get_record_id() . '/%s/';
$routes = array(
sprintf($route_base, 'answer')
, sprintf($route_base, 'lazaret')
, sprintf($route_base, 'preview')
, sprintf($route_base, 'basket')
, sprintf($route_base, 'overview')
);
foreach ($routes as $route)
{
$crawler = $this->client->request('POST', $route);
$pageContent = $this->client->getResponse()->getContent();
$this->assertTrue($this->client->getResponse()->isOk());
}
}
public function testRouteCaptionSearchEngine()
{
$route_base = '/tooltip/caption/' . self::$record_1->get_sbas_id()
. '/' . self::$record_1->get_record_id() . '/%s/';
$routes = array(
sprintf($route_base, 'answer')
, sprintf($route_base, 'lazaret')
, sprintf($route_base, 'preview')
, sprintf($route_base, 'basket')
, sprintf($route_base, 'overview')
);
foreach ($routes as $route)
{
$option = new \searchEngine_options();
$crawler = $this->client->request('POST', $route, array('options_serial' => serialize($option)));
$this->assertTrue($this->client->getResponse()->isOk());
}
}
public function testRouteTCDatas()
{
$route = '/tooltip/tc_datas/' . self::$record_1->get_sbas_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);
$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()
. '/' . self::$story_1->get_record_id() . '/';
$this->client->request('POST', $route);
$this->assertTrue($this->client->getResponse()->isOk());
}
public function testUser()
{
$route = '/tooltip/user/' . self::$user->get_id() . '/';
$this->client->request('POST', $route);
$this->assertTrue($this->client->getResponse()->isOk());
}
}

View File

@@ -0,0 +1,483 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.class.inc';
/**
* Test class for UsrLists.
* Generated by PHPUnit on 2012-01-11 at 18:24:30.
*/
class ControllerUsrListsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{
/**
* 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);
}
if ($users)
$this->assertTrue(count($list->users) > 0);
foreach ($list->users as $user)
{
$this->checkUser($user);
}
}
public function testPostList()
{
$route = '/lists/list/';
$this->client->request('POST', $route);
$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->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());
//
// $this->assertTrue(is_array($datas));
// $this->assertArrayhasKey('result', $datas);
// $this->checkList($datas['result']);
}
public function testPostUpdate()
{
$entry = $this->insertOneUsrListEntry(self::$user, self::$user_alt1);
$list_id = $entry->getList()->getId();
$route = '/lists/list/' . $list_id . '/update/';
$this->client->request('POST', $route);
$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->assertFalse($datas['success']);
$this->client->request('POST', $route, array('name' => 'New NAME'));
$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 testPostDelete()
{
$entry = $this->insertOneUsrListEntry(self::$user, self::$user_alt1);
$list_id = $entry->getList()->getId();
$route = '/lists/list/' . $list_id . '/delete/';
$this->client->request('POST', $route);
$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']);
$repository = self::$core->getEntityManager()->getRepository('Entities\UsrList');
$this->assertNull($repository->find($list_id));
}
public function testPostRemoveEntry()
{
$entry = $this->insertOneUsrListEntry(self::$user, self::$user_alt1);
$list_id = $entry->getList()->getId();
$usr_id = $entry->getUser()->get_id();
$entry_id = $entry->getId();
$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"));
$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']);
$repository = self::$core->getEntityManager()->getRepository('Entities\UsrListEntry');
$this->assertNull($repository->find($entry_id));
}
public function testPostAddEntry()
{
$list = $this->insertOneUsrList(self::$user);
$this->assertEquals(0, $list->getEntries()->count());
$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"));
$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']);
$repository = self::$core->getEntityManager()->getRepository('Entities\UsrList');
$list = $repository->find($list->getId());
$this->assertEquals(1, $list->getEntries()->count());
}
public function testPostShareList()
{
$list = $this->insertOneUsrList(self::$user);
$this->assertEquals(1, $list->getOwners()->count());
$route = '/lists/list/' . $list->getId() . '/share/' . self::$user_alt1->get_id() . '/';
$this->client->request('POST', $route);
$response = $this->client->getResponse();
$this->assertEquals(400, $response->getStatusCode());
$this->assertEquals('UTF-8', $response->getCharset());
$route = '/lists/list/' . $list->getId() . '/share/' . self::$user_alt1->get_id() . '/';
$this->client->request('POST', $route, array('role' => 'general'));
$response = $this->client->getResponse();
$this->assertEquals(400, $response->getStatusCode());
$this->assertEquals('UTF-8', $response->getCharset());
$route = '/lists/list/' . $list->getId() . '/share/' . self::$user_alt1->get_id() . '/';
$this->client->request('POST', $route, array('role' => \Entities\UsrListOwner::ROLE_ADMIN));
$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']);
$repository = self::$core->getEntityManager()->getRepository('Entities\UsrList');
$list = $repository->find($list->getId());
$this->assertEquals(2, $list->getOwners()->count());
}
public function testPostUnShareList()
{
$list = $this->insertOneUsrList(self::$user);
$this->assertEquals(1, $list->getOwners()->count());
$route = '/lists/list/' . $list->getId() . '/share/' . self::$user_alt1->get_id() . '/';
$this->client->request('POST', $route, array('role' => \Entities\UsrListOwner::ROLE_ADMIN));
$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']);
$repository = self::$core->getEntityManager()->getRepository('Entities\UsrList');
$list = $repository->find($list->getId());
$this->assertEquals(2, $list->getOwners()->count());
$route = '/lists/list/' . $list->getId() . '/unshare/' . self::$user_alt1->get_id() . '/';
$this->client->request('POST', $route);
$response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('UTF-8', $response->getCharset());
$datas = (array) json_decode($response->getContent());
$this->assertTrue($datas['success']);
$repository = self::$core->getEntityManager()->getRepository('Entities\UsrList');
$list = $repository->find($list->getId());
self::$core->getEntityManager()->refresh($list);
$this->assertEquals(1, $list->getOwners()->count());
}
public function testPostUnShareFail()
{
$list = $this->insertOneUsrList(self::$user);
$this->assertEquals(1, $list->getOwners()->count());
$route = '/lists/list/' . $list->getId() . '/share/' . self::$user_alt1->get_id() . '/';
$this->client->request('POST', $route, array('role' => \Entities\UsrListOwner::ROLE_ADMIN));
$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']);
$route = '/lists/list/' . $list->getId() . '/share/' . self::$user->get_id() . '/';
$this->client->request('POST', $route, array('role' => \Entities\UsrListOwner::ROLE_USER));
$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->assertFalse($datas['success']);
$route = '/lists/list/' . $list->getId() . '/share/' . self::$user_alt1->get_id() . '/';
$this->client->request('POST', $route, array('role' => \Entities\UsrListOwner::ROLE_USER));
$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']);
$repository = self::$core->getEntityManager()->getRepository('Entities\UsrList');
$list = $repository->find($list->getId());
$this->assertEquals(2, $list->getOwners()->count());
$route = '/lists/list/' . $list->getId() . '/unshare/' . self::$user_alt1->get_id() . '/';
$this->client->request('POST', $route);
$response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('UTF-8', $response->getCharset());
$datas = (array) json_decode($response->getContent());
$this->assertTrue($datas['success']);
}
protected function checkOwner($owner)
{
$this->assertInstanceOf('stdClass', $owner);
$this->assertObjectHasAttribute('usr_id', $owner);
$this->assertObjectHasAttribute('display_name', $owner);
$this->assertObjectHasAttribute('position', $owner);
$this->assertObjectHasAttribute('job', $owner);
$this->assertObjectHasAttribute('company', $owner);
$this->assertObjectHasAttribute('email', $owner);
$this->assertObjectHasAttribute('role', $owner);
$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);
}
}

View File

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

View File

@@ -0,0 +1,889 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAbstract.class.inc';
require_once __DIR__ . '/../../../../FeedValidator.inc';
require_once __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Controller/Root/RSSFeeds.php';
use Silex\WebTestCase;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\DomCrawler\Crawler;
class ControllerRssFeedTest extends \PhraseanetWebTestCaseAbstract
{
/**
*
* @var Feed_Adapter
*/
public static $feed;
/**
*
* @var Feed_Adapter_Entry
*/
public static $entry;
public static $publisher;
/**
*
* @var Feed_Collection
*/
protected static $public_feeds;
/**
*
* @var Feed_Collection
*/
protected static $private_feeds;
/**
*
* @var Feed_Adapter
*/
protected static $feed_1_private;
protected static $feed_1_private_title = 'Feed 1 title';
protected static $feed_1_private_subtitle = 'Feed 1 subtitle';
protected static $feed_1_entries = array();
protected static $feed_2_entries = array();
protected static $feed_3_entries = array();
protected static $feed_4_entries = array();
/**
*
* @var Feed_Adapter
*/
protected static $feed_2_private;
protected static $feed_2_private_title = 'Feed 2 title';
protected static $feed_2_private_subtitle = 'Feed 2 subtitle';
/**
*
* @var Feed_Adapter
*/
protected static $feed_3_public;
protected static $feed_3_public_title = 'Feed 3 title';
protected static $feed_3_public_subtitle = 'Feed 3 subtitle';
/**
*
* @var Feed_Adapter
*/
protected static $feed_4_public;
protected static $feed_4_public_title = 'Feed 4 title';
protected static $feed_4_public_subtitle = 'Feed 4 subtitle';
protected static $need_records = true;
protected static $need_subdefs = true;
protected $client;
public function setUp()
{
parent::setUp();
$this->client = $this->createClient();
self::$feed = Feed_Adapter::create(appbox::get_instance(\bootstrap::getCore()), self::$user, 'title', 'subtitle');
self::$publisher = Feed_Publisher_Adapter::getPublisher(appbox::get_instance(\bootstrap::getCore()), self::$feed, self::$user);
self::$entry = Feed_Entry_Adapter::create(appbox::get_instance(\bootstrap::getCore()), self::$feed, self::$publisher, 'title_entry', 'subtitle', 'hello', "test@mail.com");
Feed_Entry_Item::create(appbox::get_instance(\bootstrap::getCore()), self::$entry, self::$record_1);
Feed_Entry_Item::create(appbox::get_instance(\bootstrap::getCore()), self::$entry, self::$record_2);
self::$feed->set_public(true);
}
public function tearDown()
{
if (self::$publisher instanceof Feed_Publisher_Adapter)
{
self::$publisher->delete();
}
if (self::$entry instanceof Feed_Entry_Adapter)
{
self::$entry->delete();
}
if (self::$feed instanceof Feed_Adapter)
{
self::$feed->delete();
}
parent::tearDown();
}
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
$appbox = appbox::get_instance(\bootstrap::getCore());
$auth = new Session_Authentication_None(self::$user);
$appbox->get_session()->authenticate($auth);
self::$feed_1_private = Feed_Adapter::create($appbox, self::$user, self::$feed_1_private_title, self::$feed_1_private_subtitle);
self::$feed_1_private->set_public(false);
self::$feed_1_private->set_icon(new system_file(__DIR__ . '/../../../../testfiles/logocoll.gif'));
self::$feed_2_private = Feed_Adapter::create($appbox, self::$user, self::$feed_2_private_title, self::$feed_2_private_subtitle);
self::$feed_2_private->set_public(false);
self::$feed_3_public = Feed_Adapter::create($appbox, self::$user, self::$feed_3_public_title, self::$feed_3_public_subtitle);
self::$feed_3_public->set_public(true);
self::$feed_3_public->set_icon(new system_file(__DIR__ . '/../../../../testfiles/logocoll.gif'));
self::$feed_4_public = Feed_Adapter::create($appbox, self::$user, self::$feed_4_public_title, self::$feed_4_public_subtitle);
self::$feed_4_public->set_public(true);
$publisher = array_shift(self::$feed_4_public->get_publishers());
for ($i = 1; $i != 15; $i++)
{
$entry = Feed_Entry_Adapter::create($appbox, self::$feed_4_public, $publisher, 'titre entry', 'soustitre entry', 'Jean-Marie Biggaro', 'author@example.com');
$item = Feed_Entry_Item::create($appbox, $entry, self::$record_1);
$item = Feed_Entry_Item::create($appbox, $entry, self::$record_2);
$item = Feed_Entry_Item::create($appbox, $entry, self::$record_3);
$item = Feed_Entry_Item::create($appbox, $entry, self::$record_4);
$item = Feed_Entry_Item::create($appbox, $entry, self::$record_5);
$item = Feed_Entry_Item::create($appbox, $entry, self::$record_6);
$item = Feed_Entry_Item::create($appbox, $entry, self::$record_7);
$item = Feed_Entry_Item::create($appbox, $entry, self::$record_8);
$item = Feed_Entry_Item::create($appbox, $entry, self::$record_9);
$item = Feed_Entry_Item::create($appbox, $entry, self::$record_10);
$item = Feed_Entry_Item::create($appbox, $entry, self::$record_11);
$item = Feed_Entry_Item::create($appbox, $entry, self::$record_12);
$item = Feed_Entry_Item::create($appbox, $entry, self::$record_13);
$item = Feed_Entry_Item::create($appbox, $entry, self::$record_14);
$item = Feed_Entry_Item::create($appbox, $entry, self::$record_15);
$item = Feed_Entry_Item::create($appbox, $entry, self::$record_16);
$item = Feed_Entry_Item::create($appbox, $entry, self::$record_17);
$item = Feed_Entry_Item::create($appbox, $entry, self::$record_18);
$item = Feed_Entry_Item::create($appbox, $entry, self::$record_19);
$item = Feed_Entry_Item::create($appbox, $entry, self::$record_20);
$entry = Feed_Entry_Adapter::create($appbox, self::$feed_1_private, $publisher, 'titre entry', 'soustitre entry', 'Jean-Marie Biggaro', 'author@example.com');
$item = Feed_Entry_Item::create($appbox, $entry, self::$record_1);
$item = Feed_Entry_Item::create($appbox, $entry, self::$record_2);
$item = Feed_Entry_Item::create($appbox, $entry, self::$record_3);
$item = Feed_Entry_Item::create($appbox, $entry, self::$record_4);
$item = Feed_Entry_Item::create($appbox, $entry, self::$record_5);
$item = Feed_Entry_Item::create($appbox, $entry, self::$record_6);
$item = Feed_Entry_Item::create($appbox, $entry, self::$record_7);
$item = Feed_Entry_Item::create($appbox, $entry, self::$record_8);
$item = Feed_Entry_Item::create($appbox, $entry, self::$record_9);
$item = Feed_Entry_Item::create($appbox, $entry, self::$record_10);
$item = Feed_Entry_Item::create($appbox, $entry, self::$record_11);
$item = Feed_Entry_Item::create($appbox, $entry, self::$record_12);
$item = Feed_Entry_Item::create($appbox, $entry, self::$record_13);
$item = Feed_Entry_Item::create($appbox, $entry, self::$record_14);
$item = Feed_Entry_Item::create($appbox, $entry, self::$record_15);
$item = Feed_Entry_Item::create($appbox, $entry, self::$record_16);
$item = Feed_Entry_Item::create($appbox, $entry, self::$record_17);
$item = Feed_Entry_Item::create($appbox, $entry, self::$record_18);
$item = Feed_Entry_Item::create($appbox, $entry, self::$record_19);
$item = Feed_Entry_Item::create($appbox, $entry, self::$record_20);
self::$feed_4_entries[] = $entry;
}
self::$public_feeds = Feed_Collection::load_public_feeds($appbox);
self::$private_feeds = Feed_Collection::load_all($appbox, self::$user);
$appbox->get_session()->logout();
}
public static function tearDownAfterClass()
{
self::$feed_1_private->delete();
self::$feed_2_private->delete();
self::$feed_3_public->delete();
self::$feed_4_public->delete();
parent::tearDownAfterClass();
}
public function createApplication()
{
return require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Root.php';
}
public function testPublicFeedAggregated()
{
self::$public_feeds->get_aggregate();
$this->client->request('GET', '/feeds/aggregated/atom/');
$response = $this->client->getResponse();
$this->evaluateResponse200($response);
$this->evaluateGoodXML($response);
$this->evaluateAtom($response);
}
protected function evaluateAtom(Response $response)
{
$dom_doc = new DOMDocument();
$doc->preserveWhiteSpace = false;
$dom_doc->loadXML($response->getContent());
$xpath = new DOMXPath($dom_doc);
$xpath->registerNamespace('atom', 'http://www.w3.org/2005/Atom');
$this->assertEquals(1, $xpath->query('/atom:feed/atom:title')->length);
$this->assertEquals(1, $xpath->query('/atom:feed/atom:updated')->length);
$this->assertEquals(1, $xpath->query('/atom:feed/atom:link[@rel="self"]')->length);
$this->assertEquals(1, $xpath->query('/atom:feed/atom:id')->length);
$this->assertEquals(1, $xpath->query('/atom:feed/atom:generator')->length);
$this->assertEquals(1, $xpath->query('/atom:feed/atom:subtitle')->length);
}
protected function evaluateGoodXML(Response $response)
{
$dom_doc = new DOMDocument();
$dom_doc->loadXML($response->getContent());
$this->assertInstanceOf('DOMDocument', $dom_doc);
$this->assertEquals($dom_doc->saveXML(), $response->getContent());
}
protected function evaluateResponse200(Response $response)
{
$this->assertEquals(200, $response->getStatusCode(), 'Test status code ');
$this->assertEquals('UTF-8', $response->getCharset(), 'Test charset response');
}
//$app->get('/feeds/feed/{id}/{format}/', function($id, $format) use ($app, $appbox, $display_feed)
public function testPublicFeed()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$auth = new Session_Authentication_None(self::$user);
$appbox->get_session()->authenticate($auth);
$link = self::$feed_3_public->get_user_link($appbox->get_registry(), self::$user, Feed_Adapter::FORMAT_ATOM)->get_href();
$link = str_replace($appbox->get_registry()->get('GV_ServerName') . 'feeds/', '/', $link);
$appbox->get_session()->logout();
$this->client->request('GET', "/feeds" . $link);
$response = $this->client->getResponse();
$this->evaluateResponse200($response);
$this->evaluateGoodXML($response);
$this->evaluateAtom($response);
}
//$app->get('/feeds/userfeed/aggregated/{token}/{format}/', function($token, $format) use ($app, $appbox, $display_feed)
public function testUserFeedAggregated()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$auth = new Session_Authentication_None(self::$user);
$appbox->get_session()->authenticate($auth);
$link = self::$private_feeds->get_aggregate()->get_user_link($appbox->get_registry(), self::$user, Feed_Adapter::FORMAT_ATOM)->get_href();
$link = str_replace($appbox->get_registry()->get('GV_ServerName') . 'feeds/', '/', $link);
$appbox->get_session()->logout();
$this->client->request('GET', "/feeds" . $link);
$response = $this->client->getResponse();
$this->evaluateResponse200($response);
$this->evaluateGoodXML($response);
$this->evaluateAtom($response);
}
//$app->get('/feeds/userfeed/{token}/{id}/{format}/', function($token, $id, $format) use ($app, $appbox, $display_feed)
public function testUserFeed()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$auth = new Session_Authentication_None(self::$user);
$appbox->get_session()->authenticate($auth);
$link = self::$feed_1_private->get_user_link($appbox->get_registry(), self::$user, Feed_Adapter::FORMAT_ATOM)->get_href();
$link = str_replace($appbox->get_registry()->get('GV_ServerName') . 'feeds/', '/', $link);
$appbox->get_session()->logout();
$this->client->request('GET', "/feeds" . $link);
$response = $this->client->getResponse();
$this->evaluateResponse200($response);
$this->evaluateGoodXML($response);
$this->evaluateAtom($response);
}
public function testGetFeedFormat()
{
$feeds = Feed_Collection::load_public_feeds(appbox::get_instance(\bootstrap::getCore()));
$feed = array_shift($feeds->get_feeds());
$crawler = $this->client->request("GET", "/feeds/feed/" . $feed->get_id() . "/rss/");
$this->assertEquals("application/rss+xml", $this->client->getResponse()->headers->get("content-type"));
$xml = $this->client->getResponse()->getContent();
$this->verifyXML($xml);
$this->verifyRSS($feed, $xml);
$crawler = $this->client->request("GET", "/feeds/feed/" . $feed->get_id() . "/atom/");
$this->assertEquals("application/atom+xml", $this->client->getResponse()->headers->get("content-type"));
$xml = $this->client->getResponse()->getContent();
$this->verifyXML($xml);
$this->verifyATOM($feed, $xml);
}
public function testCooliris()
{
$crawler = $this->client->request("GET", "/feeds/cooliris/");
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertEquals("application/rss+xml", $this->client->getResponse()->headers->get("content-type"));
$xml = $this->client->getResponse()->getContent();
$this->verifyXML($xml);
}
public function testAggregatedRss()
{
$feeds = Feed_Collection::load_public_feeds(appbox::get_instance(\bootstrap::getCore()));
$all_feeds = $feeds->get_feeds();
foreach ($all_feeds as $feed)
{
$this->assertTrue($feed->is_public());
}
$crawler = $this->client->request("GET", "/feeds/aggregated/rss/");
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertEquals("application/rss+xml", $this->client->getResponse()->headers->get("content-type"));
$xml = $this->client->getResponse()->getContent();
$this->verifyXML($xml);
}
public function testAggregatedAtom()
{
$feeds = Feed_Collection::load_public_feeds(appbox::get_instance(\bootstrap::getCore()));
$all_feeds = $feeds->get_feeds();
foreach ($all_feeds as $feed)
{
$this->assertTrue($feed->is_public());
}
$crawler = $this->client->request("GET", "/feeds/aggregated/atom/");
$this->assertTrue($this->client->getResponse()->isOk());
$this->assertEquals("application/atom+xml", $this->client->getResponse()->headers->get("content-type"));
$xml = $this->client->getResponse()->getContent();
$this->verifyXML($xml);
}
public function testUnknowFeedId()
{
$crawler = $this->client->request("GET", "/feeds/feed/0/");
$this->assertFalse($this->client->getResponse()->isOk());
$this->assertEquals(404, $this->client->getResponse()->getStatusCode());
$crawler = $this->client->request("GET", "/feeds/feed/titi/");
$this->assertFalse($this->client->getResponse()->isOk());
$this->assertEquals(404, $this->client->getResponse()->getStatusCode());
}
public function testGetFeedId()
{
$feeds = Feed_Collection::load_public_feeds(appbox::get_instance(\bootstrap::getCore()));
$all_feeds = $feeds->get_feeds();
$feed = array_shift($all_feeds);
$crawler = $this->client->request("GET", "/feeds/feed/" . $feed->get_id() . "/rss/");
$this->assertTrue($this->client->getResponse()->isOk());
$xml = $this->client->getResponse()->getContent();
$this->verifyXML($xml);
$this->verifyRSS($feed, $xml);
$crawler = $this->client->request("GET", "/feeds/feed/" . $feed->get_id() . "/atom/");
$this->assertTrue($this->client->getResponse()->isOk());
$xml = $this->client->getResponse()->getContent();
$this->verifyATOM($feed, $xml);
}
public function testPrivateFeedAccess()
{
$private_feed = Feed_Adapter::create(appbox::get_instance(\bootstrap::getCore()), self::$user, 'title', 'subtitle');
$private_feed->set_public(false);
$this->client->request("GET", "/feeds/feed/" . $private_feed->get_id() . "/rss/");
$this->assertFalse($this->client->getResponse()->isOk());
$this->assertEquals(403, $this->client->getResponse()->getStatusCode());
$private_feed->delete();
}
public function verifyXML($xml)
{
/**
* XML is not verified due to Validator Service bug
*/
return;
try
{
$validator = new W3CFeedRawValidator($xml);
$response = $validator->validate();
$this->assertTrue($response->isValid(), $xml . "\n" . $response);
}
catch (W3CFeedValidatorException $e)
{
print "\nCould not use W3C FEED VALIDATOR API : " . $e->getMessage() . "\n";
}
}
function verifyRSS(Feed_Adapter $feed, $xml_string)
{
$dom_doc = new DOMDocument();
$dom_doc->loadXML($xml_string);
$xpath = new DOMXPath($dom_doc);
$xpath->registerNamespace("media", "http://search.yahoo.com/mrss/");
$xpath->registerNamespace("atom", "http://www.w3.org/2005/Atom");
$xpath->registerNamespace("dc", "http://purl.org/dc/elements/1.1/");
$this->checkRSSRootNode($xpath, $feed);
$this->checkRSSEntryNode($xpath, $feed);
}
function checkRSSRootNode(DOMXPath $xpath, Feed_Adapter $feed)
{
$channel = $xpath->query("/rss/channel");
foreach ($channel->item(0)->childNodes as $child)
{
if ($child->nodeType !== XML_TEXT_NODE)
{
switch ($child->nodeName)
{
case 'title':
$this->assertEquals($feed->get_title(), $child->nodeValue);
break;
case 'dc:title':
$this->assertEquals($feed->get_title(), $child->nodeValue);
break;
case 'description':
$this->assertEquals($feed->get_subtitle(), $child->nodeValue);
break;
case 'link':
$this->assertEquals($feed->get_homepage_link(registry::get_instance(), Feed_Adapter::FORMAT_RSS, 1)->get_href(), $child->nodeValue);
break;
case 'pubDate':
$this->assertTrue(new DateTime() >= new DateTime($child->nodeValue));
break;
case 'generator':
$this->assertEquals("Phraseanet", $child->nodeValue);
break;
case 'docs':
$this->assertEquals("http://blogs.law.harvard.edu/tech/rss", $child->nodeValue);
break;
case 'atom:link':
foreach ($child->attributes as $attribute)
{
if ($attribute->name == "href")
{
$this->assertEquals($feed->get_homepage_link(registry::get_instance(), Feed_Adapter::FORMAT_RSS, 1)->get_href(), $attribute->value);
break;
}
}
break;
}
}
}
}
function checkRSSEntryNode(DOMXPath $xpath, Feed_Adapter $feed)
{
$list_entries = $xpath->query("/rss/channel/item");
$count = 0;
$offset_start = 0;
$n_entries = 20;
$collection = $feed->get_entries($offset_start, $n_entries);
$entries = $collection->get_entries();
foreach ($list_entries as $node)
{
if (sizeof($entries) == 0)
{
$offset_start = ($offset_start++) * $n_entries;
$collection = $feed->get_entries($offset_start, $n_entries);
$entries = $collection->get_entries();
if (sizeof($entries) == 0) //no more
break;
}
$feed_entry = array_shift($entries);
switch ($node->nodeName)
{
case 'title':
$this->assertEquals($feed_entry->get_title(), $node->nodeValue);
break;
case 'description':
$this->assertEquals($feed_entry->get_subtitle(), $node->nodeValue);
break;
case 'author':
$author = sprintf(
'%s (%s)'
, $feed_entry->get_author_email()
, $feed_entry->get_author_name()
);
$this->assertEquals($author, $node->nodeValue);
break;
case 'pubDate':
$this->assertEquals($feed_entry->get_created_on()->format(DATE_RFC2822), $node->nodeValue);
break;
case 'guid':
$this->assertEquals($feed_entry->get_link()->get_href(), $node->nodeValue);
break;
case 'link':
$this->assertEquals($feed_entry->get_link()->get_href(), $node->nodeValue);
break;
}
$count++;
$this->checkRSSEntryItemsNode($xpath, $feed_entry, $count);
}
$this->assertEquals($feed->get_count_total_entries(), $count);
}
function checkRSSEntryItemsNode(DOMXPath $xpath, Feed_Entry_Adapter $entry, $count)
{
$content = $entry->get_content();
$available_medium = array('image', 'audio', 'video');
array_walk($content, $this->removeBadItems($content, $available_medium));
$media_group = $xpath->query("/rss/channel/item[" . $count . "]/media:group");
$this->assertEquals(sizeof($content), $media_group->length);
foreach ($media_group as $media)
{
$entry_item = array_shift($content);
$this->verifyMediaItem($entry_item, $media);
}
}
public function verifyMediaItem(Feed_Entry_Item $item, DOMNode $node)
{
foreach ($node->childNodes as $node)
{
if ($node->nodeType !== XML_TEXT_NODE)
{
switch ($node->nodeName)
{
case 'media:content' :
$this->checkMediaContentAttributes($item, $node);
break;
case 'media:thumbnail':
default :
$this->checkOptionnalMediaGroupNode($node, $item);
break;
}
}
}
}
public function parseAttributes(DOMNode $node)
{
$current_attributes = array();
foreach ($node->attributes as $attribute)
{
$current_attributes[$attribute->name] = $attribute->value;
}
return $current_attributes;
}
public function checkMediaContentAttributes(Feed_Entry_Item $entry_item, DOMNode $node)
{
$current_attributes = $this->parseAttributes($node);
$is_thumbnail = false;
$record = $entry_item->get_record();
if (substr($current_attributes["url"], 0 - strlen("/preview/")) == "/preview/")
{
$ressource = $record->get_subdef('preview');
}
else
{
$ressource = $record->get_thumbnail();
$is_thumbnail = true;
}
$permalink = $ressource->get_permalink();
foreach ($current_attributes as $attribute => $value)
{
switch ($attribute)
{
case "url":
$this->assertEquals($permalink->get_url(), $value);
break;
case "fileSize":
$this->assertEquals($ressource->get_size(), $value);
break;
case "type":
$this->assertEquals($ressource->get_mime(), $value);
break;
case "medium":
$this->assertEquals(strtolower($record->get_type()), $value);
break;
case "isDefault":
!$is_thumbnail ? $this->assertEquals("true", $value) : $this->assertEquals("false", $value);
break;
case "expression":
$this->assertEquals("full", $value);
break;
case "bitrate":
$this->assertEquals($value);
break;
case "height":
$this->assertEquals($ressource->get_height(), $value);
break;
case "width":
$this->assertEquals($ressource->get_width(), $value);
break;
case "duration" :
$this->assertEquals($record->get_duration(), $value);
break;
case "framerate":
case "samplingrate":
case "channels":
case "lang":
break;
default:
$this->fail($attribute . " is not valid");
break;
}
}
}
public function checkOptionnalMediaGroupNode(DOMNode $node, Feed_Entry_Item $entry_item)
{
$fields = array(
'title' => array(
'dc_field' => databox_Field_DCESAbstract::Title,
'media_field' => array(
'name' => 'media:title',
'attributes' => array(
'type' => 'plain'
)
),
'separator' => ' '
)
, 'description' => array(
'dc_field' => databox_Field_DCESAbstract::Description,
'media_field' => array(
'name' => 'media:description',
'attributes' => array()
),
'separator' => ' '
)
, 'contributor' => array(
'dc_field' => databox_Field_DCESAbstract::Contributor,
'media_field' => array(
'name' => 'media:credit',
'attributes' => array(
'role' => 'contributor',
'scheme' => 'urn:ebu'
)
),
'separator' => ' '
)
, 'director' => array(
'dc_field' => databox_Field_DCESAbstract::Creator,
'media_field' => array(
'name' => 'media:credit',
'attributes' => array(
'role' => 'creator',
'scheme' => 'urn:ebu'
)
),
'separator' => ' '
)
, 'publisher' => array(
'dc_field' => databox_Field_DCESAbstract::Publisher,
'media_field' => array(
'name' => 'media:credit',
'attributes' => array(
'role' => 'publisher',
'scheme' => 'urn:ebu'
)
),
'separator' => ' '
)
, 'rights' => array(
'dc_field' => databox_Field_DCESAbstract::Rights,
'media_field' => array(
'name' => 'media:copyright',
'attributes' => array()
),
'separator' => ' '
)
, 'keywords' => array(
'dc_field' => databox_Field_DCESAbstract::Subject,
'media_field' => array(
'name' => 'media:keywords',
'attributes' => array()
),
'separator' => ', '
)
);
foreach ($fields as $key_field => $field)
{
if ($field["media_field"]["name"] == $node->nodeName)
{
if ($p4field = $entry_item->get_record()->get_caption()->get_dc_field($field["dc_field"]))
{
$this->assertEquals($p4field->get_serialized_values($field["separator"]), $node->nodeValue
, sprintf('Asserting good value for DC %s', $field["dc_field"]));
if (sizeof($field["media_field"]["attributes"]) > 0)
{
foreach ($node->attributes as $attribute)
{
$this->assertTrue(array_key_exists($attribute->name, $field["media_field"]["attributes"]), "Checkin attribute " . $attribute->name . " for " . $field['media_field']['name']);
$this->assertEquals($attribute->value, $field["media_field"]["attributes"][$attribute->name], "Checkin attribute " . $attribute->name . " for " . $field['media_field']['name']);
}
}
}
else
{
$this->fail("Missing media:entry");
}
break;
}
}
}
public function removeBadItems(Array &$item_entries, Array $available_medium)
{
$remove = function($entry_item, $key) use (&$item_entries, $available_medium)
{
$preview_sd = $entry_item->get_record()->get_subdef('preview');
$url_preview = $preview_sd->get_permalink();
$thumbnail_sd = $entry_item->get_record()->get_thumbnail();
$url_thumb = $thumbnail_sd->get_permalink();
if (!in_array(strtolower($entry_item->get_record()->get_type()), $available_medium))
{
unset($item_entries[$key]); //remove
}
if (!$url_thumb || !$url_preview)
{
unset($item_entries[$key]); //remove
}
};
return $remove;
}
public function verifyATOM(Feed_Adapter $feed, $xml_string)
{
$this->verifyXML($xml_string);
$dom_doc = new DOMDocument();
$dom_doc->loadXML($xml_string);
$xpath = new DOMXPath($dom_doc);
$xpath->registerNamespace("media", "http://search.yahoo.com/mrss/");
$xpath->registerNamespace("Atom", "http://www.w3.org/2005/Atom");
$this->checkATOMRootNode($dom_doc, $xpath, $feed);
}
public function checkATOMRootNode(DOMDocument $dom_doc, DOMXPath $xpath, Feed_Adapter $feed)
{
$ids = $xpath->query('/Atom:feed/Atom:id');
$this->assertEquals($feed->get_homepage_link(registry::get_instance(), Feed_Adapter::FORMAT_ATOM, 1)->get_href(), $ids->item(0)->nodeValue);
$titles = $xpath->query('/Atom:feed/Atom:title');
$this->assertEquals($feed->get_title(), $titles->item(0)->nodeValue);
$subtitles = $xpath->query('/Atom:feed/Atom:subtitle');
if ($subtitles->length > 0)
$this->assertEquals($feed->get_subtitle(), $subtitles->item(0)->nodeValue);
$updateds = $xpath->query('/Atom:feed/Atom:updated');
$this->assertTrue(new DateTime() >= new DateTime($updateds->item(0)->nodeValue));
$entries_item = $xpath->query('/Atom:feed/Atom:entry');
$count = 0;
$offset_start = 0;
$n_entries = 20;
$collection = $feed->get_entries($offset_start, $n_entries);
$entries = $collection->get_entries();
foreach ($entries_item as $entry)
{
if (sizeof($entries) == 0)
{
$offset_start = ($offset_start++) * $n_entries;
$collection = $feed->get_entries($offset_start, $n_entries);
$entries = $collection->get_entries();
if (sizeof($entries) == 0) //no more
break;
}
$feed_entry = array_shift($entries);
$this->checkATOMEntryNode($entry, $xpath, $feed, $feed_entry);
$count++;
}
$this->assertEquals($feed->get_count_total_entries(), $count);
}
public function checkATOMEntryNode(DOMNode $node, DOMXPath $xpath, Feed_Adapter $feed, Feed_Entry_Adapter $entry)
{
foreach ($node->childNodes as $child)
{
if ($child->nodeType !== XML_TEXT_NODE)
{
switch ($child->nodeName)
{
case 'id':
$this->assertEquals(sprintf('%sentry/%d/', $feed->get_homepage_link(registry::get_instance(), Feed_Adapter::FORMAT_ATOM, 1)->get_href(), $entry->get_id()), $child->nodeValue);
break;
case 'link':
foreach ($child->attributes as $attribute)
{
if ($attribute->name == "href")
{
$this->assertEquals(sprintf('%sentry/%d/', $feed->get_homepage_link(registry::get_instance(), Feed_Adapter::FORMAT_ATOM, 1)->get_href(), $entry->get_id()), $attribute->value);
break;
}
}
break;
case 'updated':
$this->assertEquals($entry->get_updated_on()->format(DATE_ATOM), $child->nodeValue);
break;
case 'published':
$this->assertEquals($entry->get_created_on()->format(DATE_ATOM), $child->nodeValue);
break;
case 'title':
$this->assertEquals($entry->get_title(), $child->nodeValue);
break;
case 'content':
$this->assertEquals($entry->get_subtitle(), $child->nodeValue);
break;
case 'author':
foreach ($node->childNodes as $child)
{
if ($child->nodeType !== XML_TEXT_NODE && $child->nodeName == "email")
$this->assertEquals($entry->get_author_email(), $child->nodeValue);
if ($child->nodeType !== XML_TEXT_NODE && $child->nodeName == "name")
$this->assertEquals($entry->get_author_name(), $child->nodeValue);
}
break;
}
}
}
$content = $entry->get_content();
$available_medium = array('image', 'audio', 'video');
array_walk($content, $this->removeBadItems($content, $available_medium));
$media_group = $xpath->query("/Atom:feed/Atom:entry[0]/media:group");
if ($media_group->length > 0)
{
foreach ($media_group as $media)
{
$entry_item = array_shift($content);
if ($entry_item instanceof Feed_Entry_Item)
{
$this->verifyMediaItem($entry_item, $media);
}
}
}
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace Alchemy\Phrasea\Application;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Alchemy\Phrasea\Controller\Setup as Controller;
use Alchemy\Phrasea\Controller\Utils as ControllerUtils;
return call_user_func(function()
{
$app = new \Silex\Application();
$app['Core'] = \bootstrap::getCore();
$app['install'] = true;
$app->get('/', function() use ($app)
{
return $app->redirect('/setup/installer/');
});
$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

@@ -0,0 +1,34 @@
<?php
namespace Alchemy\Phrasea\Application;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Alchemy\Phrasea\Controller\Setup as Controller;
use Alchemy\Phrasea\Controller\Utils as ControllerUtils;
return call_user_func(function()
{
$app = new \Silex\Application();
$app['Core'] = \bootstrap::getCore();
$app['upgrade'] = true;
$app->get('/', function() use ($app)
{
return $app->redirect('/setup/upgrader/');
});
$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

@@ -0,0 +1,77 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAbstract.class.inc';
/**
* Test class for Installer.
* Generated by PHPUnit on 2012-01-11 at 18:21:34.
*/
class ControllerInstallerTest extends \PhraseanetWebTestCaseAbstract
{
/**
* 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__ . '/FakeSetupApplication.inc';
}
public function setUp()
{
parent::setUp();
$this->client = $this->createClient();
}
/**
* Default route test
*/
public function testRouteSlash()
{
$this->client->request('GET', '/');
$response = $this->client->getResponse();
/* @var $response \Symfony\Component\HttpFoundation\Response */
$this->assertEquals(302, $response->getStatusCode());
$this->assertEquals('/setup/installer/', $response->headers->get('location'));
}
public function testRouteInstaller()
{
$this->client->request('GET', '/installer/');
$response = $this->client->getResponse();
/* @var $response \Symfony\Component\HttpFoundation\Response */
$this->assertEquals(302, $response->getStatusCode());
$this->assertEquals('/setup/installer/step2/', $response->headers->get('location'));
}
public function testRouteInstallerStep2()
{
$this->client->request('GET', '/installer/step2/');
$response = $this->client->getResponse();
/* @var $response \Symfony\Component\HttpFoundation\Response */
$this->assertEquals(200, $response->getStatusCode());
$this->assertTrue($response->isOk());
}
}

View File

@@ -0,0 +1,92 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAbstract.class.inc';
/**
* Test class for Upgrader.
* Generated by PHPUnit on 2012-01-11 at 18:21:35.
*/
class ControllerUpgraderTest extends \PhraseanetWebTestCaseAbstract
{
/**
* 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__ . '/FakeUpgradeApplication.inc';
}
public function setUp()
{
parent::setUp();
$this->client = $this->createClient();
}
/**
* Default route test
*/
public function testRouteSlash()
{
$this->client->request('GET', '/');
$response = $this->client->getResponse();
/* @var $response \Symfony\Component\HttpFoundation\Response */
$this->assertEquals(302, $response->getStatusCode());
$this->assertEquals('/setup/upgrader/', $response->headers->get('location'));
}
/**
* Default route test
*/
public function testRouteUpgrader()
{
$this->client->request('GET', '/upgrader/');
$response = $this->client->getResponse();
/* @var $response \Symfony\Component\HttpFoundation\Response */
$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 */
$this->assertEquals(200, $response->getStatusCode());
}
/**
* 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

@@ -0,0 +1,127 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAbstract.class.inc';
/**
* Test class for ConnectionTest.
* Generated by PHPUnit on 2012-01-11 at 18:20:20.
*/
class ControllerConnectionTestTest extends \PhraseanetWebTestCaseAbstract
{
/**
* 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 testRouteMysql()
{
$configuration = \Alchemy\Phrasea\Core\Configuration::build();
$chooseConnexion = $configuration->getPhraseanet()->get('database');
$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')
);
$this->client->request("GET", "/tests/connection/mysql/", $params);
$response = $this->client->getResponse();
$this->assertTrue($response->isOk());
}
public function testRouteMysqlFailed()
{
$configuration = \Alchemy\Phrasea\Core\Configuration::build();
$chooseConnexion = $configuration->getPhraseanet()->get('database');
$connexion = $configuration->getConnexion($chooseConnexion);
$params = array(
"hostname" => $connexion->get('host'),
"port" => $connexion->get('port'),
"user" => $connexion->get('user'),
"password" => "fakepassword",
"dbname" => $connexion->get('dbname')
);
$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->connection);
}
public function testRouteMysqlDbFailed()
{
$configuration = \Alchemy\Phrasea\Core\Configuration::build();
$chooseConnexion = $configuration->getPhraseanet()->get('database');
$connexion = $configuration->getConnexion($chooseConnexion);
$params = array(
"hostname" => $connexion->get('host'),
"port" => $connexion->get('port'),
"user" => $connexion->get('user'),
"password" => $connexion->get('password'),
"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);
}
}

View File

@@ -0,0 +1,73 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAbstract.class.inc';
/**
* Test class for PathFileTest.
* Generated by PHPUnit on 2012-01-11 at 18:20:21.
*/
class ControllerPathFileTestTest extends \PhraseanetWebTestCaseAbstract
{
/**
* 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 testRoutePath()
{
$file = new \SplFileObject(__DIR__ . '/../../../../testfiles/cestlafete.jpg');
$this->client->request("GET", "/tests/pathurl/path/", array('path' => $file->getPathname()));
$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));
$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));
}
}

View File

@@ -0,0 +1,500 @@
<?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';
use Alchemy\Phrasea\Core as PhraseaCore;
use Alchemy\Phrasea\Core\Configuration;
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class ConfigurationTest extends \PhraseanetPHPUnitAbstract
{
/**
*
* @var \Alchemy\Phrasea\Core\Configuration
*/
protected $confProd;
/**
*
* @var \Alchemy\Phrasea\Core\Configuration
*/
protected $confDev;
/**
*
* @var \Alchemy\Phrasea\Core\Configuration
*/
protected $confTest;
/**
*
* @var \Alchemy\Phrasea\Core\Configuration
*/
protected $confNotInstalled;
/**
*
* @var \Alchemy\Phrasea\Core\Configuration
*/
protected $confExperience;
/**
*
* @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)
{
}
}
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

@@ -0,0 +1,69 @@
environment: dev
dev:
phraseanet:
servername: 'http://dev.phrasea.net/'
maintenance: false
debug: true
display_errors: true
database: main_connexion
template_engine: twig_debug
orm: doctrine_dev
cache: array_cache
prod:
phraseanet:
servername: 'http://dev.phrasea.net/'
maintenance: false
debug: false
display_errors: false
database: main_connexion
template_engine: twig
orm: doctrine_prod
cache: apc_cache
test:
phraseanet:
servername: 'http://dev.phrasea.net/'
maintenance: false
debug: true
display_errors: true
database: main_connexion
template_engine: twig_debug
orm: doctrine_test
cache: array_cache
no_debug:
phraseanet:
servername: 'http://dev.phrasea.net/'
maintenance: false
##debug: true
display_errors: true
database: main_connexion
template_engine: twig_debug
orm: doctrine_test
cache: array_cache
no_maintenance:
phraseanet:
servername: 'http://dev.phrasea.net/'
##maintenance: false
debug: true
display_errors: true
database: main_connexion
template_engine: twig_debug
orm: doctrine_test
cache: array_cache
no_display_errors:
phraseanet:
servername: 'http://dev.phrasea.net/'
maintenance: false
debug: true
##display_errors: true
database: main_connexion
template_engine: twig_debug
orm: doctrine_test
cache: array_cache
missing_phraseanet:
template_engine: twig_debug
orm: doctrine_test
cache: array_cache

View File

@@ -0,0 +1,12 @@
{
"meta": {
"api_version": "1.0",
"request": "GET /api/v1/feeds/288/content/",
"response_time": "2011-07-27T15:52:04+02:00",
"http_code": 200,
"error_message": null,
"error_details": null,
"charset": "UTF-8"
},
"response": {}
}

View File

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

View File

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

View File

@@ -0,0 +1,92 @@
<?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';
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class ServiceMemcacheCacheTest extends PhraseanetPHPUnitAbstract
{
public function testService()
{
$cache = new \Alchemy\Phrasea\Core\Service\Cache\MemcacheCache(
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)
{
}
}
}
public function testServiceException()
{
$cache = new \Alchemy\Phrasea\Core\Service\Cache\MemcacheCache(
self::$core, array()
);
try
{
$cache->getDriver();
$this->fail("should raise an exception");
}
catch (\Exception $e)
{
}
}
public function testType()
{
$cache = new \Alchemy\Phrasea\Core\Service\Cache\MemcacheCache(
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());
}
}

View File

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

View File

@@ -0,0 +1,71 @@
<?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';
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class DoctrineMonologTest extends PhraseanetPHPUnitAbstract
{
protected $options = array(
"handler" => "rotate"
, "filename" => "test"
, 'output' => 'json'
, 'channel' => 'test'
);
public function setUp()
{
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)
{
}
}
}

View File

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

View File

@@ -0,0 +1,127 @@
<?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';
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class MonologTest extends PhraseanetPHPUnitAbstract
{
protected $options;
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(
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());
}
}

View File

@@ -0,0 +1,222 @@
<?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';
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class DoctrineTest extends PhraseanetPHPUnitAbstract
{
protected $options;
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(
self::$core, $this->options
);
$this->fail("should raise an exception");
}
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 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()
{
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

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

View File

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

View File

@@ -0,0 +1,63 @@
<?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';
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class AbstractBuilderTest extends PhraseanetPHPUnitAbstract
{
public function testConstructExceptionNameEmpty()
{
try
{
$stub = $this->getMock(
"\Alchemy\Phrasea\Core\Service\Builder"
, array(
self::$core
, ''
, 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

@@ -0,0 +1,50 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
require_once __DIR__ . '/../../../../PhraseanetPHPUnitAbstract.class.inc';
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class CacheBuilderTest extends PhraseanetPHPUnitAbstract
{
public function testCreateException()
{
$configuration = new Symfony\Component\DependencyInjection\ParameterBag\ParameterBag(
array("type" => "unknow")
);
try
{
$service = Alchemy\Phrasea\Core\Service\Builder::create(self::$core, $configuration);
$this->fail("An exception should be raised");
}
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);
}
}

View File

@@ -0,0 +1,67 @@
<?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';
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class LogBuilderTest extends PhraseanetPHPUnitAbstract
{
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);
$this->fail("An exception should be raised");
}
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 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);
}
}

View File

@@ -0,0 +1,62 @@
<?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';
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class OrmBuilderTest extends PhraseanetPHPUnitAbstract
{
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);
$this->fail("An exception should be raised");
}
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);
}
}

View File

@@ -0,0 +1,58 @@
<?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';
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class TemplateBuilderTest extends PhraseanetPHPUnitAbstract
{
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);
$this->fail("An exception should be raised");
}
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);
}
}

View File

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

View File

@@ -0,0 +1,146 @@
<?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';
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class CoreTest extends PhraseanetPHPUnitAbstract
{
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->fail("test_helpers extension required");
}
set_new_overload(array($this, 'newCallback'));
$specification = new \Alchemy\Phrasea\Core\Configuration\ApplicationSpecification();
$class = $this->getMock(
'\Alchemy\Phrasea\Core\Configuration'
, array('isInstalled')
, array($specification)
, 'ConfMock'
);
$class->expects($this->any())
->method('isInstalled')
->will($this->returnValue(false));
$core = new \Alchemy\Phrasea\Core("test");
$this->assertInstanceOf("\Setup_Registry", $core->getRegistry());
unset_new_overload();
}
protected function newCallback($className)
{
switch ($className)
{
case 'Alchemy\Phrasea\Core\Configuration': return 'ConfMock';
default: return $className;
}
}
}

View File

@@ -0,0 +1,34 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetPHPUnitAuthenticatedAbstract.class.inc';
/**
* Test class for Push.
* Generated by PHPUnit on 2012-01-12 at 12:16:06.
*/
class HelperBridgeTest extends \PhraseanetPHPUnitAuthenticatedAbstract
{
/**
* @var Bridge
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
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

@@ -0,0 +1,146 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetPHPUnitAuthenticatedAbstract.class.inc';
/**
* Test class for Push.
* Generated by PHPUnit on 2012-01-12 at 12:16:06.
*/
class HelperEditTest extends \PhraseanetPHPUnitAuthenticatedAbstract
{
/**
* @var Edit
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
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

@@ -0,0 +1,34 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetPHPUnitAuthenticatedAbstract.class.inc';
/**
* Test class for Push.
* Generated by PHPUnit on 2012-01-12 at 12:16:06.
*/
class HelperFeedTest extends \PhraseanetPHPUnitAuthenticatedAbstract
{
/**
* @var Feed
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
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

@@ -0,0 +1,194 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetPHPUnitAuthenticatedAbstract.class.inc';
/**
* Test class for Push.
* Generated by PHPUnit on 2012-01-12 at 12:16:06.
*/
class HelperHelperTest extends \PhraseanetPHPUnitAuthenticatedAbstract
{
/**
* @var Helper
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
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

@@ -0,0 +1,62 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetPHPUnitAuthenticatedAbstract.class.inc';
/**
* Test class for Push.
* Generated by PHPUnit on 2012-01-12 at 12:16:06.
*/
class HelperMoveCollectionTest extends \PhraseanetPHPUnitAuthenticatedAbstract
{
/**
* @var MoveCollection
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
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

@@ -0,0 +1,50 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetPHPUnitAuthenticatedAbstract.class.inc';
/**
* Test class for Push.
* Generated by PHPUnit on 2012-01-12 at 12:16:06.
*/
class HelperPrinterTest extends \PhraseanetPHPUnitAuthenticatedAbstract
{
/**
* @var Printer
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
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

@@ -0,0 +1,39 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetPHPUnitAuthenticatedAbstract.class.inc';
/**
* Test class for Push.
* Generated by PHPUnit on 2012-01-12 at 12:16:06.
*/
class HelperPushTest extends \PhraseanetPHPUnitAuthenticatedAbstract
{
/**
* @var Push
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
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

@@ -0,0 +1,34 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetPHPUnitAuthenticatedAbstract.class.inc';
/**
* Test class for Push.
* Generated by PHPUnit on 2012-01-12 at 12:16:06.
*/
class HelperTooltipTest extends \PhraseanetPHPUnitAuthenticatedAbstract
{
/**
* @var Tooltip
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
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

@@ -0,0 +1,53 @@
<?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';
/**
* Test class for Term.
* Generated by PHPUnit on 2012-01-26 at 12:41:07.
*/
class AutoloaderTest extends \PhraseanetPHPUnitAbstract
{
public function testFindFile()
{
$testClassName = 'Test_Hello';
$autoloader = new Alchemy\Phrasea\Loader\Autoloader();
$autoloader->addPath('fixture', __DIR__ . '/Fixtures');
$autoloader->loadClass($testClassName);
$this->assertTrue(class_exists($testClassName));
}
public function testAddPath()
{
$autoloader = new Alchemy\Phrasea\Loader\Autoloader();
$pathNb = count($autoloader->getPaths());
$autoloader->addPath('fixture', __DIR__ . '/Fixtures');
$this->assertGreaterThan($pathNb, count($autoloader->getPaths()));
$this->assertArrayHasKey('fixture', $autoloader->getPaths());
}
public function testGetPath()
{
$autoloader = new Alchemy\Phrasea\Loader\Autoloader();
$this->assertTrue(is_array($autoloader->getPaths()));
$this->assertTrue(2 === count($autoloader->getPaths()));
$this->assertArrayHasKey('config', $autoloader->getPaths());
$this->assertArrayHasKey('library', $autoloader->getPaths());
}
}

View File

@@ -0,0 +1,125 @@
<?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';
/**
* Test class for Term.
* Generated by PHPUnit on 2012-01-26 at 12:41:07.
*/
class CacheAutoloaderTest extends \PhraseanetPHPUnitAbstract
{
private $apc = false;
private $xcache = false;
public function setUp()
{
parent::setUp();
if (extension_loaded('apc'))
{
$this->apc = true;
}
if (extension_loaded('xcache'))
{
$this->xcache = true;
}
}
public function testConstruct()
{
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 testFindFileApc()
{
if ($this->apc)
{
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_');
$cacheAdapter = $autoloader->getAdapter();
$this->assertEquals($autoloader->findFile('Test_HelloCache'), $cacheAdapter->fetch('test_prefix_Test_Hello'));
}
}
public function testGetPrefix()
{
if ($this->apc)
{
$autoloader = new Alchemy\Phrasea\Loader\CacheAutoloader('test_prefix_');
$this->assertEquals('test_prefix_', $autoloader->getPrefix());
}
}
public function testRegister()
{
if ($this->apc)
{
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 testFindFileXcache()
{
if ($this->xcache)
{
$this->marktestSkipped("can't use xcache in cli mode");
}
}
public function tearDown()
{
if (ini_get('apc.enabled') && ini_get('apc.enable_cli'))
{
apc_clear_cache('user');
}
parent::tearDown();
}
}

View File

@@ -0,0 +1,22 @@
<?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
{
}

View File

@@ -0,0 +1,22 @@
<?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
{
}

View File

@@ -0,0 +1,22 @@
<?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
{
}

View File

@@ -0,0 +1,97 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetPHPUnitAbstract.class.inc';
/**
* Test class for UserProvider.
* Generated by PHPUnit on 2012-01-26 at 12:41:07.
*/
class UserProviderTest extends \PhraseanetPHPUnitAbstract
{
/**
* @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);
$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

@@ -0,0 +1,41 @@
<?php
require_once __DIR__ . '/../../../PhraseanetPHPUnitAbstract.class.inc';
/**
* Test class for Controller.
* Generated by PHPUnit on 2012-01-26 at 12:41:07.
*/
class ControllerTest extends \PhraseanetPHPUnitAbstract
{
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');
$this->fail('Should raise an exception');
}
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);
}
}
}

View File

@@ -0,0 +1,74 @@
<?php
require_once __DIR__ . '/../../../PhraseanetPHPUnitAbstract.class.inc';
use \Alchemy\Phrasea\Vocabulary\Term;
/**
* Test class for Term.
* Generated by PHPUnit on 2012-01-26 at 12:41:07.
*/
class TermTest extends \PhraseanetPHPUnitAbstract
{
/**
* @var Term
*/
protected $object;
/**
* @var Term
*/
protected $basicObject;
/**
* @var Term
*/
protected $objectWithControl;
protected $value2 = 'Supa valu&é"\'(§è!)';
protected $context2 = 'context
oualibi';
protected $basicValue = 'Joli chien';
protected $value = 'One value';
protected $context = 'Another context';
protected $control;
protected $id = 25;
public function setUp()
{
$this->control = new Alchemy\Phrasea\Vocabulary\ControlProvider\UserProvider();
$this->object = new Term($this->value, $this->context);
$this->basicObject = new Term($this->basicValue);
$this->objectWithControl = new Term($this->value2, $this->context2, $this->control, $this->id);
}
public function testGetValue()
{
$this->assertEquals($this->basicValue, $this->basicObject->getValue());
$this->assertEquals($this->value, $this->object->getValue());
$this->assertEquals($this->value2, $this->objectWithControl->getValue());
}
public function testGetContext()
{
$this->assertEquals(null, $this->basicObject->getContext());
$this->assertEquals($this->context, $this->object->getContext());
$this->assertEquals($this->context2, $this->objectWithControl->getContext());
}
public function testGetType()
{
$this->assertEquals(null, $this->basicObject->getType());
$this->assertEquals(null, $this->object->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());
}
}

View File

@@ -0,0 +1,23 @@
<?php
require_once __DIR__ . '/../../../PhraseanetPHPUnitAuthenticatedAbstract.class.inc';
require_once __DIR__ . '/../../Bridge_datas.inc';
/**
* Test class for Bridge_Api_Auth_Abstract.
* Generated by PHPUnit on 2011-10-12 at 18:44:43.
*/
class Bridge_Api_Auth_AbstractTest extends PHPUnit_Framework_TestCase
{
public function testSet_settings()
{
$stub = $this->getMockForAbstractClass('Bridge_Api_Auth_Abstract');
$setting = $this->getMock("Bridge_AccountSettings", array(), array(), '' , false);
$return = $stub->set_settings($setting);
$this->assertEquals($stub, $return);
}
}
?>

View File

@@ -0,0 +1,186 @@
<?php
require_once __DIR__ . '/../../../PhraseanetPHPUnitAuthenticatedAbstract.class.inc';
require_once __DIR__ . '/../../Bridge_datas.inc';
/**
* Test class for Bridge_Api_Auth_Flickr.
* Generated by PHPUnit on 2011-10-12 at 18:45:52.
*/
class Bridge_Api_Auth_FlickrTest extends PHPUnit_Framework_TestCase
{
/**
* @var Bridge_Api_Auth_Flickr
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
public function setUp()
{
$this->object = new Bridge_Api_Auth_Flickr();
}
public function testParse_request_token()
{
$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 testConnect()
{
$api = $this->getMock("Phlickr_Api", array(), array(), "", false);
//mock api method
$api->expects($this->once())
->method("setAuthTokenFromFrob")
->will($this->returnValue("un_token"));
$api->expects($this->once())
->method("setAuthToken")
->with($this->equalTo("un_token"));
$api->expects($this->once())
->method("isAuthValid")
->will($this->returnValue(true));
$stub = $this->getMock("Bridge_Api_Auth_Flickr", array("get_api"));
$stub->expects($this->any())
->method("get_api")
->will($this->returnValue($api));
$return = $stub->connect("123");
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY, $return);
$this->assertArrayHasKey("auth_token", $return);
$this->assertEquals("un_token", $return["auth_token"]);
}
public function testBadConnect()
{
$api = $this->getMock("Phlickr_Api", array(), array(), "", false);
//mock api method
$api->expects($this->once())
->method("setAuthTokenFromFrob")
->will($this->returnValue("un_token"));
$api->expects($this->once())
->method("isAuthValid")
->will($this->returnValue(false));
$stub = $this->getMock("Bridge_Api_Auth_Flickr", array("get_api"));
$stub->expects($this->any())
->method("get_api")
->will($this->returnValue($api));
$this->setExpectedException("Bridge_Exception_ApiConnectorAccessTokenFailed");
$return = $stub->connect("123");
}
public function testReconnect()
{
$this->assertEquals($this->object, $this->object->reconnect());
}
public function testDisconnect()
{
$setting = $this->getMock("Bridge_AccountSettings", array("set"), array(), "", false);
$setting->expects($this->once())
->method("set")
->with($this->equalTo("auth_token"), $this->isNull());
$this->object->set_settings($setting);
$return = $this->object->disconnect();
$this->assertEquals($this->object, $return);
}
public function testIs_connected()
{
$setting = $this->getMock("Bridge_AccountSettings", array("get"), array(), "", false);
$setting->expects($this->any())
->method("get")
->with($this->equalTo("auth_token"))
->will($this->onConsecutiveCalls("123456", 123456, null));
$this->object->set_settings($setting);
$this->assertTrue($this->object->is_connected());
$this->assertTrue($this->object->is_connected());
$this->assertFalse($this->object->is_connected());
}
public function testGet_auth_signatures()
{
$setting = $this->getMock("Bridge_AccountSettings", array("get"), array(), "", false);
$setting->expects($this->once())
->method("get")
->with($this->equalTo("auth_token"))
->will($this->returnValue("123"));
$this->object->set_settings($setting);
$return = $this->object->get_auth_signatures();
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY, $return);
$this->assertArrayHasKey("auth_token", $return);
$this->assertEquals("123", $return["auth_token"]);
}
public function testSet_parameters()
{
$parameters = array(
"caca" => "boudain"
, "sirop" => "fraise"
, "choco" => "banane"
, "pirouette" => "cacahuete"
);
$return = $this->object->set_parameters($parameters);
$this->assertEquals(0, sizeof(get_object_vars($this->object)));
$this->assertEquals($return, $this->object);
}
public function testGet_auth_url()
{
$api = $this->getMock("Phlickr_Api", array(), array(), "", false);
//mock api method
$api->expects($this->any())
->method("requestFrob")
->will($this->returnValue("un_token"));
$api->expects($this->any())
->method("buildAuthUrl")
->with($this->equalTo("write"), $this->equalTo("un_token"))
->will($this->returnValue("une_super_url"));
$stub = $this->getMock("Bridge_Api_Auth_Flickr", array("get_api"));
$stub->expects($this->any())
->method("get_api")
->will($this->returnValue($api));
$params = array("permissions" => "write");
$stub->set_parameters($params);
$this->assertEquals("une_super_url", $stub->get_auth_url());
$this->assertEquals("une_super_url", $stub->get_auth_url($params));
}
}
?>

View File

@@ -0,0 +1,152 @@
<?php
require_once __DIR__ . '/../../../PhraseanetPHPUnitAuthenticatedAbstract.class.inc';
require_once __DIR__ . '/../../Bridge_datas.inc';
/**
* Test class for Bridge_Api_Auth_OAuth2.
* Generated by PHPUnit on 2011-10-12 at 18:45:15.
*/
class Bridge_Api_Auth_OAuth2Test extends PHPUnit_Framework_TestCase
{
/**
* @var Bridge_Api_Auth_OAuth2
*/
protected $object;
protected $parameters;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
public function setUp()
{
$this->object = new Bridge_Api_Auth_OAuth2();
$this->parameters = array(
'client_id' => "client_id"
, 'client_secret' => "client_secret"
, 'redirect_uri' => "redirect_uri"
, 'scope' => 'super_scope'
, 'response_type' => 'code'
, 'token_endpoint' => "one_token_endpoint"
, 'auth_endpoint' => "one_auth_endpoint"
);
}
public function testParse_request_token()
{
$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()
{
$this->setExpectedException("Bridge_Exception_ApiConnectorAccessTokenFailed");
$this->object->connect("123");
}
public function testReconnect()
{
$setting = $this->getMock("Bridge_AccountSettings", array("get"), array(), "", false);
$setting->expects($this->once())
->method("get")
->with($this->equalTo("refresh_token"))
->will($this->returnValue("123"));
$this->object->set_settings($setting);
$this->setExpectedException("Bridge_Exception_ApiConnectorAccessTokenFailed");
$this->object->reconnect();
}
public function testDisconnect()
{
$setting = $this->getMock("Bridge_AccountSettings", array("set"), array(), "", false);
$setting->expects($this->once())
->method("set")
->with($this->equalTo("auth_token"), $this->isNull());
$this->object->set_settings($setting);
$return = $this->object->disconnect();
$this->assertEquals($this->object, $return);
}
public function testIs_connected()
{
$setting = $this->getMock("Bridge_AccountSettings", array("get"), array(), "", false);
$setting->expects($this->any())
->method("get")
->with($this->equalTo("auth_token"))
->will($this->onConsecutiveCalls("123456",123456, null));
$this->object->set_settings($setting);
$this->assertTrue($this->object->is_connected());
$this->assertTrue($this->object->is_connected());
$this->assertFalse($this->object->is_connected());
}
public function testGet_auth_signatures()
{
$setting = $this->getMock("Bridge_AccountSettings", array("get"), array(), "", false);
$setting->expects($this->once())
->method("get")
->with($this->equalTo("auth_token"))
->will($this->returnValue("123"));
$this->object->set_settings($setting);
$return = $this->object->get_auth_signatures();
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY, $return);
$this->assertArrayHasKey("auth_token", $return);
$this->assertEquals("123" , $return["auth_token"]);
}
public function testSet_parameters()
{
$parameters = array(
"client_id" => "cid"
,"allo"=>"hello"
,"yo" => "coucou"
,"response_type" => "hihi"
);
$return = $this->object->set_parameters($parameters);
$this->assertEquals(0 , sizeof(get_object_vars($this->object)));
$this->assertEquals($return, $this->object);
}
public function testGet_auth_url()
{
$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";
$this->assertEquals($expected_url, $this->object->get_auth_url());
$more_params = array("test" => "test");
$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));
}
}
?>

View File

@@ -0,0 +1,189 @@
<?php
require_once __DIR__ . '/../../PhraseanetPHPUnitAuthenticatedAbstract.class.inc';
require_once __DIR__ . '/../Bridge_datas.inc';
/**
* Test class for Bridge_Api_AbstractCollection.
* Generated by PHPUnit on 2011-10-12 at 17:59:33.
*/
class Bridge_Api_AbstractCollectionTest extends PHPUnit_Framework_TestCase
{
/**
* @var Bridge_Api_AbstractCollection
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
public function setUp()
{
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
public function tearDown()
{
}
/**
* @todo Implement testGet_total_items().
*/
public function testGet_total_items()
{
$stub = $this->getMockForAbstractClass('Bridge_Api_AbstractCollection');
$this->assertNull($stub->get_total_items());
$stub->set_total_items("3");
$this->assertEquals(3, $stub->get_total_items());
}
/**
* @todo Implement testSet_total_items().
*/
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);
}
/**
* @todo Implement testGet_items_per_page().
*/
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());
}
/**
* @todo Implement testSet_items_per_page().
*/
public function testSet_items_per_page()
{
$stub = $this->getMockForAbstractClass('Bridge_Api_AbstractCollection');
$return = $stub->set_items_per_page("3");
$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);
}
/**
* @todo Implement testGet_current_page().
*/
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());
}
/**
* @todo Implement testSet_current_page().
*/
public function testSet_current_page()
{
$stub = $this->getMockForAbstractClass('Bridge_Api_AbstractCollection');
$return = $stub->set_current_page("3");
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_INT, $stub->get_current_page());
$this->assertEquals(3, $stub->get_current_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());
}
}
?>

View File

@@ -0,0 +1,264 @@
<?php
require_once __DIR__ . '/../../PhraseanetWebTestCaseAuthenticatedAbstract.class.inc';
require_once __DIR__ . '/../Bridge_datas.inc';
/**
* Test class for Bridge_Api_Abstract.
* Generated by PHPUnit on 2011-10-12 at 17:59:33.
*/
class Bridge_Api_AbstractTest extends PhraseanetWebTestCaseAuthenticatedAbstract
{
public static $account = null;
public static $api = null;
/**
* @var Bridge_Api_Abstract
*/
protected $auth;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
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');
}
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');
}
}
public static function tearDownAfterClass()
{
parent::tearDownAfterClass();
self::$api->delete();
if (self::$account instanceof Bridge_Account)
self::$account->delete();
}
/**
* @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())
->method('set_transport_authentication_params');
$return = $stub->set_auth_settings($settings);
$this->assertEquals($stub, $return);
}
/**
* @todo Implement testConnect().
*/
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())
->method('is_configured')
->will($this->returnValue(TRUE));
$this->auth->expects($this->once())
->method('parse_request_token')
->will($this->returnValue("token"));
$this->auth->expects($this->once())
->method('connect')
->will($this->returnValue(array("coucou")));
$return = $stub->connect();
$this->assertEquals(array("coucou"), $return);
}
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->expects($this->once())
->method('is_configured')
->will($this->returnValue(FALSE));
$this->setExpectedException("Bridge_Exception_ApiConnectorNotConfigured");
$stub->connect();
}
/**
* @todo Implement testReconnect().
*/
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())
->method('is_configured')
->will($this->returnValue(TRUE));
$this->auth->expects($this->once())
->method('reconnect');
$return = $stub->reconnect();
$this->assertEquals($stub, $return);
}
/**
* @todo Implement testReconnect().
*/
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())
->method('is_configured')
->will($this->returnValue(FALSE));
$this->setExpectedException("Bridge_Exception_ApiConnectorNotConfigured");
$stub->reconnect();
}
/**
* @todo Implement testDisconnect().
*/
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())
->method('is_configured')
->will($this->returnValue(TRUE));
$this->auth->expects($this->once())
->method('disconnect');
$return = $stub->disconnect();
$this->assertEquals($stub, $return);
}
/**
* @todo Implement testDisconnect().
*/
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())
->method('is_configured')
->will($this->returnValue(FALSE));
$this->setExpectedException("Bridge_Exception_ApiConnectorNotConfigured");
$stub->disconnect();
}
/**
* @todo Implement testIs_connected().
*/
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())
->method('is_connected')
->will($this->returnValue(TRUE));
$return = $stub->is_connected();
$this->assertEquals(TRUE, $return);
}
/**
* @todo Implement testGet_auth_url().
*/
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())
->method('get_auth_url')
->with($this->isType(PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY))
->will($this->returnValue("une url"));
$return = $stub->get_auth_url();
$this->assertEquals("une url", $return);
}
/**
* @todo Implement testSet_locale().
*/
public function testSet_locale()
{
$stub = $this->getMockForAbstractClass('Bridge_Api_Abstract', array(registry::get_instance(), $this->auth, "Mock_Bridge_Api_Abstract"));
$stub->set_locale("fr");
$this->assertEquals("fr", $stub->get_locale());
}
/**
* @todo Implement testIs_valid_object_id().
*/
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(123));
$this->assertTrue($stub->is_valid_object_id(12.25));
$this->assertFalse($stub->is_valid_object_id(array()));
$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);
}
}
?>

View File

@@ -0,0 +1,27 @@
<?php
require_once __DIR__ . '/../../PhraseanetPHPUnitAuthenticatedAbstract.class.inc';
require_once __DIR__ . '/../Bridge_datas.inc';
/**
* Test class for Bridge_Api_ContainerCollection.
* Generated by PHPUnit on 2011-10-12 at 17:59:33.
*/
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()));
}
}
?>

View File

@@ -0,0 +1,358 @@
<?php
require_once __DIR__ . '/../../PhraseanetPHPUnitAuthenticatedAbstract.class.inc';
require_once __DIR__ . '/../Bridge_datas.inc';
require_once __DIR__ . '/../../../lib/classes/Bridge/Api/Dailymotion.class.php';
/**
* Test class for Bridge_Api_Dailymotion.
* Generated by PHPUnit on 2011-10-13 at 18:03:33.
*/
class Bridge_Api_DailymotionTest extends PHPUnit_Framework_TestCase
{
/**
* @var Bridge_Api_Dailymotion
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
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

@@ -0,0 +1,28 @@
<?php
require_once __DIR__ . '/../../PhraseanetPHPUnitAuthenticatedAbstract.class.inc';
require_once __DIR__ . '/../Bridge_datas.inc';
/**
* Test class for Bridge_Api_ElementCollection.
* Generated by PHPUnit on 2011-10-12 at 17:59:33.
*/
class Bridge_Api_ElementCollectionTest extends PHPUnit_Framework_TestCase
{
public function testAdd_element()
{
$collection = new Bridge_Api_ElementCollection();
$i = 0;
while($i < 5)
{
$element = $this->getMock("Bridge_Api_ElementInterface");
$collection->add_element(new $element);
$i++;
}
$this->assertEquals(5, sizeof($collection->get_elements()));
}
}
?>

View File

@@ -0,0 +1,346 @@
<?php
require_once __DIR__ . '/../../PhraseanetPHPUnitAuthenticatedAbstract.class.inc';
require_once __DIR__ . '/../Bridge_datas.inc';
/**
* Test class for Bridge_Api_Flickr.
* Generated by PHPUnit on 2011-10-12 at 17:59:34.
*/
class Bridge_Api_FlickrTest extends PHPUnit_Framework_TestCase
{
/**
* @var Bridge_Api_Flickr
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
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

@@ -0,0 +1,349 @@
<?php
require_once __DIR__ . '/../../PhraseanetPHPUnitAuthenticatedAbstract.class.inc';
require_once __DIR__ . '/../Bridge_datas.inc';
/**
* Test class for Bridge_Api_Youtube.
* Generated by PHPUnit on 2011-10-12 at 17:59:34.
*/
class Bridge_Api_YoutubeTest extends PHPUnit_Framework_TestCase
{
/**
* @var Bridge_Api_Youtube
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
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

@@ -0,0 +1,117 @@
<?php
require_once __DIR__ . '/../../../PhraseanetPHPUnitAuthenticatedAbstract.class.inc';
require_once __DIR__ . '/../../Bridge_datas.inc';
require_once __DIR__ . '/../../../../lib/classes/Bridge/Api/Dailymotion/Container.class.php';
/**
* Test class for Bridge_Api_Dailymotion_Container.
* Generated by PHPUnit on 2011-10-13 at 18:05:19.
*/
class Bridge_Api_Dailymotion_ContainerTest extends PHPUnit_Framework_TestCase
{
/**
* @var Bridge_Api_Dailymotion_Container
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
$this->test = array(
'id' => '01234567'
,'description' => 'one description'
, 'name' => 'hello container'
);
}
/**
* @todo Implement testGet_created_on().
*/
public function testGet_created_on()
{
$this->object = new Bridge_Api_Dailymotion_Container($this->test, 'playlist', 'thumb', 'url');
$this->assertNull($this->object->get_created_on());
}
/**
* @todo Implement testGet_description().
*/
public function testGet_description()
{
$this->object = new Bridge_Api_Dailymotion_Container($this->test, 'playlist', 'thumb', 'url');
$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());
}
/**
* @todo Implement testGet_id().
*/
public function testGet_id()
{
$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());
}
/**
* @todo Implement testGet_thumbnail().
*/
public function testGet_thumbnail()
{
$this->object = new Bridge_Api_Dailymotion_Container($this->test, 'playlist', 'thumb', 'url');
$this->assertEquals('thumb', $this->object->get_thumbnail());
}
/**
* @todo Implement testGet_title().
*/
public function testGet_title()
{
$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());
}
/**
* @todo Implement testGet_type().
*/
public function testGet_type()
{
$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());
}
}
?>

View File

@@ -0,0 +1,170 @@
<?php
require_once __DIR__ . '/../../../PhraseanetPHPUnitAuthenticatedAbstract.class.inc';
require_once __DIR__ . '/../../Bridge_datas.inc';
require_once __DIR__ . '/../../../../lib/classes/Bridge/Api/Dailymotion/Element.class.php';
/**
* Test class for Bridge_Api_Dailymotion_Element.
* Generated by PHPUnit on 2011-10-13 at 18:07:26.
*/
class Bridge_Api_Dailymotion_ElementTest extends PHPUnit_Framework_TestCase
{
/**
* @var Bridge_Api_Dailymotion_Element
*/
protected $object;
protected $test;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
public function setUp()
{
$this->test = array(
'created_time' => time()
, '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()
{
$this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla');
$this->assertEquals(DateTime::createFromFormat('U', $this->test['created_time']), $this->object->get_created_on());
}
public function testGet_description()
{
$this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla');
$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_id()
{
$this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla');
$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_description());
$this->assertEmpty($this->object->get_id());
}
public function testGet_thumbnail()
{
$this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla');
$this->assertEquals($this->test['thumbnail_medium_url'], $this->object->get_thumbnail());
unset($this->test["thumbnail_medium_url"]);
$this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla');
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_thumbnail());
$this->assertEmpty($this->object->get_thumbnail());
}
public function testGet_title()
{
$this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla');
$this->assertEquals($this->test['title'], $this->object->get_title());
unset($this->test["title"]);
$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_type()
{
$type = 'kikoo';
$this->object = new Bridge_Api_Dailymotion_Element($this->test, $type);
$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()
{
$this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla');
$this->assertEquals(DateTime::createFromFormat('U', $this->test['modified_time']), $this->object->get_updated_on());
}
public function testGet_url()
{
$this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla');
$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 testIs_private()
{
$this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla');
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_BOOL, $this->object->is_private());
$this->assertTrue($this->object->is_private());
unset($this->test["private"]);
$this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla');
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_BOOL, $this->object->is_private());
$this->assertFalse($this->object->is_private());
}
public function testGet_duration()
{
$this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla');
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_duration());
$this->assertEquals("01:20", $this->object->get_duration());
unset($this->test["duration"]);
$this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla');
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_duration());
$this->assertEquals("00:00", $this->object->get_duration());
}
public function testGet_view_count()
{
$this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla');
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_INT, $this->object->get_view_count());
$this->assertEquals($this->test['views_total'], $this->object->get_view_count());
unset($this->test["views_total"]);
$this->object = new Bridge_Api_Dailymotion_Element($this->test, 'blabla');
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_INT, $this->object->get_view_count());
$this->assertEquals(0 , $this->object->get_view_count());
}
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());
}
}
?>

View File

@@ -0,0 +1,86 @@
<?php
require_once __DIR__ . '/../../../PhraseanetPHPUnitAuthenticatedAbstract.class.inc';
require_once __DIR__ . '/../../Bridge_datas.inc';
/**
* Test class for Bridge_Api_Flickr_Container.
* Generated by PHPUnit on 2011-10-12 at 18:35:50.
*/
class Bridge_Api_Flickr_ContainerTest extends PHPUnit_Framework_TestCase
{
/**
* @var Bridge_Api_Flickr_Container
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
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">
<title>Avis Blanche</title>
<description>My Grandma\'s Recipe File.</description>
</photoset>
';
$xml = simplexml_load_string($string);
$this->object = new Bridge_Api_Flickr_Container($xml, 'userid123', "photoset", "my_humbnail");
}
public function testGet_id()
{
$this->assertEquals("72157626216528324", $this->object->get_id());
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_id());
}
public function testGet_thumbnail()
{
$this->assertEquals("my_humbnail", $this->object->get_thumbnail());
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_thumbnail());
}
public function testGet_url()
{
$this->assertRegExp("/https:\/\/secure.flickr.com\/photos/", $this->object->get_url());
$this->assertRegExp("/userid123/", $this->object->get_url());
$this->assertRegExp("/72157626216528324/", $this->object->get_url());
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_thumbnail());
}
public function testGet_title()
{
$this->assertEquals("My Grandma's Recipe File.", $this->object->get_description());
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_description());
}
public function testGet_description()
{
$this->assertEquals("Avis Blanche", $this->object->get_title());
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_title());
}
public function testGet_updated_on()
{
$this->assertInstanceOf('DateTime', $this->object->get_updated_on());
$this->assertEquals(DateTime::createFromFormat('U', '1300335009'), $this->object->get_updated_on());
}
public function testGet_created_on()
{
$this->assertInstanceOf('DateTime', $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());
}
}
?>

View File

@@ -0,0 +1,172 @@
<?php
require_once __DIR__ . '/../../../PhraseanetPHPUnitAuthenticatedAbstract.class.inc';
require_once __DIR__ . '/../../Bridge_datas.inc';
/**
* Test class for Bridge_Api_Flickr_Element.
* Generated by PHPUnit on 2011-10-12 at 18:35:50.
*/
class Bridge_Api_Flickr_ElementTest extends PHPUnit_Framework_TestCase
{
/**
* @var Bridge_Api_Flickr_Element
*/
protected $object_list;
/**
* @var Bridge_Api_Flickr_Element
*/
protected $object_alone;
protected $xml_list;
protected $xml_alone;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
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">
<description>une description</description>
</photo>
';
$string = '
<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">
<owner iconfarm="0" iconserver="0" location="" realname="" username="Boontyp4" nsid="60578095@N05"></owner>
<title>Australia.gif</title>
<description>drapeau de l\'australie</description>
<visibility isfamily="0" isfriend="1" ispublic="0"></visibility>
<dates lastupdate="1314975347" takengranularity="0" taken="2011-07-12 06:37:00" posted="1310477820"></dates>
<permissions permaddmeta="2" permcomment="3"></permissions>
<editability canaddmeta="1" cancomment="1"></editability>
<publiceditability canaddmeta="0" cancomment="1"></publiceditability>
<usage canshare="0" canprint="1" canblog="1" candownload="1"></usage>
<comments>0</comments>
<notes></notes>
<people haspeople="0"></people>
<tags>
<tag>yo</tag>
</tags>
<urls>
<url type="photopage">http://www.flickr.com/photos/bees/2733/</url>
</urls>
</photo>
</rsp>
';
$this->xml_alone = simplexml_load_string($string);
$this->object_alone = new Bridge_Api_Flickr_Element($this->xml_alone, '12037949754@N01', 'album', false);
$this->xml_list = simplexml_load_string($str);
$this->object_list = new Bridge_Api_Flickr_Element($this->xml_list, '12037949754@N01', 'album', true);
}
public function testGet_id()
{
$this->assertEquals("5930279108", $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->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object_list->get_id());
}
public function testGet_url()
{
$this->assertRegExp("/6263188755/", $this->object_list->get_url());
$this->assertRegExp("/album/", $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->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_list->get_url());
}
public function testGet_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("/6135/", $this->object_alone->get_thumbnail());
$this->assertRegExp("/c06196fbd8/", $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_list->get_thumbnail());
}
public function testGet_title()
{
$this->assertEquals("un titre", $this->object_list->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_list->get_title());
}
public function testGet_description()
{
$this->assertEquals("une description", $this->object_list->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_list->get_description());
}
public function testGet_updated_on()
{
$this->assertInstanceOf('DateTime', $this->object_list->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', '1314975347'), $this->object_alone->get_updated_on());
}
public function testGet_category()
{
$this->assertEmpty($this->object_list->get_category());
$this->assertEmpty($this->object_alone->get_category());
}
public function testGet_duration()
{
$this->assertEmpty($this->object_list->get_duration());
$this->assertEmpty($this->object_alone->get_duration());
}
public function testGet_view_count()
{
$this->assertEquals(1, $this->object_list->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_list->get_view_count());
}
public function testGet_rating()
{
$this->assertNull($this->object_list->get_rating());
$this->assertNull($this->object_alone->get_rating());
}
public function testGet_created_on()
{
$this->assertInstanceOf('DateTime', $this->object_list->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', '1310477820'), $this->object_alone->get_created_on());
}
public function testIs_private()
{
$this->assertFalse($this->object_list->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_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());
}
}
?>

View File

@@ -0,0 +1,91 @@
<?php
require_once __DIR__ . '/../../../PhraseanetPHPUnitAuthenticatedAbstract.class.inc';
require_once __DIR__ . '/../../Bridge_datas.inc';
/**
* Test class for Bridge_Api_Youtube_Container.
* Generated by PHPUnit on 2011-10-12 at 18:35:50.
*/
class Bridge_Api_Youtube_ContainerTest extends PHPUnit_Framework_TestCase
{
/**
* @var Bridge_Api_Youtube_Container
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
public function setUp()
{
$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");
$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');
}
/**
* @todo fin a way to test getPlaylistId
*/
public function testGet_thumbnail()
{
$this->assertEquals("my_thumbnail", $this->object->get_thumbnail());
$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());
}
}
?>

View File

@@ -0,0 +1,134 @@
<?php
require_once __DIR__ . '/../../../PhraseanetPHPUnitAuthenticatedAbstract.class.inc';
require_once __DIR__ . '/../../Bridge_datas.inc';
/**
* Test class for Bridge_Api_Youtube_Element.
* Generated by PHPUnit on 2011-10-12 at 18:35:49.
*/
class Bridge_Api_Youtube_ElementTest extends PHPUnit_Framework_TestCase
{
/**
* @var Bridge_Api_Youtube_Element
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
public function setUp()
{
$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");
$id = new Zend_Gdata_App_Extension_Id("Az2cv12");
$rating = new Zend_Gdata_Extension_Rating(4, 1, 5, 200, 4);
$duration = new Zend_Gdata_YouTube_Extension_Duration(80);
$player = new Zend_Gdata_Media_Extension_MediaPlayer();
$player->setUrl("coucou");
$stat = new Zend_Gdata_YouTube_Extension_Statistics();
$stat->setViewCount("5");
$thumb = new Zend_Gdata_Media_Extension_MediaThumbnail('une url', '120', '90');
$media = new Zend_Gdata_YouTube_Extension_MediaGroup();
$media->setPlayer(array($player));
$media->setDuration($duration);
$media->setVideoId($id);
$media->setThumbnail(array($thumb));
$entry = new Zend_Gdata_YouTube_VideoEntry();
$entry->setMajorProtocolVersion(2);
$entry->setMediaGroup($media);
$entry->setStatistics($stat);
$entry->setRating($rating);
$entry->setVideoCategory("category");
$entry->setVideoDescription("one description");
$entry->setVideoPrivate();
$entry->setVideoTags(array('tags'));
$entry->setVideoTitle("hellow");
$entry->setUpdated($updated);
$entry->setPublished($published);
$this->object = new Bridge_Api_Youtube_Element($entry, 'video');
}
public function testGet_id()
{
$this->assertEquals("Az2cv12", $this->object->get_id());
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_id());
}
public function testGet_thumbnail()
{
$this->assertEquals("une url", $this->object->get_thumbnail());
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_thumbnail());
}
public function testGet_url()
{
$this->assertEquals("coucou", $this->object->get_url());
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_url());
}
public function testGet_title()
{
$this->assertEquals("hellow", $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_category()
{
$this->assertEquals("category", $this->object->get_category());
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_category());
}
public function testGet_duration()
{
$this->assertEquals(p4string::format_seconds(80), $this->object->get_duration());
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_duration());
}
public function testGet_view_count()
{
$this->assertEquals(5, $this->object->get_view_count());
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_INT, $this->object->get_view_count());
}
public function testGet_rating()
{
$this->assertEquals(200, $this->object->get_rating());
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_INT, $this->object->get_rating());
}
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 testIs_private()
{
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_BOOL, $this->object->is_private());
$this->assertTrue($this->object->is_private());
}
public function testGet_type()
{
$this->assertEquals("video", $this->object->get_type());
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $this->object->get_type());
}
}
?>

View File

@@ -0,0 +1,78 @@
<?php
require_once __DIR__ . '/../PhraseanetPHPUnitAuthenticatedAbstract.class.inc';
require_once __DIR__ . '/Bridge_datas.inc';
/**
* Test class for Bridge_Account.
* Generated by PHPUnit on 2011-10-10 at 13:38:20.
*/
class Bridge_AccountSettingsTest extends PhraseanetPHPUnitAuthenticatedAbstract
{
/**
* @var Bridge_AccountSettings
*/
protected $object;
protected $account;
protected $api;
protected $dist_id;
protected $named;
public function setUp()
{
try
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$sql = 'DELETE FROM bridge_apis WHERE name = "Apitest"';
$stmt = $appbox->get_connection()->prepare($sql);
$stmt->execute();
$stmt->closeCursor();
$this->api = Bridge_Api::create($appbox, 'Apitest');
$this->dist_id = 'EZ1565loPP';
$this->named = 'Fête à pinpins';
$this->account = Bridge_Account::create($appbox, $this->api, self::$user, $this->dist_id, $this->named);
$this->object = new Bridge_AccountSettings($appbox, $this->account);
}
catch (Exception $e)
{
$this->fail($e->getMessage());
}
}
public function tearDown()
{
$this->api->delete();
}
public function testGet()
{
$this->assertNull($this->object->get('test'));
$this->assertEquals('caca', $this->object->get('test', 'caca'));
$obj = new DateTime();
$this->assertEquals($obj, $this->object->get('test', $obj));
}
public function testSet()
{
$this->object->set('tip', 'top');
$this->assertEquals('top', $this->object->get('tip'));
$this->object->set('tip', 'tap');
$this->assertEquals('tap', $this->object->get('tip'));
$this->object->set('tip', null);
$this->assertEquals(null, $this->object->get('tip'));
}
public function testDelete()
{
$this->object->set('tip', 'top');
$this->assertEquals('top', $this->object->get('tip'));
$this->object->delete('tip');
$this->assertEquals(null, $this->object->get('tip'));
$this->assertEquals('flop', $this->object->get('tip', 'flop'));
}
}

View File

@@ -0,0 +1,167 @@
<?php
require_once __DIR__ . '/../PhraseanetPHPUnitAuthenticatedAbstract.class.inc';
require_once __DIR__ . '/Bridge_datas.inc';
/**
* Test class for Bridge_Account.
* Generated by PHPUnit on 2011-10-10 at 13:38:20.
*/
class Bridge_AccountTest extends PhraseanetPHPUnitAuthenticatedAbstract
{
/**
* @var Bridge_Account
*/
protected $object;
protected $api;
protected $dist_id;
protected $named;
protected $id;
public function setUp()
{
try
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$sql = 'DELETE FROM bridge_apis WHERE name = "Apitest"';
$stmt = $appbox->get_connection()->prepare($sql);
$stmt->execute();
$stmt->closeCursor();
$this->api = Bridge_Api::create($appbox, 'Apitest');
$this->dist_id = 'EZ1565loPP';
$this->named = 'Fête à pinpins';
$account = Bridge_Account::create($appbox, $this->api, self::$user, $this->dist_id, $this->named);
$this->id = $account->get_id();
$this->object = new Bridge_Account($appbox, $this->api, $this->id);
}
catch (Exception $e)
{
$this->fail($e->getMessage());
}
}
public function tearDown()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$this->object->delete();
try
{
new Bridge_Account($appbox, $this->api, $this->id);
$this->fail();
}
catch (Bridge_Exception_AccountNotFound $e)
{
}
$this->api->delete();
}
public function testGet_id()
{
$this->assertTrue(is_int($this->object->get_id()));
$this->assertEquals($this->id, $this->object->get_id());
}
public function testGet_api()
{
$this->assertInstanceOf('Bridge_Api', $this->object->get_api());
$this->assertEquals($this->api, $this->object->get_api());
$this->assertEquals($this->api->get_id(), $this->object->get_api()->get_id());
}
public function testGet_dist_id()
{
$this->assertEquals($this->dist_id, $this->object->get_dist_id());
}
public function testGet_user()
{
$this->assertInstanceOf('User_Adapter', $this->object->get_user());
$this->assertEquals(self::$user->get_id(), $this->object->get_user()->get_id());
}
public function testGet_name()
{
$this->assertEquals($this->named, $this->object->get_name());
}
public function testGet_created_on()
{
$this->assertInstanceOf('DateTime', $this->object->get_created_on());
$this->assertTrue($this->object->get_created_on() <= new DateTime());
}
public function testGet_updated_on()
{
$this->assertInstanceOf('DateTime', $this->object->get_updated_on());
$this->assertTrue($this->object->get_updated_on() <= new DateTime());
$this->assertTrue($this->object->get_updated_on() >= $this->object->get_created_on());
$update1 = $this->object->get_updated_on();
sleep(2);
$this->object->set_name('prout');
$update2 = $this->object->get_updated_on();
$this->assertTrue($update2 > $update1);
}
public function testSet_name()
{
$new_name = 'YODELALI &é"\'(-è_çà)';
$this->object->set_name($new_name);
$this->assertEquals($new_name, $this->object->get_name());
$new_name = 'BACHI BOUZOUKS';
$this->object->set_name($new_name);
$this->assertEquals($new_name, $this->object->get_name());
}
public function testGet_accounts_by_api()
{
$accounts = Bridge_Account::get_accounts_by_api(appbox::get_instance(\bootstrap::getCore()), $this->api);
$this->assertTrue(is_array($accounts));
$this->assertGreaterThan(0, count($accounts));
foreach ($accounts as $account)
{
$this->assertInstanceOf('Bridge_Account', $account);
}
}
public function testGet_settings()
{
$this->assertInstanceOf('Bridge_AccountSettings', $this->object->get_settings());
}
public function testGet_accounts_by_user()
{
$accounts = Bridge_Account::get_accounts_by_user(appbox::get_instance(\bootstrap::getCore()), self::$user);
$this->assertTrue(is_array($accounts));
$this->assertTrue(count($accounts) > 0);
foreach ($accounts as $account)
{
$this->assertInstanceOf('Bridge_Account', $account);
}
}
public function testLoad_account()
{
$account = Bridge_Account::load_account(appbox::get_instance(\bootstrap::getCore()), $this->object->get_id());
$this->assertEquals($this->object->get_id(), $account->get_id());
}
public function testLoad_account_from_distant_id()
{
$this->markTestIncomplete();
}
}

View File

@@ -0,0 +1,198 @@
<?php
require_once __DIR__ . '/../PhraseanetPHPUnitAuthenticatedAbstract.class.inc';
require_once __DIR__ . '/Bridge_datas.inc';
/**
* Test class for Bridge_Api.
* Generated by PHPUnit on 2011-10-10 at 13:38:20.
*/
class Bridge_ApiTest extends PhraseanetPHPUnitAuthenticatedAbstract
{
/**
* @var Bridge_Api
*/
protected $object;
protected $id;
protected $type;
public function setUp()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$sql = 'DELETE FROM bridge_apis WHERE name = "Apitest"';
$stmt = $appbox->get_connection()->prepare($sql);
$stmt->execute();
$stmt->closeCursor();
$this->type = 'Apitest';
$api = Bridge_Api::create($appbox, $this->type);
$this->id = $api->get_id();
$this->object = new Bridge_Api($appbox, $api->get_id());
}
public function tearDown()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$this->object->delete();
try
{
new Bridge_Api($appbox, $this->id);
$this->fail();
}
catch (Bridge_Exception_ApiNotFound $e)
{
}
}
public function testGet_id()
{
$this->assertTrue(is_int($this->object->get_id()));
$this->assertTrue($this->object->get_id() > 0);
$this->assertEquals($this->id, $this->object->get_id());
}
public function testis_disabled()
{
$this->assertTrue(is_bool($this->object->is_disabled()));
$this->assertFalse($this->object->is_disabled());
}
public function testenable()
{
$this->assertTrue(is_bool($this->object->is_disabled()));
$this->assertFalse($this->object->is_disabled());
sleep(1);
$update1 = $this->object->get_updated_on();
$this->object->disable(new DateTime('+2 seconds'));
$this->assertTrue($this->object->is_disabled());
sleep(3);
$update2 = $this->object->get_updated_on();
$this->assertTrue($update2 > $update1);
$this->assertFalse($this->object->is_disabled());
$this->object->enable();
$this->assertFalse($this->object->is_disabled());
}
public function testdisable()
{
$this->testenable();
}
public function testGet_created_on()
{
$this->assertInstanceOf('DateTime', $this->object->get_created_on());
$this->assertTrue($this->object->get_created_on() <= new DateTime());
}
public function testGet_updated_on()
{
$this->assertInstanceOf('DateTime', $this->object->get_updated_on());
$this->assertTrue($this->object->get_updated_on() <= new DateTime());
$this->assertTrue($this->object->get_updated_on() >= $this->object->get_created_on());
}
public function testGet_connector()
{
$this->markTestIncomplete();
}
public function testlist_elements()
{
$this->markTestIncomplete();
}
public function testlist_containers()
{
$this->markTestIncomplete();
}
public function testupdate_element()
{
$this->markTestIncomplete();
}
public function testcreate_container()
{
$this->markTestIncomplete();
}
public function testadd_element_to_container()
{
$this->markTestIncomplete();
}
public function testdelete_object()
{
$this->markTestIncomplete();
}
public function testacceptable_records()
{
$this->markTestIncomplete();
}
public function testget_element_from_id()
{
$this->markTestIncomplete();
}
public function testget_container_from_id()
{
$this->markTestIncomplete();
}
public function testget_category_list()
{
$this->markTestIncomplete();
}
public function testget_element_status()
{
$this->markTestIncomplete();
}
public function testmap_connector_to_element_status()
{
$this->markTestIncomplete();
}
public function testupload()
{
$this->markTestIncomplete();
}
public function testgenerate_callback_url()
{
$this->markTestIncomplete();
}
public function testgenerate_login_url()
{
$this->markTestIncomplete();
}
public function testget_connector_by_name()
{
$this->markTestIncomplete();
}
public function testget_by_api_name()
{
$this->markTestIncomplete();
}
public function testget_availables()
{
$this->markTestIncomplete();
}
}

View File

@@ -0,0 +1,189 @@
<?php
require_once __DIR__ . '/../PhraseanetPHPUnitAuthenticatedAbstract.class.inc';
require_once __DIR__ . '/Bridge_datas.inc';
/**
* Test class for Bridge_Element.
* Generated by PHPUnit on 2011-10-10 at 13:38:20.
*/
class Bridge_ElementTest extends PhraseanetPHPUnitAuthenticatedAbstract
{
/**
* @var Bridge_Element
*/
protected $object;
protected $account;
protected $api;
protected $dist_id;
protected $named;
protected $id;
protected $title;
protected $status;
protected static $need_records = 1;
public function setUp()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$sql = 'DELETE FROM bridge_apis WHERE name = "Apitest"';
$stmt = $appbox->get_connection()->prepare($sql);
$stmt->execute();
$stmt->closeCursor();
$this->api = Bridge_Api::create($appbox, 'Apitest');
$this->dist_id = 'EZ1565loPP';
$this->named = 'Fête à pinpins';
$this->account = Bridge_Account::create($appbox, $this->api, self::$user, $this->dist_id, $this->named);
$this->title = 'GOGACKO';
$this->status = 'Processing';
$element = Bridge_Element::create($appbox, $this->account, self::$record_1, $this->title, $this->status, $this->account->get_api()->get_connector()->get_default_element_type());
$this->id = $element->get_id();
$this->object = new Bridge_Element($appbox, $this->account, $this->id);
}
public function tearDown()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$this->object->delete();
try
{
new Bridge_Element($appbox, $this->account, $this->id);
$this->fail();
}
catch (Bridge_Exception_ElementNotFound $e)
{
}
$this->api->delete();
}
public function testGet_account()
{
$this->assertInstanceOf('Bridge_Account', $this->object->get_account());
$this->assertEquals($this->account, $this->object->get_account());
$this->assertEquals($this->account->get_id(), $this->object->get_account()->get_id());
}
public function testGet_id()
{
}
public function testGet_record()
{
$this->assertInstanceOf('record_adapter', $this->object->get_record());
$this->assertEquals(self::$record_1->get_sbas_id(), $this->object->get_record()->get_sbas_id());
$this->assertEquals(self::$record_1->get_record_id(), $this->object->get_record()->get_record_id());
}
public function testGet_dist_id()
{
$this->assertNull($this->object->get_dist_id());
}
public function testGet_status()
{
$this->assertEquals($this->status, $this->object->get_status());
}
public function testSet_status()
{
$update1 = $this->object->get_updated_on();
$new_status = '&é"\'(-è_çà)';
$this->object->set_status($new_status);
$this->assertEquals($new_status, $this->object->get_status());
sleep(1);
$new_status = '&é"0687345àç_)à)';
$this->object->set_status($new_status);
$this->assertEquals($new_status, $this->object->get_status());
$update2 = $this->object->get_updated_on();
$this->assertTrue($update2 > $update1);
}
public function testGet_title()
{
$this->assertEquals($this->title, $this->object->get_title());
}
public function testGet_type()
{
$this->markTestIncomplete();
}
public function testSet_title()
{
$update1 = $this->object->get_updated_on();
sleep(1);
$new_title = 'Cigares du pharaon';
$this->object->set_title($new_title);
$this->assertEquals($new_title, $this->object->get_title());
$update2 = $this->object->get_updated_on();
$this->assertTrue($update2 > $update1);
}
public function testSet_distid()
{
$update1 = $this->object->get_updated_on();
sleep(1);
$this->object->set_dist_id($this->dist_id);
$this->assertEquals($this->dist_id, $this->object->get_dist_id());
$update2 = $this->object->get_updated_on();
$this->assertTrue($update2 > $update1);
}
public function testGet_created_on()
{
$this->assertInstanceOf('DateTime', $this->object->get_created_on());
}
public function testGet_updated_on()
{
$this->assertInstanceOf('DateTime', $this->object->get_updated_on());
}
public function testGet_elements_by_account()
{
$elements = Bridge_Element::get_elements_by_account(appbox::get_instance(\bootstrap::getCore()), $this->account);
$this->assertTrue(is_array($elements));
$this->assertGreaterThan(0, count($elements));
foreach ($elements as $element)
{
$this->assertInstanceOf('Bridge_Element', $element);
}
}
public function testGet_connector_status()
{
$this->markTestIncomplete();
}
public function testSet_connector_status()
{
$this->markTestIncomplete();
}
public function testGet_datas()
{
$this->markTestIncomplete();
}
public function testSet_datas()
{
$this->markTestIncomplete();
}
public function test()
{
$this->markTestIncomplete();
}
}

View File

@@ -0,0 +1,547 @@
<?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 Bridge_Api_Apitest_Containers implements Bridge_Api_ContainerInterface
{
public $id;
public $type;
public function __construct()
{
}
public function get_created_on()
{
}
public function get_description()
{
}
public function get_id()
{
return $this->id;
}
public function get_thumbnail($width = 120, $height = 90)
{
}
public function get_title()
{
}
public function get_type()
{
return $this->type;
}
public function get_updated_on()
{
}
public function get_url()
{
}
public function get_category()
{
}
public function is_private()
{
}
public function get_rating()
{
}
}
class Bridge_Api_Apitest_Element implements Bridge_Api_ElementInterface
{
public $id;
public $type;
public function __construct()
{
}
public function get_category()
{
}
public function get_created_on()
{
}
public function get_description()
{
}
public function get_duration()
{
}
public function get_id()
{
return $this->id;
}
public function get_rating()
{
}
public function get_thumbnail()
{
}
public function get_title()
{
}
public function get_type()
{
return $this->type;
}
public function get_updated_on()
{
}
public function get_url()
{
}
public function get_view_count()
{
}
public function is_private()
{
}
}
class Bridge_Api_Apitest extends Bridge_Api_Abstract implements Bridge_Api_Interface
{
const AUTH_TYPE = 'None';
public static $hasError = false;
public static $hasException = false;
public function __construct(registryInterface $registry, Bridge_Api_Auth_Interface $auth)
{
parent::__construct($registry, $auth);
}
protected function initialize_transport()
{
}
protected function set_auth_params()
{
}
protected function set_transport_authentication_params()
{
}
public function get_terms_url()
{
return 'http://example.com/terms.html';
}
/**
*
* @return Array
*/
public function connect()
{
return array('auth_token' => 'kikoo', 'refresh_token' => 'kooki');
}
/**
*
* @return Bridge_Api_Interface
*/
public function reconnect()
{
return parent::reconnect();
}
/**
*
* @return Bridge_Api_Interface
*/
public function disconnect()
{
return parent::disconnect();
}
/**
*
* @return boolean
*/
public function is_connected()
{
return parent::is_connected();
}
/**
*
* @return Bridge_Api_Interface
*/
public function set_locale($locale)
{
}
/**
*
* @return string
*/
public function get_name()
{
return 'Youtube';
}
/**
*
* @return string
*/
public function get_icon_url()
{
}
/**
*
* @return string
*/
public function get_image_url()
{
}
/**
*
* @return string
*/
public function get_url()
{
}
/**
*
* @return string
*/
public function get_infos()
{
}
public function get_object_class_from_type($type)
{
switch ($type)
{
case $this->get_default_element_type() :
return Bridge_Api_Interface::OBJECT_CLASS_ELEMENT;
break;
case $this->get_default_container_type() :
return Bridge_Api_Interface::OBJECT_CLASS_CONTAINER;
break;
}
}
public function get_default_element_type()
{
return 'video';
}
public function get_default_container_type()
{
return 'playlist';
}
public function get_element_types()
{
}
public function get_container_types()
{
}
public function get_element_from_id($element_id, $object)
{
$element = new Bridge_Api_Apitest_Element();
$element->id = $element_id;
$element->type = $object;
return $element;
}
public function get_container_from_id($element_id, $object)
{
$container = new Bridge_Api_Apitest_Containers();
$container->id = $element_id;
$container->type = $object;
return $container;
}
public function get_category_list()
{
}
public function get_user_name()
{
return "coucou";
}
public function get_user_id()
{
return 'kirikoo';
}
public function list_elements($type, $offset_start = 0, $quantity = 10)
{
$element_collection = new Bridge_Api_ElementCollection();
$i = 0;
while ($i < 5)
{
$element_collection->add_element(new Bridge_Api_Apitest_Element());
$i++;
}
return $element_collection;
}
public function list_containers($type, $offset_start = 0, $quantity = 10)
{
$container_collection = new Bridge_Api_ContainerCollection();
$i = 0;
while ($i < 5)
{
$container_collection->add_element(new Bridge_Api_Apitest_Containers());
$i++;
}
return $container_collection;
}
public function update_element($object, $object_id, Array $datas)
{
}
public function create_container($container_type, \Symfony\Component\HttpFoundation\Request $request)
{
if (self::$hasException)
{
self::$hasException = false;
throw new \Exception("une erreur");
}
}
public function add_element_to_container($element_type, $element_id, $destination, $container_id)
{
if (self::$hasException)
{
self::$hasException = false;
throw new \Exception("une erreur");
}
}
public function delete_object($object, $object_id)
{
if (self::$hasException)
{
self::$hasException = false;
throw new \Exception("une erreur");
}
}
/**
*
* @return Closure
*/
public function acceptable_records()
{
$func = function($record)
{
return true;
};
return $func;
}
public function get_element_status(Bridge_Element $element)
{
}
public function map_connector_to_element_status($status)
{
}
public function get_error_message_from_status($connector_status)
{
}
public function upload(record_adapter &$record, array $options = array())
{
}
public function is_valid_object_id($object_id)
{
}
public function is_configured()
{
return true;
}
public function check_upload_constraints(array $datas, record_adapter $record)
{
if (self::$hasError)
{
self::$hasError = false;
return array('title' => 'too long');
}
return array();
}
public function get_upload_datas(\Symfony\Component\HttpFoundation\Request $request, record_adapter $record)
{
return array();
}
public function is_multiple_upload()
{
}
public function check_update_constraints(Array $datas)
{
if (!self::$hasError)
{
if (self::$hasException)
{
self::$hasException = false;
throw new \Exception('une erreur');
}
return array();
}
elseif (self::$hasError)
{
self::$hasError = false;
return array('title' => 'too long');
}
}
public function get_update_datas(\Symfony\Component\HttpFoundation\Request $request)
{
return array();
}
}
class Bridge_Api_Auth_None extends Bridge_Api_Auth_Abstract implements Bridge_Api_Auth_Interface
{
public function connect($param)
{
}
public function parse_request_token()
{
}
public function reconnect()
{
$this->settings->set('access_token', 'biloute');
}
public function disconnect()
{
$this->settings->set('auth_token', null);
}
public function is_connected()
{
return $this->settings->get('auth_token', null) !== null;
}
public function get_auth_url(Array $supp_parameters = array())
{
return 'kameamea';
}
public function get_auth_signatures()
{
}
public function set_parameters(Array $parameters)
{
}
}

View File

@@ -0,0 +1,195 @@
<?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__ . '/../../PhraseanetPHPUnitAuthenticatedAbstract.class.inc';
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class EntityBasketTest extends PhraseanetPHPUnitAuthenticatedAbstract
{
protected static $need_records = 1;
/**
*
* @var \Entities\Basket
*/
protected $basket;
/**
*
* @var \Doctrine\ORM\EntityManager
*/
protected $em;
public function setUp()
{
parent::setUp();
$this->em = self::$core->getEntityManager();
$this->basket = $this->insertOneBasket();
}
public function tearDown()
{
parent::tearDown();
}
public function testGetId()
{
$this->assertTrue(is_int($this->basket->getId()));
$otherBasket = $this->insertOneBasket();
$this->assertGreaterThan($this->basket->getId(), $otherBasket->getId());
}
public function testGetName()
{
$this->basket->setName('one name');
$this->em->persist($this->basket);
$this->em->flush();
$this->assertEquals('one name', $this->basket->getName());
}
public function testGetDescription()
{
$this->basket->setDescription('une jolie description pour mon super panier');
$this->em->persist($this->basket);
$this->em->flush();
$this->assertEquals('une jolie description pour mon super panier', $this->basket->getDescription());
}
public function testGetUsrId()
{
$this->basket->setUsrId(1);
$this->em->persist($this->basket);
$this->em->flush();
$this->assertEquals(1, $this->basket->getUsrId());
}
public function testGetPusherId()
{
$this->basket->setPusherId(1);
$this->em->persist($this->basket);
$this->em->flush();
$this->assertEquals(1, $this->basket->getPusherId());
}
public function testGetArchived()
{
$this->basket->setArchived(true);
$this->em->persist($this->basket);
$this->em->flush();
$this->assertTrue($this->basket->GetArchived());
$this->basket->setArchived(false);
$this->em->persist($this->basket);
$this->em->flush();
$this->assertFalse($this->basket->GetArchived());
}
public function testGetCreated()
{
$date = $this->basket->getCreated();
$this->assertInstanceOf('\DateTime', $date);
}
public function testGetUpdated()
{
$date = $this->basket->getUpdated();
$this->assertInstanceOf('\DateTime', $date);
}
public function testGetElements()
{
$elements = $this->basket->getElements();
$this->assertInstanceOf('\Doctrine\ORM\PersistentCollection', $elements);
$this->assertEquals(0, $elements->count());
$basketElement = new \Entities\BasketElement();
$basketElement->setRecord(self::$record_1);
$basketElement->setBasket($this->basket);
$this->em->persist($basketElement);
$this->em->flush();
$this->em->refresh($this->basket);
$this->assertEquals(1, $this->basket->getElements()->count());
}
public function testGetPusher()
{
$this->assertNull($this->basket->getPusher()); //no pusher
$this->basket->setPusherId(self::$user->get_id());
$this->assertInstanceOf('\User_Adapter', $this->basket->getPusher());
$this->assertEquals($this->basket->getPusher()->get_id(), self::$user->get_id());
}
public function testGetOwner()
{
$this->assertNotNull($this->basket->getOwner()); //no owner
$this->basket->setUsrId(self::$user->get_id());
$this->assertInstanceOf('\User_Adapter', $this->basket->getOwner());
$this->assertEquals($this->basket->getOwner()->get_id(), self::$user->get_id());
}
public function testGetValidation()
{
$this->assertNull($this->basket->getValidation());
$validationSession = new \Entities\ValidationSession();
$validationSession->setBasket($this->basket);
$validationSession->setDescription('Une description au hasard');
$validationSession->setName('Un nom de validation');
$expires = new \DateTime();
$expires->modify('+1 week');
$validationSession->setExpires($expires);
$validationSession->setInitiator(self::$user);
$this->em->persist($validationSession);
$this->em->flush();
$this->em->refresh($this->basket);
$this->assertInstanceOf('\Entities\ValidationSession', $this->basket->getValidation());
}
public function testGetIsRead()
{
$this->markTestIncomplete();
}
public function testGetSize()
{
$this->markTestIncomplete();
}
public function hasRecord()
{
$this->markTestIncomplete();
}
}

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