コード例 #1
0
 /**
  * @covers ::formElement
  */
 public function testFormElement()
 {
     $entity_type_id = $this->randomMachineName();
     $bundle = $this->randomMachineName();
     $field_name = $this->randomMachineName();
     $user_id = mt_rand();
     $required = TRUE;
     $entity = $this->getMock(EntityInterface::class);
     $entity->expects($this->atLeastOnce())->method('bundle')->willReturn($bundle);
     $entity->expects($this->atLeastOnce())->method('getEntityTypeId')->willReturn($entity_type_id);
     $this->fieldDefinition->expects($this->once())->method('getName')->willReturn($field_name);
     $this->fieldDefinition->expects($this->once())->method('isRequired')->willReturn($required);
     $payment = $this->getMock(PaymentInterface::class);
     $this->paymentFactory->expects($this->once())->method('createPayment')->with($this->fieldDefinition)->willReturn($payment);
     $this->currentUser->expects($this->exactly(1))->method('id')->willReturn($user_id);
     $items = $this->getMockBuilder(FieldItemList::class)->disableOriginalConstructor()->getMock();
     $items->expects($this->atLeastOnce())->method('getEntity')->willReturn($entity);
     $form = [];
     $form_state = $this->getMock(FormStateInterface::class);
     $build = $this->sut->formElement($items, 3, [], $form, $form_state);
     $expected_build = array('target_id' => array('#default_value' => NULL, '#limit_allowed_plugin_ids' => $this->configFactoryConfiguration['payment_reference.payment_type']['allowed_plugin_ids'], '#plugin_selector_id' => $this->configFactoryConfiguration['payment_reference.payment_type']['plugin_selector_id'], '#prototype_payment' => $payment, '#queue_category_id' => $entity_type_id . '.' . $bundle . '.' . $field_name, '#queue_owner_id' => (int) $user_id, '#required' => $required, '#type' => 'payment_reference'));
     $this->assertSame($expected_build, $build);
 }