Commit 59deeea6 authored by beagaliana's avatar beagaliana Committed by beagaliana
Browse files

Issue #3259603 by beagaliana: Add another key to test multiple choice

parent 7c59c180
Loading
Loading
Loading
Loading
+27 −6
Original line number Diff line number Diff line
@@ -2,8 +2,6 @@

namespace Drupal\Tests\whatsapp\Functional;

namespace Drupal\onlyone\Utility;

use Drupal\Tests\BrowserTestBase;

/**
@@ -17,7 +15,7 @@ class WhatsappFormTest extends BrowserTestBase
  /**
   * {@inheritdoc}
   */
  protected static $modules = ['whatsapp', 'whatsapp_test', 'key', 'user'];
  protected static $modules = ['whatsapp', 'key', 'user'];

  /**
   * {@inheritdoc}
@@ -29,7 +27,8 @@ class WhatsappFormTest extends BrowserTestBase
   */
  protected function setUp(): void {
    parent::setUp();
    $this->adminUser = $this->drupalCreateUser(['whatsapp configuration form',
    $this->adminUser = $this->drupalCreateUser([
      'whatsapp configuration form',
      'administer keys',
    ]);
    $this->drupalLogin($this->adminUser);
@@ -39,7 +38,6 @@ class WhatsappFormTest extends BrowserTestBase
   * Tests the config form.
   */
  public function testSettingsForm() {
    // Add a key with a 4 characters.
    $this->drupalGet('admin/config/system/keys/add');

    $testingKey = [
@@ -48,8 +46,20 @@ class WhatsappFormTest extends BrowserTestBase
      'key_type' => 'authentication',
      'key_input_settings[key_value]' => str_pad('', 4, 'z'),
    ];

    $this->submitForm($testingKey, 'Save');

    $this->drupalGet('admin/config/system/keys/add');

    $changedKey = [
      'id' => 'changed_key',
      'label' => 'Changed Key',
      'key_type' => 'authentication',
      'key_input_settings[key_value]' => str_pad('', 4, 'y'),
    ];

    $this->submitForm($changedKey, 'Save');

    $assert_session = $this->assertSession();

    $edit = [
@@ -60,8 +70,19 @@ class WhatsappFormTest extends BrowserTestBase
    $this->submitForm($edit, 'Save configuration');

    $assert_session->statusCodeEquals(200);
    $widget_key_testing = $this->container->get('config.factory')->get('whatsapp.settings')->get('widget_key');
    $this->assertEquals('Testing Key', $this->container->get('key.repository')->getKey($widget_key_testing)->label());

    $change = [
      'id' => 'changed_key',
    ];

    $assert_session->pageTextNotContains('No keys are available.');
    $this->drupalGet('admin/config/services/whatsapp');
    $this->submitForm($change, 'Save configuration');

    $assert_session->statusCodeEquals(200);
    $widget_key_changed = $this->container->get('config.factory')->get('whatsapp.settings')->get('widget_key');
    $this->assertEquals('Changed Key', $this->container->get('key.repository')->getKey($widget_key_changed)->label());

  }