function EntityAddUITest::testAddPageWithoutBundleEntities

Same name in other branches
  1. 9 core/modules/system/tests/src/Functional/Entity/EntityAddUITest.php \Drupal\Tests\system\Functional\Entity\EntityAddUITest::testAddPageWithoutBundleEntities()
  2. 8.9.x core/modules/system/tests/src/Functional/Entity/EntityAddUITest.php \Drupal\Tests\system\Functional\Entity\EntityAddUITest::testAddPageWithoutBundleEntities()
  3. 11.x core/modules/system/tests/src/Functional/Entity/EntityAddUITest.php \Drupal\Tests\system\Functional\Entity\EntityAddUITest::testAddPageWithoutBundleEntities()

Tests the add page for an entity type not using bundle entities.

File

core/modules/system/tests/src/Functional/Entity/EntityAddUITest.php, line 139

Class

EntityAddUITest
Tests the /add and /add/{type} controllers.

Namespace

Drupal\Tests\system\Functional\Entity

Code

public function testAddPageWithoutBundleEntities() : void {
    $admin_user = $this->drupalCreateUser([
        'administer entity_test content',
    ]);
    $this->drupalLogin($admin_user);
    entity_test_create_bundle('test', 'Test label', 'entity_test_mul');
    // Delete the default bundle, so that we can rely on our own. The form
    // display has to be deleted first to prevent schema errors when fields
    // attached to the deleted bundle are themselves deleted, which triggers
    // an update of the form display.
    $this->container
        ->get('entity_display.repository')
        ->getFormDisplay('entity_test_mul', 'entity_test_mul')
        ->delete();
    entity_test_delete_bundle('entity_test_mul', 'entity_test_mul');
    // One bundle exists, confirm redirection to the add-form.
    $this->drupalGet('/entity_test_mul/add');
    $this->assertSession()
        ->addressEquals('/entity_test_mul/add/test');
    // Two bundles exist, confirm both are shown.
    entity_test_create_bundle('test2', 'Test2 label', 'entity_test_mul');
    $this->drupalGet('/entity_test_mul/add');
    $this->assertSession()
        ->linkExists('Test label');
    $this->assertSession()
        ->linkExists('Test2 label');
    $this->clickLink('Test2 label');
    $this->drupalGet('/entity_test_mul/add/test2');
    $this->submitForm([
        'name[0][value]' => 'test name',
    ], 'Save');
    $entity = EntityTestMul::load(1);
    $this->assertEquals('test name', $entity->label());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.