View source
<?php
namespace Drupal\Tests\upgrade_status\Functional;
use Drupal\Core\Url;
class UpgradeStatusUiTest extends UpgradeStatusTestBase {
public function setUp() {
parent::setUp();
$this
->drupalLogin($this
->drupalCreateUser([
'administer software updates',
]));
}
public function testUiBeforeScan() {
$this
->drupalGet(Url::fromRoute('upgrade_status.report'));
$assert_session = $this
->assertSession();
$assert_session
->buttonExists('Scan selected');
$assert_session
->buttonExists('Export selected as HTML');
$status = $this
->getSession()
->getPage()
->findAll('css', '.upgrade-status-summary-custom td.status-info');
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());
}
}
public function testUiAfterScan() {
$this
->runFullScan();
$page = $this
->getSession()
->getPage();
$assert_session = $this
->assertSession();
$assert_session
->buttonExists('Scan selected');
$assert_session
->buttonExists('Export selected as HTML');
$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());
$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());
$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');
$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');
$this
->drupalGet(Url::fromRoute('upgrade_status.report'));
$this
->clickLink('2 errors, 2 warnings');
$this
->clickLink('Export as text');
$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');
$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,
];
$expected = [
'Export selected as HTML' => [
'Contributed projects',
'Custom projects',
],
'Export selected as text' => [
'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');
}
}
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-\']'));
}
}