function CommentNonNodeTest::testsNonIntegerIdEntities

Same name and namespace in other branches
  1. 9 core/modules/comment/tests/src/Functional/CommentNonNodeTest.php \Drupal\Tests\comment\Functional\CommentNonNodeTest::testsNonIntegerIdEntities()
  2. 8.9.x core/modules/comment/tests/src/Functional/CommentNonNodeTest.php \Drupal\Tests\comment\Functional\CommentNonNodeTest::testsNonIntegerIdEntities()
  3. 11.x core/modules/comment/tests/src/Functional/CommentNonNodeTest.php \Drupal\Tests\comment\Functional\CommentNonNodeTest::testsNonIntegerIdEntities()

Tests comment fields cannot be added to entity types without integer IDs.

File

core/modules/comment/tests/src/Functional/CommentNonNodeTest.php, line 496

Class

CommentNonNodeTest
Tests commenting on a test entity.

Namespace

Drupal\Tests\comment\Functional

Code

public function testsNonIntegerIdEntities() : void {
  // Create a bundle for entity_test_string_id.
  entity_test_create_bundle('entity_test', 'Entity Test', 'entity_test_string_id');
  $limited_user = $this->drupalCreateUser([
    'administer entity_test_string_id fields',
    'administer comment types',
  ]);
  $this->drupalLogin($limited_user);
  // Visit the Field UI field add page.
  $this->drupalGet('entity_test_string_id/structure/entity_test/fields/add-field');
  // Ensure field isn't shown for string IDs.
  $this->assertSession()
    ->elementNotExists('css', "[name='new_storage_type'][value='comment']");
  // Ensure a core field type shown.
  $this->assertSession()
    ->elementExists('css', "[name='new_storage_type'][value='boolean']");
  // Attempt to add a comment-type referencing this entity-type.
  $this->drupalGet('admin/structure/comment/types/add');
  $this->assertSession()
    ->optionNotExists('edit-target-entity-type-id', 'entity_test_string_id');
  $this->assertSession()
    ->responseNotContains('Test entity with string_id');
  // Create a bundle for entity_test_no_id.
  entity_test_create_bundle('entity_test', 'Entity Test', 'entity_test_no_id');
  $this->drupalLogin($this->drupalCreateUser([
    'administer entity_test_no_id fields',
  ]));
  // Visit the Field UI field add page.
  $this->drupalGet('entity_test_no_id/structure/entity_test/fields/add-field');
  // Ensure field isn't shown for empty IDs.
  $this->assertSession()
    ->elementNotExists('css', "[name='new_storage_type'][value='comment']");
  // Ensure a core field type shown.
  $this->assertSession()
    ->elementExists('css', "[name='new_storage_type'][value='boolean']");
}

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