View source
<?php
namespace Drupal\Tests\upgrade_status\Functional;
use Drupal\Core\Url;
use Drupal\user\Entity\Role;
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', 'td.scan-result');
$this
->assertNotEmpty($status);
foreach ($status as $project_status) {
$this
->assertSame('N/A', $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');
$this
->assertSame('5 problems', strip_tags($page
->find('css', 'tr.project-upgrade_status_test_error td.scan-result')
->getHtml()));
$this
->assertSame($this
->getDrupalCoreMajorVersion() < 9 ? 'No problems found' : '1 problem', strip_tags($page
->find('css', 'tr.project-upgrade_status_test_9_compatible td.scan-result')
->getHtml()));
$this
->assertSame('No problems found', strip_tags($page
->find('css', 'tr.project-upgrade_status_test_10_compatible td.scan-result')
->getHtml()));
$this
->assertSame($this
->getDrupalCoreMajorVersion() < 9 ? 'No problems found' : '2 problems', 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'));
$this
->assertSame('5 problems', strip_tags($page
->find('css', 'tr.project-upgrade_status_test_contrib_error td.scan-result')
->getHtml()));
$this
->assertSame($this
->getDrupalCoreMajorVersion() < 9 ? 'No problems found' : '1 problem', strip_tags($page
->find('css', 'tr.project-upgrade_status_test_contrib_9_compatible td.scan-result')
->getHtml()));
$next_major = $this
->getDrupalCoreMajorVersion() + 1;
$this
->assertSession()
->linkByHrefExists('https://drupal.org/project/issues/upgrade_status_test_contributed_9_compatible?text=Drupal+' . $next_major . '&status=All');
$this
->clickLink('5 problems', 1);
$this
->assertText('Upgrade status test error ' . \Drupal::VERSION);
$this
->assertText('2 errors found. 3 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. 3 warnings found.');
$this
->assertText('Syntax error, unexpected T_STRING on line 3');
$this
->drupalGet(Url::fromRoute('upgrade_status.report'));
$this
->clickLink('5 problems', 1);
$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. 3 warnings found.');
$this
->assertText('Syntax error, unexpected T_STRING on line 3');
$edit = [
'manual[data][list][upgrade_status_test_error]' => TRUE,
($this
->getDrupalCoreMajorVersion() < 9 ? 'relax' : 'manual') . '[data][list][upgrade_status_test_9_compatible]' => TRUE,
'collaborate[data][list][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 9 compatible ' . \Drupal::VERSION);
$this
->assertText('Upgrade status test error ' . \Drupal::VERSION);
$this
->assertNoText('Upgrade status test root module');
$this
->assertNoText('Upgrade status test contrib 9 compatbile');
$this
->assertText('2 errors found. 3 warnings found.');
$this
->assertText('Syntax error, unexpected T_STRING on line 3');
}
}
public function testRoleChecking() {
if ($this
->getDrupalCoreMajorVersion() == 9) {
$authenticated = Role::load('authenticated');
$authenticated
->grantPermission('upgrade status invalid permission test');
$authenticated
->save();
$this
->drupalGet(Url::fromRoute('upgrade_status.report'));
$this
->assertSession()
->pageTextContains('"upgrade status invalid permission test" of user role: "Authenticated user".');
}
}
}