UpdatePostUpdateFailingTest.php in Drupal 9
File
core/modules/system/tests/src/Functional/UpdateSystem/UpdatePostUpdateFailingTest.php
View source
<?php
namespace Drupal\Tests\system\Functional\UpdateSystem;
use Drupal\Core\Database\Database;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\UpdatePathTestTrait;
class UpdatePostUpdateFailingTest extends BrowserTestBase {
use UpdatePathTestTrait;
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
$connection = Database::getConnection();
\Drupal::service('update.update_hook_registry')
->setInstalledVersion('update_test_failing', 8000);
$extensions = $connection
->select('config')
->fields('config', [
'data',
])
->condition('collection', '')
->condition('name', 'core.extension')
->execute()
->fetchField();
$extensions = unserialize($extensions);
$extensions['module']['update_test_failing'] = 8000;
$connection
->update('config')
->fields([
'data' => serialize($extensions),
])
->condition('collection', '')
->condition('name', 'core.extension')
->execute();
}
public function testPostUpdate() {
$this->checkFailedUpdates = FALSE;
$this
->runUpdates();
$this
->assertSame([], \Drupal::state()
->get('post_update_test_execution', []));
$key_value = \Drupal::keyValue('update__post_update');
$this
->assertEquals([], $key_value
->get('existing_updates', []));
}
protected function doSelectionTest() {
$this
->assertSession()
->responseContains('8001 - This update will fail.');
$this
->assertSession()
->responseContains('8002 - A further update');
$this
->assertSession()
->assertEscaped("First update, should not be run since this module's update hooks fail.");
}
}