public function PaymentReferenceWebTest::testWidget in Payment 8.2
Tests the widget.
File
- modules/
payment_reference/ tests/ src/ Functional/ Plugin/ Field/ FieldWidget/ PaymentReferenceWebTest.php, line 42
Class
- PaymentReferenceWebTest
- \Drupal\payment_reference\Plugin\Field\FieldWidget\PaymentReference web test.
Namespace
Drupal\Tests\payment_reference\Functional\Plugin\Field\FieldWidgetCode
public function testWidget() {
// Create the field and field instance.
$field_name = strtolower($this
->randomMachineName());
FieldStorageConfig::create(array(
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
'entity_type' => 'user',
'field_name' => $field_name,
'type' => 'payment_reference',
))
->save();
FieldConfig::create(array(
'bundle' => 'user',
'entity_type' => 'user',
'field_name' => $field_name,
'settings' => array(
'currency_code' => 'EUR',
'line_items' => [],
),
))
->save();
\Drupal::service('entity_display.repository')
->getFormDisplay('user', 'user', 'default')
->setComponent($field_name, [])
->save();
$user = $this
->drupalCreateUser(array(
'payment.payment.view.own',
));
$this
->drupalLogin($user);
$payment_method = Generate::createPaymentMethodConfiguration(mt_rand(), 'payment_basic');
$payment_method
->setPluginConfiguration(array(
'brand_label' => $this
->randomMachineName(),
'execute_status_id' => 'payment_success',
'message_text' => $this
->randomMachineName(),
));
$payment_method
->save();
// Test the widget when editing an entity.
$this
->drupalGet('user/' . $user
->id() . '/edit');
$this
->drupalPostForm(NULL, [], t('Re-check available payments'));
$this
->drupalPostForm(NULL, [], t('Pay'));
$this
->assertNoFieldByXPath('//input[@value="Pay"]');
$this
->assertLinkByHref('payment/1');
}