function FilterCRUDTestCase::verifyFilters

Verifies that filters are properly stored for a text format.

1 call to FilterCRUDTestCase::verifyFilters()
FilterCRUDTestCase::testTextFormatCRUD in modules/filter/filter.test
Tests CRUD operations for text formats and filters.

File

modules/filter/filter.test, line 125

Class

FilterCRUDTestCase
Tests for text format and filter CRUD operations.

Code

function verifyFilters($format) {
    // Verify filter database records.
    $filters = db_query("SELECT * FROM {filter} WHERE format = :format", array(
        ':format' => $format->format,
    ))
        ->fetchAllAssoc('name');
    $format_filters = $format->filters;
    foreach ($filters as $name => $filter) {
        $t_args = array(
            '%format' => $format->name,
            '%filter' => $name,
        );
        // Verify that filter status is properly stored.
        $this->assertEqual($filter->status, $format_filters[$name]['status'], format_string('Database: Proper status for %filter in text format %format.', $t_args));
        // Verify that filter settings were properly stored.
        $this->assertEqual(unserialize($filter->settings), isset($format_filters[$name]['settings']) ? $format_filters[$name]['settings'] : array(), format_string('Database: Proper filter settings for %filter in text format %format.', $t_args));
        // Verify that each filter has a module name assigned.
        $this->assertTrue(!empty($filter->module), format_string('Database: Proper module name for %filter in text format %format.', $t_args));
        // Remove the filter from the copy of saved $format to check whether all
        // filters have been processed later.
        unset($format_filters[$name]);
    }
    // Verify that all filters have been processed.
    $this->assertTrue(empty($format_filters), 'Database contains values for all filters in the saved format.');
    // Verify filter_list_format().
    $filters = filter_list_format($format->format);
    $format_filters = $format->filters;
    foreach ($filters as $name => $filter) {
        $t_args = array(
            '%format' => $format->name,
            '%filter' => $name,
        );
        // Verify that filter status is properly stored.
        $this->assertEqual($filter->status, $format_filters[$name]['status'], format_string('filter_list_format: Proper status for %filter in text format %format.', $t_args));
        // Verify that filter settings were properly stored.
        $this->assertEqual($filter->settings, isset($format_filters[$name]['settings']) ? $format_filters[$name]['settings'] : array(), format_string('filter_list_format: Proper filter settings for %filter in text format %format.', $t_args));
        // Verify that each filter has a module name assigned.
        $this->assertTrue(!empty($filter->module), format_string('filter_list_format: Proper module name for %filter in text format %format.', $t_args));
        // Remove the filter from the copy of saved $format to check whether all
        // filters have been processed later.
        unset($format_filters[$name]);
    }
    // Verify that all filters have been processed.
    $this->assertTrue(empty($format_filters), 'filter_list_format: Loaded filters contain values for all filters in the saved format.');
}

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