function NodeTypeTest::testNodeTypeNoContentType

Same name in other branches
  1. 9 core/modules/node/tests/src/Functional/NodeTypeTest.php \Drupal\Tests\node\Functional\NodeTypeTest::testNodeTypeNoContentType()
  2. 8.9.x core/modules/node/tests/src/Functional/NodeTypeTest.php \Drupal\Tests\node\Functional\NodeTypeTest::testNodeTypeNoContentType()
  3. 10 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 266

Class

NodeTypeTest
Ensures that node type functions work correctly.

Namespace

Drupal\Tests\node\Functional

Code

public function testNodeTypeNoContentType() : void {
    
    /** @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.');
}

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