You are here

public function UpgradeStatusUiTest::testUiAfterScan in Upgrade Status 8

Same name and namespace in other branches
  1. 8.3 tests/src/Functional/UpgradeStatusUiTest.php \Drupal\Tests\upgrade_status\Functional\UpgradeStatusUiTest::testUiAfterScan()
  2. 8.2 tests/src/Functional/UpgradeStatusUiTest.php \Drupal\Tests\upgrade_status\Functional\UpgradeStatusUiTest::testUiAfterScan()

Test the user interface after running a scan.

File

tests/src/Functional/UpgradeStatusUiTest.php, line 42

Class

UpgradeStatusUiTest
Tests the UI before and after running scans.

Namespace

Drupal\Tests\upgrade_status\Functional

Code

public function testUiAfterScan() {
  $this
    ->runFullScan();
  $page = $this
    ->getSession()
    ->getPage();
  $assert_session = $this
    ->assertSession();
  $assert_session
    ->buttonExists('Scan selected');
  $assert_session
    ->buttonExists('Export as HTML');

  // Custom projects have 3 columns of information.
  $upgrade_status_test_error = $page
    ->find('css', '.upgrade-status-summary-custom .project-upgrade_status_test_error');
  $this
    ->assertCount(3, $upgrade_status_test_error
    ->findAll('css', 'td'));
  $this
    ->assertSame('2 errors, 2 warnings', strip_tags($upgrade_status_test_error
    ->find('css', 'td.status-info')
    ->getHtml()));
  $upgrade_status_test_no_error = $page
    ->find('css', '.upgrade-status-summary-custom .project-upgrade_status_test_no_error');
  $this
    ->assertCount(3, $upgrade_status_test_no_error
    ->findAll('css', 'td'));
  $this
    ->assertSame('No known errors', $upgrade_status_test_no_error
    ->find('css', 'td.status-info')
    ->getHtml());
  $upgrade_status_test_submodules = $page
    ->find('css', '.upgrade-status-summary-custom .project-upgrade_status_test_submodules');
  $this
    ->assertCount(3, $upgrade_status_test_submodules
    ->findAll('css', 'td'));
  $this
    ->assertSame('No known errors', $upgrade_status_test_submodules
    ->find('css', 'td.status-info')
    ->getHtml());

  // Contributed modules should have one extra column because of possible
  // available update information.
  $upgrade_status_test_contrib_error = $page
    ->find('css', '.upgrade-status-summary-contrib .project-upgrade_status_test_contrib_error');
  $this
    ->assertCount(4, $upgrade_status_test_contrib_error
    ->findAll('css', 'td'));
  $this
    ->assertSame('1 error, 1 warning', strip_tags($upgrade_status_test_contrib_error
    ->find('css', 'td.status-info')
    ->getHtml()));
  $upgrade_status_test_contrib_no_error = $page
    ->find('css', '.upgrade-status-summary-contrib .project-upgrade_status_test_contrib_no_error');
  $this
    ->assertCount(4, $upgrade_status_test_contrib_no_error
    ->findAll('css', 'td'));
  $this
    ->assertSame('No known errors', $upgrade_status_test_contrib_no_error
    ->find('css', 'td.status-info')
    ->getHtml());

  // Click the '2 errors, 2 warnings' link. Should be the contrib project.
  $this
    ->clickLink('2 errors, 2 warnings');
  $this
    ->assertText('Upgrade status test error ' . \Drupal::VERSION);
  $this
    ->assertText('2 errors found. 2 warnings found.');
  $this
    ->assertText('Syntax error, unexpected T_STRING on line 3');

  // Go forward to the export page and assert that still contains the results
  // as well as an export specific title.
  $this
    ->clickLink('Export as HTML');
  $this
    ->assertText('Upgrade Status report');
  $this
    ->assertText('Upgrade status test error ' . \Drupal::VERSION);
  $this
    ->assertText('Custom projects');
  $this
    ->assertNoText('Contributed projects');
  $this
    ->assertText('2 errors found. 2 warnings found.');
  $this
    ->assertText('Syntax error, unexpected T_STRING on line 3');

  // Go back to the listing page and click over to exporting in single ASCII.
  $this
    ->drupalGet(Url::fromRoute('upgrade_status.report'));
  $this
    ->clickLink('2 errors, 2 warnings');
  $this
    ->clickLink('Export as ASCII');
  $this
    ->assertText('Upgrade status test error ' . \Drupal::VERSION);
  $this
    ->assertText('CUSTOM PROJECTS');
  $this
    ->assertNoText('CONTRIBUTED PROJECTS');
  $this
    ->assertText('2 errors found. 2 warnings found.');
  $this
    ->assertText('Syntax error, unexpected T_STRING on line 3');

  // Run partial export of multiple projects.
  $edit = [
    'custom[data][data][upgrade_status_test_error]' => TRUE,
    'custom[data][data][upgrade_status_test_no_error]' => TRUE,
    'contrib[data][data][upgrade_status_test_contrib_error]' => TRUE,
  ];
  $expected = [
    'Export as HTML' => [
      'Contributed projects',
      'Custom projects',
    ],
    'Export as ASCII' => [
      'CONTRIBUTED PROJECTS',
      'CUSTOM PROJECTS',
    ],
  ];
  foreach ($expected as $button => $assert) {
    $this
      ->drupalPostForm('admin/reports/upgrade-status', $edit, $button);
    $this
      ->assertText($assert[0]);
    $this
      ->assertText($assert[1]);
    $this
      ->assertText('Upgrade status test contrib error ' . \Drupal::VERSION);
    $this
      ->assertText('Upgrade status test no error ' . \Drupal::VERSION);
    $this
      ->assertText('Upgrade status test error ' . \Drupal::VERSION);
    $this
      ->assertNoText('Upgrade status test root module');
    $this
      ->assertNoText('Upgrade status test contrib no error');
    $this
      ->assertText('2 errors found. 2 warnings found.');
    $this
      ->assertText('Syntax error, unexpected T_STRING on line 3');
  }
}