You are here

function NodeTypeTest::testNodeTypeCreation in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/node/src/Tests/NodeTypeTest.php \Drupal\node\Tests\NodeTypeTest::testNodeTypeCreation()

Tests creating a content type programmatically and via a form.

File

core/modules/node/src/Tests/NodeTypeTest.php, line 50
Contains \Drupal\node\Tests\NodeTypeTest.

Class

NodeTypeTest
Ensures that node type functions work correctly.

Namespace

Drupal\node\Tests

Code

function testNodeTypeCreation() {

  // Create a content type programmatically.
  $type = $this
    ->drupalCreateContentType();
  $type_exists = (bool) NodeType::load($type
    ->id());
  $this
    ->assertTrue($type_exists, 'The new content type has been created in the database.');

  // Login a test user.
  $web_user = $this
    ->drupalCreateUser(array(
    'create ' . $type
      ->label() . ' content',
  ));
  $this
    ->drupalLogin($web_user);
  $this
    ->drupalGet('node/add/' . $type
    ->id());
  $this
    ->assertResponse(200, 'The new content type can be accessed at node/add.');

  // Create a content type via the user interface.
  $web_user = $this
    ->drupalCreateUser(array(
    'bypass node access',
    'administer content types',
  ));
  $this
    ->drupalLogin($web_user);
  $this
    ->drupalGet('node/add');
  $this
    ->assertCacheTag('config:node_type_list');
  $this
    ->assertCacheContext('user.permissions');
  $elements = $this
    ->cssSelect('dl.node-type-list dt');
  $this
    ->assertEqual(3, count($elements));
  $edit = array(
    'name' => 'foo',
    'title_label' => 'title for foo',
    'type' => 'foo',
  );
  $this
    ->drupalPostForm('admin/structure/types/add', $edit, t('Save and manage fields'));
  $type_exists = (bool) NodeType::load('foo');
  $this
    ->assertTrue($type_exists, 'The new content type has been created in the database.');
  $this
    ->drupalGet('node/add');
  $elements = $this
    ->cssSelect('dl.node-type-list dt');
  $this
    ->assertEqual(4, count($elements));
}