You are here

public function AcquiaConnectorModuleTest::testAcquiaConnectorGetConnectedTests in Acquia Connector 8

Same name and namespace in other branches
  1. 8.2 tests/src/Functional/AcquiaConnectorModuleTest.php \Drupal\Tests\acquia_connector\Functional\AcquiaConnectorModuleTest::testAcquiaConnectorGetConnectedTests()
  2. 3.x tests/src/Functional/AcquiaConnectorModuleTest.php \Drupal\Tests\acquia_connector\Functional\AcquiaConnectorModuleTest::testAcquiaConnectorGetConnectedTests()

Test get connected.

File

tests/src/Functional/AcquiaConnectorModuleTest.php, line 281

Class

AcquiaConnectorModuleTest
Tests the functionality of the Acquia Connector module.

Namespace

Drupal\Tests\acquia_connector\Functional

Code

public function testAcquiaConnectorGetConnectedTests() {

  // Check for call to get connected.
  $this
    ->drupalGet('admin');
  $this
    ->assertText($this
    ->acquiaConnectorStrings('free'), 'The explanation of services text exists');
  $this
    ->assertLinkByHref($this->cloudFreeUrl, 0, 'Link to Acquia.com Cloud Services exists');
  $this
    ->assertText($this
    ->acquiaConnectorStrings('get-connected'), 'The call-to-action to connect text exists');
  $this
    ->assertLink('connect now', 0, 'The "connect now" link exists');

  // Check connection setup page.
  $this
    ->drupalGet($this->setupPath);
  $this
    ->assertText($this
    ->acquiaConnectorStrings('enter-email'), 'The email address field label exists');
  $this
    ->assertText($this
    ->acquiaConnectorStrings('enter-password'), 'The password field label exists');
  $this
    ->assertLinkByHref($this->cloudFreeUrl, 0, 'Link to Acquia.com free signup exists');

  // Check errors on automatic setup page.
  $edit_fields = [
    'email' => $this
      ->randomString(),
    'pass' => $this
      ->randomString(),
  ];
  $submit_button = 'Next';
  $this
    ->drupalPostForm($this->setupPath, $edit_fields, $submit_button);
  $this
    ->assertText($this
    ->acquiaConnectorStrings('account-not-found'), 'Account not found for random automatic setup attempt');
  $this
    ->assertText($this
    ->acquiaConnectorStrings('menu-inactive'), 'Subscription not active menu message appears');

  // Check manual connection.
  $this
    ->drupalGet($this->credentialsPath);
  $this
    ->assertText($this
    ->acquiaConnectorStrings('id-key'), 'The network key and id description exists');
  $this
    ->assertText($this
    ->acquiaConnectorStrings('enter-key'), 'The network key field label exists');
  $this
    ->assertLinkByHref($this->cloudFreeUrl, 0, 'Link to Acquia.com free signup exists');

  // Check errors on connection page.
  $edit_fields = [
    'acquia_identifier' => $this
      ->randomString(),
    'acquia_key' => $this
      ->randomString(),
  ];
  $submit_button = 'Connect';
  $this
    ->drupalPostForm($this->credentialsPath, $edit_fields, $submit_button);
  $this
    ->assertText($this
    ->acquiaConnectorStrings('subscription-not-found'), 'Subscription not found for random credentials');
  $this
    ->assertText($this
    ->acquiaConnectorStrings('menu-inactive'), 'Subscription not active menu message appears');

  // Connect site on key and id.
  $edit_fields = [
    'acquia_identifier' => $this->acqtestId,
    'acquia_key' => $this->acqtestKey,
  ];
  $submit_button = 'Connect';
  $this
    ->drupalPostForm($this->credentialsPath, $edit_fields, $submit_button);
  $this
    ->drupalGet($this->settingsPath);
  $this
    ->assertText($this
    ->acquiaConnectorStrings('subscription'), 'Subscription connected with key and identifier');
  $this
    ->assertLinkByHref($this->setupPath, 0, 'Link to change subscription exists');
  $this
    ->disconnectSite();

  // Connect via automatic setup.
  $edit_fields = [
    'email' => $this->acqtestEmail,
    'pass' => $this->acqtestPass,
  ];
  $submit_button = 'Next';
  $this
    ->drupalPostForm($this->setupPath, $edit_fields, $submit_button);
  $this
    ->drupalGet($this->setupPath);
  $this
    ->drupalGet($this->settingsPath);
  $this
    ->assertText($this
    ->acquiaConnectorStrings('subscription'), 'Subscription connected with credentials');

  // Confirm menu reports active subscription.
  $this
    ->drupalGet('admin');
  $this
    ->assertText($this
    ->acquiaConnectorStrings('menu-active'), 'Subscription active menu message appears');

  // Check errors if name or machine name empty.
  $submit_button = 'Save configuration';
  $this
    ->drupalPostForm($this->settingsPath, [], $submit_button);
  $this
    ->assertText($this
    ->acquiaConnectorStrings('site-name-required'), 'Name is required message appears');
  $this
    ->assertText($this
    ->acquiaConnectorStrings('site-machine-name-required'), 'Machine name is required message appears');

  // Acquia hosted sites.
  $edit_fields = [
    'acquia_dynamic_banner' => TRUE,
    'name' => 'test_name',
    'machine_name' => 'test_name',
  ];
  $submit_button = 'Save configuration';
  $this
    ->drupalPostForm($this->settingsPath, $edit_fields, $submit_button);
  $this
    ->assertFieldChecked('edit-acquia-dynamic-banner', '"Receive updates from Acquia" option stays saved');

  // Test acquia hosted site.
  $settings['_SERVER']['AH_SITE_NAME'] = (object) [
    'value' => 'acqtest_drupal',
    'required' => TRUE,
  ];
  $settings['_SERVER']['AH_SITE_ENVIRONMENT'] = (object) [
    'value' => 'dev',
    'required' => TRUE,
  ];
  $this
    ->writeSettings($settings);
  sleep(10);
  $this
    ->drupalGet($this->settingsPath);
  $elements = $this
    ->xpath('//input[@name=:name]', [
    ':name' => 'machine_name',
  ]);
  foreach ($elements as $element) {
    $this
      ->assertIdentical($element
      ->getAttribute('disabled'), 'disabled', 'Machine name field is disabled.');
  }
  $this
    ->disconnectSite();
}