You are here

public function NodeTypeTest::testNodeTypeNoContentType in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/node/tests/src/Functional/NodeTypeTest.php \Drupal\Tests\node\Functional\NodeTypeTest::testNodeTypeNoContentType()
  2. 9 core/modules/node/tests/src/Functional/NodeTypeTest.php \Drupal\Tests\node\Functional\NodeTypeTest::testNodeTypeNoContentType()

Tests for when there are no content types defined.

File

core/modules/node/tests/src/Functional/NodeTypeTest.php, line 262

Class

NodeTypeTest
Ensures that node type functions work correctly.

Namespace

Drupal\Tests\node\Functional

Code

public function testNodeTypeNoContentType() {

  /** @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface $bundle_info */
  $bundle_info = \Drupal::service('entity_type.bundle.info');
  $this
    ->assertCount(2, $bundle_info
    ->getBundleInfo('node'), 'The bundle information service has 2 bundles for the Node entity type.');
  $web_user = $this
    ->drupalCreateUser([
    'administer content types',
  ]);
  $this
    ->drupalLogin($web_user);

  // Delete 'article' bundle.
  $this
    ->drupalGet('admin/structure/types/manage/article/delete');
  $this
    ->submitForm([], 'Delete');

  // Delete 'page' bundle.
  $this
    ->drupalGet('admin/structure/types/manage/page/delete');
  $this
    ->submitForm([], 'Delete');

  // Navigate to content type administration screen
  $this
    ->drupalGet('admin/structure/types');
  $this
    ->assertSession()
    ->pageTextContains("No content types available. Add content type.");
  $this
    ->assertSession()
    ->linkExists("Add content type");
  $this
    ->assertSession()
    ->linkByHrefExists(Url::fromRoute('node.type_add')
    ->toString());
  $bundle_info
    ->clearCachedBundles();
  $this
    ->assertCount(0, $bundle_info
    ->getBundleInfo('node'), 'The bundle information service has 0 bundles for the Node entity type.');
}