3 namespace Drupal\comment\Tests\Views;
5 use Drupal\Component\Serialization\Json;
6 use Drupal\comment\Entity\Comment;
9 * Tests a comment rest export view.
13 class CommentRestExportTest extends CommentTestBase {
16 * Views used by this test.
20 public static $testViews = ['test_comment_rest'];
25 public static $modules = ['node', 'comment', 'comment_test_views', 'rest', 'hal'];
27 protected function setUp() {
29 // Add another anonymous comment.
32 'entity_id' => $this->nodeUserCommented->id(),
33 'entity_type' => 'node',
34 'field_name' => 'comment',
35 'subject' => 'A lot, apparently',
37 'pid' => $this->comment->id(),
38 'mail' => 'someone@example.com',
39 'name' => 'bobby tables',
40 'hostname' => 'public.example.com',
42 $this->comment = Comment::create($comment);
43 $this->comment->save();
45 $user = $this->drupalCreateUser(['access comments']);
46 $this->drupalLogin($user);
53 public function testCommentRestExport() {
54 $this->drupalGetWithFormat(sprintf('node/%d/comments', $this->nodeUserCommented->id()), 'hal_json');
55 $this->assertResponse(200);
56 $contents = Json::decode($this->getRawContent());
57 $this->assertEqual($contents[0]['subject'], 'How much wood would a woodchuck chuck');
58 $this->assertEqual($contents[1]['subject'], 'A lot, apparently');
59 $this->assertEqual(count($contents), 2);
61 // Ensure field-level access is respected - user shouldn't be able to see
62 // mail or hostname fields.
63 $this->assertNoText('someone@example.com');
64 $this->assertNoText('public.example.com');