You are here

public function CommentFieldNameTest::testCommentFieldName in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/comment/src/Tests/Views/CommentFieldNameTest.php \Drupal\comment\Tests\Views\CommentFieldNameTest::testCommentFieldName()

Test comment field name.

File

core/modules/comment/src/Tests/Views/CommentFieldNameTest.php, line 61
Contains \Drupal\comment\Tests\Views\CommentFieldNameTest.

Class

CommentFieldNameTest
Tests the comment field name field.

Namespace

Drupal\comment\Tests\Views

Code

public function testCommentFieldName() {

  /** @var \Drupal\Core\Render\RendererInterface $renderer */
  $renderer = \Drupal::service('renderer');

  // Grant permission to properly check view access on render.
  user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, [
    'access comments',
  ]);
  $this->container
    ->get('account_switcher')
    ->switchTo(new AnonymousUserSession());
  $view = Views::getView('test_comment_field_name');
  $this
    ->executeView($view);
  $expected_result = [
    [
      'cid' => $this->comment
        ->id(),
      'field_name' => $this->comment
        ->getFieldName(),
    ],
    [
      'cid' => $this->customComment
        ->id(),
      'field_name' => $this->customComment
        ->getFieldName(),
    ],
  ];
  $column_map = [
    'cid' => 'cid',
    'comment_field_data_field_name' => 'field_name',
  ];
  $this
    ->assertIdenticalResultset($view, $expected_result, $column_map);

  // Test that data rendered.
  $output = $renderer
    ->executeInRenderContext(new RenderContext(), function () use ($view) {
    return $view->field['field_name']
      ->advancedRender($view->result[0]);
  });
  $this
    ->assertEqual($this->comment
    ->getFieldName(), $output);
  $output = $renderer
    ->executeInRenderContext(new RenderContext(), function () use ($view) {
    return $view->field['field_name']
      ->advancedRender($view->result[1]);
  });
  $this
    ->assertEqual($this->customComment
    ->getFieldName(), $output);
}