View source
<?php
namespace Drupal\Tests\payment_form\Functional\Plugin\Field\FieldWidget;
use Drupal\Tests\BrowserTestBase;
class PaymentFormWebTest extends BrowserTestBase {
public static $modules = [
'field_ui',
'payment',
'payment_form',
];
protected $defaultTheme = 'stark';
public function testWidget() {
$config_importer = \Drupal::service('currency.config_importer');
$config_importer
->importCurrency('EUR');
$user = $this
->drupalCreateUser([
'administer user fields',
]);
$this
->drupalLogin($user);
$field_name = strtolower($this
->randomMachineName());
$this
->drupalPostForm('admin/config/people/accounts/fields/add-field', [
'label' => $this
->randomString(),
'field_name' => $field_name,
'new_storage_type' => 'payment_form',
], t('Save and continue'));
$this
->drupalPostForm(NULL, [], t('Save field settings'));
$this
->drupalPostForm(NULL, [], t('Add and configure a new line item'));
$this
->drupalPostForm(NULL, [
'default_value_input[field_' . $field_name . '][line_items][line_items][payment_basic][plugin_form][description]' => $this
->randomString(),
], t('Save settings'));
$field_names = \Drupal::entityQuery('field_storage_config')
->condition('type', 'payment_form')
->execute();
$this
->assertTrue(in_array('user.field_' . $field_name, $field_names));
$this
->drupalPostForm('user/' . $user
->id() . '/edit', [
'field_' . $field_name . '[line_items][add_more][type]' => 'payment_basic',
], t('Add and configure a new line item'));
$description = $this
->randomString();
$this
->drupalPostForm(NULL, [
'field_' . $field_name . '[line_items][line_items][payment_basic][plugin_form][amount][amount]' => '9,87',
'field_' . $field_name . '[line_items][line_items][payment_basic][plugin_form][amount][currency_code]' => 'EUR',
'field_' . $field_name . '[line_items][line_items][payment_basic][plugin_form][description]' => $description,
'field_' . $field_name . '[line_items][line_items][payment_basic][plugin_form][quantity]' => 37,
], t('Save'));
$this
->drupalGet('user/' . $user
->id() . '/edit');
$this
->assertFieldByName('field_' . $field_name . '[line_items][line_items][payment_basic][plugin_form][amount][amount]', '9.87');
$this
->assertFieldByName('field_' . $field_name . '[line_items][line_items][payment_basic][plugin_form][amount][currency_code]', 'EUR');
$this
->assertFieldByName('field_' . $field_name . '[line_items][line_items][payment_basic][plugin_form][description]', $description);
$this
->assertFieldByName('field_' . $field_name . '[line_items][line_items][payment_basic][plugin_form][quantity]', 37);
}
}