Commit 1dbabe7e authored by Gábor Hojtsy's avatar Gábor Hojtsy
Browse files

Issue #3168546 by Gábor Hojtsy: Fix automated tests on 3.x branch

parent 344aa6d0
......@@ -99,7 +99,7 @@ class ScanResultController extends ControllerBase {
}
$build = ['#theme' => 'upgrade_status_' . $format . '_export' ];
$build['#projects'][empty($extension->info['project']) ? 'custom' : 'contrib'] = [
$build['#projects'][$extension->info['upgrade_status_type'] == ProjectCollector::TYPE_CUSTOM ? 'custom' : 'contrib'] = [
$project_machine_name =>
$format == 'html' ?
$this->resultFormatter->formatResult($extension) :
......
......@@ -239,7 +239,7 @@ class UpgradeStatusForm extends FormBase {
'#type' => 'submit',
'#value' => $this->t('Export selected as HTML'),
'#weight' => 5,
'#submit' => [[$this, 'exportReportHTML']],
'#submit' => [[$this, 'exportReport']],
'#disabled' => !$analyzer_ready,
];
$form['drupal_upgrade_status_form']['action']['export_ascii'] = [
......@@ -283,7 +283,9 @@ class UpgradeStatusForm extends FormBase {
'#options' => [],
];
foreach ($projects as $name => $extension) {
$option = [];
$option = [
'#attributes' => ['class' => 'project-' . $name],
];
$option['project'] = [
'data' => [
'label' => [
......@@ -334,7 +336,7 @@ class UpgradeStatusForm extends FormBase {
];
$report = $this->projectCollector->getResults($name);
$result_summary = $this->t('N/A');
$result_summary = !empty($report) ? $this->t('No problems found') : $this->t('N/A');
if (!empty($report['data']['totals']['file_errors'])) {
$result_summary = $this->formatPlural(
$report['data']['totals']['file_errors'],
......@@ -354,7 +356,8 @@ class UpgradeStatusForm extends FormBase {
'height' => 568,
]),
],
]
],
'class' => 'scan-result',
];
}
else {
......@@ -364,7 +367,8 @@ class UpgradeStatusForm extends FormBase {
'#type' => 'markup',
'#markup' => $result_summary,
],
]
],
'class' => 'scan-result',
];
}
......@@ -921,52 +925,23 @@ MARKUP
* An associative array containing the structure of the form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*/
public function exportReportHTML(array &$form, FormStateInterface $form_state) {
$selected = $form_state->getValues();
$form_state->setResponse($this->exportReport($selected, 'html'));
}
/**
* Form submission handler.
*
* @param array $form
* An associative array containing the structure of the form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*/
public function exportReportASCII(array &$form, FormStateInterface $form_state) {
$selected = $form_state->getValues();
$form_state->setResponse($this->exportReport($selected, 'ascii'));
}
/**
* Export generator.
*
* @param array $selected
* Selected projects from the form.
* @param string $format
* The format of export to do: html or ascii.
*
* @return \Symfony\Component\HttpFoundation\Response
* Response object for this export.
* Either 'html' or 'ascii' depending on what the format should be.
*/
public function exportReport(array $selected, string $format) {
public function exportReport(array &$form, FormStateInterface $form_state, string $format = 'html') {
$extensions = [];
$projects = $this->projectCollector->collectProjects();
foreach (['custom', 'contrib'] as $type) {
$states = ['uninstalled', 'installed'];
foreach ($states as $state) {
if (!empty($selected[$type]['data'][$state])) {
foreach($selected[$type]['data'][$state] as $project => $checked) {
if ($checked !== 0) {
// If the checkbox was checked, add it to the list.
$extensions[$type][$project] =
$format == 'html' ?
$this->resultFormatter->formatResult($projects[$type][$project]) :
$this->resultFormatter->formatAsciiResult($projects[$type][$project]);
}
$submitted = $form_state->getValues();
$next_steps = $this->projectCollector->getNextStepInfo();
foreach ($next_steps as $next_step => $step_label) {
if (!empty($submitted[$next_step]['data']['list'])) {
foreach ($submitted[$next_step]['data']['list'] as $item) {
if (isset($projects[$item])) {
$type = $projects[$item]->info['upgrade_status_type'] == ProjectCollector::TYPE_CUSTOM ? 'custom' : 'contrib';
$extensions[$type][$item] =
$format == 'html' ?
$this->resultFormatter->formatResult($projects[$item]) :
$this->resultFormatter->formatAsciiResult($projects[$item]);
}
}
}
......@@ -988,7 +963,19 @@ MARKUP
$response = new Response($this->renderer->renderRoot($build));
$response->headers->set('Content-Disposition', 'attachment; filename="' . $filename . '"');
return $response;
$form_state->setResponse($response);
}
/**
* Form submission handler.
*
* @param array $form
* An associative array containing the structure of the form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*/
public function exportReportASCII(array &$form, FormStateInterface $form_state) {
$this->exportReport($form, $form_state, 'ascii');
}
/**
......
......@@ -350,7 +350,7 @@ class ProjectCollector {
foreach ($extensions as $name_b => $extension_b) {
// Skip collation for test modules except where we test that.
if ((strpos($name_b, 'upgrade_status_test_') === 0) && (strpos($name_b, 'upgrade_status_test_submodules_') !== 0)) {
if ((strpos($name_b, 'upgrade_status_test_') === 0) && ($name_b != 'upgrade_status_test_submodules_a') && ($name_b != 'upgrade_status_test_submodules_with_errors_a')) {
continue;
}
......
name: 'Upgrade status test library'
name: 'Upgrade status test library exception'
type: module
description: 'Support module for upgrade status module testing.'
package: Testing
......
......@@ -32,9 +32,8 @@ class UpgradeStatusAnalyzeTest extends UpgradeStatusTestBase {
// and we always want to run the scan on root modules.
$this->assertFalse($key_value->has('upgrade_status_test_submodules_a'));
$project = $key_value->get('upgrade_status_test_error');
$this->assertNotEmpty($project);
$report = json_decode($project, TRUE);
$report = $key_value->get('upgrade_status_test_error');
$this->assertNotEmpty($report);
$this->assertEquals(4, $report['data']['totals']['file_errors']);
$this->assertCount(4, $report['data']['files']);
$file = reset($report['data']['files']);
......@@ -46,15 +45,13 @@ class UpgradeStatusAnalyzeTest extends UpgradeStatusTestBase {
$this->assertEquals("Call to deprecated function menu_cache_clear_all(). Deprecated in drupal:8.6.0 and is removed from drupal:9.0.0. Use \Drupal::cache('menu')->invalidateAll() instead.", $message['message']);
$this->assertEquals(10, $message['line']);
$project = $key_value->get('upgrade_status_test_no_error');
$this->assertNotEmpty($project);
$report = json_decode($project, TRUE);
$report = $key_value->get('upgrade_status_test_no_error');
$this->assertNotEmpty($report);
$this->assertEquals(0, $report['data']['totals']['file_errors']);
$this->assertCount(0, $report['data']['files']);
$project = $key_value->get('upgrade_status_test_contrib_error');
$this->assertNotEmpty($project);
$report = json_decode($project, TRUE);
$report = $key_value->get('upgrade_status_test_contrib_error');
$this->assertNotEmpty($report);
$this->assertEquals(2, $report['data']['totals']['file_errors']);
$this->assertCount(2, $report['data']['files']);
$file = reset($report['data']['files']);
......@@ -62,9 +59,8 @@ class UpgradeStatusAnalyzeTest extends UpgradeStatusTestBase {
$this->assertEquals("Call to deprecated function drupal_set_message(). Deprecated in drupal:8.5.0 and is removed from drupal:9.0.0. Use Drupal\Core\Messenger\MessengerInterface::addMessage() instead.", $message['message']);
$this->assertEquals(13, $message['line']);
$project = $key_value->get('upgrade_status_test_twig');
$this->assertNotEmpty($project);
$report = json_decode($project, TRUE);
$report = $key_value->get('upgrade_status_test_twig');
$this->assertNotEmpty($report);
$this->assertEquals(3, $report['data']['totals']['file_errors']);
$this->assertCount(1, $report['data']['files']);
$file = reset($report['data']['files']);
......@@ -75,9 +71,8 @@ class UpgradeStatusAnalyzeTest extends UpgradeStatusTestBase {
$this->assertEquals('Template is attaching a deprecated library. The "upgrade_status_test_twig/deprecated_library" asset library is deprecated for testing.', $file['messages'][2]['message']);
$this->assertEquals(2, $file['messages'][2]['line']);
$project = $key_value->get('upgrade_status_test_theme');
$this->assertNotEmpty($project);
$report = json_decode($project, TRUE);
$report = $key_value->get('upgrade_status_test_theme');
$this->assertNotEmpty($report);
$this->assertEquals(4, $report['data']['totals']['file_errors']);
$this->assertCount(3, $report['data']['files']);
$file = reset($report['data']['files']);
......@@ -93,9 +88,8 @@ class UpgradeStatusAnalyzeTest extends UpgradeStatusTestBase {
$this->assertEquals('The theme is overriding the "upgrade_status_test_theme_function_theme_function_override" theme function. Theme functions are deprecated. For more info, see https://www.drupal.org/node/2575445.', $file['messages'][0]['message']);
$this->assertEquals(6, $file['messages'][0]['line']);
$project = $key_value->get('upgrade_status_test_theme_functions');
$this->assertNotEmpty($project);
$report = json_decode($project, TRUE);
$report = $key_value->get('upgrade_status_test_theme_functions');
$this->assertNotEmpty($report);
$this->assertEquals(3, $report['data']['totals']['file_errors']);
$this->assertCount(1, $report['data']['files']);
$file = reset($report['data']['files']);
......@@ -106,9 +100,8 @@ class UpgradeStatusAnalyzeTest extends UpgradeStatusTestBase {
$this->assertEquals('The module is defining an unknown theme function. Theme functions are deprecated. For more info, see https://www.drupal.org/node/2575445.', $file['messages'][2]['message']);
$this->assertEquals(21, $file['messages'][2]['line']);
$project = $key_value->get('upgrade_status_test_library');
$this->assertNotEmpty($project);
$report = json_decode($project, TRUE);
$report = $key_value->get('upgrade_status_test_library');
$this->assertNotEmpty($report);
$this->assertEquals(4, $report['data']['totals']['file_errors']);
$this->assertCount(2, $report['data']['files']);
$file = reset($report['data']['files']);
......@@ -122,9 +115,8 @@ class UpgradeStatusAnalyzeTest extends UpgradeStatusTestBase {
$this->assertEquals('The referenced library is deprecated. The "upgrade_status_test_twig/deprecated_library" asset library is deprecated for testing.', $file['messages'][1]['message']);
$this->assertEquals(10, $file['messages'][1]['line']);
$project = $key_value->get('upgrade_status_test_library_exception');
$this->assertNotEmpty($project);
$report = json_decode($project, TRUE);
$report = $key_value->get('upgrade_status_test_library_exception');
$this->assertNotEmpty($report);
$this->assertEquals(1, $report['data']['totals']['file_errors']);
$this->assertCount(1, $report['data']['files']);
$file = reset($report['data']['files']);
......@@ -133,9 +125,8 @@ class UpgradeStatusAnalyzeTest extends UpgradeStatusTestBase {
// Module upgrade_status_test_submodules_with_error_a shouldn't have scan
// result, but its info.yml errors should appear in its parent scan.
$this->assertFalse($key_value->has('upgrade_status_test_submodules_with_error_a'));
$project = $key_value->get('upgrade_status_test_submodules_with_error');
$this->assertNotEmpty($project);
$report = json_decode($project, TRUE);
$report = $key_value->get('upgrade_status_test_submodules_with_error');
$this->assertNotEmpty($report);
$this->assertEquals(2, $report['data']['totals']['file_errors']);
$this->assertCount(2, $report['data']['files']);
}
......
......@@ -47,18 +47,18 @@ abstract class UpgradeStatusTestBase extends BrowserTestBase {
*/
protected function runFullScan() {
$edit = [
'contrib[data][installed][upgrade_status]' => TRUE,
'custom[data][installed][upgrade_status_test_error]' => TRUE,
'custom[data][installed][upgrade_status_test_no_error]' => TRUE,
'custom[data][installed][upgrade_status_test_submodules]' => TRUE,
'custom[data][installed][upgrade_status_test_submodules_with_error]' => TRUE,
'custom[data][installed][upgrade_status_test_twig]' => TRUE,
'custom[data][installed][upgrade_status_test_theme]' => TRUE,
'custom[data][installed][upgrade_status_test_theme_functions]' => TRUE,
'custom[data][installed][upgrade_status_test_library]' => TRUE,
'custom[data][installed][upgrade_status_test_library_exception]' => TRUE,
'contrib[data][installed][upgrade_status_test_contrib_error]' => TRUE,
'contrib[data][installed][upgrade_status_test_contrib_no_error]' => TRUE,
'relax[data][list][upgrade_status]' => TRUE,
'scan[data][list][upgrade_status_test_error]' => TRUE,
'scan[data][list][upgrade_status_test_no_error]' => TRUE,
'scan[data][list][upgrade_status_test_submodules]' => TRUE,
'scan[data][list][upgrade_status_test_submodules_with_error]' => TRUE,
'scan[data][list][upgrade_status_test_twig]' => TRUE,
'scan[data][list][upgrade_status_test_theme]' => TRUE,
'scan[data][list][upgrade_status_test_theme_functions]' => TRUE,
'scan[data][list][upgrade_status_test_library]' => TRUE,
'scan[data][list][upgrade_status_test_library_exception]' => TRUE,
'collaborate[data][list][upgrade_status_test_contrib_error]' => TRUE,
'relax[data][list][upgrade_status_test_contrib_no_error]' => TRUE,
];
$this->drupalPostForm('admin/reports/upgrade-status', $edit, 'Scan selected');
}
......
......@@ -29,14 +29,11 @@ class UpgradeStatusUiTest extends UpgradeStatusTestBase {
$assert_session->buttonExists('Scan selected');
$assert_session->buttonExists('Export selected as HTML');
// Status for every project should be 'Not scanned'.
$status = $this->getSession()->getPage()->findAll('css', '.upgrade-status-summary-custom td.status-info');
// Scan result for every project should be 'N/A'.
$status = $this->getSession()->getPage()->findAll('css', 'td.scan-result');
$this->assertNotEmpty($status);
foreach ($status as $project_status) {
$this->assertSame('Not scanned', $project_status->getHtml());
}
$status = $this->getSession()->getPage()->findAll('css', '.upgrade-status-summary-contrib td.status-info');
foreach ($status as $project_status) {
$this->assertSame('Not scanned', $project_status->getHtml());
$this->assertSame('N/A', $project_status->getHtml());
}
}
......@@ -52,31 +49,20 @@ class UpgradeStatusUiTest extends UpgradeStatusTestBase {
$assert_session->buttonExists('Scan selected');
$assert_session->buttonExists('Export selected 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());
// Error and no-error test module results should show.
$this->assertSame('4 problems', strip_tags($page->find('css', 'tr.project-upgrade_status_test_error td.scan-result')->getHtml()));
$this->assertSame('No problems found', strip_tags($page->find('css', 'tr.project-upgrade_status_test_no_error td.scan-result')->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());
// Parent module should show up without errors and submodule should not appear.
$this->assertSame('No problems found', strip_tags($page->find('css', 'tr.project-upgrade_status_test_submodules td.scan-result')->getHtml()));
$this->assertEmpty($page->find('css', 'tr.upgrade_status_test_submodules_a'));
// 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()));
// Contrib test modules should show with results.
$this->assertSame('2 problems', strip_tags($page->find('css', 'tr.project-upgrade_status_test_contrib_error td.scan-result')->getHtml()));
$this->assertSame('No problems found', strip_tags($page->find('css', 'tr.project-upgrade_status_test_contrib_no_error td.scan-result')->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');
// Click the first '4 problems' link. Should be the contrib project.
$this->clickLink('4 problems');
$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');
......@@ -93,7 +79,7 @@ class UpgradeStatusUiTest extends UpgradeStatusTestBase {
// 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('4 problems');
$this->clickLink('Export as text');
$this->assertText('Upgrade status test error ' . \Drupal::VERSION);
$this->assertText('CUSTOM PROJECTS');
......@@ -103,9 +89,9 @@ class UpgradeStatusUiTest extends UpgradeStatusTestBase {
// Run partial export of multiple projects.
$edit = [
'custom[data][installed][upgrade_status_test_error]' => TRUE,
'custom[data][installed][upgrade_status_test_no_error]' => TRUE,
'contrib[data][installed][upgrade_status_test_contrib_error]' => TRUE,
'manual[data][list][upgrade_status_test_error]' => TRUE,
'relax[data][list][upgrade_status_test_no_error]' => TRUE,
'collaborate[data][list][upgrade_status_test_contrib_error]' => TRUE,
];
$expected = [
'Export selected as HTML' => ['Contributed projects', 'Custom projects'],
......@@ -124,16 +110,4 @@ class UpgradeStatusUiTest extends UpgradeStatusTestBase {
$this->assertText('Syntax error, unexpected T_STRING on line 3');
}
}
/**
* Test project collection's result by checking the amount of projects.
*/
public function testProjectCollector() {
$this->drupalGet(Url::fromRoute('upgrade_status.report'));
$page = $this->getSession()->getPage();
$this->assertCount(9, $page->findAll('css', '.upgrade-status-summary-custom tr[class*=\'project-\']'));
$this->assertCount(3, $page->findAll('css', '.upgrade-status-summary-contrib tr[class*=\'project-\']'));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment