You are here

public function AcquiaConnectorModuleTest::testSpiChangeFormTests in Acquia Connector 3.x

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

Tests the SPI change form.

This should be a separate test.

File

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

Class

AcquiaConnectorModuleTest
Tests the functionality of the Acquia Connector module.

Namespace

Drupal\Tests\acquia_connector\Functional

Code

public function testSpiChangeFormTests() {

  // 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');

  // No changes detected.
  $edit_fields = [
    'acquia_dynamic_banner' => TRUE,
    'name' => $this->acqtestName,
    'machine_name' => $this->acqtestMachineName,
  ];
  $submit_button = 'Save configuration';
  $this
    ->drupalPostForm($this->settingsPath, $edit_fields, $submit_button);
  $this
    ->assertText($this
    ->acquiaConnectorStrings('saved'), 'The configuration options have been saved.');
  $this
    ->drupalGet($this->statusReportUrl);
  $this
    ->clickLink('manually send SPI data');
  $this
    ->drupalGet($this->environmentChangePath);
  $this
    ->assertText('No changes detected', 'No changes are currently detected.');

  // Detect Changes.
  $edit_fields = [
    'acquia_dynamic_banner' => TRUE,
    'name' => $this->acqtestName,
    'machine_name' => $this->acqtestMachineName . '_change',
  ];
  $submit_button = 'Save configuration';
  $this
    ->drupalPostForm($this->settingsPath, $edit_fields, $submit_button);
  $this
    ->assertText($this
    ->acquiaConnectorStrings('saved'), 'The configuration options have been saved.');
  $this
    ->assertText('A change has been detected in your site environment. Please check the Acquia SPI status on your Status Report page for more information', 'Changes have been detected');
  $this
    ->drupalGet($this->environmentChangePath);

  // Check environment change action.
  $elements = $this
    ->xpath('//input[@name=:name]', [
    ':name' => 'env_change_action',
  ]);
  $expected_values = [
    'block',
    'update',
    'create',
  ];
  foreach ($elements as $element) {
    $expected = array_shift($expected_values);
    $this
      ->assertIdentical($element
      ->getAttribute('value'), $expected);
  }

  // Test "block" the connector from sending data to NSPI.
  $edit_fields = [
    'env_change_action' => 'block',
  ];
  $submit_button = 'Save configuration';
  $this
    ->drupalPostForm($this->environmentChangePath, $edit_fields, $submit_button);
  $this
    ->assertText('This site has been disabled from sending profile data to Acquia.');
  $this
    ->assertText('You have disabled your site from sending data to Acquia Cloud.');

  // Test unblock site.
  $this
    ->clickLink('Enable this site');
  $this
    ->assertText('The Acquia Connector is disabled and is not sending site profile data to Acquia Cloud for evaluation.');
  $edit_fields = [
    'env_change_action[unblock]' => TRUE,
  ];
  $submit_button = 'Save configuration';
  $this
    ->drupalPostForm($this->environmentChangePath, $edit_fields, $submit_button);
  $this
    ->assertText('Your site has been enabled and is sending data to Acquia Cloud.');
  $this
    ->clickLink('manually send SPI data');
  $this
    ->assertText('A change has been detected in your site environment. Please check the Acquia SPI status on your Status Report page for more information.');

  // Test update existing site.
  $this
    ->clickLink('confirm the action you wish to take');
  $edit_fields = [
    'env_change_action' => 'update',
  ];
  $submit_button = 'Save configuration';
  $this
    ->drupalPostForm($this->environmentChangePath, $edit_fields, $submit_button);

  // Test new site in Acquia Cloud.
  $edit_fields = [
    'acquia_dynamic_banner' => TRUE,
    'name' => $this->acqtestName,
    'machine_name' => $this->acqtestMachineName,
  ];
  $submit_button = 'Save configuration';
  $this
    ->drupalPostForm($this->settingsPath, $edit_fields, $submit_button);
  $this
    ->assertText($this
    ->acquiaConnectorStrings('saved'), 'The configuration options have been saved.');
  $this
    ->assertText('A change has been detected in your site environment. Please check the Acquia SPI status on your Status Report page for more information.');
  $this
    ->drupalGet($this->statusReportUrl);
  $this
    ->clickLink('confirm the action you wish to take');
  $edit_fields = [
    'env_change_action' => 'create',
    'name' => '',
    'machine_name' => '',
  ];
  $submit_button = 'Save configuration';
  $this
    ->drupalPostForm($this->environmentChangePath, $edit_fields, $submit_button);
  $this
    ->assertText($this
    ->acquiaConnectorStrings('site-name-required'), 'Name field is required.');
  $this
    ->assertText($this
    ->acquiaConnectorStrings('site-machine-name-required'), 'Machine name field is required.');
  $edit_fields = [
    'env_change_action' => 'create',
    'name' => $this->acqtestName,
    'machine_name' => $this->acqtestMachineName,
  ];
  $submit_button = 'Save configuration';
  $this
    ->drupalPostForm($this->environmentChangePath, $edit_fields, $submit_button);
  $this
    ->assertText($this
    ->acquiaConnectorStrings('first-connection'), 'First connection from this site');
}