class EntityFormBuilderTest
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Entity/EntityFormBuilderTest.php \Drupal\Tests\Core\Entity\EntityFormBuilderTest
- 8.9.x core/tests/Drupal/Tests/Core/Entity/EntityFormBuilderTest.php \Drupal\Tests\Core\Entity\EntityFormBuilderTest
- 10 core/tests/Drupal/Tests/Core/Entity/EntityFormBuilderTest.php \Drupal\Tests\Core\Entity\EntityFormBuilderTest
@coversDefaultClass \Drupal\Core\Entity\EntityFormBuilder @group Entity
Hierarchy
- class \Drupal\Tests\Core\Entity\EntityFormBuilderTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of EntityFormBuilderTest
File
-
core/
tests/ Drupal/ Tests/ Core/ Entity/ EntityFormBuilderTest.php, line 14
Namespace
Drupal\Tests\Core\EntityView source
class EntityFormBuilderTest extends UnitTestCase {
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $entityTypeManager;
/**
* The form builder.
*
* @var \Drupal\Core\Form\FormBuilderInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $formBuilder;
/**
* The entity form builder.
*
* @var \Drupal\Core\Entity\EntityFormBuilderInterface
*/
protected $entityFormBuilder;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->formBuilder = $this->createMock('Drupal\\Core\\Form\\FormBuilderInterface');
$this->entityTypeManager = $this->createMock('Drupal\\Core\\Entity\\EntityTypeManagerInterface');
$this->entityFormBuilder = new EntityFormBuilder($this->entityTypeManager, $this->formBuilder);
}
/**
* Tests the getForm() method.
*
* @covers ::getForm
*/
public function testGetForm() : void {
$form_controller = $this->createMock('Drupal\\Core\\Entity\\EntityFormInterface');
$form_controller->expects($this->any())
->method('getFormId')
->willReturn('the_form_id');
$this->entityTypeManager
->expects($this->any())
->method('getFormObject')
->with('the_entity_type', 'default')
->willReturn($form_controller);
$this->formBuilder
->expects($this->once())
->method('buildForm')
->with($form_controller, $this->isInstanceOf('Drupal\\Core\\Form\\FormStateInterface'))
->willReturn('the form contents');
$entity = $this->createMock('Drupal\\Core\\Entity\\EntityInterface');
$entity->expects($this->once())
->method('getEntityTypeId')
->willReturn('the_entity_type');
$this->assertSame('the form contents', $this->entityFormBuilder
->getForm($entity));
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
EntityFormBuilderTest::$entityFormBuilder | protected | property | The entity form builder. | |
EntityFormBuilderTest::$entityTypeManager | protected | property | The entity type manager. | |
EntityFormBuilderTest::$formBuilder | protected | property | The form builder. | |
EntityFormBuilderTest::setUp | protected | function | Overrides UnitTestCase::setUp | |
EntityFormBuilderTest::testGetForm | public | function | Tests the getForm() method. | |
ExpectDeprecationTrait::expectDeprecation | public | function | Adds an expected deprecation. | |
ExpectDeprecationTrait::getCallableName | private static | function | Returns a callable as a string suitable for inclusion in a message. | |
ExpectDeprecationTrait::setUpErrorHandler | public | function | Sets up the test error handler. | |
ExpectDeprecationTrait::tearDownErrorHandler | public | function | Tears down the test error handler. | |
RandomGeneratorTrait::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | |
RandomGeneratorTrait::randomMachineName | protected | function | Generates a unique random string containing letters and numbers. | |
RandomGeneratorTrait::randomObject | public | function | Generates a random PHP object. | |
RandomGeneratorTrait::randomString | public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | |
UnitTestCase::$root | protected | property | The app root. | |
UnitTestCase::getClassResolverStub | protected | function | Returns a stub class resolver. | |
UnitTestCase::getConfigFactoryStub | public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase::getConfigStorageStub | public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase::setUpBeforeClass | public static | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.