3 namespace Drupal\Tests\Core\Entity;
5 use Drupal\Core\Entity\EntityFormBuilder;
6 use Drupal\Tests\UnitTestCase;
9 * @coversDefaultClass \Drupal\Core\Entity\EntityFormBuilder
12 class EntityFormBuilderTest extends UnitTestCase {
17 * @var \Drupal\Core\Entity\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject
19 protected $entityManager;
24 * @var \Drupal\Core\Form\FormBuilderInterface|\PHPUnit_Framework_MockObject_MockObject
26 protected $formBuilder;
29 * The entity form builder.
31 * @var \Drupal\Core\Entity\EntityFormBuilderInterface
33 protected $entityFormBuilder;
38 protected function setUp() {
41 $this->formBuilder = $this->getMock('Drupal\Core\Form\FormBuilderInterface');
42 $this->entityManager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
43 $this->entityFormBuilder = new EntityFormBuilder($this->entityManager, $this->formBuilder);
47 * Tests the getForm() method.
51 public function testGetForm() {
52 $form_controller = $this->getMock('Drupal\Core\Entity\EntityFormInterface');
53 $form_controller->expects($this->any())
55 ->will($this->returnValue('the_form_id'));
56 $this->entityManager->expects($this->any())
57 ->method('getFormObject')
58 ->with('the_entity_type', 'default')
59 ->will($this->returnValue($form_controller));
61 $this->formBuilder->expects($this->once())
63 ->with($form_controller, $this->isInstanceOf('Drupal\Core\Form\FormStateInterface'))
64 ->will($this->returnValue('the form contents'));
66 $entity = $this->getMock('Drupal\Core\Entity\EntityInterface');
67 $entity->expects($this->once())
68 ->method('getEntityTypeId')
69 ->will($this->returnValue('the_entity_type'));
71 $this->assertSame('the form contents', $this->entityFormBuilder->getForm($entity));