Browse Source
hook_islandora_object_alter(AbstractFedoraObject $object, array &$context) hook_CMODEL_PID_islandora_object_alter(AbstractFedoraObject $object, array &$context) hook_islandora_datastream_alter(AbstractFedoraObject $object, AbstractFedoraDatastream $datastream, array &$context) hook_CMODEL_PID_DSID_islandora_datastream_altezr(AbstractFedoraObject $object, AbstractFedoraDatastream $datastream, array &$context) hook_islandora_object_ingested(FedoraObject $object) hook_CMODEL_PID_islandora_object_ingested(FedoraObject $object) hook_islandora_object_modified(FedoraObject $object) hook_CMODEL_PID_islandora_object_modified(FedoraObject $object) hook_islandora_object_purged($pid) hook_CMODEL_PID_islandora_object_purged($pid) hook_islandora_datastream_ingested(FedoraObject $object, FedoraDatastream $datastream) hook_CMODEL_PID_DSID_islandora_datastream_ingested(FedoraObject $object, FedoraDatastream $datastream) hook_islandora_datastream_modified(FedoraObject $object, FedoraDatastream $datastream) hook_CMODEL_PID_islandora_datastream_modified(FedoraObject $object, FedoraDatastream $datastream) hook_islandora_datastream_purged(FedoraObject $object, $dsid) hook_CMODEL_PID_islandora_datastream_purged(FedoraObject $object, $dsid) Also updated the testing scripts to support different configurations, as well wrote tests for all the implemented hooks. This requires the latest version of Tuque so be sure to update.pull/243/head
Nigel Banks
12 years ago
16 changed files with 1201 additions and 389 deletions
@ -1,2 +1,3 @@
|
||||
cache.properties |
||||
.DS_Store |
||||
tests/test_config.ini |
@ -1,78 +0,0 @@
|
||||
<?php |
||||
|
||||
/** |
||||
* @file |
||||
* |
||||
* Wrapper around the tuque library, allows for autoloading of Islandora Tuque |
||||
* Objects. |
||||
* |
||||
* @todo Overload functions and apply pre/post hooks. |
||||
*/ |
||||
|
||||
$islandora_module_path = drupal_get_path('module', 'islandora'); |
||||
|
||||
//do this until we expost these in a module or library |
||||
@include_once 'sites/all/libraries/tuque/Datastream.php'; |
||||
@include_once 'sites/all/libraries/tuque/FedoraApi.php'; |
||||
@include_once 'sites/all/libraries/tuque/FedoraApiSerializer.php'; |
||||
@include_once 'sites/all/libraries/tuque/Object.php'; |
||||
@include_once 'sites/all/libraries/tuque/RepositoryConnection.php'; |
||||
@include_once 'sites/all/libraries/tuque/Cache.php'; |
||||
@include_once 'sites/all/libraries/tuque/RepositoryException.php'; |
||||
@include_once 'sites/all/libraries/tuque/Repository.php'; |
||||
@include_once 'sites/all/libraries/tuque/FedoraRelationships.php'; |
||||
|
||||
@include_once "$islandora_module_path/libraries/tuque/Datastream.php"; |
||||
@include_once "$islandora_module_path/libraries/tuque/FedoraApi.php"; |
||||
@include_once "$islandora_module_path/libraries/tuque/FedoraApiSerializer.php"; |
||||
@include_once "$islandora_module_path/libraries/tuque/Object.php"; |
||||
@include_once "$islandora_module_path/libraries/tuque/RepositoryConnection.php"; |
||||
@include_once "$islandora_module_path/libraries/tuque/Cache.php"; |
||||
@include_once "$islandora_module_path/libraries/tuque/RepositoryException.php"; |
||||
@include_once "$islandora_module_path/libraries/tuque/Repository.php"; |
||||
@include_once "$islandora_module_path/libraries/tuque/FedoraRelationships.php"; |
||||
|
||||
class IslandoraFedoraRepository extends FedoraRepository { |
||||
protected $queryClass = 'IslandoraRepositoryQuery'; |
||||
protected $newObjectClass = 'IslandoraNewFedoraObject'; |
||||
protected $objectClass = 'IslandoraFedoraObject'; |
||||
} |
||||
|
||||
class IslandoraRepositoryQuery extends RepositoryQuery {} |
||||
|
||||
class IslandoraNewFedoraObject extends NewFedoraObject { |
||||
protected $newFedoraDatastreamClass = 'IslandoraNewFedoraDatastream'; |
||||
protected $fedoraDatastreamClass = 'IslandoraFedoraDatastream'; |
||||
protected $fedoraRelsExtClass = 'IslandoraFedoraRelsExt'; |
||||
} |
||||
|
||||
class IslandoraFedoraObject extends FedoraObject { |
||||
protected $newFedoraDatastreamClass = 'IslandoraNewFedoraDatastream'; |
||||
protected $fedoraDatastreamClass = 'IslandoraFedoraDatastream'; |
||||
protected $fedoraRelsExtClass = 'IslandoraFedoraRelsExt'; |
||||
} |
||||
|
||||
class IslandoraRepositoryConnection extends RepositoryConnection {} |
||||
|
||||
class IslandoraFedoraApi extends FedoraApi {} |
||||
|
||||
class IslandoraSimpleCache extends SimpleCache {} |
||||
|
||||
class IslandoraNewFedoraDatastream extends NewFedoraDatastream { |
||||
protected $fedoraRelsIntClass = 'IslandoraFedoraRelsInt'; |
||||
protected $fedoraDatastreamVersionClass = 'IslandoraFedoraDatastreamVersion'; |
||||
} |
||||
|
||||
class IslandoraFedoraDatastream extends FedoraDatastream { |
||||
protected $fedoraRelsIntClass = 'IslandoraFedoraRelsInt'; |
||||
protected $fedoraDatastreamVersionClass = 'IslandoraFedoraDatastreamVersion'; |
||||
} |
||||
|
||||
class IslandoraFedoraDatastreamVersion extends FedoraDatastreamVersion { |
||||
protected $fedoraRelsIntClass = 'IslandoraFedoraRelsInt'; |
||||
protected $fedoraDatastreamVersionClass = 'IslandoraFedoraDatastreamVersion'; |
||||
} |
||||
|
||||
class IslandoraFedoraRelsExt extends FedoraRelsExt {} |
||||
|
||||
class IslandoraFedoraRelsInt extends FedoraRelsInt {} |
@ -0,0 +1,360 @@
|
||||
<?php |
||||
|
||||
/** |
||||
* @file |
||||
* Wrapper around the tuque library, allows for autoloading of Islandora Tuque |
||||
* Objects. |
||||
* |
||||
* @todo Overload functions and apply pre/post hooks. |
||||
*/ |
||||
|
||||
$islandora_module_path = drupal_get_path('module', 'islandora'); |
||||
|
||||
// @todo this until we expost these in a module or library |
||||
@include_once 'sites/all/libraries/tuque/Datastream.php'; |
||||
@include_once 'sites/all/libraries/tuque/FedoraApi.php'; |
||||
@include_once 'sites/all/libraries/tuque/FedoraApiSerializer.php'; |
||||
@include_once 'sites/all/libraries/tuque/Object.php'; |
||||
@include_once 'sites/all/libraries/tuque/RepositoryConnection.php'; |
||||
@include_once 'sites/all/libraries/tuque/Cache.php'; |
||||
@include_once 'sites/all/libraries/tuque/RepositoryException.php'; |
||||
@include_once 'sites/all/libraries/tuque/Repository.php'; |
||||
@include_once 'sites/all/libraries/tuque/FedoraRelationships.php'; |
||||
|
||||
@include_once "$islandora_module_path/libraries/tuque/Datastream.php"; |
||||
@include_once "$islandora_module_path/libraries/tuque/FedoraApi.php"; |
||||
@include_once "$islandora_module_path/libraries/tuque/FedoraApiSerializer.php"; |
||||
@include_once "$islandora_module_path/libraries/tuque/Object.php"; |
||||
@include_once "$islandora_module_path/libraries/tuque/RepositoryConnection.php"; |
||||
@include_once "$islandora_module_path/libraries/tuque/Cache.php"; |
||||
@include_once "$islandora_module_path/libraries/tuque/RepositoryException.php"; |
||||
@include_once "$islandora_module_path/libraries/tuque/Repository.php"; |
||||
@include_once "$islandora_module_path/libraries/tuque/FedoraRelationships.php"; |
||||
|
||||
/** |
||||
* Allow modules to alter an object before a mutable event occurs. |
||||
*/ |
||||
function islandora_alter_object(AbstractFedoraObject $object, array &$context) { |
||||
$types = array('islandora_object'); |
||||
foreach ($object->models as $model) { |
||||
$types[] = "{$model}_islandora_object"; |
||||
} |
||||
drupal_alter($types, $object, $context); |
||||
} |
||||
|
||||
/** |
||||
* Allow modules to alter a datastream before a mutable event occurs. |
||||
*/ |
||||
function islandora_alter_datastream(AbstractFedoraObject $object, AbstractDatastream $datastream, array &$context) { |
||||
$types = array('islandora_datastream'); |
||||
foreach ($object->models as $model) { |
||||
$types[] = "{$model}_{$datastream->id}_islandora_datastream"; |
||||
} |
||||
drupal_alter($types, $object, $datastream, $context); |
||||
} |
||||
|
||||
/** |
||||
* Constructs a list of hooks from the given paramenters and invokes them. |
||||
*/ |
||||
function islandora_invoke_object_hooks($hook, array $models) { |
||||
module_load_include('inc', 'islandora', 'includes/utilities'); |
||||
return islandora_invoke_hook_list($hook, $models, array_slice(func_get_args(), 2)); |
||||
} |
||||
|
||||
/** |
||||
* Constructs a list of hooks from the given paramenters and invokes them. |
||||
*/ |
||||
function islandora_invoke_datastream_hooks($hook, array $models, $dsid) { |
||||
module_load_include('inc', 'islandora', 'includes/utilities'); |
||||
$refinements = array(); |
||||
foreach ($models as $model) { |
||||
$refinements[] = "{$model}_{$dsid}"; |
||||
} |
||||
return islandora_invoke_hook_list($hook, $refinements, array_slice(func_get_args(), 3)); |
||||
} |
||||
|
||||
class IslandoraFedoraRepository extends FedoraRepository { |
||||
protected $queryClass = 'IslandoraRepositoryQuery'; |
||||
protected $newObjectClass = 'IslandoraNewFedoraObject'; |
||||
protected $objectClass = 'IslandoraFedoraObject'; |
||||
|
||||
/** |
||||
* Ingest the given object. |
||||
* |
||||
* @see FedoraRepository::ingestObject() |
||||
*/ |
||||
public function ingestObject(NewFedoraObject &$object) { |
||||
$context = array( |
||||
'action' => 'ingest', |
||||
'block' => FALSE, |
||||
); |
||||
islandora_alter_object($object, $context); |
||||
try { |
||||
if ($context['block']) { |
||||
throw new Exception('Ingest Object was blocked.'); |
||||
} |
||||
$ret = parent::ingestObject($object); |
||||
islandora_invoke_object_hooks(ISLANDORA_OBJECT_INGESTED_HOOK, $object->models, $object); |
||||
// Call the ingested datastream hooks for NewFedoraObject's after the |
||||
// object had been ingested. |
||||
foreach ($object as $dsid => $datastream) { |
||||
islandora_invoke_datastream_hooks(ISLANDORA_DATASTREAM_INGESTED_HOOK, $object->models, $dsid, $object, $datastream); |
||||
} |
||||
return $ret; |
||||
} |
||||
catch (Exception $e) { |
||||
watchdog('islandora', 'Failed to ingest object: @pid</br>code: @code<br/>message: @msg', array( |
||||
'@pid' => $object->id, |
||||
'@code' => $e->getCode(), |
||||
'@msg' => $e->getMessage()), WATCHDOG_ERROR); |
||||
throw $e; |
||||
} |
||||
} |
||||
} |
||||
|
||||
class IslandoraRepositoryQuery extends RepositoryQuery {} |
||||
|
||||
class IslandoraNewFedoraObject extends NewFedoraObject { |
||||
protected $newFedoraDatastreamClass = 'IslandoraNewFedoraDatastream'; |
||||
protected $fedoraDatastreamClass = 'IslandoraFedoraDatastream'; |
||||
protected $fedoraRelsExtClass = 'IslandoraFedoraRelsExt'; |
||||
} |
||||
|
||||
class IslandoraFedoraObject extends FedoraObject { |
||||
protected $newFedoraDatastreamClass = 'IslandoraNewFedoraDatastream'; |
||||
protected $fedoraDatastreamClass = 'IslandoraFedoraDatastream'; |
||||
protected $fedoraRelsExtClass = 'IslandoraFedoraRelsExt'; |
||||
|
||||
/** |
||||
* Ingest the given datastream. |
||||
* |
||||
* @see FedoraObject::ingestDatastream() |
||||
*/ |
||||
public function ingestDatastream(&$datastream) { |
||||
$object = $datastream->parent; |
||||
$context = array( |
||||
'action' => 'ingest', |
||||
'block' => FALSE, |
||||
); |
||||
islandora_alter_datastream($object, $datastream, $context); |
||||
try { |
||||
if ($context['block']) { |
||||
throw new Exception('Ingest Datastream was blocked.'); |
||||
} |
||||
$ret = parent::ingestDatastream($datastream); |
||||
islandora_invoke_datastream_hooks(ISLANDORA_DATASTREAM_INGESTED_HOOK, $object->models, $datastream->id, $object, $datastream); |
||||
return $ret; |
||||
} |
||||
catch (Exception $e) { |
||||
watchdog('islandora', 'Failed to ingest object: @pid</br>code: @code<br/>message: @msg', array( |
||||
'@pid' => $object->id, |
||||
'@dsid' => $datastream->id, |
||||
'@code' => $e->getCode(), |
||||
'@msg' => $e->getMessage()), WATCHDOG_ERROR); |
||||
throw $e; |
||||
} |
||||
} |
||||
} |
||||
|
||||
class IslandoraRepositoryConnection extends RepositoryConnection {} |
||||
|
||||
class IslandoraFedoraApi extends FedoraApi { |
||||
|
||||
/** |
||||
* Instantiate a IslandoraFedoraApi object. |
||||
* |
||||
* @see FedoraApi::__construct() |
||||
*/ |
||||
public function __construct(IslandoraRepositoryConnection $connection, FedoraApiSerializer $serializer = NULL) { |
||||
if (!$serializer) { |
||||
$serializer = new FedoraApiSerializer(); |
||||
} |
||||
$this->a = new FedoraApiA($connection, $serializer); |
||||
$this->m = new IslandoraFedoraApiM($connection, $serializer); |
||||
$this->connection = $connection; |
||||
} |
||||
} |
||||
|
||||
class IslandoraFedoraApiM extends FedoraApiM { |
||||
|
||||
/** |
||||
* Update a datastream. |
||||
* |
||||
* Either changing its metadata, updaing the datastream contents or both. |
||||
* |
||||
* @throws Exception |
||||
* If the modify datastream request was block by some module. |
||||
* |
||||
* @see FedoraApiM::modifyDatastream |
||||
*/ |
||||
public function modifyDatastream($pid, $dsid, $params = array()) { |
||||
$object = islandora_object_load($pid); |
||||
$datastream = $object[$dsid]; |
||||
$context = array( |
||||
'action' => 'modify', |
||||
'block' => FALSE, |
||||
'params' => $params, |
||||
); |
||||
islandora_alter_datastream($object, $datastream, $context); |
||||
try { |
||||
if ($context['block']) { |
||||
throw new Exception('Modify Datastream was blocked.'); |
||||
} |
||||
$ret = parent::modifyDatastream($pid, $dsid, $params); |
||||
islandora_invoke_datastream_hooks(ISLANDORA_DATASTREAM_MODIFIED_HOOK, $object->models, $dsid, $object, $datastream); |
||||
if (isset($params['dsState']) && $params['dsState'] == 'D') { |
||||
islandora_invoke_datastream_hooks(ISLANDORA_DATASTREAM_PURGED_HOOK, $object->models, $dsid, $object, $dsid); |
||||
} |
||||
return $ret; |
||||
} |
||||
catch(Exception $e) { |
||||
watchdog('islandora', 'Failed to modify datastream @dsid from @pid</br>code: @code<br/>message: @msg', array( |
||||
'@pid' => $pid, |
||||
'@dsid' => $dsid, |
||||
'@code' => $e->getCode(), |
||||
'@msg' => $e->getMessage()), WATCHDOG_ERROR); |
||||
throw $e; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Update Fedora Object parameters. |
||||
* |
||||
* @see FedoraApiM::modifyObject |
||||
*/ |
||||
public function modifyObject($pid, $params = NULL) { |
||||
$object = islandora_object_load($pid); |
||||
$context = array( |
||||
'action' => 'modify', |
||||
'block' => FALSE, |
||||
'params' => $params, |
||||
); |
||||
islandora_alter_object($object, $context); |
||||
try { |
||||
if ($context['block']) { |
||||
throw new Exception('Modify Object was blocked.'); |
||||
} |
||||
$ret = parent::modifyObject($pid, $params); |
||||
islandora_invoke_object_hooks(ISLANDORA_OBJECT_MODIFIED_HOOK, $object->models, $object); |
||||
if (isset($params['state']) && $params['state'] == 'D') { |
||||
islandora_invoke_object_hooks(ISLANDORA_OBJECT_PURGED_HOOK, $object->models, $object->id); |
||||
} |
||||
return $ret; |
||||
} |
||||
catch(Exception $e) { |
||||
watchdog('islandora', 'Failed to modify object: @pid</br>code: @code<br/>message: @msg', array( |
||||
'@pid' => $pid, |
||||
'@code' => $e->getCode(), |
||||
'@msg' => $e->getMessage()), WATCHDOG_ERROR); |
||||
throw $e; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Purge a datastream from from Fedora. |
||||
* |
||||
* @see FedoraApiM::purgeDatastream |
||||
*/ |
||||
public function purgeDatastream($pid, $dsid, $params = array()) { |
||||
$object = islandora_object_load($pid); |
||||
$context = array( |
||||
'action' => 'purge', |
||||
'purge' => TRUE, |
||||
'delete' => FALSE, |
||||
'block' => FALSE, |
||||
); |
||||
islandora_alter_datastream($object, $object[$dsid], $context); |
||||
try { |
||||
$action = $context['block'] ? 'block' : FALSE; |
||||
$action = (!$action && $context['delete']) ? 'delete' : $action; |
||||
$action = !$action ? 'purge' : $action; |
||||
switch ($action) { |
||||
case 'block': |
||||
throw new Exception('Purge Datastream was blocked.'); |
||||
break; |
||||
|
||||
case 'delete': |
||||
$object[$dsid]->state = 'D'; |
||||
return array(); |
||||
|
||||
default: |
||||
$ret = parent::purgeDatastream($pid, $dsid, $params); |
||||
islandora_invoke_datastream_hooks(ISLANDORA_DATASTREAM_PURGED_HOOK, $object->models, $dsid, $object, $dsid); |
||||
return $ret; |
||||
} |
||||
} |
||||
catch(Exception $e) { |
||||
watchdog('islandora', 'Failed to purge datastream @dsid from @pid</br>code: @code<br/>message: @msg', array( |
||||
'@pid' => $pid, |
||||
'@dsid' => $dsid, |
||||
'@code' => $e->getCode(), |
||||
'@msg' => $e->getMessage()), WATCHDOG_ERROR); |
||||
throw $e; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Purge an object. |
||||
* |
||||
* @see FedoraApiM::purgeObject |
||||
*/ |
||||
public function purgeObject($pid, $log_message = NULL) { |
||||
$object = islandora_object_load($pid); |
||||
$context = array( |
||||
'action' => 'purge', |
||||
'purge' => TRUE, |
||||
'delete' => FALSE, |
||||
'block' => FALSE, |
||||
); |
||||
islandora_alter_object($object, $context); |
||||
try { |
||||
$action = $context['block'] ? 'block' : FALSE; |
||||
$action = (!$action && $context['delete']) ? 'delete' : $action; |
||||
$action = !$action ? 'purge' : $action; |
||||
$models = $object->models; |
||||
switch ($action) { |
||||
case 'block': |
||||
throw new Exception('Purge object was blocked.'); |
||||
break; |
||||
|
||||
case 'delete': |
||||
$object->state = 'D'; |
||||
return ''; |
||||
|
||||
default: |
||||
$ret = parent::purgeObject($pid, $log_message); |
||||
islandora_invoke_object_hooks(ISLANDORA_OBJECT_PURGED_HOOK, $models, $pid); |
||||
return $ret; |
||||
} |
||||
} |
||||
catch(Exception $e) { |
||||
watchdog('islandora', 'Failed to purge object @pid</br>code: @code<br/>message: @msg', array( |
||||
'@pid' => $pid, |
||||
'@code' => $e->getCode(), |
||||
'@msg' => $e->getMessage()), WATCHDOG_ERROR); |
||||
throw $e; |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
class IslandoraSimpleCache extends SimpleCache {} |
||||
|
||||
class IslandoraNewFedoraDatastream extends NewFedoraDatastream { |
||||
protected $fedoraRelsIntClass = 'IslandoraFedoraRelsInt'; |
||||
protected $fedoraDatastreamVersionClass = 'IslandoraFedoraDatastreamVersion'; |
||||
} |
||||
|
||||
class IslandoraFedoraDatastream extends FedoraDatastream { |
||||
protected $fedoraRelsIntClass = 'IslandoraFedoraRelsInt'; |
||||
protected $fedoraDatastreamVersionClass = 'IslandoraFedoraDatastreamVersion'; |
||||
} |
||||
|
||||
class IslandoraFedoraDatastreamVersion extends FedoraDatastreamVersion { |
||||
protected $fedoraRelsIntClass = 'IslandoraFedoraRelsInt'; |
||||
protected $fedoraDatastreamVersionClass = 'IslandoraFedoraDatastreamVersion'; |
||||
} |
||||
|
||||
class IslandoraFedoraRelsExt extends FedoraRelsExt {} |
||||
|
||||
class IslandoraFedoraRelsInt extends FedoraRelsInt {} |
@ -0,0 +1,3 @@
|
||||
You can define your own configurations specific to your enviroment by copying |
||||
default.test_config.ini to test_config.ini, making your changes in the copied |
||||
file. |
@ -0,0 +1,6 @@
|
||||
[fedora] |
||||
fedora_url = "http://localhost:8080/fedora" |
||||
use_drupal_filter = TRUE |
||||
drupal_filter_file = "/usr/local/fedora/server/config/filter-drupal.xml" |
||||
admin_user = "fedoraAdmin" |
||||
admin_pass = "fedoraAdmin" |
@ -0,0 +1,213 @@
|
||||
<?php |
||||
|
||||
/** |
||||
* @file |
||||
* Tests to see if the hooks get called when appropriate. |
||||
* |
||||
* In the test module 'islandora_hooks_test' there are implementations |
||||
* of hooks being tested. These implementations modifies the session, and |
||||
* that's how we test if the hook gets called. |
||||
* |
||||
* To make sense of these tests reference islandora_hooks_test.module. |
||||
*/ |
||||
|
||||
class IslandoraHooksTestCase extends IslandoraWebTestCase { |
||||
|
||||
/** |
||||
* Gets info to display to describe this test. |
||||
* |
||||
* @see IslandoraWebTestCase::getInfo() |
||||
*/ |
||||
public static function getInfo() { |
||||
return array( |
||||
'name' => 'Islandora Hooks', |
||||
'description' => 'Ensure that the hooks for ingestion/purge/modification are called at the appropriate times.', |
||||
'group' => 'Islandora', |
||||
); |
||||
} |
||||
|
||||
/** |
||||
* Creates an admin user and a connection to a fedora repository. |
||||
* |
||||
* @see IslandoraWebTestCase::setUp() |
||||
*/ |
||||
public function setUp() { |
||||
parent::setUp('islandora_hooks_test', 'devel'); |
||||
$this->repository = $this->admin->repository; |
||||
$this->purgeTestObjects(); |
||||
} |
||||
|
||||
/** |
||||
* Free any objects/resources created for this test. |
||||
* |
||||
* @see IslandoraWebTestCase::tearDown() |
||||
*/ |
||||
public function tearDown() { |
||||
$this->purgeTestObjects(); |
||||
unset($this->repository); |
||||
parent::tearDown(); |
||||
} |
||||
|
||||
/** |
||||
* Purge any objects created by the test's in this class. |
||||
*/ |
||||
public function purgeTestObjects() { |
||||
$objects = array( |
||||
'test:testIngestedObjectHook', |
||||
'test:testBlockedIngestedObjectHook', |
||||
'test:testModifiedObjectHook', |
||||
'test:testPurgedObjectHook', |
||||
'test:testIngestedDatastreamHook', |
||||
'test:testModifiedDatastreamHook', |
||||
'test:testPurgedDatastreamHook', |
||||
); |
||||
foreach ($objects as $object) { |
||||
try { |
||||
$object = $this->repository->getObject($object); |
||||
$object->label = "Don't Block"; |
||||
$this->repository->purgeObject($object->id); |
||||
} |
||||
catch(Exception $e) { |
||||
// Meh... Either it didn't exist or the purge failed. |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Test ALL THE HOOKS!. |
||||
*/ |
||||
public function testHooks() { |
||||
// Test ingesting with FedoraRepository::ingestObject(). |
||||
$object = $this->repository->constructObject('test:testIngestedObjectHook'); |
||||
$_SESSION['islandora_hooks']['hook'][ISLANDORA_OBJECT_INGESTED_HOOK] = FALSE; |
||||
$_SESSION['islandora_hooks']['alter'][ISLANDORA_OBJECT_INGESTED_HOOK] = FALSE; |
||||
$this->repository->ingestObject($object); |
||||
$this->assert($_SESSION['islandora_hooks']['alter'][ISLANDORA_OBJECT_INGESTED_HOOK], 'Called "hook_islandora_object_alter" when ingesting via FedoraRepository::ingestObject.'); |
||||
$this->assert($_SESSION['islandora_hooks']['hook'][ISLANDORA_OBJECT_INGESTED_HOOK], 'Called ISLANDORA_OBJECT_INGESTED_HOOK when ingesting via FedoraRepository::ingestObject.'); |
||||
$this->repository->purgeObject($object->id); |
||||
// Test blocking the ingest. |
||||
$object = $this->repository->constructObject('test:testIngestedObjectHook'); |
||||
$object->label = 'block'; |
||||
try { |
||||
$_SESSION['islandora_hooks']['hook'][ISLANDORA_OBJECT_INGESTED_HOOK] = FALSE; |
||||
$_SESSION['islandora_hooks']['alter'][ISLANDORA_OBJECT_INGESTED_HOOK] = FALSE; |
||||
$this->repository->ingestObject($object); |
||||
$this->fail('Blocked ingest should throw an Exception.'); |
||||
$this->repository->purgeObject($object->id); |
||||
} |
||||
catch(Exception $e) { |
||||
$this->pass('Ingest blocked and exception thrown.'); |
||||
$this->assert($_SESSION['islandora_hooks']['alter'][ISLANDORA_OBJECT_INGESTED_HOOK], 'Called "hook_islandora_object_alter" when blocking ingesting via FedoraRepository::ingestObject.'); |
||||
$this->assertFalse($_SESSION['islandora_hooks']['hook'][ISLANDORA_OBJECT_INGESTED_HOOK], 'Did not called ISLANDORA_OBJECT_INGESTED_HOOK when blocking ingesting via FedoraRepository::ingestObject.'); |
||||
} |
||||
// Test modifying via set magic functions. |
||||
$object = $this->repository->constructObject('test:testModifiedObjectHook'); |
||||
$this->repository->ingestObject($object); |
||||
$_SESSION['islandora_hooks']['hook'][ISLANDORA_OBJECT_MODIFIED_HOOK] = FALSE; |
||||
$_SESSION['islandora_hooks']['alter'][ISLANDORA_OBJECT_MODIFIED_HOOK] = FALSE; |
||||
$object->label = "New Label!"; |
||||
$this->assert($_SESSION['islandora_hooks']['alter'][ISLANDORA_OBJECT_MODIFIED_HOOK], 'Called "hook_islandora_object_alter" when modifying via set magic functions.'); |
||||
$this->assert($_SESSION['islandora_hooks']['hook'][ISLANDORA_OBJECT_MODIFIED_HOOK], 'Called ISLANDORA_OBJECT_MODIFIED_HOOK when modifying via set magic functions.'); |
||||
// Test blocking the modification. |
||||
try { |
||||
$_SESSION['islandora_hooks']['hook'][ISLANDORA_OBJECT_MODIFIED_HOOK] = FALSE; |
||||
$_SESSION['islandora_hooks']['alter'][ISLANDORA_OBJECT_MODIFIED_HOOK] = FALSE; |
||||
$object->label = 'block'; |
||||
$this->fail('Blocked modify should throw an Exception.'); |
||||
} |
||||
catch(Exception $e) { |
||||
$this->pass('Modify blocked and exception thrown.'); |
||||
$this->assertNotEqual($object->label, 'block', 'Modification did not stick.'); |
||||
$this->assert($_SESSION['islandora_hooks']['alter'][ISLANDORA_OBJECT_MODIFIED_HOOK], 'Called "hook_islandora_object_alter" when blocking modifying via set magic functions.'); |
||||
$this->assertFALSE($_SESSION['islandora_hooks']['hook'][ISLANDORA_OBJECT_MODIFIED_HOOK], 'Called ISLANDORA_OBJECT_MODIFIED_HOOK when blocking modifying via set magic functions.'); |
||||
} |
||||
$this->repository->purgeObject($object->id); |
||||
// Test purging with FedoraRepository::purgeObject(). |
||||
$object = $this->repository->constructObject('test:testPurgedObjectHook'); |
||||
$this->repository->ingestObject($object); |
||||
$_SESSION['islandora_hooks']['hook'][ISLANDORA_OBJECT_PURGED_HOOK] = FALSE; |
||||
$_SESSION['islandora_hooks']['alter'][ISLANDORA_OBJECT_PURGED_HOOK] = FALSE; |
||||
$this->repository->purgeObject($object->id); |
||||
$this->assert($_SESSION['islandora_hooks']['alter'][ISLANDORA_OBJECT_PURGED_HOOK], 'Called "hook_islandora_object_alter" when purging via FedoraRepository::purgeObject.'); |
||||
$this->assert($_SESSION['islandora_hooks']['hook'][ISLANDORA_OBJECT_PURGED_HOOK], 'Called ISLANDORA_OBJECT_PURGED_HOOK when purging via FedoraRepository::purgeObject.'); |
||||
// Test deleting. |
||||
$object = $this->repository->constructObject('test:testPurgedObjectHook'); |
||||
$this->repository->ingestObject($object); |
||||
$_SESSION['islandora_hooks']['hook'][ISLANDORA_OBJECT_PURGED_HOOK] = FALSE; |
||||
$_SESSION['islandora_hooks']['alter'][ISLANDORA_OBJECT_PURGED_HOOK] = FALSE; |
||||
$object->delete(); |
||||
$this->assert($_SESSION['islandora_hooks']['alter'][ISLANDORA_OBJECT_PURGED_HOOK], 'Called "hook_islandora_object_alter" when deleting via FedoraObject::delete.'); |
||||
$this->assert($_SESSION['islandora_hooks']['hook'][ISLANDORA_OBJECT_PURGED_HOOK], 'Called ISLANDORA_OBJECT_PURGED_HOOK when purging via FedoraObject::delete.'); |
||||
$this->repository->purgeObject($object->id); |
||||
// Test alter blocking. |
||||
$object = $this->repository->constructObject('test:testPurgedObjectHook'); |
||||
$this->repository->ingestObject($object); |
||||
try { |
||||
$_SESSION['islandora_hooks']['hook'][ISLANDORA_OBJECT_PURGED_HOOK] = FALSE; |
||||
$_SESSION['islandora_hooks']['alter'][ISLANDORA_OBJECT_PURGED_HOOK] = FALSE; |
||||
$object->label = 'block'; |
||||
$this->repository->purgeObject($object->id); |
||||
$this->fail('Blocked modify should throw an Exception.'); |
||||
} |
||||
catch(Exception $e) { |
||||
$this->pass('Modify blocked and exception thrown.'); |
||||
$this->assert($_SESSION['islandora_hooks']['alter'][ISLANDORA_OBJECT_PURGED_HOOK], 'Called "hook_islandora_object_alter" when blocking purge via FedoraRepository::purgeObject.'); |
||||
$this->assertFalse($_SESSION['islandora_hooks']['hook'][ISLANDORA_OBJECT_PURGED_HOOK], 'Called ISLANDORA_OBJECT_PURGED_HOOK when blocking purge via FedoraRepository::purgeObject.'); |
||||
} |
||||
// Test alter delete. |
||||
$_SESSION['islandora_hooks']['hook'][ISLANDORA_OBJECT_PURGED_HOOK] = FALSE; |
||||
$_SESSION['islandora_hooks']['alter'][ISLANDORA_OBJECT_PURGED_HOOK] = FALSE; |
||||
$object->label = 'delete'; |
||||
$this->repository->purgeObject($object->id); |
||||
$this->assertEqual($object->state, 'D', '"hook_islandora_object_alter" prevented purge and deleted the object.'); |
||||
$this->assert($_SESSION['islandora_hooks']['alter'][ISLANDORA_OBJECT_PURGED_HOOK], 'Called "hook_islandora_object_alter" when preventing purge and deleting.'); |
||||
$this->assert($_SESSION['islandora_hooks']['hook'][ISLANDORA_OBJECT_PURGED_HOOK], 'Called ISLANDORA_OBJECT_PURGED_HOOK when preventing purge and deleting.'); |
||||
$object->label = 'Something other than delete'; |
||||
$this->repository->purgeObject($object->id); |
||||
// Test ingesting with FedoraRepository::ingestObject(). |
||||
$object = $this->repository->constructObject('test:testIngestedDatastreamHook'); |
||||
$this->repository->ingestObject($object); |
||||
$ds = $object->constructDatastream('TEST'); |
||||
$_SESSION['islandora_hooks']['hook'][ISLANDORA_DATASTREAM_INGESTED_HOOK] = FALSE; |
||||
$_SESSION['islandora_hooks']['alter'][ISLANDORA_DATASTREAM_INGESTED_HOOK] = FALSE; |
||||
$object->ingestDatastream($ds); |
||||
$this->assert($_SESSION['islandora_hooks']['alter'][ISLANDORA_DATASTREAM_INGESTED_HOOK], 'Called "hook_islandora_datastream_alter" when ingesting via FedoraObject::ingestDatastream.'); |
||||
$this->assert($_SESSION['islandora_hooks']['hook'][ISLANDORA_DATASTREAM_INGESTED_HOOK], 'Called ISLANDORA_DATASTREAM_INGESTED_HOOK when ingesting via FedoraObject::ingestDatastream.'); |
||||
$this->repository->purgeObject($object->id); |
||||
// Test modifying a datastream. |
||||
$object = $this->repository->constructObject('test:testModifiedDatastreamHook'); |
||||
$this->repository->ingestObject($object); |
||||
$ds = $object->constructDatastream('TEST'); |
||||
$object->ingestDatastream($ds); |
||||
$_SESSION['islandora_hooks']['hook'][ISLANDORA_DATASTREAM_MODIFIED_HOOK] = FALSE; |
||||
$_SESSION['islandora_hooks']['alter'][ISLANDORA_DATASTREAM_MODIFIED_HOOK] = FALSE; |
||||
$ds->label = "New Label!"; |
||||
$this->assert($_SESSION['islandora_hooks']['alter'][ISLANDORA_DATASTREAM_MODIFIED_HOOK], 'Called "hook_islandora_datastream_alter" when modifying via set magic functions.'); |
||||
$this->assert($_SESSION['islandora_hooks']['hook'][ISLANDORA_DATASTREAM_MODIFIED_HOOK], 'Called ISLANDORA_DATASTREAM_MODIFIED_HOOK when modifying via set magic functions.'); |
||||
// Test blocking modifying. |
||||
try { |
||||
$_SESSION['islandora_hooks']['hook'][ISLANDORA_DATASTREAM_MODIFIED_HOOK] = FALSE; |
||||
$_SESSION['islandora_hooks']['alter'][ISLANDORA_DATASTREAM_MODIFIED_HOOK] = FALSE; |
||||
$ds->label = 'block'; |
||||
$this->fail('Blocked modify should throw an Exception.'); |
||||
} |
||||
catch(Exception $e) { |
||||
$this->pass('Modify blocked and exception thrown.'); |
||||
$this->assert($_SESSION['islandora_hooks']['alter'][ISLANDORA_DATASTREAM_MODIFIED_HOOK], 'Called "hook_islandora_datastream_alter" when blocking modifying via set magic functions.'); |
||||
$this->assertFALSE($_SESSION['islandora_hooks']['hook'][ISLANDORA_DATASTREAM_MODIFIED_HOOK], 'Called ISLANDORA_DATASTREAM_MODIFIED_HOOK when blocking modifying via set magic functions.'); |
||||
} |
||||
$this->repository->purgeObject($object->id); |
||||
// Test purging with FedoraRepository::purgeObject(). |
||||
$object = $this->repository->constructObject('test:testPurgedDatastreamHook'); |
||||
$this->repository->ingestObject($object); |
||||
$ds = $object->constructDatastream('TEST'); |
||||
$object->ingestDatastream($ds); |
||||
$_SESSION['islandora_hooks']['hook'][ISLANDORA_DATASTREAM_PURGED_HOOK] = FALSE; |
||||
$_SESSION['islandora_hooks']['alter'][ISLANDORA_DATASTREAM_PURGED_HOOK] = FALSE; |
||||
$object->purgeDatastream($ds->id); |
||||
$this->assert($_SESSION['islandora_hooks']['alter'][ISLANDORA_DATASTREAM_PURGED_HOOK], 'Called "hook_islandora_datastream_alter" when purging via FedoraObject::purgeDatastream.'); |
||||
$this->assert($_SESSION['islandora_hooks']['hook'][ISLANDORA_DATASTREAM_PURGED_HOOK], 'Called ISLANDORA_DATASTREAM_PURGED_HOOK when purging via FedoraObject::purgeDatastream.'); |
||||
$this->repository->purgeObject($object->id); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,7 @@
|
||||
name = Islandora Hook testing |
||||
description = Tests Hooks. Do not enable. |
||||
core = 7.x |
||||
package = Testing |
||||
hidden = TRUE |
||||
dependencies[] = islandora |
||||
files[] = islandora_hooks_test.module |
@ -0,0 +1,152 @@
|
||||
<?php |
||||
|
||||
/** |
||||
* @file |
||||
* Implements hooks that get tested by islandora_hooks.test |
||||
*/ |
||||
|
||||
/** |
||||
* Implements hook_islandora_object_alter(). |
||||
*/ |
||||
function islandora_hooks_test_islandora_object_alter(AbstractFedoraObject $object, array &$context) { |
||||
switch ($context['action']) { |
||||
case 'ingest': |
||||
if ($object->id == 'test:testIngestedObjectHook') { |
||||
$_SESSION['islandora_hooks']['alter'][ISLANDORA_OBJECT_INGESTED_HOOK] = TRUE; |
||||
if ($object->label == 'block') { |
||||
$context['block'] = TRUE; |
||||
} |
||||
} |
||||
break; |
||||
|
||||
case 'modify': |
||||
if ($object->id == 'test:testModifiedObjectHook') { |
||||
$_SESSION['islandora_hooks']['alter'][ISLANDORA_OBJECT_MODIFIED_HOOK] = TRUE; |
||||
if (isset($context['params']['label']) && $context['params']['label'] == 'block') { |
||||
$context['block'] = TRUE; |
||||
} |
||||
} |
||||
elseif ($object->id == 'test:testPurgedObjectHook') { |
||||
$_SESSION['islandora_hooks']['alter'][ISLANDORA_OBJECT_PURGED_HOOK] = TRUE; |
||||
if (isset($context['params']['label']) && $context['params']['label'] == 'block') { |
||||
$context['block'] = TRUE; |
||||
} |
||||
elseif (isset($context['params']['label']) && $context['params']['label'] == 'delete') { |
||||
$context['delete'] = TRUE; |
||||
} |
||||
} |
||||
break; |
||||
|
||||
case 'purge': |
||||
if ($object->id == 'test:testPurgedObjectHook') { |
||||
$_SESSION['islandora_hooks']['alter'][ISLANDORA_OBJECT_PURGED_HOOK] = TRUE; |
||||
if ($object->label == 'block') { |
||||
$context['block'] = TRUE; |
||||
} |
||||
elseif ($object->label == 'delete') { |
||||
$context['delete'] = TRUE; |
||||
} |
||||
} |
||||
break; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Implements hook_islandora_object_alter(). |
||||
*/ |
||||
function islandora_hooks_test_islandora_datastream_alter(AbstractFedoraObject $object, AbstractFedoraDatastream $datastream, array &$context) { |
||||
switch ($context['action']) { |
||||
case 'ingest': |
||||
if ($object->id == 'test:testIngestedDatastreamHook') { |
||||
$_SESSION['islandora_hooks']['alter'][ISLANDORA_DATASTREAM_INGESTED_HOOK] = TRUE; |
||||
if ($datastream->label == 'block') { |
||||
$context['block'] = TRUE; |
||||
} |
||||
} |
||||
break; |
||||
|
||||
case 'modify': |
||||
if ($object->id == 'test:testModifiedDatastreamHook') { |
||||
$_SESSION['islandora_hooks']['alter'][ISLANDORA_DATASTREAM_MODIFIED_HOOK] = TRUE; |
||||
if (isset($context['params']['dsLabel']) && $context['params']['dsLabel'] == 'block') { |
||||
$context['block'] = TRUE; |
||||
} |
||||
} |
||||
elseif ($object->id == 'test:testPurgedDatastreamHook') { |
||||
$_SESSION['islandora_hooks']['alter'][ISLANDORA_DATASTREAM_PURGED_HOOK] = TRUE; |
||||
if (isset($context['params']['dsLabel']) && $context['params']['dsLabel'] == 'block') { |
||||
$context['block'] = TRUE; |
||||
} |
||||
elseif (isset($context['params']['dsLabel']) && $context['params']['dsLabel'] == 'delete') { |
||||
$context['delete'] = TRUE; |
||||
} |
||||
} |
||||
break; |
||||
|
||||
case 'purge': |
||||
if ($object->id == 'test:testPurgedDatastreamHook') { |
||||
$_SESSION['islandora_hooks']['alter'][ISLANDORA_DATASTREAM_PURGED_HOOK] = TRUE; |
||||
if ($datastream->label == 'block') { |
||||
$context['block'] = TRUE; |
||||
} |
||||
elseif ($datastream->label == 'delete') { |
||||
$context['delete'] = TRUE; |
||||
} |
||||
} |
||||
break; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Implements hook_islandora_object_ingested(). |
||||
*/ |
||||
function islandora_hooks_test_islandora_object_ingested(FedoraObject $object) { |
||||
if ($object->id == 'test:testIngestedObjectHook') { |
||||
$_SESSION['islandora_hooks']['hook'][ISLANDORA_OBJECT_INGESTED_HOOK] = TRUE; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Implements hook_islandora_object_modified(). |
||||
*/ |
||||
function islandora_hooks_test_islandora_object_modified(FedoraObject $object) { |
||||
if ($object->id == 'test:testModifiedObjectHook') { |
||||
$_SESSION['islandora_hooks']['hook'][ISLANDORA_OBJECT_MODIFIED_HOOK] = TRUE; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Implements hook_islandora_object_purged(). |
||||
*/ |
||||
function islandora_hooks_test_islandora_object_purged($pid) { |
||||
if ($pid == 'test:testPurgedObjectHook') { |
||||
$_SESSION['islandora_hooks']['hook'][ISLANDORA_OBJECT_PURGED_HOOK] = TRUE; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Implements hook_islandora_datastream_ingested(). |
||||
*/ |
||||
function islandora_hooks_test_islandora_datastream_ingested(FedoraObject $object, FedoraDatastream $datastream) { |
||||
if ($object->id == 'test:testIngestedDatastreamHook' && $datastream->id == "TEST") { |
||||
$_SESSION['islandora_hooks']['hook'][ISLANDORA_DATASTREAM_INGESTED_HOOK] = TRUE; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Implements hook_islandora_datastream_modified(). |
||||
*/ |
||||
function islandora_hooks_test_islandora_datastream_modified(FedoraObject $object, FedoraDatastream $datastream) { |
||||
if ($object->id == 'test:testModifiedDatastreamHook' && $datastream->id == "TEST") { |
||||
$_SESSION['islandora_hooks']['hook'][ISLANDORA_DATASTREAM_MODIFIED_HOOK] = TRUE; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Implements hook_islandora_datastream_purged(). |
||||
*/ |
||||
function islandora_hooks_test_islandora_datastream_purged(FedoraObject $object, $dsid) { |
||||
if ($object->id == 'test:testPurgedDatastreamHook' && $dsid == "TEST") { |
||||
$_SESSION['islandora_hooks']['hook'][ISLANDORA_DATASTREAM_PURGED_HOOK] = TRUE; |
||||
} |
||||
} |
@ -1,36 +1,124 @@
|
||||
<?php |
||||
|
||||
/** |
||||
* @file |
||||
* Defines the class IslandoraWebTestCase, which allows tests to access Fedora. |
||||
*/ |
||||
|
||||
class IslandoraWebTestCase extends DrupalWebTestCase { |
||||
|
||||
/** |
||||
* Sets up the Drupal filter to access this test Drupal instances database. |
||||
* |
||||
* @see DrupalWebTestCase::setUp() |
||||
*/ |
||||
public function setUp() { |
||||
$args = func_get_args(); |
||||
call_user_func_array(array('parent', 'setUp'), $args); |
||||
$args = (isset($args[0]) && is_array($args[0])) ? $args[0] : $args; |
||||
// Always enable islandora. |
||||
$args[] = 'islandora'; |
||||
parent::setUp($args); |
||||
$this->configuration = $this->getTestConfiguration(); |
||||
if ($this->configuration['use_drupal_filter']) { |
||||
$this->backUpDrupalFilter(); |
||||
$this->setUpDrupalFilter(); |
||||
} |
||||
$this->createAdminUser(); |
||||
} |
||||
|
||||
$islandora_path = drupal_get_path('module', 'islandora'); |
||||
$this->config_info = parse_ini_file("$islandora_path/tests/test_config.ini"); |
||||
$connection_info = Database::getConnectionInfo('default'); |
||||
/** |
||||
* Parses and returns the settings from the test configuration file. |
||||
* |
||||
* If no install specific test_config.ini file is found, it will use the |
||||
* assumed default configs found in default.test_config.ini. |
||||
* |
||||
* @return array |
||||
* The test configuration. |
||||
* |
||||
* @see parse_ini_file() |
||||
*/ |
||||
protected function getTestConfiguration() { |
||||
$path = drupal_get_path('module', 'islandora'); |
||||
if (file_exists("$path/tests/test_config.ini")) { |
||||
$this->pass('Using custom test configuration.'); |
||||
return parse_ini_file("$path/tests/test_config.ini"); |
||||
} |
||||
elseif (file_exists("$path/tests/default.test_config.ini")) { |
||||
$this->pass('Using default test configuration.'); |
||||
return parse_ini_file("$path/tests/default.test_config.ini"); |
||||
} |
||||
throw new Exception('Required default.test_config.ini/test_config.ini file not found'); |
||||
} |
||||
|
||||
$this->original_drupal_fiter = file_get_contents($this->config_info['filter_drupal_file']); |
||||
/** |
||||
* Stores the content of the Drupal Filter for later restoration. |
||||
*/ |
||||
protected function backUpDrupalFilter() { |
||||
if (file_exists($this->configuration['filter_drupal_file'])) { |
||||
$this->originalDrupalFilterContent = file_get_contents($this->configuration['filter_drupal_file']); |
||||
} |
||||
else { |
||||
throw new Exception('Failed to find the required Drupal Filter configuration file.'); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Sets up a drupal filter that can read for the tests users table. |
||||
*/ |
||||
protected function setUpDrupalFilter() { |
||||
$connection_info = Database::getConnectionInfo('default'); |
||||
$drupal_filter_dom = new DomDocument(); |
||||
$drupal_filter_dom->loadXML($this->original_drupal_fiter); |
||||
$drupal_filter_dom->loadXML($this->originalDrupalFilterContent); |
||||
$drupal_filter_xpath = new DOMXPath($drupal_filter_dom); |
||||
|
||||
$server = $connection_info['default']['host']; |
||||
$dbname = $connection_info['default']['database']; |
||||
$user = $connection_info['default']['username']; |
||||
$password = $connection_info['default']['password']; |
||||
$port = $connection_info['default']['port'] ? $connection_info['default']['port'] : '3306'; |
||||
$prefix = $connection_info['default']['prefix']['default']; |
||||
|
||||
$results = $drupal_filter_xpath->query("/FilterDrupal_Connection/connection[@server='$server' and @dbname='$dbname' and @user='$user' and @password='$password' and @port='$port']/sql"); |
||||
$results->item(0)->nodeValue = "SELECT DISTINCT u.uid AS userid, u.name AS Name, u.pass AS Pass, r.name AS Role FROM ({$prefix}users u LEFT JOIN {$prefix}users_roles ON u.uid={$prefix}users_roles.uid) LEFT JOIN {$prefix}role r ON r.rid={$prefix}users_roles.rid WHERE u.name=? AND u.pass=?;"; |
||||
file_put_contents($this->configuration['drupal_filter_file'], $drupal_filter_dom->saveXML()); |
||||
} |
||||
|
||||
file_put_contents($this->config_info['filter_drupal_file'], $drupal_filter_dom->saveXML()); |
||||
/** |
||||
* Creates the a full fedora admin user with a repository connection. |
||||
*/ |
||||
protected function createAdminUser() { |
||||
$this->admin = new stdClass(); |
||||
$this->admin->uid = 1; |
||||
$this->admin->name = $this->configuration['admin_user']; |
||||
$this->admin->pass = $this->configuration['admin_pass']; |
||||
$url = variable_get('islandora_base_url', $this->configuration['fedora_url']); |
||||
$connection = islandora_get_tuque_connection($this->admin, $url); |
||||
$this->admin->repository = $connection->repository; |
||||
return $this->admin; |
||||
} |
||||
/** |
||||
* Stores the content of the Drupal Filter for later restoration. |
||||
*/ |
||||
protected function restoreDrupalFilter() { |
||||
$file = $this->configuration['filter_drupal_file']; |
||||
if (isset($this->originalDrupalFilterContent)) { |
||||
file_put_contents($file, $this->originalDrupalFilterContent); |
||||
} |
||||
elseif (file_exists($file)) { |
||||
// Remove if there was never an original. |
||||
drupal_unlink($file); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Restores the original Drupal filter, frees any allocated resources. |
||||
* |
||||
* @see DrupalWebTestCase::tearDown() |
||||
*/ |
||||
public function tearDown() { |
||||
file_put_contents($this->config_info['filter_drupal_file'], $this->original_drupal_fiter); |
||||
if ($this->configuration['use_drupal_filter']) { |
||||
$this->restoreDrupalFilter(); |
||||
} |
||||
unset($this->admin); |
||||
unset($this->configuration); |
||||
parent::tearDown(); |
||||
} |
||||
} |
||||
} |
||||
|
@ -1,4 +1,6 @@
|
||||
[fedora] |
||||
filter_drupal_file = "/usr/local/fedora/server/config/filter-drupal.xml" |
||||
fedora_url = "http://localhost:8080/fedora" |
||||
use_drupal_filter = FALSE |
||||
drupal_filter_file = "/home/nbanks/projects/default/repository/server/config/filter-drupal.xml" |
||||
admin_user = "fedoraAdmin" |
||||
admin_pass = "fedoraAdmin" |
||||
|
Loading…
Reference in new issue