Commit c84a4206 authored by bojanz's avatar bojanz

Sort the gateway plugins on the admin add form, fix tests.

parent b1cfa002
......@@ -5,6 +5,7 @@ namespace Drupal\commerce_payment\Form;
use Drupal\commerce\Form\CommercePluginEntityFormBase;
use Drupal\commerce_payment\PaymentGatewayManager;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\SortArray;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -46,6 +47,7 @@ class PaymentGatewayForm extends CommercePluginEntityFormBase {
$plugins = array_map(function ($definition) {
return $definition['label'];
}, $this->pluginManager->getDefinitions());
uasort($plugins, [SortArray::class, 'sortByTitleElement']);
// Use the first available plugin as the default value.
if (!$gateway->getPluginId()) {
......
......@@ -38,8 +38,8 @@ class PaymentGatewayTest extends CommerceBrowserTestBase {
$values = [
'label' => 'Example',
'plugin' => 'example_onsite',
'configuration[api_key]' => 'bunny',
'plugin' => 'example_offsite_redirect',
'configuration[redirect_method]' => 'post',
'configuration[mode]' => 'test',
'status' => '1',
// Setting the 'id' can fail if focus switches to another field.
......@@ -54,12 +54,12 @@ class PaymentGatewayTest extends CommerceBrowserTestBase {
$payment_gateway = PaymentGateway::load('example');
$this->assertEquals('example', $payment_gateway->id());
$this->assertEquals('Example', $payment_gateway->label());
$this->assertEquals('example_onsite', $payment_gateway->getPluginId());
$this->assertEquals('example_offsite_redirect', $payment_gateway->getPluginId());
$this->assertEquals(TRUE, $payment_gateway->status());
$payment_gateway_plugin = $payment_gateway->getPlugin();
$this->assertEquals('test', $payment_gateway_plugin->getMode());
$configuration = $payment_gateway_plugin->getConfiguration();
$this->assertEquals('bunny', $configuration['api_key']);
$this->assertEquals('post', $configuration['redirect_method']);
}
/**
......@@ -69,14 +69,14 @@ class PaymentGatewayTest extends CommerceBrowserTestBase {
$values = [
'id' => 'edit_example',
'label' => 'Edit example',
'plugin' => 'example_onsite',
'plugin' => 'example_offsite_redirect',
'status' => TRUE,
];
$payment_gateway = $this->createEntity('commerce_payment_gateway', $values);
$this->drupalGet('admin/commerce/config/payment-gateways/manage/' . $payment_gateway->id());
$values += [
'configuration[api_key]' => 'donkey',
'configuration[redirect_method]' => 'get',
'configuration[mode]' => 'live',
];
$this->submitForm($values, 'Save');
......@@ -85,12 +85,12 @@ class PaymentGatewayTest extends CommerceBrowserTestBase {
$payment_gateway = PaymentGateway::load('edit_example');
$this->assertEquals('edit_example', $payment_gateway->id());
$this->assertEquals('Edit example', $payment_gateway->label());
$this->assertEquals('example_onsite', $payment_gateway->getPluginId());
$this->assertEquals('example_offsite_redirect', $payment_gateway->getPluginId());
$this->assertEquals(TRUE, $payment_gateway->status());
$payment_gateway_plugin = $payment_gateway->getPlugin();
$this->assertEquals('live', $payment_gateway_plugin->getMode());
$configuration = $payment_gateway_plugin->getConfiguration();
$this->assertEquals('donkey', $configuration['api_key']);
$this->assertEquals('get', $configuration['redirect_method']);
}
/**
......@@ -100,7 +100,7 @@ class PaymentGatewayTest extends CommerceBrowserTestBase {
$payment_gateway = $this->createEntity('commerce_payment_gateway', [
'id' => 'for_deletion',
'label' => 'For deletion',
'plugin' => 'example_onsite',
'plugin' => 'example_offsite_redirect',
]);
$this->drupalGet('admin/commerce/config/payment-gateways/manage/' . $payment_gateway->id() . '/delete');
$this->submitForm([], 'Delete');
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment