public function AcquiaConnectorSpiTest::testAcquiaSpiGetTests in Acquia Connector 8
Same name and namespace in other branches
- 8.2 tests/src/Functional/AcquiaConnectorSpiTest.php \Drupal\Tests\acquia_connector\Functional\AcquiaConnectorSpiTest::testAcquiaSpiGetTests()
- 3.x tests/src/Functional/AcquiaConnectorSpiTest.php \Drupal\Tests\acquia_connector\Functional\AcquiaConnectorSpiTest::testAcquiaSpiGetTests()
Test Acquia SPI get.
File
- tests/
src/ Functional/ AcquiaConnectorSpiTest.php, line 415
Class
- AcquiaConnectorSpiTest
- Tests the functionality of the Acquia SPI module.
Namespace
Drupal\Tests\acquia_connector\FunctionalCode
public function testAcquiaSpiGetTests() {
// Connect site on non-error key and id.
$this
->connectSite();
$edit_fields = [
'name' => $this->acqtestName,
'machine_name' => $this->acqtestMachineName,
];
$submit_button = 'Save configuration';
$this
->drupalPostForm($this->settingsPath, $edit_fields, $submit_button);
// Test spiControllerTest::get.
$spi = new SpiController(\Drupal::service('acquia_connector.client'), \Drupal::service('config.factory'), \Drupal::service('path_alias.manager'));
$spi_data = $spi
->get();
$valid = is_array($spi_data);
$this
->assertTrue($valid, 'spiController::get returns an array');
if ($valid) {
foreach ($this->spiDataKeys as $key) {
if (!array_key_exists($key, $spi_data)) {
$valid = FALSE;
break;
}
}
$this
->assertTrue($valid, 'Array has expected keys');
$private_key = \Drupal::service('private_key')
->get();
$this
->assertEqual(sha1($private_key), $spi_data['site_key'], 'Site key is sha1 of Drupal private key');
$this
->assertNotEmpty($spi_data['spi_data_version'], 'SPI data version is set');
$vars = Json::decode($spi_data['system_vars']);
$this
->assertIsArray($vars, 'SPI data system_vars is a JSON-encoded array');
$this
->assertArrayHasKey('test_variable_3', $vars, 'test_variable_3 included in SPI data');
$this
->assertNotEmpty($spi_data['modules'], 'Modules is not empty');
$modules = [
'status',
'name',
'version',
'package',
'core',
'project',
'filename',
'module_data',
];
$diff = array_diff(array_keys($spi_data['modules'][0]), $modules);
$this
->assertEmpty($diff, 'Module elements have expected keys');
$diff = array_diff(array_keys($spi_data['platform']), $this->platformKeys);
$this
->assertEmpty($diff, 'Platform contains expected keys');
$roles = Json::decode($spi_data['roles']);
$this
->assertIsArray($roles, 'Roles is an array');
$this
->assertArrayHasKey('anonymous', $roles, 'Roles array contains anonymous user');
}
}