function EntityFormTest::testFormId

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/Tests/Core/Entity/EntityFormTest.php \Drupal\Tests\Core\Entity\EntityFormTest::testFormId()
  2. 10 core/tests/Drupal/Tests/Core/Entity/EntityFormTest.php \Drupal\Tests\Core\Entity\EntityFormTest::testFormId()
  3. 9 core/tests/Drupal/Tests/Core/Entity/EntityFormTest.php \Drupal\Tests\Core\Entity\EntityFormTest::testFormId()
  4. 8.9.x core/tests/Drupal/Tests/Core/Entity/EntityFormTest.php \Drupal\Tests\Core\Entity\EntityFormTest::testFormId()

Tests the form ID generation.

@legacy-covers ::getFormId

Attributes

#[DataProvider('providerTestFormIds')]

File

core/tests/Drupal/Tests/Core/Entity/EntityFormTest.php, line 57

Class

EntityFormTest
Tests Drupal\Core\Entity\EntityForm.

Namespace

Drupal\Tests\Core\Entity

Code

public function testFormId($expected, $definition) : void {
  $this->entityType
    ->set('entity_keys', [
    'bundle' => $definition['bundle'],
  ]);
  $entity = $this->getMockBuilder(StubEntityBase::class)
    ->setConstructorArgs([
    [],
    $definition['entity_type'],
  ])
    ->onlyMethods([
    'getEntityType',
    'bundle',
  ])
    ->getMock();
  $entity->expects($this->any())
    ->method('getEntityType')
    ->willReturn($this->entityType);
  $entity->expects($this->any())
    ->method('bundle')
    ->willReturn($definition['bundle']);
  $this->entityForm
    ->setEntity($entity);
  $this->entityForm
    ->setOperation($definition['operation']);
  $this->assertSame($expected, $this->entityForm
    ->getFormId());
}

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