17e04b5c5cf775a7cbeb973190a1f5afbd470257
[yaffs-website] / web / core / modules / comment / tests / src / Functional / Views / CommentRestExportTest.php
1 <?php
2
3 namespace Drupal\Tests\comment\Functional\Views;
4
5 use Drupal\Component\Serialization\Json;
6 use Drupal\comment\Entity\Comment;
7
8 /**
9  * Tests a comment rest export view.
10  *
11  * @group comment
12  */
13 class CommentRestExportTest extends CommentTestBase {
14
15   /**
16    * Views used by this test.
17    *
18    * @var array
19    */
20   public static $testViews = ['test_comment_rest'];
21
22   /**
23    * {@inheritdoc}
24    */
25   public static $modules = ['node', 'comment', 'comment_test_views', 'rest', 'hal'];
26
27   protected function setUp($import_test_views = TRUE) {
28     parent::setUp($import_test_views);
29     // Add another anonymous comment.
30     $comment = [
31       'uid' => 0,
32       'entity_id' => $this->nodeUserCommented->id(),
33       'entity_type' => 'node',
34       'field_name' => 'comment',
35       'subject' => 'A lot, apparently',
36       'cid' => '',
37       'pid' => $this->comment->id(),
38       'mail' => 'someone@example.com',
39       'name' => 'bobby tables',
40       'hostname' => 'public.example.com',
41     ];
42     $this->comment = Comment::create($comment);
43     $this->comment->save();
44
45     $user = $this->drupalCreateUser(['access comments']);
46     $this->drupalLogin($user);
47   }
48
49
50   /**
51    * Test comment row.
52    */
53   public function testCommentRestExport() {
54     $this->drupalGet(sprintf('node/%d/comments', $this->nodeUserCommented->id()), ['query' => ['_format' => '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);
60
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');
65   }
66
67 }