/** * @covers ::massageFormValues */ public function testMassageFormValues() { $field_name = $this->randomMachineName(); $payment_id = mt_rand(); $this->fieldDefinition->expects($this->atLeastOnce())->method('getName')->willReturn($field_name); $form_state = $this->getMock(FormStateInterface::class); $form[$field_name]['widget']['target_id']['#value'] = $payment_id; $values = []; $expected_value = array('target_id' => $payment_id); $this->assertSame($expected_value, $this->sut->massageFormValues($values, $form, $form_state)); }
/** * Tests the match method. */ public function testMatch() { $this->field->expects($this->any())->method('getType')->will($this->returnValue('crap')); $this->contact->expects($this->any())->method('getFieldDefinitions')->will($this->returnValue(array('foo' => $this->field))); $this->pluginManager->expects($this->any())->method('hasDefinition')->will($this->returnValue(TRUE)); $this->matchHandler->expects($this->any())->method('match')->will($this->returnValue(array('42' => array('value' => 100)))); // $this->pluginManager->expects($this->once()) // ->method('createInstance') // ->will($this->returnValue($this->matchHandler)); // $ids = $this->engine->match($this->contact); // $this->assertEquals([], $ids); }
/** * @covers ::formElementProcess */ public function testFormElementProcess() { $field_storage_definition = $this->getMock(FieldStorageDefinitionInterface::class); $this->fieldDefinition->expects($this->atLeastOnce())->method('getFieldStorageDefinition')->willReturn($field_storage_definition); $iterator = new \ArrayIterator([(object) ['plugin_configuration' => [], 'plugin_id' => $this->randomMachineName()]]); $items = $this->getMockBuilder(FieldItemList::class)->disableOriginalConstructor()->setMethods(['getIterator'])->getMock(); $items->expects($this->once())->method('getIterator')->willReturn($iterator); $element = ['#array_parents' => ['line_items'], '#items' => $items]; $form = []; $form_state = $this->getMock(FormStateInterface::class); $element = $this->sut->formElementProcess($element, $form_state, $form); $this->assertInternalType('array', $element); $this->arrayHasKey('array_parents', $element); $this->arrayHasKey('line_items', $element); }
/** * @covers ::viewElements */ public function testViewElements() { $entity_type_id = $this->randomMachineName(); $bundle = $this->randomMachineName(); $field_name = $this->randomMachineName(); $destination_url = $this->randomMachineName(); $currency_code = $this->randomMachineName(); $plugin_id = $this->randomMachineName(); $plugin_configuration = [$this->randomMachineName() => $this->randomMachineName()]; $plugin_id_property = $this->getMock(TypedDataInterface::class); $plugin_id_property->expects($this->once())->method('getValue')->willReturn($plugin_id); $plugin_configuration_property = $this->getMock(TypedDataInterface::class); $plugin_configuration_property->expects($this->once())->method('getValue')->willReturn($plugin_configuration); $map = [['plugin_id', $plugin_id_property], ['plugin_configuration', $plugin_configuration_property]]; $item = $this->getMockBuilder(PaymentFormFieldType::class)->disableOriginalConstructor()->getMock(); $item->expects($this->exactly(2))->method('get')->willReturnMap($map); $entity = $this->getMock(EntityInterface::class); $entity->expects($this->atLeastOnce())->method('bundle')->willReturn($bundle); $entity->expects($this->atLeastOnce())->method('getEntityTypeId')->willReturn($entity_type_id); $iterator = new \ArrayIterator([$item]); $items = $this->getMockBuilder(FieldItemList::class)->disableOriginalConstructor()->setMethods(['getEntity', 'getIterator'])->getMock(); $items->expects($this->atLeastOnce())->method('getEntity')->willReturn($entity); $items->expects($this->atLeastOnce())->method('getIterator')->willReturn($iterator); $this->fieldDefinition->expects($this->once())->method('getName')->willReturn($field_name); $this->fieldDefinition->expects($this->atLeastOnce())->method('getSetting')->with('currency_code')->willReturn($currency_code); $payment_type = $this->getMockBuilder(PaymentFormPaymentType::class)->disableOriginalConstructor()->getMock(); $payment_type->expects($this->once())->method('setEntityTypeId')->with($entity_type_id); $payment_type->expects($this->once())->method('setBundle')->with($bundle); $payment_type->expects($this->once())->method('setFieldName')->with($field_name); $payment_type->expects($this->once())->method('setDestinationUrl')->with($destination_url); $payment = $this->getMock(PaymentInterface::class); $payment->expects($this->once())->method('setCurrencyCode')->with($currency_code); $payment->expects($this->once())->method('getPaymentType')->willReturn($payment_type); $payment_line_item = $this->getMock(PaymentLineItemInterface::class); $this->paymentLineItemManager->expects($this->once())->method('createInstance')->with($plugin_id, $plugin_configuration)->willReturn($payment_line_item); $this->paymentStorage->expects($this->once())->method('create')->with(['bundle' => 'payment_form'])->willReturn($payment); $this->request->expects($this->atLeastOnce())->method('getUri')->willReturn($destination_url); $form = ['#foo' => $this->randomMachineName()]; $this->entityFormBuilder->expects($this->once())->method('getForm')->with($payment, 'payment_form')->willReturn($form); $this->assertSame($form, $this->sut->viewElements($items, 'en')); }