class CommentHalExportTest
Tests a comment rest export view.
@group hal @group legacy
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait implements \PHPUnit\Framework\TestCase
- class \Drupal\Tests\views\Functional\ViewTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait implements \Drupal\Tests\BrowserTestBase
- class \Drupal\Tests\comment\Functional\Views\CommentTestBase uses \Drupal\comment\Tests\CommentTestTrait implements \Drupal\Tests\views\Functional\ViewTestBase
- class \Drupal\Tests\hal\Functional\comment\Views\CommentHalExportTest implements \Drupal\Tests\comment\Functional\Views\CommentTestBase
- class \Drupal\Tests\comment\Functional\Views\CommentTestBase uses \Drupal\comment\Tests\CommentTestTrait implements \Drupal\Tests\views\Functional\ViewTestBase
- class \Drupal\Tests\views\Functional\ViewTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait implements \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of CommentHalExportTest
File
-
core/
modules/ hal/ tests/ src/ Functional/ comment/ Views/ CommentHalExportTest.php, line 15
Namespace
Drupal\Tests\hal\Functional\comment\ViewsView source
class CommentHalExportTest extends CommentTestBase {
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = [
'test_comment_hal',
];
/**
* {@inheritdoc}
*/
protected static $modules = [
'node',
'comment',
'hal_test_views',
'rest',
'hal',
];
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE, $modules = [
'hal_test_views',
]) : void {
parent::setUp($import_test_views, $modules);
// Add another anonymous comment.
$comment = [
'uid' => 0,
'entity_id' => $this->nodeUserCommented
->id(),
'entity_type' => 'node',
'field_name' => 'comment',
'subject' => 'A lot, apparently',
'cid' => '',
'pid' => $this->comment
->id(),
'mail' => 'someone@example.com',
'name' => 'bobby tables',
'hostname' => 'public.example.com',
];
$this->comment = Comment::create($comment);
$this->comment
->save();
$user = $this->drupalCreateUser([
'access comments',
]);
$this->drupalLogin($user);
}
/**
* Tests comment row.
*/
public function testCommentRestExport() {
$this->drupalGet(sprintf('node/%d/comments', $this->nodeUserCommented
->id()), [
'query' => [
'_format' => 'hal_json',
],
]);
$this->assertSession()
->statusCodeEquals(200);
$contents = Json::decode($this->getSession()
->getPage()
->getContent());
$this->assertEquals('How much wood would a woodchuck chuck', $contents[0]['subject']);
$this->assertEquals('A lot, apparently', $contents[1]['subject']);
$this->assertCount(2, $contents);
// Ensure field-level access is respected - user shouldn't be able to see
// mail or hostname fields.
$this->assertSession()
->responseNotContains('someone@example.com');
$this->assertSession()
->responseNotContains('public.example.com');
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.