3 namespace Drupal\Tests\comment\Functional\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($import_test_views = TRUE) {
28 parent::setUp($import_test_views);
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);
52 public function testCommentRestExport() {
53 $this->drupalGet(sprintf('node/%d/comments', $this->nodeUserCommented->id()), ['query' => ['_format' => 'hal_json']]);
54 $this->assertResponse(200);
55 $contents = Json::decode($this->getSession()->getPage()->getContent());
56 $this->assertEqual($contents[0]['subject'], 'How much wood would a woodchuck chuck');
57 $this->assertEqual($contents[1]['subject'], 'A lot, apparently');
58 $this->assertEqual(count($contents), 2);
60 // Ensure field-level access is respected - user shouldn't be able to see
61 // mail or hostname fields.
62 $this->assertNoText('someone@example.com');
63 $this->assertNoText('public.example.com');