View source
<?php
namespace Drupal\Tests\system\Functional\UpdateSystem;
use Drupal\Core\Database\Database;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\UpdatePathTestTrait;
class UpdateRemovedPostUpdateTest extends BrowserTestBase {
use UpdatePathTestTrait;
protected $defaultTheme = 'stark';
protected function setUp() {
parent::setUp();
$connection = Database::getConnection();
$connection
->merge('key_value')
->condition('collection', 'system.schema')
->condition('name', 'update_test_postupdate')
->fields([
'collection' => 'system.schema',
'name' => 'update_test_postupdate',
'value' => 'i:8000;',
])
->execute();
$extensions = $connection
->select('config')
->fields('config', [
'data',
])
->condition('collection', '')
->condition('name', 'core.extension')
->execute()
->fetchField();
$extensions = unserialize($extensions);
$extensions['module']['update_test_postupdate'] = 8000;
$connection
->update('config')
->fields([
'data' => serialize($extensions),
])
->condition('collection', '')
->condition('name', 'core.extension')
->execute();
$this->updateUrl = Url::fromRoute('system.db_update');
$this->updateUser = $this
->drupalCreateUser([
'administer software updates',
]);
}
public function testRemovedPostUpdate() {
$key_value = \Drupal::service('keyvalue');
$existing_updates = $key_value
->get('post_update')
->get('existing_updates', []);
$post_updates = [
'update_test_postupdate_post_update_first',
'update_test_postupdate_post_update_second',
'update_test_postupdate_post_update_test1',
'update_test_postupdate_post_update_test0',
'update_test_postupdate_post_update_foo',
];
$key_value
->get('post_update')
->set('existing_updates', array_merge($existing_updates, $post_updates));
$this
->drupalLogin($this->updateUser);
$this
->drupalGet($this->updateUrl);
$assert_session = $this
->assertSession();
$assert_session
->pageTextContains('Requirements problem');
$assert_session
->pageTextContains('The installed version of the Update test after module is too old to update. Update first to a version prior to all of the following: 8.x-2.0, 3.0.0');
$assert_session
->pageTextContains('update_test_postupdate_post_update_baz');
$assert_session
->pageTextContains('update_test_postupdate_post_update_bar');
$assert_session
->pageTextContains('update_test_postupdate_post_update_pub');
$post_updates = [
'update_test_postupdate_post_update_first',
'update_test_postupdate_post_update_second',
'update_test_postupdate_post_update_test1',
'update_test_postupdate_post_update_test0',
'update_test_postupdate_post_update_foo',
'update_test_postupdate_post_update_bar',
];
$key_value
->get('post_update')
->set('existing_updates', array_merge($existing_updates, $post_updates));
$this
->drupalGet($this->updateUrl);
$assert_session = $this
->assertSession();
$assert_session
->pageTextContains('Requirements problem');
$assert_session
->pageTextContains('The installed version of the Update test after module is too old to update. Update to a version prior to 3.0.0');
$assert_session
->pageTextContains('update_test_postupdate_post_update_baz');
$assert_session
->pageTextContains('update_test_postupdate_post_update_pub');
$post_updates = [
'update_test_postupdate_post_update_first',
'update_test_postupdate_post_update_second',
'update_test_postupdate_post_update_test1',
'update_test_postupdate_post_update_test0',
'update_test_postupdate_post_update_foo',
'update_test_postupdate_post_update_bar',
'update_test_postupdate_post_update_pub',
];
$key_value
->get('post_update')
->set('existing_updates', array_merge($existing_updates, $post_updates));
$this
->drupalGet($this->updateUrl);
$assert_session = $this
->assertSession();
$assert_session
->pageTextContains('Requirements problem');
$assert_session
->pageTextContains('The installed version of the Update test after module is too old to update. Update to a version prior to 3.0.0');
$assert_session
->pageTextContains('update_test_postupdate_post_update_baz');
}
}