/** * Tests the getForm() method. * * @covers ::getForm() */ public function testGetForm() { $form_controller = $this->getMock('Drupal\\Core\\Entity\\EntityFormInterface'); $form_controller->expects($this->any())->method('getFormId')->will($this->returnValue('the_form_id')); $this->entityManager->expects($this->any())->method('getFormObject')->with('the_entity_type', 'default')->will($this->returnValue($form_controller)); $this->formBuilder->expects($this->once())->method('buildForm')->with($form_controller, $this->isInstanceOf('Drupal\\Core\\Form\\FormStateInterface'))->will($this->returnValue('the form contents')); $entity = $this->getMock('Drupal\\Core\\Entity\\EntityInterface'); $entity->expects($this->once())->method('getEntityTypeId')->will($this->returnValue('the_entity_type')); $this->assertSame('the form contents', $this->entityFormBuilder->getForm($entity)); }
/** * @covers ::execute */ public function testExecute() { $bundle_exists = $this->randomMachineName(); $bundle_exists_definition = ['configuration_form' => $this->randomMachineName()]; $bundle_exists_no_form = $this->randomMachineName(); $bundle_exists_no_form_definition = []; $bundle_no_exists = $this->randomMachineName(); $bundle_no_exists_definition = NULL; $form_build = ['#type' => $this->randomMachineName()]; $this->formBuilder->expects($this->once())->method('getForm')->with($bundle_exists_definition['configuration_form'])->willReturn($form_build); $map = [[$bundle_exists, FALSE, $bundle_exists_definition], [$bundle_exists_no_form, FALSE, $bundle_exists_no_form_definition], [$bundle_no_exists, FALSE, $bundle_no_exists_definition]]; $this->paymentTypeManager->expects($this->any())->method('getDefinition')->willReturnMap($map); // Test with a bundle of a plugin with a form. $build = $this->sut->execute($bundle_exists); $this->assertSame($form_build, $build); // Test with a bundle of a plugin without a form. $build = $this->sut->execute($bundle_exists_no_form); $this->assertInternalType('array', $build); // Test with a non-existing bundle. $this->setExpectedException(NotFoundHttpException::class); $this->sut->execute($bundle_no_exists); }