From 736c809c2eed3106c44f333b2e1ddd7082c53967 Mon Sep 17 00:00:00 2001 From: William Panting Date: Tue, 19 Mar 2013 17:25:56 -0300 Subject: [PATCH 1/3] Revived islandora_hooks_test module to get hook tests working --- tests/islandora_hooks_test.info | 7 ++ tests/islandora_hooks_test.module | 152 ++++++++++++++++++++++++++++++ 2 files changed, 159 insertions(+) create mode 100644 tests/islandora_hooks_test.info create mode 100644 tests/islandora_hooks_test.module diff --git a/tests/islandora_hooks_test.info b/tests/islandora_hooks_test.info new file mode 100644 index 00000000..9d211978 --- /dev/null +++ b/tests/islandora_hooks_test.info @@ -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 diff --git a/tests/islandora_hooks_test.module b/tests/islandora_hooks_test.module new file mode 100644 index 00000000..315b88ee --- /dev/null +++ b/tests/islandora_hooks_test.module @@ -0,0 +1,152 @@ +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; + } +} From f5c1729cd2de266b2ed82d61a960385a6b80e340 Mon Sep 17 00:00:00 2001 From: William Panting Date: Fri, 22 Mar 2013 10:11:35 -0300 Subject: [PATCH 2/3] test setup docs --- tests/README.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/README.txt b/tests/README.txt index 797d788b..3e7fe11d 100644 --- a/tests/README.txt +++ b/tests/README.txt @@ -1,3 +1,4 @@ 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. \ No newline at end of file +file. These test need write access to the system's $FEDORA_HOME/server/config +directory as they need to temporarily replace the filter-drupal.xml file. \ No newline at end of file From 822c9211a27671b9efae05c0fb9e124ca6dc2124 Mon Sep 17 00:00:00 2001 From: William Panting Date: Fri, 22 Mar 2013 10:28:11 -0300 Subject: [PATCH 3/3] need access to the filter file too --- tests/README.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/README.txt b/tests/README.txt index 3e7fe11d..c03004ae 100644 --- a/tests/README.txt +++ b/tests/README.txt @@ -1,4 +1,4 @@ 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. These test need write access to the system's $FEDORA_HOME/server/config -directory as they need to temporarily replace the filter-drupal.xml file. \ No newline at end of file +directory as well as the filter-drupal.xml file. \ No newline at end of file