X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fcomment%2Ftests%2Fsrc%2FFunctional%2FViews%2FCommentFieldNameTest.php;fp=web%2Fcore%2Fmodules%2Fcomment%2Ftests%2Fsrc%2FFunctional%2FViews%2FCommentFieldNameTest.php;h=a5e25be69c804934463edf1ac90c9f961fbaa47e;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hp=0000000000000000000000000000000000000000;hpb=aea91e65e895364e460983b890e295aa5d5540a5;p=yaffs-website diff --git a/web/core/modules/comment/tests/src/Functional/Views/CommentFieldNameTest.php b/web/core/modules/comment/tests/src/Functional/Views/CommentFieldNameTest.php new file mode 100644 index 000000000..a5e25be69 --- /dev/null +++ b/web/core/modules/comment/tests/src/Functional/Views/CommentFieldNameTest.php @@ -0,0 +1,92 @@ +addDefaultCommentField('node', 'page', $this->fieldName); + $this->customComment = Comment::create([ + 'entity_id' => $this->nodeUserCommented->id(), + 'entity_type' => 'node', + 'field_name' => $this->fieldName, + ]); + $this->customComment->save(); + } + + /** + * Test comment field name. + */ + 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); + } + +}