1 user.test UserSignatureTestCase::testUserSignature()

Test that a user can change their signature format and that it is respected upon display.

File

core/modules/user/tests/user.test, line 2248
Tests for user.module.

Class

UserSignatureTestCase
Test case for user signatures.

Code

function testUserSignature() {
  // Enable comment subjects on 'page' nodes
  $node_type = node_type_get_type('page');
  $node_type->settings['comment_title_options'] = COMMENT_TITLE_CUSTOM;
  node_type_save($node_type);

  // Create a new node with comments on.
  $node = $this->backdropCreateNode(array('comment' => COMMENT_NODE_OPEN));

  // Verify that user signature field is not displayed on registration form.
  $this->backdropGet('user/register');
  $this->assertNoText(t('Signature'));

  // Log in as a regular user and create a signature.
  $this->backdropLogin($this->web_user);
  $signature_text = "<h1>" . $this->randomName() . "</h1>";
  $edit = array(
    'signature[value]' => $signature_text,
  );
  $this->backdropPost('user/' . $this->web_user->uid . '/edit', $edit, t('Save'));

  // Verify that values were stored.
  $this->backdropGet('user/' . $this->web_user->uid . '/edit');
  $this->assertFieldByName('signature[value]', $edit['signature[value]'], 'Submitted signature text found.');

  // Create a comment.
  $langcode = LANGUAGE_NONE;
  $edit = array();
  $edit['subject'] = $this->randomName(8);
  $edit['comment_body[' . $langcode . '][0][value]'] = $this->randomName(16);
  $this->backdropPost('comment/reply/' . $node->nid, $edit, t('Preview'));
  $this->backdropPost(NULL, array(), t('Save'));

  // Get the comment ID. (This technique is the same one used in the Comment
  // module's CommentHelperCase test case.)
  preg_match('/#comment-([0-9]+)/', $this->getURL(), $match);
  $comment_id = $match[1];

  // Log in as an administrator and edit the comment to use Raw HTML
  // (full_html), so that the comment text itself is not filtered at all.
  $this->backdropLogin($this->admin_user);
  $edit['comment_body[' . $langcode . '][0][format]'] = $this->full_html_format->format;
  $this->backdropPost('comment/' . $comment_id . '/edit', $edit, t('Save'));

  // Assert that the signature did not make it through unfiltered.
  $this->backdropGet('node/' . $node->nid);
  $this->assertNoRaw($signature_text, 'Unfiltered signature text not found.');
  $this->assertRaw(check_markup($signature_text, $this->filtered_html_format->format), 'Filtered signature text found.');
}