? .project ? sites/all/modules/devel ? sites/default/files ? sites/default/settings.php Index: modules/comment/comment.install =================================================================== RCS file: /cvs/drupal/drupal/modules/comment/comment.install,v retrieving revision 1.36 diff -u -p -r1.36 comment.install --- modules/comment/comment.install 4 Jun 2009 03:33:27 -0000 1.36 +++ modules/comment/comment.install 10 Jun 2009 21:12:32 -0000 @@ -87,7 +87,7 @@ function comment_update_6002() { 'comment_controls' => COMMENT_CONTROLS_HIDDEN, 'comment_anonymous' => COMMENT_ANONYMOUS_MAYNOT_CONTACT, 'comment_subject_field' => 1, - 'comment_preview' => COMMENT_PREVIEW_REQUIRED, + 'comment_preview' => 1, 'comment_form_location' => COMMENT_FORM_SEPARATE_PAGE, ); $types = node_type_get_types(); @@ -154,6 +154,26 @@ function comment_update_7002() { } /** + * Update preview setting variable to use new constants + */ +function comment_update_7003() { + foreach (node_type_get_types() as $type => $object) { + // There were only two comment modes in the past: + // - 1 was 'required' previously, convert into DRUPAL_REQUIRED (2). + // - 0 was 'optional' previously, convert into DRUPAL_OPTIONAL (1). + $original_preview = variable_get('comment_preview_' . $type, 1); + if ($original_preview) { + $preview = DRUPAL_REQUIRED; + } + else { + $preview = DRUPAL_OPTIONAL; + } + variable_set('comment_preview_' . $type, $preview); + } + return array(); +} + +/** * @} End of "defgroup updates-6.x-to-7.x" * The next series of updates should start at 8000. */ Index: modules/comment/comment.module =================================================================== RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v retrieving revision 1.721 diff -u -p -r1.721 comment.module --- modules/comment/comment.module 8 Jun 2009 05:12:15 -0000 1.721 +++ modules/comment/comment.module 10 Jun 2009 21:12:32 -0000 @@ -81,16 +81,6 @@ define('COMMENT_NODE_CLOSED', 1); define('COMMENT_NODE_OPEN', 2); /** - * Comment preview is optional. - */ -define('COMMENT_PREVIEW_OPTIONAL', 0); - -/** - * Comment preview is required. - */ -define('COMMENT_PREVIEW_REQUIRED', 1); - -/** * Implement hook_help(). */ function comment_help($path, $arg) { @@ -565,10 +555,14 @@ function comment_form_node_type_form_alt '#description' => t('Can users provide a unique subject for their comments?'), ); $form['comment']['comment_preview'] = array( - '#type' => 'radios', + '#type' => 'select', '#title' => t('Preview comment'), - '#default_value' => variable_get('comment_preview_' . $form['#node_type']->type, COMMENT_PREVIEW_REQUIRED), - '#options' => array(t('Optional'), t('Required')), + '#default_value' => variable_get('comment_preview_' . $form['#node_type']->type, DRUPAL_REQUIRED), + '#options' => array( + DRUPAL_DISABLED => t('Disabled'), + DRUPAL_OPTIONAL => t('Optional'), + DRUPAL_REQUIRED => t('Required'), + ), '#description' => t("Forces a user to look at their comment by clicking on a 'Preview' button before they can actually add the comment"), ); $form['comment']['comment_form_location'] = array( @@ -1629,18 +1623,20 @@ function comment_form(&$form_state, $edi // already previewing the submission. However, if there are form errors, // we hide the save button no matter what, so that optional form elements // (e.g., captchas) can be updated. - if (!form_get_errors() && ((variable_get('comment_preview_' . $node->type, COMMENT_PREVIEW_REQUIRED) == COMMENT_PREVIEW_OPTIONAL) || ($op == t('Preview')) || ($op == t('Save')))) { + if (!form_get_errors() && ((variable_get('comment_preview_' . $node->type, DRUPAL_REQUIRED) != DRUPAL_REQUIRED) || ($op == t('Preview')) || ($op == t('Save')))) { $form['submit'] = array( '#type' => 'submit', '#value' => t('Save'), '#weight' => 19, ); } - $form['preview'] = array( - '#type' => 'button', - '#value' => t('Preview'), - '#weight' => 20, - ); + if (variable_get('comment_preview_' . $node->type, DRUPAL_REQUIRED) != DRUPAL_DISABLED) { + $form['preview'] = array( + '#type' => 'button', + '#value' => t('Preview'), + '#weight' => 20, + ); + } $form['#token'] = 'comment' . $edit['nid'] . (isset($edit['pid']) ? $edit['pid'] : ''); if ($op == t('Preview')) { @@ -1928,7 +1924,6 @@ function template_preprocess_comment_fol $variables['classes_array'][] = 'comment-new'; } } - } /** Index: modules/comment/comment.test =================================================================== RCS file: /cvs/drupal/drupal/modules/comment/comment.test,v retrieving revision 1.31 diff -u -p -r1.31 comment.test --- modules/comment/comment.test 3 Jun 2009 06:52:29 -0000 1.31 +++ modules/comment/comment.test 10 Jun 2009 21:12:32 -0000 @@ -21,29 +21,48 @@ class CommentHelperCase extends DrupalWe * Post comment. * * @param object $node Node to post comment on. - * @param string $subject Comment subject. * @param string $comment Comment body. - * @param boolean $preview Should preview be required. + * @param string $subject Comment subject. * @param mixed $contact Set to NULL for no contact info, TRUE to ignore success checking, and array of values to set contact info. */ - function postComment($node, $subject, $comment, $preview = TRUE, $contact = NULL) { + function postComment($node, $comment, $subject = '', $contact = NULL) { $edit = array(); - $edit['subject'] = $subject; $edit['comment'] = $comment; - if ($contact !== NULL && is_array($contact)) { - $edit += $contact; - } + $preview_mode = variable_get('comment_preview_article', DRUPAL_REQUIRED); + $subject_mode = variable_get('comment_subject_field_article', 1); + // Must get the page before we test for fields. if ($node !== NULL) { $this->drupalGet('comment/reply/' . $node->nid); } - if ($preview) { - $this->assertNoFieldByName('op', t('Save'), t('Save button not found.')); // Preview required so no save button should be found. - $this->drupalPost(NULL, $edit, t('Preview')); + if ($subject_mode == TRUE) { + $edit['subject'] = $subject; + } + else { + $this->assertNoFieldByName('subject', '', t('Subject field not found.')); + } + + if ($contact !== NULL && is_array($contact)) { + $edit += $contact; + } + switch ($preview_mode) { + case DRUPAL_REQUIRED: + $this->assertNoFieldByName('op', t('Save'), t('Save button not found.')); // Preview required so no save button should be found. + $this->drupalPost(NULL, $edit, t('Preview')); + // Don't break here so that we can test post-preview field presence and function below. + case DRUPAL_OPTIONAL: + $this->assertFieldByName('op', t('Preview'), t('Preview button found.')); + $this->assertFieldByName('op', t('Save'), t('Save button found.')); + $this->drupalPost(NULL, $edit, t('Save')); + break; + case DRUPAL_DISABLED: + $this->assertNoFieldByName('op', t('Preview'), t('Preview button not found.')); + $this->assertFieldByName('op', t('Save'), t('Save button found.')); + $this->drupalPost(NULL, $edit, t('Save')); + break; } - $this->drupalPost(NULL, $edit, t('Save')); $match = array(); // Get comment ID preg_match('/#comment-([^"]+)/', $this->getURL(), $match); @@ -109,11 +128,22 @@ class CommentHelperCase extends DrupalWe /** * Set comment preview setting. * - * @param boolean $required + * @param int $mode * Preview value. */ - function setCommentPreview($required) { - $this->setCommentSettings('comment_preview', ($required ? '1' : '0'), 'Comment preview ' . ($required ? 'required' : 'optional') . '.'); + function setCommentPreview($mode) { + switch ($mode) { + case DRUPAL_DISABLED: + $mode_text = 'disabled'; + break; + case DRUPAL_OPTIONAL: + $mode_text = 'optional'; + break; + case DRUPAL_REQUIRED: + $mode_text = 'required'; + break; + } + $this->setCommentSettings('comment_preview', $mode, 'Comment preview ' . $mode_text . '.'); } /** @@ -241,29 +271,31 @@ class CommentInterfaceTest extends Comme * Test comment interface. */ function testCommentInterface() { - // Set comments to not have subject. + // Set comments to have subject and preview disabled. $this->drupalLogin($this->admin_user); - $this->setCommentPreview(TRUE); + $this->setCommentPreview(DRUPAL_DISABLED); $this->setCommentSubject(FALSE); $this->drupalLogout(); - // Post comment without subject. + // Post comment #1 without subject or preview. $this->drupalLogin($this->web_user); - $this->drupalGet('comment/reply/' . $this->node->nid); - $this->assertNoFieldByName('subject', '', t('Subject field not found.')); + $comment_text = $this->randomName(); + $comment = $this->postComment($this->node, $comment_text); + $comment_loaded = comment_load($comment->id); + $this->assertTrue($this->commentExists($comment), t('Comment found.')); // Set comments to have subject and preview to required. $this->drupalLogout(); $this->drupalLogin($this->admin_user); $this->setCommentSubject(TRUE); - $this->setCommentPreview(TRUE); + $this->setCommentPreview(DRUPAL_REQUIRED); $this->drupalLogout(); - // Create comment that requires preview. + // Create comment #2 that allows subject and requires preview. $this->drupalLogin($this->web_user); $subject_text = $this->randomName(); $comment_text = $this->randomName(); - $comment = $this->postComment($this->node, $subject_text, $comment_text); + $comment = $this->postComment($this->node, $comment_text, $subject_text); $comment_loaded = comment_load($comment->id); $this->assertTrue($this->commentExists($comment), t('Comment found.')); @@ -272,17 +304,25 @@ class CommentInterfaceTest extends Comme $this->assertText($subject_text, t('Individual comment subject found.')); $this->assertText($comment_text, t('Individual comment body found.')); - // Reply to comment without a subject. + // Set comments to have subject and preview to optional. + $this->drupalLogout(); + $this->drupalLogin($this->admin_user); + $this->setCommentSubject(TRUE); + $this->setCommentPreview(DRUPAL_OPTIONAL); + $this->drupalLogout(); + + // Reply to comment #2 creating comment #3 with optional preview and no subject though field enabled. + $this->drupalLogin($this->web_user); $this->drupalGet('comment/reply/' . $this->node->nid . '/' . $comment->id); $this->assertText($subject_text, t('Individual comment-reply subject found.')); $this->assertText($comment_text, t('Individual comment-reply body found.')); - $reply = $this->postComment(NULL, '', $this->randomName()); + $reply = $this->postComment(NULL, $this->randomName()); $reply_loaded = comment_load($reply->id); $this->assertTrue($this->commentExists($reply, TRUE), t('Reply found.')); $this->assertEqual($comment->id, $reply_loaded->pid, t('Pid of a reply to a comment is set correctly.')); $this->assertEqual(rtrim($comment_loaded->thread, '/') . '.00/', $reply_loaded->thread, t('Thread of reply grows correctly.')); - // Second reply to comment + // Second reply to comment #3 creating comment #4. $this->drupalGet('comment/reply/' . $this->node->nid . '/' . $comment->id); $this->assertText($subject_text, t('Individual comment-reply subject found.')); $this->assertText($comment_text, t('Individual comment-reply body found.')); @@ -298,7 +338,7 @@ class CommentInterfaceTest extends Comme // Correct link count $this->drupalGet('node'); - $this->assertRaw('3 comments', t('Link to the 3 comments exist.')); + $this->assertRaw('4 comments', t('Link to the 4 comments exist.')); // Pager $this->setCommentsPerPage(2); @@ -407,12 +447,12 @@ class CommentAnonymous extends CommentHe $this->drupalGet('comment/reply/' . $this->node->nid); $this->assertTrue($this->commentContactInfoAvailable(), t('Contact information available.')); - $anonymous_comment3 = $this->postComment($this->node, $this->randomName(), $this->randomName(), TRUE, TRUE); + $anonymous_comment3 = $this->postComment($this->node, $this->randomName(), $this->randomName(), TRUE); $this->assertText(t('E-mail field is required.'), t('E-mail required.')); // Name should have 'Anonymous' for value by default. $this->assertFalse($this->commentExists($anonymous_comment3), t('Anonymous comment with contact info (required) not found.')); // Post comment with contact info (required). - $anonymous_comment3 = $this->postComment($this->node, $this->randomName(), $this->randomName(), TRUE, array('mail' => 'tester@simpletest.org')); + $anonymous_comment3 = $this->postComment($this->node, $this->randomName(), $this->randomName(), array('mail' => 'tester@simpletest.org')); $this->assertTrue($this->commentExists($anonymous_comment3), t('Anonymous comment with contact info (required) found.')); // Unpublish comment. @@ -477,7 +517,7 @@ class CommentApprovalTest extends Commen // Post anonymous comment without contact info. $subject = $this->randomName(); $body = $this->randomName(); - $this->postComment($this->node, $subject, $body, TRUE, TRUE); // Set $contact to true so that it won't check for id and message. + $this->postComment($this->node, $body, $subject, TRUE); // Set $contact to true so that it won't check for id and message. $this->assertText(t('Your comment has been queued for review by site administrators and will be published after approval.'), t('Comment requires approval.')); // Get unapproved comment id. @@ -511,7 +551,7 @@ class CommentApprovalTest extends Commen // Post anonymous comment without contact info. $subject = $this->randomName(); $body = $this->randomName(); - $this->postComment($this->node, $subject, $body, TRUE, TRUE); // Set $contact to true so that it won't check for id and message. + $this->postComment($this->node, $body, $subject, TRUE); // Set $contact to true so that it won't check for id and message. $this->assertText(t('Your comment has been queued for review by site administrators and will be published after approval.'), t('Comment requires approval.')); // Get unapproved comment id. @@ -569,7 +609,7 @@ class CommentBlockFunctionalTest extends // Add some test comments, one without a subject. $comment1 = $this->postComment($this->node, $this->randomName(), $this->randomName()); $comment2 = $this->postComment($this->node, $this->randomName(), $this->randomName()); - $comment3 = $this->postComment($this->node, '', $this->randomName()); + $comment3 = $this->postComment($this->node, $this->randomName()); // Test that a user without the 'access comments' permission can not see the block. $this->drupalLogout(); Index: modules/search/search.test =================================================================== RCS file: /cvs/drupal/drupal/modules/search/search.test,v retrieving revision 1.22 diff -u -p -r1.22 search.test --- modules/search/search.test 8 Jun 2009 04:51:46 -0000 1.22 +++ modules/search/search.test 10 Jun 2009 21:12:32 -0000 @@ -458,7 +458,7 @@ class SearchCommentTestCase extends Drup function testSearchResultsComment() { $comment_body = $this->randomName(5); - variable_set('comment_preview_article', COMMENT_PREVIEW_OPTIONAL); + variable_set('comment_preview_article', DRUPAL_OPTIONAL); // Enable check_plain() for 'Filtered HTML' text format. $edit = array( 'filters[filter/4]' => 1,