public function EntityViewControllerTest::testEntityViewController in Drupal 9
Same name and namespace in other branches
- 8 core/modules/system/tests/src/Functional/Entity/EntityViewControllerTest.php \Drupal\Tests\system\Functional\Entity\EntityViewControllerTest::testEntityViewController()
Tests EntityViewController.
File
- core/
modules/ system/ tests/ src/ Functional/ Entity/ EntityViewControllerTest.php, line 49
Class
- EntityViewControllerTest
- Tests EntityViewController functionality.
Namespace
Drupal\Tests\system\Functional\EntityCode
public function testEntityViewController() {
$get_label_markup = function ($label) {
return '<h1 class="page-title">
<div class="field field--name-name field--type-string field--label-hidden field__item">' . $label . '</div>
</h1>';
};
foreach ($this->entities as $entity) {
$this
->drupalGet('entity_test/' . $entity
->id());
$this
->assertSession()
->pageTextContains($entity
->label());
$this
->assertSession()
->responseContains($get_label_markup($entity
->label()));
$this
->assertSession()
->pageTextContains('full');
$this
->drupalGet('entity_test_converter/' . $entity
->id());
$this
->assertSession()
->pageTextContains($entity
->label());
$this
->assertSession()
->pageTextContains('full');
$this
->drupalGet('entity_test_no_view_mode/' . $entity
->id());
$this
->assertSession()
->pageTextContains($entity
->label());
$this
->assertSession()
->pageTextContains('full');
}
// Test viewing a revisionable entity.
$entity_test_rev = $this
->createTestEntity('entity_test_rev');
$entity_test_rev
->save();
$entity_test_rev->name->value = 'rev 2';
$entity_test_rev
->setNewRevision(TRUE);
$entity_test_rev
->isDefaultRevision(TRUE);
$entity_test_rev
->save();
$this
->drupalGet('entity_test_rev/' . $entity_test_rev
->id() . '/revision/' . $entity_test_rev->revision_id->value . '/view');
$this
->assertSession()
->pageTextContains($entity_test_rev
->label());
$this
->assertSession()
->responseContains($get_label_markup($entity_test_rev
->label()));
// As entity_test IDs must be integers, make sure requests for non-integer
// IDs return a page not found error.
$this
->drupalGet('entity_test/invalid');
$this
->assertSession()
->statusCodeEquals(404);
}