You are here

public function ReadinessValidationTest::testReadinessCheckAfterInstall in Automatic Updates 8.2

Tests installing a module with a checker before installing automatic_updates.

File

tests/src/Functional/ReadinessValidationTest.php, line 299

Class

ReadinessValidationTest
Tests readiness validation.

Namespace

Drupal\Tests\automatic_updates\Functional

Code

public function testReadinessCheckAfterInstall() : void {
  $assert = $this
    ->assertSession();
  $this
    ->drupalLogin($this->checkerRunnerUser);
  $this
    ->drupalGet('admin/reports/status');
  $assert
    ->pageTextNotContains('Update readiness checks');

  // We have to install the automatic_updates_test module because it provides
  // the functionality to retrieve our fake release history metadata.
  $this->container
    ->get('module_installer')
    ->install([
    'automatic_updates',
    'automatic_updates_test',
  ]);
  $this
    ->drupalGet('admin/reports/status');
  $this
    ->assertReadinessReportMatches('Your site is ready for automatic updates. Run readiness checks now.', 'checked');
  $expected_results = $this->testResults['checker_1']['1 error'];
  TestChecker2::setTestResult($expected_results);
  $this->container
    ->get('module_installer')
    ->install([
    'automatic_updates_test2',
  ]);
  $this
    ->drupalGet('admin/structure');
  $assert
    ->pageTextContainsOnce($expected_results[0]
    ->getMessages()[0]);

  // Confirm that installing a module that does not provide a new checker does
  // not run the checkers on install.
  $unexpected_results = $this->testResults['checker_1']['2 errors 2 warnings'];
  TestChecker2::setTestResult($unexpected_results);
  $this->container
    ->get('module_installer')
    ->install([
    'help',
  ]);

  // Check for message on 'admin/structure' instead of the status report
  // because checkers will be run if needed on the status report.
  $this
    ->drupalGet('admin/structure');

  // Confirm that new checker message is not displayed because the checker was
  // not run again.
  $assert
    ->pageTextContainsOnce($expected_results[0]
    ->getMessages()[0]);
  $assert
    ->pageTextNotContains($unexpected_results['1:errors']
    ->getMessages()[0]);
  $assert
    ->pageTextNotContains($unexpected_results['1:errors']
    ->getSummary());
}