diff --git a/tests/src/Functional/PaymentAdminTest.php b/tests/src/Functional/PaymentAdminTest.php index 79049bd..542f202 100644 --- a/tests/src/Functional/PaymentAdminTest.php +++ b/tests/src/Functional/PaymentAdminTest.php @@ -29,13 +29,15 @@ protected function getAdministratorPermissions() { } /** - * Tests creating a payment gateway. + * Tests creating a payment gateway through the admin UI. */ public function testPaymentGatewayCreation() { + // Go to the admin UI and start adding a new payment gateway. $this->drupalGet('admin/commerce/config/payment-gateways'); $this->getSession()->getPage()->clickLink('Add payment gateway'); $this->assertSession()->addressEquals('admin/commerce/config/payment-gateways/add'); + // Create an array of values to be posted to the add form. $values = [ 'label' => 'SIPS', 'plugin' => 'sips_payment', @@ -47,23 +49,47 @@ public function testPaymentGatewayCreation() { 'configuration[sips_key_version]' => 'owl', ]; $this->submitForm($values, 'Save'); + + // Check that we ended up on the overview. $this->assertSession()->addressEquals('admin/commerce/config/payment-gateways'); $this->assertSession()->responseContains('SIPS'); $this->assertSession()->responseContains('Test'); + // Edit the same gateway again; and check that the values were saved + // correctly. + $this->drupalGet('admin/commerce/config/payment-gateways/manage/example'); + $this->assertSession()->fieldValueEquals('configuration[sips_merchant_id]', 'giraffe'); + $this->assertSession()->fieldValueEquals('configuration[sips_passphrase]', 'kitten'); + $this->assertSession()->fieldValueEquals('configuration[sips_payment_method]', ''); + + // Save the optional payment method field and check that has been saved + // correctly and that the other fields haven't been emptied. + $this->submitForm(['configuration[sips_payment_method]' => 'bunny'], 'Save'); + $this->drupalGet('admin/commerce/config/payment-gateways/manage/example'); + $this->assertSession()->fieldValueEquals('configuration[sips_merchant_id]', 'giraffe'); + $this->assertSession()->fieldValueEquals('configuration[sips_passphrase]', 'kitten'); + $this->assertSession()->fieldValueEquals('configuration[sips_payment_method]', 'bunny'); + + // Load the payment gateway through the API. $payment_gateway = PaymentGateway::load('example'); $this->assertEquals('example', $payment_gateway->id()); $this->assertEquals('SIPS', $payment_gateway->label()); $this->assertEquals('sips_payment', $payment_gateway->getPluginId()); $this->assertTrue($payment_gateway->status()); + + // Load the plugin from the gateway and check it's configuration. $payment_gateway_plugin = $payment_gateway->getPlugin(); $this->assertEquals('0', $payment_gateway_plugin->getMode()); + $this->assertEquals('SIPS Payment bunny', $payment_gateway_plugin->getDisplayLabel()); + // Load the configuration of the gateway plugin and check that the values we + // set earlier are here. $configuration = $payment_gateway_plugin->getConfiguration(); $this->assertEquals('llama', $configuration['sips_interface_version']); $this->assertEquals('kitten', $configuration['sips_passphrase']); $this->assertEquals('giraffe', $configuration['sips_merchant_id']); $this->assertEquals('owl', $configuration['sips_key_version']); + $this->assertEquals('bunny', $configuration['sips_payment_method']); } }