Index: modules/search/search.test =================================================================== RCS file: /cvs/drupal/drupal/modules/search/search.test,v retrieving revision 1.27 diff -u -r1.27 search.test --- modules/search/search.test 31 Jul 2009 19:01:02 -0000 1.27 +++ modules/search/search.test 11 Aug 2009 15:37:13 -0000 @@ -461,7 +461,7 @@ variable_set('comment_preview_article', COMMENT_PREVIEW_OPTIONAL); // Enable check_plain() for 'Filtered HTML' text format. $edit = array( - 'filters[filter/4]' => 1, + 'filters[filter_html_escape]' => 1, ); $this->drupalPost('admin/settings/formats/1', $edit, t('Save configuration')); // Allow anonymous users to search content. Index: modules/filter/filter.install =================================================================== RCS file: /cvs/drupal/drupal/modules/filter/filter.install,v retrieving revision 1.16 diff -u -r1.16 filter.install --- modules/filter/filter.install 27 May 2009 18:33:57 -0000 1.16 +++ modules/filter/filter.install 11 Aug 2009 15:36:41 -0000 @@ -10,90 +10,83 @@ * Implement hook_schema(). */ function filter_schema() { - $schema['filter'] = array( - 'description' => 'Table that maps filters (HTML corrector) to text formats (Filtered HTML).', + $schema['filter_format'] = array( + 'description' => 'Stores text formats: custom groupings of filters, such as Filtered HTML.', 'fields' => array( - 'fid' => array( + 'format_id' => array( 'type' => 'serial', 'not null' => TRUE, - 'description' => 'Primary Key: Auto-incrementing filter ID.', + 'description' => 'Primary Key: Unique ID for format.', ), - 'format' => array( - 'type' => 'int', + 'name' => array( + 'type' => 'varchar', + 'length' => 255, 'not null' => TRUE, - 'default' => 0, - 'description' => 'Foreign key: The {filter_format}.format to which this filter is assigned.', + 'default' => '', + 'description' => 'Name of the text format (Filtered HTML).', ), - 'module' => array( + 'roles' => array( 'type' => 'varchar', - 'length' => 64, + 'length' => 255, 'not null' => TRUE, 'default' => '', - 'description' => 'The origin module of the filter.', + 'description' => 'A comma-separated string of roles; references {role}.rid.', // This is bad since you can't use joins, nor index. ), - 'delta' => array( + 'cache' => array( 'type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny', - 'description' => 'ID to identify which filter within module is being referenced.', + 'description' => 'Flag to indicate whether format is cacheable. (1 = cacheable, 0 = not cacheable)', ), 'weight' => array( 'type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny', - 'description' => 'Weight of filter within format.', + 'description' => 'Weight of text format to use when listing.', ) ), - 'primary key' => array('fid'), + 'primary key' => array('format_id'), 'unique keys' => array( - 'fmd' => array('format', 'module', 'delta'), - ), - 'indexes' => array( - 'list' => array('format', 'weight', 'module', 'delta'), + 'name' => array('name'), ), ); - $schema['filter_format'] = array( - 'description' => 'Stores text formats: custom groupings of filters, such as Filtered HTML.', + + $schema['filter_format_filter'] = array( + 'description' => 'Table that maps text formats (Filtered HTML) to text formats (HTML corrector).', 'fields' => array( - 'format' => array( - 'type' => 'serial', + 'format_id' => array( + 'type' => 'int', 'not null' => TRUE, - 'description' => 'Primary Key: Unique ID for format.', + 'default' => 0, + 'description' => 'Foreign key: The {filter_format}.format_id', ), - 'name' => array( + 'module' => array( 'type' => 'varchar', - 'length' => 255, + 'length' => 64, 'not null' => TRUE, 'default' => '', - 'description' => 'Name of the text format (Filtered HTML).', + 'description' => 'The origin module of the filter.', ), - 'roles' => array( + 'filter_id' => array( 'type' => 'varchar', - 'length' => 255, + 'length' => 64, 'not null' => TRUE, 'default' => '', - 'description' => 'A comma-separated string of roles; references {role}.rid.', // This is bad since you can't use joins, nor index. - ), - 'cache' => array( - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, - 'size' => 'tiny', - 'description' => 'Flag to indicate whether format is cacheable. (1 = cacheable, 0 = not cacheable)', - ), + 'description' => 'The filter referenced unique ID as defined in hook_filter_info().', + ), 'weight' => array( 'type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny', - 'description' => 'Weight of text format to use when listing.', + 'description' => 'Weight of filter within format.', ) ), - 'primary key' => array('format'), - 'unique keys' => array( - 'name' => array('name'), + 'primary key' => array('format_id', 'module', 'filter_id'), + 'foreign keys' => array( + 'format_id' => array('filter_format' => 'format_id'), ), ); Index: modules/filter/filter.test =================================================================== RCS file: /cvs/drupal/drupal/modules/filter/filter.test,v retrieving revision 1.28 diff -u -r1.28 filter.test --- modules/filter/filter.test 27 Jul 2009 20:15:35 -0000 1.28 +++ modules/filter/filter.test 11 Aug 2009 15:37:07 -0000 @@ -1,7 +1,49 @@ admin_user = $this->drupalCreateUser(array('administer filters')); + $this->drupalLogin($this->admin_user); + + $this->filtered_html_format = $this->getFormatByName('Filtered HTML'); + $this->full_html_format = $this->getFormatByName('Full HTML'); + } + + /** + * Get a text format from the database based on its name. + * + * @param $name + * The name of the text format. + * @return + * The format object with the given name. + */ + protected function getFormatByName($name) { + $format = db_select('filter_format', 'f') + ->fields('f') + ->condition('name', $name) + ->execute() + ->fetchObject(); + $this->assertFalse(empty($format), t('Text format %format found.', array('%format' => $name))); + return $format; + } +} + +/** + * Tests for format administration functionality. + */ +class FilterAdminTestCase extends FilterWebTestCase { public static function getInfo() { return array( 'name' => 'Filter administration functionality', @@ -9,100 +51,147 @@ 'group' => 'Filter', ); } - + /** - * Test filter administration functionality. + * Test text formats administration functionality. */ - function testFilterAdmin() { - // URL filter. - $first_filter = 2; - // Line filter. - $second_filter = 1; - - // Create users. - $admin_user = $this->drupalCreateUser(array('administer filters')); - $web_user = $this->drupalCreateUser(array('create page content')); - $this->drupalLogin($admin_user); - - list($filtered, $full) = $this->checkFilterFormats(); + function testFormatsAdmin() { + $default_format_id = variable_get('filter_default_format', 1); - // Change default filter. + // Check if the default format is set correctly. + $this->drupalGet('admin/settings/formats'); + $this->assertFieldByName('default', $default_format_id, t('Default format set correctly.')); + + // Check if the default format can not be deleted. + $this->assertNoRaw('admin/settings/formats/delete/' . $default_format_id, t('Delete link not found for default format.')); + $this->drupalGet('admin/settings/formats/delete/' . $default_format_id); + $this->assertRaw(t('The default format cannot be deleted.'), t('The default format cannot be deleted.')); + + // Change default format and check if set correctly. $edit = array(); - $edit['default'] = $full; + $edit['default'] = $this->full_html_format->format_id; $this->drupalPost('admin/settings/formats', $edit, t('Save changes')); - $this->assertText(t('Default format updated.'), t('Default filter updated successfully.')); - - $this->assertNoRaw('admin/settings/formats/delete/' . $full, t('Delete link not found.')); - - // Add an additional tag. + $this->assertText(t('Default format updated.'), t('Default format updated successfully.')); + $this->assertFieldByName('default', $this->full_html_format->format_id, t('Default format set correctly.')); + + // Add a new format. + $edit = array(); + $edit['name'] = $this->randomName(); + $edit['roles[2]'] = TRUE; + $edit['filters[filter_url]'] = TRUE; + $edit['filters[filter_html_escape]'] = TRUE; + $this->drupalPost('admin/settings/formats/add', $edit, t('Save configuration')); + $this->assertRaw(t('Added text format %format.', array('%format' => $edit['name'])), t('New format created.')); + $new_format = $this->getFormatByName($edit['name']); + $this->assertFalse(empty($new_format), t('Format found in database.')); + + // Test if format settings were saved correctly. + $this->drupalGet('admin/settings/formats/' . $new_format->format_id); + // Check format name. + $this->assertFieldByName('name', $edit['name'], t('Format name set correctly')); + // Check if filters are set correctly. + $this->assertFieldChecked('edit-filters-filter-url', t('Convert URLs into links filter selected.')); + $this->assertFieldChecked('edit-filters-filter-html-escape', t('Escape all HTML filter selected.')); + $this->assertNoFieldChecked('edit-filters-filter-autop', t('Convert line breaks filter not selected')); + // Check if roles are set correctly + $this->assertNoFieldChecked('edit-roles-1', t('anonymous user role not selected')); + $this->assertFieldChecked('edit-roles-2', t('authenticated user role selected.')); + + // Test updating format settings. + $edit = array(); + $edit['name'] = $this->randomName(); + $edit['roles[1]'] = TRUE; + $edit['roles[2]'] = FALSE; + $edit['filters[filter_url]'] = TRUE; + $edit['filters[filter_html_escape]'] = FALSE; + $edit['filters[filter_html]'] = TRUE; + $this->drupalPost('admin/settings/formats/' . $new_format->format_id, $edit, t('Save configuration')); + $this->drupalGet('admin/settings/formats/' . $new_format->format_id); + $this->assertFieldByName('name', $edit['name'], t('Format name set correctly')); + // Check if filters are set correctly. + $this->assertFieldChecked('edit-filters-filter-url', t('Convert URLs into links filter selected.')); + $this->assertFieldChecked('edit-filters-filter-html', t('Limit allowed HTML tags selected')); + $this->assertNoFieldChecked('edit-filters-filter-html-escape', t('Escape all HTML filter not selected.')); + $this->assertNoFieldChecked('edit-filters-filter-autop', t('Convert line breaks filter not selected')); + // Check if roles are set correctly + $this->assertFieldChecked('edit-roles-1', t('anonymous user role selected')); + $this->assertNoFieldChecked('edit-roles-2', t('authenticated user role not selected.')); + + // Test format deletion. + $this->drupalPost('admin/settings/formats/delete/' . $new_format->format_id, array(), t('Delete')); + $this->assertRaw(t('Deleted text format %format.', array('%format' => $edit['name'])), t('Format successfully deleted.')); + // Check if the format was deleted from {filter_format} database table. + $format = db_select('filter_format', 'f')->fields('f')->condition('format_id', $new_format->format_id)->execute()->fetchObject(); + $this->assertTrue(empty($format), t('Format successfully deleted from database.')); + // Check if the format relationships were deleted from database. + $filters = db_select('filter_format_filter', 'f')->fields('f')->condition('format_id', $new_format->format_id)->execute()->fetchObject(); + $this->assertTrue(empty($filters), t('Format - filters relationship successfully deleted from database.')); + + + // Test format configuration. $edit = array(); - $edit['allowed_html_1'] = '