function NodeCreationTest::testNodeAddWithoutContentTypes

Same name in other branches
  1. 9 core/modules/node/tests/src/Functional/NodeCreationTest.php \Drupal\Tests\node\Functional\NodeCreationTest::testNodeAddWithoutContentTypes()
  2. 8.9.x core/modules/node/tests/src/Functional/NodeCreationTest.php \Drupal\Tests\node\Functional\NodeCreationTest::testNodeAddWithoutContentTypes()
  3. 10 core/modules/node/tests/src/Functional/NodeCreationTest.php \Drupal\Tests\node\Functional\NodeCreationTest::testNodeAddWithoutContentTypes()

Check node/add when no node types exist.

File

core/modules/node/tests/src/Functional/NodeCreationTest.php, line 289

Class

NodeCreationTest
Create a node and test saving it.

Namespace

Drupal\Tests\node\Functional

Code

public function testNodeAddWithoutContentTypes() : void {
    $this->drupalGet('node/add');
    $this->assertSession()
        ->statusCodeEquals(200);
    $this->assertSession()
        ->linkByHrefNotExists('/admin/structure/types/add');
    // Test /node/add page without content types.
    foreach (\Drupal::entityTypeManager()->getStorage('node_type')
        ->loadMultiple() as $entity) {
        $entity->delete();
    }
    $this->drupalGet('node/add');
    $this->assertSession()
        ->statusCodeEquals(403);
    $admin_content_types = $this->drupalCreateUser([
        'administer content types',
    ]);
    $this->drupalLogin($admin_content_types);
    $this->drupalGet('node/add');
    $this->assertSession()
        ->linkByHrefExists('/admin/structure/types/add');
}

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