From f0a49fd44e6b003a3f7ad23b34a007965a39bbe0 Mon Sep 17 00:00:00 2001 From: qadan Date: Wed, 16 Jul 2014 12:43:29 -0300 Subject: [PATCH] code review changes --- tests/includes/islandora_unit_test_case.inc | 1 - tests/includes/islandora_web_test_case.inc | 8 +-- tests/includes/utilities.inc | 68 ++++++++------------- 3 files changed, 30 insertions(+), 47 deletions(-) diff --git a/tests/includes/islandora_unit_test_case.inc b/tests/includes/islandora_unit_test_case.inc index baffc62e..da0a8a71 100644 --- a/tests/includes/islandora_unit_test_case.inc +++ b/tests/includes/islandora_unit_test_case.inc @@ -56,7 +56,6 @@ class IslandoraUnitTestCase extends DrupalUnitTestCase { // It's possible test are running before class autoloading. module_load_include('inc', 'islandora', 'includes/tuque'); - module_load_include('inc', 'islandora', 'includes/tuque_wrapper'); $this->configuration = IslandoraTestUtilityClass::getTestConfiguration(); $this->connection = new RepositoryConnection($this->configuration['fedora_url'], $this->configuration['admin_user'], $this->configuration['admin_pass']); diff --git a/tests/includes/islandora_web_test_case.inc b/tests/includes/islandora_web_test_case.inc index 56645f83..55ee5824 100644 --- a/tests/includes/islandora_web_test_case.inc +++ b/tests/includes/islandora_web_test_case.inc @@ -222,7 +222,7 @@ class IslandoraWebTestCase extends DrupalWebTestCase { if (!$message) { $message = "Error found on current page when error was expected."; } - return $this->assertRaw("
", $message, $group); + return $this->assertFieldByXPath('//div[contains(@class, "message") and contains(@class, "error")]', NULL, $message, $group); } /** @@ -240,7 +240,7 @@ class IslandoraWebTestCase extends DrupalWebTestCase { if (!$message) { $message = "No error found on current page when no error was expected."; } - return $this->assertNoRaw("
", $message, $group); + return $this->assertNoFieldByXPath('//div[contains(@class, "message") and contains(@class, "error")]', NULL, $message, $group); } /** @@ -258,7 +258,7 @@ class IslandoraWebTestCase extends DrupalWebTestCase { if (!$message) { $message = "Warning found on current page when warning was expected."; } - return $this->assertRaw("
", $message, $group); + return $this->assertFieldByXPath('//div[contains(@class, "message") and contains(@class, "warning")]', NULL, $message, $group); } /** @@ -276,7 +276,7 @@ class IslandoraWebTestCase extends DrupalWebTestCase { if (!$message) { $message = "No warning found on current page when no warning was expected."; } - return $this->assertNoRaw("
", $message, $group); + return $this->assertNoFieldByXPath('//div[contains(@class, "message") and contains(@class, "warning")]', NULL, $message, $group); } /** diff --git a/tests/includes/utilities.inc b/tests/includes/utilities.inc index 81758880..719e76ca 100644 --- a/tests/includes/utilities.inc +++ b/tests/includes/utilities.inc @@ -40,29 +40,24 @@ class IslandoraTestUtilities extends IslandoraTestUtilityClass { } /** - * Sets up a drupal filter that can read for the tests users table. + * Sets up a drupal filter that can read from the tests users table. */ public function setUpDrupalFilter() { $original_drupal_filter_content = file_get_contents($this->configuration['drupal_filter_file']); $connection_info = Database::getConnectionInfo('default'); $drupal_filter_dom = new DomDocument(); $drupal_filter_dom->loadXML($original_drupal_filter_content); - $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']; $filter_drupal_connection_node = $drupal_filter_dom->getElementsByTagName('FilterDrupal_Connection')->item(0); $first_connection_node = $drupal_filter_dom->getElementsByTagName('connection')->item(0); $connection_node = $filter_drupal_connection_node->insertBefore($drupal_filter_dom->createElement('connection'), $first_connection_node); - $connection_node->setAttributeNode(new DOMAttr('server', $server)); - $connection_node->setAttributeNode(new DOMAttr('dbname', $dbname)); - $connection_node->setAttributeNode(new DOMAttr('user', $user)); - $connection_node->setAttributeNode(new DOMAttr('password', $password)); - $connection_node->setAttributeNode(new DOMAttr('port', $port)); - $sql_node = $connection_node->appendChild(new DOMElement('sql')); - $sql_node->appendChild($drupal_filter_dom->createTextNode("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=?;")); + $connection_node->setAttribute('server', $connection_info['default']['host']); + $connection_node->setAttribute('dbname', $connection_info['default']['database']); + $connection_node->setAttribute('user', $connection_info['default']['username']); + $connection_node->setAttribute('password', $connection_info['default']['password']); + $connection_node->setAttribute('port', $connection_info['default']['port'] ? $connection_info['default']['port'] : '3306'); + $sql_node = $drupal_filter_dom->createElement('sql', "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=?;"); + $connection_node->appendChild($sql_node); file_put_contents($this->configuration['drupal_filter_file'], $drupal_filter_dom->saveXML()); } @@ -117,7 +112,7 @@ class IslandoraTestUtilities extends IslandoraTestUtilityClass { * TRUE on success, FALSE on fail. */ public function assertDatastreams($object, array $datastreams) { - if (!is_object($object)) { + if (!$this->assertFedoraObject($object)) { $this->addResult(FALSE, "Failed. Object passed in is invalid.", 'Islandora'); } else { @@ -142,7 +137,7 @@ class IslandoraTestUtilities extends IslandoraTestUtilityClass { * An array of datastreams to confirm not present. */ public function assertNoDatastreams($object, array $datastreams) { - if (!is_object($object)) { + if (!$this->assertFedoraObject($object)) { $this->addResult(FALSE, "Failed. Object passed in is invalid.", 'Islandora'); return; } @@ -175,7 +170,7 @@ class IslandoraTestUtilities extends IslandoraTestUtilityClass { */ public function validateDatastreams($object, array $datastreams) { - if (!is_object($object)) { + if (!$this->assertFedoraObject($object)) { $this->addResult(FALSE, "Datastream validation failed; Object passed in is invalid.", 'Islandora'); return; } @@ -183,32 +178,8 @@ class IslandoraTestUtilities extends IslandoraTestUtilityClass { module_load_include('inc', 'islandora', 'tests/includes/datastream_validators'); foreach ($datastreams as $datastream) { - // Let's give them conventional names. - $dsid = $datastream[0]; - $prefix = $datastream[1]; - $params = array(); - if (isset($datastream[2])) { - $params = $datastream[2]; - } - - // Legacy tests were created before the CamelCase conventions of the class - // system now in place. So, we need to automagically seek out prefixes - // that start with a lower-case letter and convert them to the proper - // format (rather than fixing every single legacy test). - if (ctype_lower(substr($prefix, 0, 1))) { - // Handle the case where the prefix is "image". - if ($prefix === 'image') { - $prefix = 'Image'; - } - // Handle the case where the prefix is "text". - elseif ($prefix === 'text') { - $prefix = 'Text'; - } - // All other cases involve just converting everything to caps. - else { - $prefix = strtoupper($prefix); - } - } + // XXX: The "+ array (2 => array())" is to allow the value to be optional. + list($dsid, $prefix, $params) = $datastream + array(2 => array()); // Instantiate the appropriate class, and grab the results. $class_name = "{$prefix}DatastreamValidator"; @@ -367,4 +338,17 @@ QUERY; } } + /** + * Asserts that an object is a FedoraObject or an IslandoraFedoraObject. + * + * @param object $object + * The object to assess. + * + * @return bool + * TRUE if it is either of those object types, or FALSE otherwise. + */ + public static function assertFedoraObject($object) { + return ($object instanceof FedoraObject); + } + }