Index: modules/block/block.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/block/block.test,v
retrieving revision 1.60
diff -u -p -r1.60 block.test
--- modules/block/block.test	25 Oct 2010 15:51:21 -0000	1.60
+++ modules/block/block.test	4 Nov 2010 22:41:09 -0000
@@ -23,7 +23,7 @@ class BlockTestCase extends DrupalWebTes
 
     // Create and log in an administrative user having access to the Full HTML
     // text format.
-    $full_html_format = db_query_range('SELECT * FROM {filter_format} WHERE name = :name', 0, 1, array(':name' => 'Full HTML'))->fetchObject();
+    $full_html_format = filter_format_load('full_html');
     $this->admin_user = $this->drupalCreateUser(array(
       'administer blocks',
       filter_permission_name($full_html_format),
@@ -113,8 +113,8 @@ class BlockTestCase extends DrupalWebTes
     $custom_block['info'] = $this->randomName(8);
     $custom_block['title'] = $this->randomName(8);
     $custom_block['body[value]'] = '<h1>Full HTML</h1>';
-    $full_html_format_id = db_query_range('SELECT format FROM {filter_format} WHERE name = :name', 0, 1, array(':name' => 'Full HTML'))->fetchField();
-    $custom_block['body[format]'] = $full_html_format_id;
+    $full_html_format = filter_format_load('full_html');
+    $custom_block['body[format]'] = $full_html_format->format;
     $this->drupalPost('admin/structure/block/add', $custom_block, t('Save block'));
 
     // Set the created custom block to a specific region.
Index: modules/filter/filter.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/filter/filter.test,v
retrieving revision 1.80
diff -u -p -r1.80 filter.test
--- modules/filter/filter.test	23 Oct 2010 02:26:11 -0000	1.80
+++ modules/filter/filter.test	4 Nov 2010 22:58:31 -0000
@@ -169,8 +169,8 @@ class FilterAdminTestCase extends Drupal
     parent::setUp();
 
     // Create users.
-    $filtered_html_format = db_query_range('SELECT * FROM {filter_format} WHERE name = :name', 0, 1, array(':name' => 'Filtered HTML'))->fetchObject();
-    $full_html_format = db_query_range('SELECT * FROM {filter_format} WHERE name = :name', 0, 1, array(':name' => 'Full HTML'))->fetchObject();
+    $filtered_html_format = filter_format_load('filtered_html');
+    $full_html_format = filter_format_load('full_html');
     $this->admin_user = $this->drupalCreateUser(array(
       'administer filters',
       filter_permission_name($filtered_html_format),
@@ -192,7 +192,7 @@ class FilterAdminTestCase extends Drupal
     $this->drupalPost(NULL, $edit, t('Save configuration'));
 
     // Edit text format.
-    $format = $this->getFormat($edit['name']);
+    $format = filter_format_load($edit['name']);
     $this->drupalGet('admin/config/content/formats');
     $this->assertRaw('admin/config/content/formats/' . $format->format);
     $this->drupalGet('admin/config/content/formats/' . $format->format);
@@ -236,7 +236,9 @@ class FilterAdminTestCase extends Drupal
     // Line filter.
     $second_filter = 'filter_autop';
 
-    list($filtered, $full, $plain) = $this->checkFilterFormats();
+    $filtered = 'filtered_html';
+    $full = 'full_html';
+    $plain = 'plain_text';
 
     // Check that the fallback format exists and cannot be disabled.
     $this->assertTrue(!empty($plain) && $plain == filter_fallback_format(), t('The fallback format is set to plain text.'));
@@ -297,7 +299,7 @@ class FilterAdminTestCase extends Drupal
     $this->drupalPost('admin/config/content/formats/add', $edit, t('Save configuration'));
     $this->assertRaw(t('Added text format %format.', array('%format' => $edit['name'])), t('New filter created.'));
 
-    $format = $this->getFormat($edit['name']);
+    $format = filter_format_load($edit['name']);
     $this->assertNotNull($format, t('Format found in database.'));
 
     $this->assertFieldByName('roles[2]', '', t('Role found.'));
@@ -375,45 +377,6 @@ class FilterAdminTestCase extends Drupal
     $this->assertFieldByName('filters[' . $second_filter . '][weight]', $edit['filters[' . $second_filter . '][weight]'], t('Changes reverted.'));
     $this->assertFieldByName('filters[' . $first_filter . '][weight]', $edit['filters[' . $first_filter . '][weight]'], t('Changes reverted.'));
   }
-
-  /**
-   * Query the database to get the three basic formats.
-   *
-   * @return
-   *   An array containing filtered, full, and plain text format ids.
-   */
-  function checkFilterFormats() {
-    $result = db_query('SELECT format, name FROM {filter_format}');
-
-    $filtered = -1;
-    $full = -1;
-    $plain = -1;
-    foreach ($result as $format) {
-      if ($format->name == 'Filtered HTML') {
-        $filtered = $format->format;
-      }
-      elseif ($format->name == 'Full HTML') {
-        $full = $format->format;
-      }
-      elseif ($format->name == 'Plain text') {
-        $plain = $format->format;
-      }
-    }
-
-    return array($filtered, $full, $plain);
-  }
-
-  /**
-   * Retrieve a text format object by name.
-   *
-   * @param $name
-   *   The name of a text format.
-   * @return
-   *   A text format object.
-   */
-  function getFormat($name) {
-    return db_query("SELECT * FROM {filter_format} WHERE name = :name", array(':name' => $name))->fetchObject();
-  }
 }
 
 class FilterFormatAccessTestCase extends DrupalWebTestCase {
@@ -452,8 +415,7 @@ class FilterFormatAccessTestCase extends
       );
       $this->drupalPost('admin/config/content/formats/add', $edit, t('Save configuration'));
       $this->resetFilterCaches();
-      $format_id = db_query("SELECT format FROM {filter_format} WHERE name = :name", array(':name' => $edit['name']))->fetchField();
-      $formats[] = filter_format_load($format_id);
+      $formats[] = filter_format_load($edit['format']);
     }
     list($this->allowed_format, $this->disallowed_format) = $formats;
     $this->drupalLogout();
@@ -684,8 +646,7 @@ class FilterDefaultFormatTestCase extend
       );
       $this->drupalPost('admin/config/content/formats/add', $edit, t('Save configuration'));
       $this->resetFilterCaches();
-      $format_id = db_query("SELECT format FROM {filter_format} WHERE name = :name", array(':name' => $edit['name']))->fetchField();
-      $formats[] = filter_format_load($format_id);
+      $formats[] = filter_format_load($edit['format']);
     }
     list($first_format, $second_format) = $formats;
     $first_user = $this->drupalCreateUser(array(filter_permission_name($first_format), filter_permission_name($second_format)));
@@ -1716,7 +1677,7 @@ class FilterHooksTestCase extends Drupal
     $this->assertRaw(t('Added text format %format.', array('%format' => $name)), t('New format created.'));
     $this->assertText('hook_filter_format_insert invoked.', t('hook_filter_format_insert was invoked.'));
 
-    $format_id = db_query("SELECT format FROM {filter_format} WHERE name = :name", array(':name' => $name))->fetchField();
+    $format_id = $edit['format'];
 
     // Update text format.
     $edit = array();
Index: modules/php/php.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/php/php.test,v
retrieving revision 1.26
diff -u -p -r1.26 php.test
--- modules/php/php.test	5 Aug 2010 23:53:38 -0000	1.26
+++ modules/php/php.test	4 Nov 2010 22:52:06 -0000
@@ -15,9 +15,9 @@ class PHPTestCase extends DrupalWebTestC
     $this->drupalLogin($admin_user);
 
     // Verify that the PHP code text format was inserted.
-    $php_format_id = db_query_range('SELECT format FROM {filter_format} WHERE name = :name', 0, 1, array(':name' => 'PHP code'))->fetchField();
-    $php_format = filter_format_load($php_format_id);
-    $this->assertEqual($php_format->name, 'PHP code', t('PHP code text format was created.'));
+    $php_format_id = 'php_code';
+    $this->php_code_format = filter_format_load($php_format_id);
+    $this->assertEqual($this->php_code_format->name, 'PHP code', t('PHP code text format was created.'));
 
     // Verify that the format has the PHP code filter enabled.
     $filters = filter_list_format($php_format_id);
@@ -31,9 +31,6 @@ class PHPTestCase extends DrupalWebTestC
     $this->drupalGet('admin/config/content/formats/' . $php_format_id);
     $this->assertFieldByName('roles[1]', FALSE, t('Anonymous users do not have access to PHP code format.'));
     $this->assertFieldByName('roles[2]', FALSE, t('Authenticated users do not have access to PHP code format.'));
-
-    // Store the format ID of the PHP code text format for later use.
-    $this->php_code_format = $php_format_id;
   }
 
   /**
@@ -63,7 +60,7 @@ class PHPFilterTestCase extends PHPTestC
    */
   function testPHPFilter() {
     // Log in as a user with permission to use the PHP code text format.
-    $php_code_permission = filter_permission_name(filter_format_load($this->php_code_format));
+    $php_code_permission = filter_permission_name(filter_format_load('php_code'));
     $web_user = $this->drupalCreateUser(array('access content', 'create page content', 'edit own page content', $php_code_permission));
     $this->drupalLogin($web_user);
 
@@ -77,7 +74,7 @@ class PHPFilterTestCase extends PHPTestC
     // Change filter to PHP filter and see that PHP code is evaluated.
     $edit = array();
     $langcode = LANGUAGE_NONE;
-    $edit["body[$langcode][0][format]"] = $this->php_code_format;
+    $edit["body[$langcode][0][format]"] = $this->php_code_format->format;
     $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
     $this->assertRaw(t('Basic page %title has been updated.', array('%title' => $node->title)), t('PHP code filter turned on.'));
 
@@ -114,6 +111,6 @@ class PHPAccessTestCase extends PHPTestC
 
     // Make sure that user doesn't have access to filter.
     $this->drupalGet('node/' . $node->nid . '/edit');
-    $this->assertNoRaw('<option value="' . $this->php_code_format . '">', t('PHP code format not available.'));
+    $this->assertNoRaw('<option value="' . $this->php_code_format->format . '">', t('PHP code format not available.'));
   }
 }
Index: modules/search/search.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/search/search.test,v
retrieving revision 1.77
diff -u -p -r1.77 search.test
--- modules/search/search.test	20 Oct 2010 01:15:58 -0000	1.77
+++ modules/search/search.test	4 Nov 2010 22:53:52 -0000
@@ -693,7 +693,7 @@ class SearchCommentTestCase extends Drup
 
     // Create and log in an administrative user having access to the Full HTML
     // text format.
-    $full_html_format = db_query_range('SELECT * FROM {filter_format} WHERE name = :name', 0, 1, array(':name' => 'Full HTML'))->fetchObject();
+    $full_html_format = filter_format_load('full_html');
     $permissions = array(
       'administer filters',
       filter_permission_name($full_html_format),
@@ -714,7 +714,7 @@ class SearchCommentTestCase extends Drup
 
     variable_set('comment_preview_article', DRUPAL_OPTIONAL);
     // Enable check_plain() for 'Filtered HTML' text format.
-    $filtered_html_format_id = db_query_range('SELECT format FROM {filter_format} WHERE name = :name', 0, 1, array(':name' => 'Filtered HTML'))->fetchField();
+    $filtered_html_format_id = 'filtered_html';
     $edit = array(
       'filters[filter_html_escape][status]' => TRUE,
     );
@@ -733,7 +733,7 @@ class SearchCommentTestCase extends Drup
     $edit_comment = array();
     $edit_comment['subject'] = 'Test comment subject';
     $edit_comment['comment_body[' . LANGUAGE_NONE . '][0][value]'] = '<h1>' . $comment_body . '</h1>';
-    $full_html_format_id = db_query_range('SELECT format FROM {filter_format} WHERE name = :name', 0, 1, array(':name' => 'Full HTML'))->fetchField();
+    $full_html_format_id = 'full_html';
     $edit_comment['comment_body[' . LANGUAGE_NONE . '][0][format]'] = $full_html_format_id;
     $this->drupalPost('comment/reply/' . $node->nid, $edit_comment, t('Save'));
 
@@ -968,7 +968,7 @@ class SearchCommentCountToggleTestCase e
     $edit_comment = array();
     $edit_comment['subject'] = $this->randomName();
     $edit_comment['comment_body[' . LANGUAGE_NONE . '][0][value]'] = $this->randomName();
-    $filtered_html_format_id = db_query_range('SELECT format FROM {filter_format} WHERE name = :name', 0, 1, array(':name' => 'Filtered HTML'))->fetchField();
+    $filtered_html_format_id = 'filtered_html';
     $edit_comment['comment_body[' . LANGUAGE_NONE . '][0][format]'] = $filtered_html_format_id;
     
     // Post comment to the test node with comment
Index: modules/simpletest/tests/common.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/common.test,v
retrieving revision 1.130
diff -u -p -r1.130 common.test
--- modules/simpletest/tests/common.test	8 Oct 2010 15:36:12 -0000	1.130
+++ modules/simpletest/tests/common.test	4 Nov 2010 22:54:10 -0000
@@ -680,7 +680,7 @@ class CascadingStylesheetsTestCase exten
     $expected = 'body{font-size:254px;}';
 
     // Create a node, using the PHP filter that tests drupal_add_css().
-    $php_format_id = db_query_range('SELECT format FROM {filter_format} WHERE name = :name', 0, 1, array(':name' => 'PHP code'))->fetchField();
+    $php_format_id = 'php_code';
     $settings = array(
       'type' => 'page',
       'body' => array(
Index: modules/user/user.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.test,v
retrieving revision 1.104
diff -u -p -r1.104 user.test
--- modules/user/user.test	23 Oct 2010 03:20:40 -0000	1.104
+++ modules/user/user.test	4 Nov 2010 22:56:14 -0000
@@ -1549,8 +1549,8 @@ class UserSignatureTestCase extends Drup
     variable_set('user_signatures', 1);
 
     // Prefetch text formats.
-    $this->full_html_format = db_query_range('SELECT * FROM {filter_format} WHERE name = :name', 0, 1, array(':name' => 'Full HTML'))->fetchObject();
-    $this->plain_text_format = db_query_range('SELECT * FROM {filter_format} WHERE name = :name', 0, 1, array(':name' => 'Plain text'))->fetchObject();
+    $this->full_html_format = filter_format_load('full_html');
+    $this->plain_text_format = filter_format_load('plain_text');
 
     // Create regular and administrative users.
     $this->web_user = $this->drupalCreateUser(array());
