You are here

public function EntityAddUITest::testAddPageWithoutBundleEntities in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/system/tests/src/Functional/Entity/EntityAddUITest.php \Drupal\Tests\system\Functional\Entity\EntityAddUITest::testAddPageWithoutBundleEntities()
  2. 9 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 126

Class

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

Namespace

Drupal\Tests\system\Functional\Entity

Code

public function testAddPageWithoutBundleEntities() {
  $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.
  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());
}