You are here

public function TestStatusController::testStatus in Acquia Connector 8

Same name and namespace in other branches
  1. 8.2 src/Controller/TestStatusController.php \Drupal\acquia_connector\Controller\TestStatusController::testStatus()
  2. 3.x src/Controller/TestStatusController.php \Drupal\acquia_connector\Controller\TestStatusController::testStatus()

Determines status of user-contributed tests.

Determines the status of all user-contributed tests and logs any failures to a tracking table.

Parameters

bool $log: (Optional) If TRUE, log all failures.

Return value

array|\Symfony\Component\HttpFoundation\RedirectResponse An associative array containing any tests which failed validation.

1 string reference to 'TestStatusController::testStatus'
acquia_connector.routing.yml in ./acquia_connector.routing.yml
acquia_connector.routing.yml

File

src/Controller/TestStatusController.php, line 24

Class

TestStatusController
Class SpiController.

Namespace

Drupal\acquia_connector\Controller

Code

public function testStatus($log = FALSE) {
  $custom_data = [];

  // Iterate through modules which contain hook_acquia_spi_test().
  foreach ($this
    ->moduleHandler()
    ->getImplementations('acquia_connector_spi_test') as $module) {
    $function = $module . '_acquia_connector_spi_test';
    if (function_exists($function)) {
      $result = $this
        ->testValidate($function());
      if (!$result['result']) {
        $custom_data[$module] = $result;
        foreach ($result['failure'] as $test_name => $test_failures) {
          foreach ($test_failures as $test_param => $test_value) {
            $variables = [
              '@module' => $module,
              '@message' => $test_value['message'],
              '@param_name' => $test_param,
              '@test' => $test_name,
              '@value' => $test_value['value'],
            ];

            // Only log if we're performing a full validation check.
            if ($log) {
              $this
                ->messenger()
                ->addError($this
                ->t("Custom test validation failed for @test in @module and has been logged: @message for parameter '@param_name'; current value '@value'.", $variables));
              $this
                ->getLogger('acquia spi test')
                ->notice("<em>Custom test validation failed</em>: @message for parameter '@param_name'; current value '@value'. (<em>Test '@test_name' in module '@module_name'</em>)", $variables);
            }
          }
        }
      }
    }
  }

  // If a full validation check is being performed, go to the status page to
  // show the results.
  if ($log) {
    return $this
      ->redirect('system.status');
  }
  return $custom_data;
}