908a86a3592e94dc4c225db514c44e2182fcfd25
[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    * Test comment row.
51    */
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);
59
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');
64   }
65
66 }