diff options
-rw-r--r-- | modules/block/block.test | 6 | ||||
-rw-r--r-- | modules/filter/filter.test | 81 | ||||
-rw-r--r-- | modules/php/php.test | 15 | ||||
-rw-r--r-- | modules/search/search.test | 8 | ||||
-rw-r--r-- | modules/simpletest/tests/common.test | 2 | ||||
-rw-r--r-- | modules/user/user.test | 4 |
6 files changed, 39 insertions, 77 deletions
diff --git a/modules/block/block.test b/modules/block/block.test index 30e91f617..67e503aa3 100644 --- a/modules/block/block.test +++ b/modules/block/block.test @@ -23,7 +23,7 @@ class BlockTestCase extends DrupalWebTestCase { // 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), @@ -119,8 +119,8 @@ class BlockTestCase extends DrupalWebTestCase { $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. diff --git a/modules/filter/filter.test b/modules/filter/filter.test index d9aad514e..524d9de0e 100644 --- a/modules/filter/filter.test +++ b/modules/filter/filter.test @@ -169,8 +169,8 @@ class FilterAdminTestCase extends DrupalWebTestCase { 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,26 +192,27 @@ class FilterAdminTestCase extends DrupalWebTestCase { $this->drupalPost(NULL, $edit, t('Save configuration')); // Edit text format. - $format = $this->getFormat($edit['name']); + $format_id = $edit['format']; + $name = $edit['name']; $this->drupalGet('admin/config/content/formats'); - $this->assertRaw('admin/config/content/formats/' . $format->format); - $this->drupalGet('admin/config/content/formats/' . $format->format); + $this->assertLinkByHref('admin/config/content/formats/' . $format_id); + $this->drupalGet('admin/config/content/formats/' . $format_id); $this->drupalPost(NULL, array(), t('Save configuration')); // Disable text format. $this->drupalGet('admin/config/content/formats'); - $this->assertRaw('admin/config/content/formats/' . $format->format . '/disable'); - $this->drupalGet('admin/config/content/formats/' . $format->format . '/disable'); + $this->assertLinkByHref('admin/config/content/formats/' . $format_id . '/disable'); + $this->drupalGet('admin/config/content/formats/' . $format_id . '/disable'); $this->drupalPost(NULL, array(), t('Disable')); // Verify that disabled text format no longer exists. - $this->drupalGet('admin/config/content/formats/' . $format->format); + $this->drupalGet('admin/config/content/formats/' . $format_id); $this->assertResponse(404, t('Disabled text format no longer exists.')); // Attempt to create a format of the same machine name as the disabled // format but with a different human readable name. $edit = array( - 'format' => $format->format, + 'format' => $format_id, 'name' => 'New format', ); $this->drupalPost('admin/config/content/formats/add', $edit, t('Save configuration')); @@ -221,10 +222,12 @@ class FilterAdminTestCase extends DrupalWebTestCase { // disabled format but with a different machine name. $edit = array( 'format' => 'new_format', - 'name' => $format->name, + 'name' => $name, ); $this->drupalPost('admin/config/content/formats/add', $edit, t('Save configuration')); - $this->assertText('Text format names must be unique. A format named ' . check_plain($format->name) . ' already exists.'); + $this->assertRaw(t('Text format names must be unique. A format named %name already exists.', array( + '%name' => $name, + ))); } /** @@ -236,10 +239,12 @@ class FilterAdminTestCase extends DrupalWebTestCase { // 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.')); + $this->assertTrue($plain == filter_fallback_format(), t('The fallback format is set to plain text.')); $this->drupalGet('admin/config/content/formats'); $this->assertNoRaw('admin/config/content/formats/' . $plain . '/disable', t('Disable link for the fallback format not found.')); $this->drupalGet('admin/config/content/formats/' . $plain . '/disable'); @@ -297,7 +302,8 @@ class FilterAdminTestCase extends DrupalWebTestCase { $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']); + drupal_static_reset('filter_formats'); + $format = filter_format_load($edit['format']); $this->assertNotNull($format, t('Format found in database.')); $this->assertFieldByName('roles[2]', '', t('Role found.')); @@ -375,45 +381,6 @@ class FilterAdminTestCase extends DrupalWebTestCase { $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 +419,7 @@ class FilterFormatAccessTestCase extends DrupalWebTestCase { ); $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 +650,7 @@ class FilterDefaultFormatTestCase extends DrupalWebTestCase { ); $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 +1681,7 @@ class FilterHooksTestCase extends DrupalWebTestCase { $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(); diff --git a/modules/php/php.test b/modules/php/php.test index 6f36e4f5f..10079d67a 100644 --- a/modules/php/php.test +++ b/modules/php/php.test @@ -15,9 +15,9 @@ class PHPTestCase extends DrupalWebTestCase { $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 DrupalWebTestCase { $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 PHPTestCase { */ 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 PHPTestCase { // 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 PHPTestCase { // 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.')); } } diff --git a/modules/search/search.test b/modules/search/search.test index a1ef61250..bf1f69419 100644 --- a/modules/search/search.test +++ b/modules/search/search.test @@ -700,7 +700,7 @@ class SearchCommentTestCase extends DrupalWebTestCase { // 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), @@ -721,7 +721,7 @@ class SearchCommentTestCase extends DrupalWebTestCase { 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, ); @@ -740,7 +740,7 @@ class SearchCommentTestCase extends DrupalWebTestCase { $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')); @@ -975,7 +975,7 @@ class SearchCommentCountToggleTestCase extends DrupalWebTestCase { $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 diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test index 5fca979d9..793770521 100644 --- a/modules/simpletest/tests/common.test +++ b/modules/simpletest/tests/common.test @@ -680,7 +680,7 @@ class CascadingStylesheetsTestCase extends DrupalWebTestCase { $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( diff --git a/modules/user/user.test b/modules/user/user.test index d576a75b5..a15e22c0f 100644 --- a/modules/user/user.test +++ b/modules/user/user.test @@ -1549,8 +1549,8 @@ class UserSignatureTestCase extends DrupalWebTestCase { 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()); |