diff options
-rw-r--r-- | modules/forum/forum.install | 50 | ||||
-rw-r--r-- | modules/system/system.test | 35 |
2 files changed, 62 insertions, 23 deletions
diff --git a/modules/forum/forum.install b/modules/forum/forum.install index ea1771230..205430dd1 100644 --- a/modules/forum/forum.install +++ b/modules/forum/forum.install @@ -24,6 +24,10 @@ function forum_install() { * Implements hook_enable(). */ function forum_enable() { + // If we enable forum at the same time as taxonomy we need to call + // field_associate_fields() as otherwise the field won't be enabled until + // hook modules_enabled is called which takes place after hook_enable events. + field_associate_fields('taxonomy'); // Create the forum vocabulary if it does not exist. $vocabulary = taxonomy_vocabulary_load(variable_get('forum_nav_vocabulary', 0)); if (!$vocabulary) { @@ -56,28 +60,6 @@ function forum_enable() { ); field_create_field($field); - $instance = array( - 'field_name' => 'taxonomy_' . $vocabulary->machine_name, - 'entity_type' => 'node', - 'label' => $vocabulary->name, - 'bundle' => 'forum', - 'required' => TRUE, - 'widget' => array( - 'type' => 'options_select', - ), - 'display' => array( - 'default' => array( - 'type' => 'taxonomy_term_reference_link', - 'weight' => 10, - ), - 'teaser' => array( - 'type' => 'taxonomy_term_reference_link', - 'weight' => 10, - ), - ), - ); - field_create_instance($instance); - variable_set('forum_nav_vocabulary', $vocabulary->vid); // Create a default forum so forum posts can be created. @@ -90,6 +72,30 @@ function forum_enable() { $term = (object) $edit; taxonomy_term_save($term); } + + // Create the instance on the bundle. + $instance = array( + 'field_name' => 'taxonomy_' . $vocabulary->machine_name, + 'entity_type' => 'node', + 'label' => $vocabulary->name, + 'bundle' => 'forum', + 'required' => TRUE, + 'widget' => array( + 'type' => 'options_select', + ), + 'display' => array( + 'default' => array( + 'type' => 'taxonomy_term_reference_link', + 'weight' => 10, + ), + 'teaser' => array( + 'type' => 'taxonomy_term_reference_link', + 'weight' => 10, + ), + ), + ); + field_create_instance($instance); + // Ensure the forum node type is available. node_types_rebuild(); $types = node_type_get_types(); diff --git a/modules/system/system.test b/modules/system/system.test index 42a9d0635..c5a67f9d0 100644 --- a/modules/system/system.test +++ b/modules/system/system.test @@ -218,7 +218,7 @@ class ModuleDependencyTestCase extends ModuleTestCase { $edit = array(); $edit['modules[Core][translation][enable]'] = 'translation'; $this->drupalPost('admin/modules', $edit, t('Save configuration')); - $this->assertText(t('Some required modules must be enabled'), t('Dependecy required.')); + $this->assertText(t('Some required modules must be enabled'), t('Dependency required.')); $this->assertModules(array('translation', 'locale'), FALSE); @@ -285,6 +285,39 @@ class ModuleDependencyTestCase extends ModuleTestCase { $this->assertModules(array('comment'), TRUE); } + + /** + * Tests re-enabling forum with taxonomy disabled. + */ + function testEnableForumTaxonomyFieldDependency() { + // Enable the forum module. + $edit = array(); + $edit['modules[Core][forum][enable]'] = 'forum'; + $this->drupalPost('admin/modules', $edit, t('Save configuration')); + $this->assertModules(array('forum'), TRUE); + + // Disable the forum module. + $edit = array(); + $edit['modules[Core][forum][enable]'] = FALSE; + $this->drupalPost('admin/modules', $edit, t('Save configuration')); + $this->assertModules(array('forum'), FALSE); + + // Disable the taxonomy module. + $edit = array(); + $edit['modules[Core][taxonomy][enable]'] = FALSE; + $this->drupalPost('admin/modules', $edit, t('Save configuration')); + $this->assertModules(array('taxonomy'), FALSE); + + // Attempt to re-enable the forum module with taxonomy disabled and ensure + // forum does not try to recreate the taxonomy_forums field. + $edit = array(); + $edit['modules[Core][forum][enable]'] = 'forum'; + $this->drupalPost('admin/modules', $edit, t('Save configuration')); + $this->assertText(t('Some required modules must be enabled'), t('Dependency required.')); + $this->drupalPost(NULL, NULL, t('Continue')); + $this->assertText(t('The configuration options have been saved.'), t('Modules status has been updated.')); + $this->assertModules(array('taxonomy', 'forum'), TRUE); + } } /** |