function CommentUninstallTestCase::testCommentUninstall

File

modules/comment/comment.test, line 2401

Class

CommentUninstallTestCase
Tests uninstalling the comment module.

Code

function testCommentUninstall() {
    $this->drupalLogin($this->super_user);
    // Disable comment module.
    $edit['modules[Core][comment][enable]'] = FALSE;
    $this->drupalPost('admin/modules', $edit, t('Save configuration'));
    $this->assertText(t('The configuration options have been saved.'), 'Comment module was disabled.');
    // Uninstall comment module.
    $edit = array(
        'uninstall[comment]' => 'comment',
    );
    $this->drupalPost('admin/modules/uninstall', $edit, t('Uninstall'));
    $this->drupalPost(NULL, NULL, t('Uninstall'));
    $this->assertText(t('The selected modules have been uninstalled.'), 'Comment module was uninstalled.');
    // Run cron and clear field cache so that comment fields and instances
    // marked for deletion are actually removed.
    $this->cronRun();
    field_cache_clear();
    // Verify that comment fields have been removed.
    $all_fields = array_keys(field_info_field_map());
    $this->assertFalse(in_array('comment_body', $all_fields), 'Comment fields were removed by uninstall.');
    // Verify that comment field instances have been removed (or at least marked
    // for deletion).
    // N.B. field_read_instances does an INNER JOIN on field_config so if the
    // comment_body row has been removed successfully from there no instances
    // will be returned, but that does not guarantee that no rows are left over
    // in the field_config_instance table.
    $count = db_select('field_config_instance', 'fci')->condition('entity_type', 'comment')
        ->condition('field_name', 'comment_body')
        ->condition('deleted', 0)
        ->countQuery()
        ->execute()
        ->fetchField();
    $this->assertTrue($count == 0, 'Comment field instances were removed by uninstall.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.