You are here

public function CreateUITest::testAddPage in Entity API 8.0

Tests the add page.

File

tests/src/Functional/CreateUITest.php, line 48
Contains \Drupal\Tests\entity\Functional\CreateUITest.

Class

CreateUITest
Tests the entity creation UI provided by EntityCreateController.

Namespace

Drupal\Tests\entity\Functional

Code

public function testAddPage() {

  // This test revealed that if the first bundle gets created in testAddPage
  // before drupalGet(), the built cache won't get reset when the second
  // bundle is created. This is a BrowserTestBase specific bug.
  // @todo Remove comment when the bug is fixed.
  // When only one bundle exists, the add page should redirect to the form.
  $this
    ->drupalGet('/entity_test_enhanced/add');
  $this
    ->assertSession()
    ->addressEquals('/entity_test_enhanced/add/first');
  EnhancedEntityBundle::create([
    'id' => 'second',
    'label' => 'Second',
    'description' => 'The <b>second</b> bundle',
  ])
    ->save();
  $this
    ->drupalGet('/entity_test_enhanced/add');
  $assert = $this
    ->assertSession();
  $assert
    ->addressEquals('/entity_test_enhanced/add');
  $assert
    ->statusCodeEquals(200);
  $assert
    ->elementTextContains('css', '.page-title', 'Add entity test with enhancements');

  // Confirm the presence of unescaped descriptions.
  $assert
    ->responseContains('The first bundle');
  $assert
    ->responseContains('The <b>second</b> bundle');

  // Validate the links.
  $link = $this
    ->getSession()
    ->getPage()
    ->findLink('First');
  $this
    ->assertEquals('/entity_test_enhanced/add/first', $link
    ->getAttribute('href'));
  $link = $this
    ->getSession()
    ->getPage()
    ->findLink('Second');
  $this
    ->assertEquals('/entity_test_enhanced/add/second', $link
    ->getAttribute('href'));
}