diff options
author | Dries Buytaert <dries@buytaert.net> | 2010-03-02 09:07:09 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2010-03-02 09:07:09 +0000 |
commit | a5d180b9c0c49aa2eb277d0c0eab764fcf38ef73 (patch) | |
tree | 61bd91ba8846b011507e61733d93680660e3f788 /modules | |
parent | 0d9eedc8fb26b550c766b432e3e237c563272ace (diff) | |
download | brdo-a5d180b9c0c49aa2eb277d0c0eab764fcf38ef73.tar.gz brdo-a5d180b9c0c49aa2eb277d0c0eab764fcf38ef73.tar.bz2 |
- Patch #347959 by sun, Damien Tournoud, justinrandell, scor, chx: modules_installed() was broken during testing.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/rdf/rdf.module | 4 | ||||
-rw-r--r-- | modules/rdf/rdf.test | 70 | ||||
-rw-r--r-- | modules/simpletest/drupal_web_test_case.php | 34 |
3 files changed, 53 insertions, 55 deletions
diff --git a/modules/rdf/rdf.module b/modules/rdf/rdf.module index edd4f1007..01a3f8c7a 100644 --- a/modules/rdf/rdf.module +++ b/modules/rdf/rdf.module @@ -267,10 +267,6 @@ function rdf_rdfa_attributes($mapping, $data = NULL) { * database so that they can be altered via the RDF CRUD mapping API. */ function rdf_modules_installed($modules) { - // We need to clear the caches of entity_info as this is not done right - // during the tests. see http://drupal.org/node/594234 - entity_info_cache_clear(); - foreach ($modules as $module) { $function = $module . '_rdf_mapping'; if (function_exists($function)) { diff --git a/modules/rdf/rdf.test b/modules/rdf/rdf.test index 908cfec4c..fa0c8c58f 100644 --- a/modules/rdf/rdf.test +++ b/modules/rdf/rdf.test @@ -17,9 +17,6 @@ class RdfMappingHookTestCase extends DrupalWebTestCase { function setUp() { parent::setUp('rdf', 'rdf_test', 'field_test'); - // We need to trigger rdf_modules_installed() because - // hook_modules_installed() is not automatically invoked during testing. - rdf_modules_installed(array('rdf_test')); } /** @@ -53,7 +50,6 @@ class RdfMarkupTestCase extends DrupalWebTestCase { function setUp() { parent::setUp('rdf', 'field_test', 'rdf_test'); - rdf_modules_installed(array('field_test', 'rdf_test')); } /** @@ -193,31 +189,54 @@ class RdfCrudTestCase extends DrupalWebTestCase { * Test inserting, loading, updating, and deleting RDF mappings. */ function testCRUD() { - $test_mapping = rdf_test_rdf_mapping(); - // Verify loading of a default mapping. - $this->assertFalse(count(_rdf_mapping_load('test_entity', 'test_bundle')), t('Default mapping was found.')); + $mapping = _rdf_mapping_load('test_entity', 'test_bundle'); + $this->assertTrue(count($mapping), t('Default mapping was found.')); // Verify saving a mapping. - $mapping = (array) $test_mapping; - rdf_mapping_save($mapping[0]); - $this->assertEqual($mapping[0]['mapping'], $test_mapping[0]['mapping'], t('Saved mapping equals default mapping.')); - $this->assertTrue(rdf_mapping_save($mapping[1]) === SAVED_NEW, t('Second mapping was inserted.')); - $this->assertEqual($mapping[1]['mapping'], _rdf_mapping_load($test_mapping[1]['type'], $test_mapping[1]['bundle']), t('Second mapping equals default mapping.')); + $mapping = array( + 'type' => 'crud_test_entity', + 'bundle' => 'crud_test_bundle', + 'mapping' => array( + 'rdftype' => array('sioc:Post'), + 'title' => array( + 'predicates' => array('dc:title'), + ), + 'uid' => array( + 'predicates' => array('sioc:has_creator', 'dc:creator'), + 'type' => 'rel', + ), + ), + ); + $this->assertTrue(rdf_mapping_save($mapping) === SAVED_NEW, t('Mapping was saved.')); + + // Read the raw record from the {rdf_mapping} table. + $result = db_query('SELECT * FROM {rdf_mapping} WHERE type = :type AND bundle = :bundle', array(':type' => $mapping['type'], ':bundle' => $mapping['bundle'])); + $stored_mapping = $result->fetchAssoc(); + $stored_mapping['mapping'] = unserialize($stored_mapping['mapping']); + $this->assertEqual($mapping, $stored_mapping, t('Mapping was stored properly in the {rdf_mapping} table.')); // Verify loading of saved mapping. - $this->assertEqual($mapping[0]['mapping'], _rdf_mapping_load($test_mapping[0]['type'], $test_mapping[0]['bundle']), t('Saved mapping equals loaded default mapping.')); + $this->assertEqual($mapping['mapping'], _rdf_mapping_load($mapping['type'], $mapping['bundle']), t('Saved mapping loaded successfully.')); // Verify updating of mapping. - $mapping[0]['mapping']['boofar'] = array( - 'predicates' => array('foo:bar'), + $mapping['mapping']['title'] = array( + 'predicates' => array('dc2:bar2'), ); - $this->assertTrue(rdf_mapping_save($mapping[0]) === SAVED_UPDATED, t('Mapping was updated.')); - $this->assertEqual($mapping[0]['mapping'], _rdf_mapping_load($test_mapping[0]['type'], $test_mapping[0]['bundle']), t('Updated and loaded mapping are equal.')); + $this->assertTrue(rdf_mapping_save($mapping) === SAVED_UPDATED, t('Mapping was updated.')); + + // Read the raw record from the {rdf_mapping} table. + $result = db_query('SELECT * FROM {rdf_mapping} WHERE type = :type AND bundle = :bundle', array(':type' => $mapping['type'], ':bundle' => $mapping['bundle'])); + $stored_mapping = $result->fetchAssoc(); + $stored_mapping['mapping'] = unserialize($stored_mapping['mapping']); + $this->assertEqual($mapping, $stored_mapping, t('Updated mapping was stored properly in the {rdf_mapping} table.')); + + // Verify loading of saved mapping. + $this->assertEqual($mapping['mapping'], _rdf_mapping_load($mapping['type'], $mapping['bundle']), t('Saved mapping loaded successfully.')); // Verify deleting of mapping. - $this->assertTrue(rdf_mapping_delete($test_mapping[0]['type'], $test_mapping[0]['bundle']), t('Mapping was deleted.')); - $this->assertFalse(_rdf_mapping_load($test_mapping[0]['type'], $test_mapping[0]['bundle']), t('Deleted mapping is no longer found.')); + $this->assertTrue(rdf_mapping_delete($mapping['type'], $mapping['bundle']), t('Mapping was deleted.')); + $this->assertFalse(_rdf_mapping_load($mapping['type'], $mapping['bundle']), t('Deleted mapping is no longer found in the database.')); } } @@ -232,12 +251,6 @@ class RdfMappingDefinitionTestCase extends DrupalWebTestCase { function setUp() { parent::setUp('rdf', 'rdf_test', 'blog'); - // We need to trigger rdf_modules_installed() because - // hook_modules_installed() is not automatically invoked during testing. - rdf_modules_installed(array('rdf_test', 'node')); - // entity_info caches must be cleared during testing. This is done - // automatically during the manual installation. - entity_info_cache_clear(); } /** @@ -327,13 +340,6 @@ class RdfTrackerAttributesTestCase extends DrupalWebTestCase { function setUp() { parent::setUp('rdf', 'rdf_test', 'tracker'); - // We need to trigger rdf_modules_installed() because - // hook_modules_installed() is not automatically invoked during testing. - rdf_modules_installed(array('rdf_test', 'node')); - // entity_info caches must be cleared during testing. This is done - // automatically during the manual installation. - cache_clear_all('entity_info', 'cache'); - drupal_static_reset('entity_get_info'); // Enable anonymous posting of content. user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array( 'create article content' => TRUE, diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php index 5a364f9b9..d07e0b2f1 100644 --- a/modules/simpletest/drupal_web_test_case.php +++ b/modules/simpletest/drupal_web_test_case.php @@ -547,8 +547,7 @@ abstract class DrupalTestCase { * * These tests can not access the database nor files. Calling any Drupal * function that needs the database will throw exceptions. These include - * watchdog(), function_exists(), module_implements(), - * module_invoke_all() etc. + * watchdog(), module_implements(), module_invoke_all() etc. */ class DrupalUnitTestCase extends DrupalTestCase { @@ -1124,8 +1123,7 @@ class DrupalWebTestCase extends DrupalTestCase { ini_set('log_errors', 1); ini_set('error_log', $public_files_directory . '/error.log'); - // Reset all statics and variables so that test is performed with a clean - // environment. + // Reset all statics and variables to perform tests in a clean environment. $conf = array(); drupal_static_reset(); @@ -1139,32 +1137,30 @@ class DrupalWebTestCase extends DrupalTestCase { $profile_details = install_profile_info('standard', 'en'); // Install the modules specified by the default profile. - module_enable($profile_details['dependencies'], FALSE, TRUE); - - drupal_static_reset('_node_types_build'); + module_enable($profile_details['dependencies'], FALSE); + // Install modules needed for this test. if ($modules = func_get_args()) { - // Install modules needed for this test. - module_enable($modules, TRUE, TRUE); + module_enable($modules, TRUE); } - // Because the schema is static cached, we need to flush - // it between each run. If we don't, then it will contain - // stale data for the previous run's database prefix and all - // calls to it will fail. - drupal_get_schema(NULL, TRUE); - // Run default profile tasks. - $install_state = array(); - module_enable(array('standard'), FALSE, TRUE); + module_enable(array('standard'), FALSE); // Rebuild caches. - node_types_rebuild(); + drupal_static_reset(); + drupal_flush_all_caches(); + + // Register actions declared by any modules. actions_synchronize(); - _drupal_flush_css_js(); + + // Reload global $conf array and permissions. $this->refreshVariables(); $this->checkPermissions(array(), TRUE); + // Reset statically cached schema for new database prefix. + drupal_get_schema(NULL, TRUE); + // Run cron once in that environment, as install.php does at the end of // the installation process. drupal_cron_run(); |