public function PaymentFormWebTest::testField in Payment 8.2
Tests the field.
File
- modules/
payment_form/ tests/ src/ Functional/ Plugin/ Field/ FieldType/ PaymentFormWebTest.php, line 33
Class
Namespace
Drupal\Tests\payment_form\Functional\Plugin\Field\FieldTypeCode
public function testField() {
// Create the field and field instance.
$field_name = strtolower($this
->randomMachineName());
FieldStorageConfig::create([
'cardinality' => FieldStorageConfigInterface::CARDINALITY_UNLIMITED,
'entity_type' => 'user',
'field_name' => $field_name,
'type' => 'payment_form',
])
->save();
FieldConfig::create([
'bundle' => 'user',
'entity_type' => 'user',
'field_name' => $field_name,
'settings' => [
'currency_code' => 'EUR',
],
])
->save();
// Set a field value on an entity and test getting it.
$user = User::create([
'name' => $this
->randomString(),
]);
foreach (Generate::createPaymentLineItems() as $line_item) {
$user
->get($field_name)
->appendItem([
'plugin_id' => $line_item
->getPluginId(),
'plugin_configuration' => $line_item
->getConfiguration(),
]);
}
$this
->assertFieldValue($user, $field_name);
// Save the entity, load it from storage and test getting the field value.
$user
->save();
$user = User::load($user
->id());
$this
->assertFieldValue($user, $field_name);
}