AutomaticUpdatesTest.php in Automatic Updates 8
File
tests/src/Functional/AutomaticUpdatesTest.php
View source
<?php
namespace Drupal\Tests\automatic_updates\Functional;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
class AutomaticUpdatesTest extends BrowserTestBase {
protected $defaultTheme = 'stark';
protected static $modules = [
'automatic_updates',
'test_automatic_updates',
'update',
];
protected $user;
protected function setUp() {
parent::setUp();
$this->user = $this
->drupalCreateUser([
'access administration pages',
'administer site configuration',
'administer software updates',
]);
$this
->drupalLogin($this->user);
}
public function testPsa() {
$end_point = $this
->buildUrl(Url::fromRoute('test_automatic_updates.json_test_controller'));
$this
->config('automatic_updates.settings')
->set('psa_endpoint', $end_point)
->save();
$this
->drupalGet(Url::fromRoute('system.admin'));
$this
->assertSession()
->pageTextContains('Critical Release - SA-2019-02-19');
$this
->assertSession()
->pageTextContains('Critical Release - PSA-Really Old');
$this
->assertSession()
->pageTextNotContains('Node - Moderately critical - Access bypass - SA-CONTRIB-2019');
$this
->assertSession()
->pageTextNotContains('Views - Moderately critical - Access bypass - SA-CONTRIB-2019');
$this
->drupalGet(Url::fromRoute('system.status'));
$this
->assertSession()
->pageTextContains('3 urgent announcements require your attention:');
$end_point = $this
->buildUrl(Url::fromRoute('test_automatic_updates.json_test_denied_controller'));
$this
->config('automatic_updates.settings')
->set('psa_endpoint', $end_point)
->save();
$this
->drupalGet(Url::fromRoute('system.admin'));
$this
->assertSession()
->pageTextContains('Critical Release - SA-2019-02-19');
drupal_flush_all_caches();
$this
->drupalGet(Url::fromRoute('system.admin'));
$this
->assertSession()
->pageTextContains("Drupal PSA endpoint {$end_point} is unreachable.");
$end_point = $this
->buildUrl(Url::fromRoute('test_automatic_updates.json_test_controller'));
$this
->config('automatic_updates.settings')
->set('psa_endpoint', $end_point)
->set('enable_psa', FALSE)
->save();
drupal_flush_all_caches();
$this
->drupalGet(Url::fromRoute('system.admin'));
$this
->assertSession()
->pageTextNotContains('Critical Release - PSA-2019-02-19');
$this
->drupalGet(Url::fromRoute('system.status'));
$this
->assertSession()
->pageTextNotContains('urgent announcements require your attention');
}
public function testReadinessChecks() {
$ignore_paths = "modules/custom/*\nthemes/custom/*\nprofiles/custom/*";
$this
->config('automatic_updates.settings')
->set('ignored_paths', $ignore_paths)
->save();
$this
->drupalGet(Url::fromRoute('automatic_updates.settings'));
$this
->clickLink('run the readiness checks');
$this
->assertSession()
->pageTextContains('Your site does not pass some readiness checks for automatic updates. Depending on the nature of the failures, it might effect the eligibility for automatic updates.');
$ignore_paths = "vendor/*\ncore/*\nmodules/*\nthemes/*\nprofiles/*\ncomposer.*\nautoload.php\nLICENSE.txt";
$this
->config('automatic_updates.settings')
->set('ignored_paths', $ignore_paths)
->save();
$this
->drupalGet(Url::fromRoute('automatic_updates.settings'));
$this
->clickLink('run the readiness checks');
$this
->assertSession()
->pageTextContains('No issues found. Your site is ready for automatic updates.');
}
}