diff --git a/ilives/tests/fedora_ilives.test b/ilives/tests/fedora_ilives.test new file mode 100644 index 00000000..be8c0ffd --- /dev/null +++ b/ilives/tests/fedora_ilives.test @@ -0,0 +1,132 @@ + 'Fedora Book', + 'description' => t('The Fedora repository book content model.'), + 'group' => t('fedora repository'), + ); + } + + function setUp() { + parent::setUp('fedora_repository', 'fedora_ilives', 'tabs'); + + module_load_include('inc', 'fedora_repository', 'api/fedora_item'); + + // Create and login user. + $repository_user = $this->drupalCreateFedoraUser(array('add fedora datastreams', + 'edit fedora meta data', + 'edit tags datastream', + 'ingest new fedora objects', + 'purge objects and datastreams', + 'view fedora collection', + 'view detailed list of content')); + + + $this->drupalLogin($repository_user); + + } + + public function testBookCModel() { + // First add a book collection + + $pid_list = array(); + // Create a collection for ingesting book content model objects. + + $ingest_form = array(); + $ingest_form['models'] = 'islandora:collectionCModel/ISLANDORACM'; + + $this->drupalPost('fedora/ingestObject/islandora:top/Islandora%20Top-Level%20Collection', $ingest_form, 'Next'); + + $ingest_title = $this->randomName(32); + $ingest_form_step_2['dc:title'] = $ingest_title; + $ingest_form_step_2['dc:description'] = $this->randomName(256); + $ingest_form_step_2['files[ingest-file-location]'] = realpath(drupal_get_path('module', 'fedora_ilives') . '/xml/book_collection_policy.xml'); + $this->drupalPost(NULL, $ingest_form_step_2, 'Ingest'); + $this->assertPattern('/Item .* created successfully./', "Verified item created."); + + $pid = $this->getIngestedPid(); + $this->drupalGet("fedora/repository/$pid"); + $pid_list[] = $pid; + + // Now add a book into the new collection + $this->pass("Create book collection $pid below top-level collection.", 'fedora book'); + $ingest_book_form = array(); + $ingest_book_form['models'] = 'ilives:bookCModel/ISLANDORACM'; + $this->drupalPost("fedora/ingestObject/$pid/", $ingest_book_form, 'Next'); + $ingest_book_form_step_2 = array(); + + $ingest_book_form_step_2['mods[mods_record]'] = file_get_contents(drupal_get_path('module', 'fedora_ilives') . '/tests/test_files/mods_record.xml'); + $this->outputScreenContents(); + $this->drupalPost(NULL, $ingest_book_form_step_2, 'Ingest'); + $this->outputScreenContents(); + $book_pid = $this->getIngestedPid(); + $pid_list[] = $book_pid; + if (!empty($book_pid)) { + $this->pass("Successfully ingested book object $book_pid."); + } + $this->cleanUpRepository($pid_list); + + } + + private function cleanUpRepository($pid_list = array()) { + $this->pass("This is the PID list to purge: ". implode(", ", $pid_list) ); + foreach ($pid_list as $pid) { + $this->drupalPost("fedora/repository/purgeObject/$pid", array(), 'Purge'); + $this->drupalPost(NULL, array(), 'Delete'); + } + } + + private function getIngestedPid() { + $subject = $this->drupalGetContent(); + $pattern = '/">(.*)<\/a> created successfully./'; + $matches = array(); + $res = preg_match($pattern, $subject, $matches); + return $matches[1]; + } + + private function outputScreenContents($description = '', $basename = '') { + // This is a hack to get a directory that won't be cleaned up by SimpleTest. + $file_dir = file_directory_path() . '../simpletest_output_pages'; + if (!is_dir($file_dir)) { + mkdir($file_dir, 0777, TRUE); + } + $output_path = "$file_dir/$basename.". $this->randomName(10) . '.html'; + $rv = file_put_contents($output_path, $this->drupalGetContent()); + $this->pass("$description: Contents of result page are ". l('here', $output_path)); + } + + protected function drupalCreateFedoraUser($permissions = array('access comments', 'access content', 'post comments', 'post comments without approval')) { + // Create a role with the given permission set. + if (!($rid = $this->drupalCreateRole($permissions))) { + return FALSE; + } + + // Create a user assigned to that role. + $edit = array(); + $edit['name'] = 'simpletestuser'; + $edit['mail'] = $edit['name'] . '@example.com'; + $edit['roles'] = array($rid => $rid); + $edit['pass'] = 'simpletestpass'; + $edit['status'] = 1; + + $account = user_save('', $edit); + + $this->assertTrue(!empty($account->uid), t('User created with name %name and pass %pass', array('%name' => $edit['name'], '%pass' => $edit['pass'])), t('User login')); + if (empty($account->uid)) { + return FALSE; + } + + // Add the raw password so that we can log in as this user. + $account->pass_raw = $edit['pass']; + return $account; + } + +} \ No newline at end of file diff --git a/ilives/tests/test_files/mods_record.xml b/ilives/tests/test_files/mods_record.xml new file mode 100644 index 00000000..6ec2a1d2 --- /dev/null +++ b/ilives/tests/test_files/mods_record.xml @@ -0,0 +1,83 @@ + + + + + The + amazing Maurice and his educated rodents + + + Pratchett, Terry. + + creator + + + text + novel + + + enk + + + London + + Corgi Books + 2002 + 2001 + monographic + + + eng + + +
print
+ 269 p. ; 22 cm. +
+ A talking cat, intelligent rats, and a strange boy cooperate in a Pied Piper scam until they try to con the wrong town and are confronted by a deadly evil rat king. + juvenile + Terry Pratchett. + Carnegie Medal winner. + + Discworld (Imaginary place) + Fiction + + + Discworld (Imaginary place) + Fiction + + + Rats + Fiction + + + Cats + Fiction + + + Fantasy fiction + + + Humorous stories + + PZ7.P8865 Am 2002 + + + Discworld series + + + Pratchett, Terry. + + + 006001234X (library binding) + 0385601239 + 0552546933 (pbk.) + + CaNWHRN + 010730 + 20020314 .0 + + eng + + +
+
+