Commit d2683f29 authored by George's avatar George
Browse files

Issue #3265729 by geoanders: Update tests to account for Key module and test key saving.

parent 0e2b7558
Loading
Loading
Loading
Loading
+49 −8
Original line number Diff line number Diff line
@@ -2,7 +2,9 @@

namespace Drupal\Tests\az_blob_fs\Functional;

use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Url;

/**
 * Tests Azure Blog Storage configuration form.
@@ -30,7 +32,7 @@ class AzBlobFsConfigFormTest extends AzBlobFsTestBase {
  /**
   * {@inheritdoc}
   */
  protected static $modules = ['az_blob_fs'];
  protected static $modules = ['az_blob_fs', 'key'];

  /**
   * {@inheritdoc}
@@ -42,11 +44,13 @@ class AzBlobFsConfigFormTest extends AzBlobFsTestBase {
   */
  public function testAzBlobFsConfigurationFormAccess() {

    // Setup admin user.
    $this->adminUser = $this->drupalCreateUser([
      'access administration pages',
      'administer site configuration',
      'administer az_blob_fs',
      'administer keys',
    ]);

    // Perform login.
    $this->drupalLogin($this->adminUser);

    // Access to the path.
@@ -78,21 +82,58 @@ class AzBlobFsConfigFormTest extends AzBlobFsTestBase {

  /**
   * Test the Azure Blog Storage config form.
   *
   * @throws \Behat\Mink\Exception\ResponseTextException
   */
  public function testAzBlobFsConfigurationForm() {

    // Setup admin user.
    $this->adminUser = $this->drupalCreateUser([
      'access administration pages',
      'administer site configuration',
      'administer az_blob_fs',
      'administer keys',
    ]);

    // Perform login.
    $this->drupalLogin($this->adminUser);

    $edit['az_blob_account_name'] = $this->azBlobFsConfig['az_blob_account_name'];
    $edit['az_blob_container_name'] = $this->azBlobFsConfig['az_blob_container_name'];
    // Go to the Key list page.
    $this->drupalGet('admin/config/system/keys');
    $this->assertSession()->statusCodeEquals(200);

    // @todo Add key name testing via Key module.
    // Verify that the "no keys" message displays.
    $this->assertSession()->responseContains(
      new FormattableMarkup('No keys are available. <a href=":link">Add a key</a>.', [
        ':link' => Url::fromRoute('entity.key.add_form')->toString(),
      ]));

    // Add a key.
    $this->drupalGet('admin/config/system/keys/add');
    $edit = [
      'id' => $this->azBlobFsConfig['az_blob_account_key_name'],
      'label' => 'Azure Access Key',
      'key_type' => 'authentication',
      'key_provider' => 'config',
      'key_input_settings[key_value]' => $this->azBlobFsConfig['az_blob_account_key'],
    ];
    $this->drupalPostForm(NULL, $edit, 'Save');

    // Go to the Key list page.
    $this->drupalGet('admin/config/system/keys');
    $this->assertSession()->statusCodeEquals(200);

    // Verify that the "no keys" message does not display.
    $this->assertSession()->pageTextNotContains('No keys are available.');

    // Get Azure Blob Storage config page.
    $this->drupalGet('admin/config/media/az_blob_fs');
    $this->assertSession()->statusCodeEquals(200);

    // Update Azure Blob Storage config.
    $edit = [
      'az_blob_account_name' => $this->azBlobFsConfig['az_blob_account_name'],
      'az_blob_container_name' => $this->azBlobFsConfig['az_blob_container_name'],
      'az_blob_account_key_name' => $this->azBlobFsConfig['az_blob_account_key_name'],
    ];
    $this->drupalPostForm('admin/config/media/az_blob_fs', $edit, $this->t('Save configuration'));
    $this->assertSession()->statusCodeEquals(200);
  }
+1 −1
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ class AzBlobFsInstallTest extends WebDriverTestBase {
  /**
   * {@inheritdoc}
   */
  protected static $modules = ['az_blob_fs'];
  protected static $modules = ['az_blob_fs', 'key'];

  /**
   * Assert that the az_blob_fs module installed correctly.
+4 −7
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ abstract class AzBlobFsTestBase extends BrowserTestBase {
   *
   * @var array
   */
  protected static $modules = ['az_blob_fs'];
  protected static $modules = ['az_blob_fs', 'key'];

  /**
   * {@inheritdoc}
@@ -56,19 +56,16 @@ abstract class AzBlobFsTestBase extends BrowserTestBase {
   *   A config object.
   */
  protected function prepareConfig(Config $config) {
    // @todo Figure out how to have a pre-setup account for testing?
    $this->azBlobFsConfig = [
      'az_blob_account_name' => 'devstoreaccount1',
      'az_blob_account_key_name' => 'azure_account_key',
      'az_blob_account_key' => 'Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==',
      'az_blob_container_name' => 'devstorecontainer',
    ];

    // @todo Setup key via Key module

    // Configuration for test bots here.
    // Setup dummy data below.
    // Set configuration.
    $config
      ->set('az_blob_account_name', $this->azBlobFsConfig['az_blob_account_name'])
      ->set('az_blob_account_key_name', '')
      ->set('az_blob_container_name', $this->azBlobFsConfig['az_blob_container_name'])
      ->save();
  }