Verified Commit c187cc63 authored by Dave Long's avatar Dave Long
Browse files

Issue #3153468 by mondrake, mohrerao, mallezie, smustgrave, meena.bisht,...

Issue #3153468 by mondrake, mohrerao, mallezie, smustgrave, meena.bisht, naresh_bavaskar, hash6, ravi.shankar, Hardik_Patel_12, longwave, xjm: Strip HTML tags when using assertEquals() to compare markup
parent f0269a48
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -93,7 +93,7 @@ public function testBasicRendering() {
    $expected[] = '  </div>';
    $expected[] = '';
    $expected_output = implode("\n", $expected);
    $this->assertEquals($expected_output, $this->renderer->renderRoot($output));
    $this->assertSame($expected_output, (string) $this->renderer->renderRoot($output));

    // Reset the HTML IDs so that the next render is not affected.
    Html::resetSeenIds();
@@ -118,7 +118,7 @@ public function testBasicRendering() {
    $expected[] = '  </div>';
    $expected[] = '';
    $expected_output = implode("\n", $expected);
    $this->assertEquals($expected_output, $this->renderer->renderRoot($output));
    $this->assertSame($expected_output, (string) $this->renderer->renderRoot($output));
  }

  /**
+3 −4
Original line number Diff line number Diff line
@@ -3,7 +3,6 @@
namespace Drupal\Tests\comment\Functional;

use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\UrlHelper;
use Drupal\comment\Entity\Comment;
@@ -139,7 +138,7 @@ public function testCommentTokenReplacement() {
    foreach ($tests as $input => $expected) {
      $bubbleable_metadata = new BubbleableMetadata();
      $output = $token_service->replace($input, ['comment' => $comment], ['langcode' => $language_interface->getId()], $bubbleable_metadata);
      $this->assertEquals($expected, $output, new FormattableMarkup('Comment token %token replaced.', ['%token' => $input]));
      $this->assertSame((string) $expected, (string) $output, "Failed test case: {$input}");
      $this->assertEquals($metadata_tests[$input], $bubbleable_metadata);
    }

@@ -148,7 +147,7 @@ public function testCommentTokenReplacement() {
    $comment->setOwnerId(0)->setAuthorName($author_name);
    $input = '[comment:author]';
    $output = $token_service->replace($input, ['comment' => $comment], ['langcode' => $language_interface->getId()]);
    $this->assertEquals(Html::escape($author_name), $output, new FormattableMarkup('Comment author token %token replaced.', ['%token' => $input]));
    $this->assertSame((string) Html::escape($author_name), (string) $output);
    // Add comment field to user and term entities.
    $this->addDefaultCommentField('user', 'user', 'comment', CommentItemInterface::OPEN, 'comment_user');
    $this->addDefaultCommentField('taxonomy_term', 'tags', 'comment', CommentItemInterface::OPEN, 'comment_term');
@@ -186,7 +185,7 @@ public function testCommentTokenReplacement() {

    foreach ($tests as $input => $expected) {
      $output = $token_service->replace($input, ['entity' => $node, 'node' => $node, 'user' => $user, 'term' => $term], ['langcode' => $language_interface->getId()]);
      $this->assertEquals($expected, $output, new FormattableMarkup('Comment token %token replaced.', ['%token' => $input]));
      $this->assertSame((string) $expected, (string) $output, "Failed test case: {$input}");
    }
  }

+2 −2
Original line number Diff line number Diff line
@@ -101,7 +101,7 @@ public function testValidation() {
    $violations = $comment->validate();
    $this->assertCount(1, $violations, "Violation found on author name collision");
    $this->assertEquals("name", $violations[0]->getPropertyPath());
    $this->assertEquals(t('The name you used (%name) belongs to a registered user.', ['%name' => 'test']), $violations[0]->getMessage());
    $this->assertEquals('The name you used (test) belongs to a registered user.', $violations[0]->getMessage());

    // Make the name valid.
    $comment->set('name', 'valid unused name');
@@ -197,7 +197,7 @@ protected function assertLengthViolation(CommentInterface $comment, string $fiel
    $this->assertCount(1, $violations, "Violation found when $field_name is too long.");
    $this->assertEquals("{$field_name}.0.value", $violations[0]->getPropertyPath());
    $field_label = $comment->get($field_name)->getFieldDefinition()->getLabel();
    $this->assertEquals(t('%name: may not be longer than @max characters.', ['%name' => $field_label, '@max' => $length]), $violations[0]->getMessage());
    $this->assertEquals("{$field_label}: may not be longer than {$length} characters.", $violations[0]->getMessage());
  }

}
+2 −2
Original line number Diff line number Diff line
@@ -82,7 +82,7 @@ public function testLinkApprove() {
    $approve_comment = $view->style_plugin->getField(0, 'approve_comment');
    $options = ['query' => ['destination' => '/']];
    $url = Url::fromRoute('comment.approve', ['comment' => $comment->id()], $options);
    $this->assertEquals((string) $approve_comment, Link::fromTextAndUrl('Approve', $url)->toString(), 'Found a comment approve link for an unapproved comment.');
    $this->assertSame((string) $approve_comment, (string) Link::fromTextAndUrl('Approve', $url)->toString(), 'Found a comment approve link for an unapproved comment.');

    // Approve the comment.
    $comment->setPublished();
@@ -182,7 +182,7 @@ public function testLinkReply() {
      'field_name' => 'comment',
      'pid' => $comment->id(),
    ]);
    $this->assertEquals((string) $replyto_comment, Link::fromTextAndUrl('Reply', $url)->toString(), 'Found the comment reply link as an admin user.');
    $this->assertSame((string) $replyto_comment, (string) Link::fromTextAndUrl('Reply', $url)->toString(), 'Found the comment reply link as an admin user.');

    // Check if I can see the reply link as an anonymous user.
    $account_switcher->switchTo(new AnonymousUserSession());
+6 −6
Original line number Diff line number Diff line
@@ -108,8 +108,8 @@ public function permissionsTestCases() {
        ],
        [
          'use simple_workflow transition publish' => [
            'title' => '<em class="placeholder">Simple Workflow</em> workflow: Use <em class="placeholder">Publish</em> transition.',
            'description' => 'Move content from <em class="placeholder">Draft, Published</em> states to <em class="placeholder">Published</em> state.',
            'title' => 'Simple Workflow workflow: Use Publish transition.',
            'description' => 'Move content from Draft, Published states to Published state.',
            'dependencies' => [
              'config' => [
                'workflows.workflow.simple_workflow',
@@ -117,8 +117,8 @@ public function permissionsTestCases() {
            ],
          ],
          'use simple_workflow transition create_new_draft' => [
            'title' => '<em class="placeholder">Simple Workflow</em> workflow: Use <em class="placeholder">Create New Draft</em> transition.',
            'description' => 'Move content from <em class="placeholder">Draft, Published</em> states to <em class="placeholder">Draft</em> state.',
            'title' => 'Simple Workflow workflow: Use Create New Draft transition.',
            'description' => 'Move content from Draft, Published states to Draft state.',
            'dependencies' => [
              'config' => [
                'workflows.workflow.simple_workflow',
@@ -126,8 +126,8 @@ public function permissionsTestCases() {
            ],
          ],
          'use simple_workflow transition archive' => [
            'title' => '<em class="placeholder">Simple Workflow</em> workflow: Use <em class="placeholder">Archive</em> transition.',
            'description' => 'Move content from <em class="placeholder">Published</em> state to <em class="placeholder">Archived</em> state.',
            'title' => 'Simple Workflow workflow: Use Archive transition.',
            'description' => 'Move content from Published state to Archived state.',
            'dependencies' => [
              'config' => [
                'workflows.workflow.simple_workflow',
Loading