You are here

public function CheckTest::testLastResultUpdate in Security Review 8

Tests stored result correction on lastResult() call.

Tests the case when the check doesn't store its findings, and the new result that lastResult() returns overwrites the old one if the result integer is not the same.

File

tests/src/Kernel/CheckTest.php, line 112

Class

CheckTest
Contains tests for Checks.

Namespace

Drupal\Tests\security_review\Kernel

Code

public function testLastResultUpdate() {
  foreach ($this->testChecks as $check) {
    if (!$check
      ->storesFindings()) {

      // Get the real result.
      $result = $check
        ->run();

      // Build the fake result.
      $new_result_result = $result
        ->result() == CheckResult::SUCCESS ? CheckResult::FAIL : CheckResult::SUCCESS;
      $new_result = new CheckResult($check, $new_result_result, [], TRUE);

      // Store it.
      $check
        ->storeResult($new_result);

      // Check if lastResult()'s result integer is the same as $result's.
      $last_result = $check
        ->lastResult(TRUE);
      $this
        ->assertEquals($result
        ->result(), $last_result
        ->result(), 'Invalid result got updated.');
    }
  }
}