You are here

protected function ValidationTestTrait::createTestValidationResults in Automatic Updates 8.2

Creates ValidationResult objects to be used in tests.

3 calls to ValidationTestTrait::createTestValidationResults()
ReadinessValidationManagerTest::setUp in tests/src/Kernel/ReadinessValidation/ReadinessValidationManagerTest.php
ReadinessValidationTest::setUp in tests/src/Functional/ReadinessValidationTest.php
UpdaterFormTest::testUpdateErrors in tests/src/Functional/UpdaterFormTest.php
Tests handling of errors and warnings during the update process.

File

tests/src/Traits/ValidationTestTrait.php, line 36

Class

ValidationTestTrait
Common methods for testing validation.

Namespace

Drupal\Tests\automatic_updates\Traits

Code

protected function createTestValidationResults() : void {

  // Set up various validation results for the test checkers.
  foreach ([
    1,
    2,
  ] as $listener_number) {

    // Set test validation results.
    $this->testResults["checker_{$listener_number}"]['1 error'] = [
      ValidationResult::createError([
        t("{$listener_number}:OMG 🚒. Your server is on 🔥!"),
      ], t("{$listener_number}:Summary: 🔥")),
    ];
    $this->testResults["checker_{$listener_number}"]['1 error 1 warning'] = [
      "{$listener_number}:error" => ValidationResult::createError([
        t("{$listener_number}:OMG 🔌. Some one unplugged the server! How is this site even running?"),
      ], t("{$listener_number}:Summary: 🔥")),
      "{$listener_number}:warning" => ValidationResult::createWarning([
        t("{$listener_number}:It looks like it going to rain and your server is outside."),
      ], t("{$listener_number}:Warnings summary not displayed because only 1 warning message.")),
    ];
    $this->testResults["checker_{$listener_number}"]['2 errors 2 warnings'] = [
      "{$listener_number}:errors" => ValidationResult::createError([
        t("{$listener_number}:😬Your server is in a cloud, a literal cloud!☁️."),
        t("{$listener_number}:😂PHP only has 32k memory."),
      ], t("{$listener_number}:Errors summary displayed because more than 1 error message")),
      "{$listener_number}:warnings" => ValidationResult::createWarning([
        t("{$listener_number}:Your server is a smart fridge. Will this work?"),
        t("{$listener_number}:Your server case is duct tape!"),
      ], t("{$listener_number}:Warnings summary displayed because more than 1 warning message.")),
    ];
    $this->testResults["checker_{$listener_number}"]['2 warnings'] = [
      ValidationResult::createWarning([
        t("{$listener_number}:The universe could collapse in on itself in the next second, in which case automatic updates will not run."),
        t("{$listener_number}:An asteroid could hit your server farm, which would also stop automatic updates from running."),
      ], t("{$listener_number}:Warnings summary displayed because more than 1 warning message.")),
    ];
    $this->testResults["checker_{$listener_number}"]['1 warning'] = [
      ValidationResult::createWarning([
        t("{$listener_number}:This is your one and only warning. You have been warned."),
      ], t("{$listener_number}:No need for this summary with only 1 warning.")),
    ];
  }
}