From ec41d08258ddebb08f1dd79af3211e11cc6a4063 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Mon, 31 Aug 2015 07:53:44 +0100 Subject: [PATCH] Issue #2558247 by dawehner, catch, mradcliffe, jhedstrom, Berdir, jibran, effulgentsia, webchick: Remove rebuildAll() and module install from UpdatePathTestBase --- core/lib/Drupal/Core/Extension/Extension.php | 6 +- .../Update/BlockContextMappingUpdateTest.php | 2 + .../src/Controller/DbUpdateController.php | 9 ++- .../src/Tests/Update/UpdatePathTestBase.php | 30 ++-------- .../Update/UpdatePathTestBaseFilledTest.php | 1 + .../Tests/Update/UpdatePathTestBaseTest.php | 5 +- core/modules/system/system.module | 2 +- .../update/drupal-8.block-test-enabled.php | 49 ++++++++++++++++ .../update/drupal-8.language-enabled.php | Bin 0 -> 6316 bytes .../drupal-8.update-test-schema-enabled.php | 54 ++++++++++++++++++ 10 files changed, 126 insertions(+), 32 deletions(-) create mode 100644 core/modules/system/tests/fixtures/update/drupal-8.block-test-enabled.php create mode 100644 core/modules/system/tests/fixtures/update/drupal-8.language-enabled.php create mode 100644 core/modules/system/tests/fixtures/update/drupal-8.update-test-schema-enabled.php diff --git a/core/lib/Drupal/Core/Extension/Extension.php b/core/lib/Drupal/Core/Extension/Extension.php index 3c765fe70a..17d8b09012 100644 --- a/core/lib/Drupal/Core/Extension/Extension.php +++ b/core/lib/Drupal/Core/Extension/Extension.php @@ -166,8 +166,9 @@ public function __call($method, array $args) { * Serializes the Extension object in the most optimized way. */ public function serialize() { + // Don't serialize the app root, since this could change if the install is + // moved. $data = array( - 'root' => $this->root, 'type' => $this->type, 'pathname' => $this->pathname, 'filename' => $this->filename, @@ -188,7 +189,8 @@ public function serialize() { */ public function unserialize($data) { $data = unserialize($data); - $this->root = $data['root']; + // Get the app root from the container. + $this->root = DRUPAL_ROOT; $this->type = $data['type']; $this->pathname = $data['pathname']; $this->filename = $data['filename']; diff --git a/core/modules/block/src/Tests/Update/BlockContextMappingUpdateTest.php b/core/modules/block/src/Tests/Update/BlockContextMappingUpdateTest.php index 4aa0ac02cb..0362390679 100644 --- a/core/modules/block/src/Tests/Update/BlockContextMappingUpdateTest.php +++ b/core/modules/block/src/Tests/Update/BlockContextMappingUpdateTest.php @@ -32,6 +32,8 @@ protected function setDatabaseDumpFiles() { $this->databaseDumpFiles = [ __DIR__ . '/../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz', __DIR__ . '/../../../../system/tests/fixtures/update/drupal-8.block-context-manager-2354889.php', + __DIR__ . '/../../../../system/tests/fixtures/update/drupal-8.language-enabled.php', + __DIR__ . '/../../../../system/tests/fixtures/update/drupal-8.block-test-enabled.php', ]; } diff --git a/core/modules/system/src/Controller/DbUpdateController.php b/core/modules/system/src/Controller/DbUpdateController.php index 28ab72b021..fa8104d6c1 100644 --- a/core/modules/system/src/Controller/DbUpdateController.php +++ b/core/modules/system/src/Controller/DbUpdateController.php @@ -228,7 +228,8 @@ protected function info(Request $request) { '#type' => 'link', '#title' => $this->t('Continue'), '#attributes' => array('class' => array('button', 'button--primary')), - '#url' => Url::fromUri($request->getUriForPath('/selection')), + // @todo Revisit once https://www.drupal.org/node/2548095 is in. + '#url' => Url::fromUri('base://selection'), ); return $build; } @@ -484,6 +485,9 @@ protected function results(Request $request) { */ public function requirements($severity, array $requirements, Request $request) { $options = $severity == REQUIREMENT_WARNING ? array('continue' => 1) : array(); + // @todo Revisit once https://www.drupal.org/node/2548095 is in. Something + // like Url::fromRoute('system.db_update')->setOptions() should then be + // possible. $try_again_url = Url::fromUri($request->getUriForPath(''))->setOptions(['query' => $options])->toString(TRUE)->getGeneratedUrl(); $build['status_report'] = array( @@ -580,7 +584,8 @@ protected function triggerBatch(Request $request) { ); batch_set($batch); - return batch_process(Url::fromUri($request->getUriForPath('/results')), Url::fromUri($request->getUriForPath('/start'))); + // @todo Revisit once https://www.drupal.org/node/2548095 is in. + return batch_process(Url::fromUri('base://results'), Url::fromUri('base://start')); } /** diff --git a/core/modules/system/src/Tests/Update/UpdatePathTestBase.php b/core/modules/system/src/Tests/Update/UpdatePathTestBase.php index c5197a29e2..fc8d4c379a 100644 --- a/core/modules/system/src/Tests/Update/UpdatePathTestBase.php +++ b/core/modules/system/src/Tests/Update/UpdatePathTestBase.php @@ -179,16 +179,15 @@ protected function setUp() { // Add the config directories to settings.php. drupal_install_config_directories(); - // Install any additional modules. - $this->installModulesFromClassProperty($container); - // Restore the original Simpletest batch. $this->restoreBatch(); - // Rebuild and reset. - $this->rebuildAll(); + // Set the container. parent::rebuildAll() would normally do this, but this + // not safe to do here, because the database has not been updated yet. + $this->container = \Drupal::getContainer(); // Replace User 1 with the user created here. + // @todo: do this without saving the user account. /** @var \Drupal\user\UserInterface $account */ $account = User::load(1); $account->setPassword($this->rootUser->pass_raw); @@ -267,25 +266,4 @@ protected function runUpdates() { $this->assertFalse(\Drupal::service('entity.definition_update_manager')->needsUpdates(), 'After all updates ran, entity schema is up to date.'); } - /** - * {@inheritdoc} - */ - protected function rebuildAll() { - // We know the rebuild causes notices, so don't exit on failure. - $die_on_fail = $this->dieOnFail; - $this->dieOnFail = FALSE; - parent::rebuildAll(); - - // Remove the notices we get due to the menu link rebuild prior to running - // the system updates for the schema change. - foreach ($this->assertions as $key => $assertion) { - if ($assertion['message_group'] == 'Notice' && basename($assertion['file']) == 'MenuTreeStorage.php' && strpos($assertion['message'], 'unserialize(): Error at offset 0') !== FALSE) { - unset($this->assertions[$key]); - $this->deleteAssert($assertion['message_id']); - $this->results['#exception']--; - } - } - $this->dieOnFail = $die_on_fail; - } - } diff --git a/core/modules/system/src/Tests/Update/UpdatePathTestBaseFilledTest.php b/core/modules/system/src/Tests/Update/UpdatePathTestBaseFilledTest.php index 30ed37d3bb..623a40013a 100644 --- a/core/modules/system/src/Tests/Update/UpdatePathTestBaseFilledTest.php +++ b/core/modules/system/src/Tests/Update/UpdatePathTestBaseFilledTest.php @@ -18,6 +18,7 @@ class UpdatePathTestBaseFilledTest extends UpdatePathTestBaseTest { * {@inheritdoc} */ protected function setDatabaseDumpFiles() { + parent::setDatabaseDumpFiles(); $this->databaseDumpFiles[0] = __DIR__ . '/../../../tests/fixtures/update/drupal-8.filled.standard.php.gz'; } diff --git a/core/modules/system/src/Tests/Update/UpdatePathTestBaseTest.php b/core/modules/system/src/Tests/Update/UpdatePathTestBaseTest.php index 28e003a7af..65e0b21ab5 100644 --- a/core/modules/system/src/Tests/Update/UpdatePathTestBaseTest.php +++ b/core/modules/system/src/Tests/Update/UpdatePathTestBaseTest.php @@ -25,7 +25,10 @@ class UpdatePathTestBaseTest extends UpdatePathTestBase { * {@inheritdoc} */ protected function setDatabaseDumpFiles() { - $this->databaseDumpFiles = [__DIR__ . '/../../../tests/fixtures/update/drupal-8.bare.standard.php.gz']; + $this->databaseDumpFiles = [ + __DIR__ . '/../../../tests/fixtures/update/drupal-8.bare.standard.php.gz', + __DIR__ . '/../../../tests/fixtures/update/drupal-8.update-test-schema-enabled.php', + ]; } /** diff --git a/core/modules/system/system.module b/core/modules/system/system.module index b1bdee762e..923e722027 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -241,7 +241,7 @@ function system_theme_suggestions_html(array $variables) { $path_args = ['']; } else { - $path_args = explode('/', Url::fromRoute('')->getInternalPath()); + $path_args = explode('/', ltrim(\Drupal::service('path.current')->getPath(), '/')); } return theme_get_suggestions($path_args, 'html'); } diff --git a/core/modules/system/tests/fixtures/update/drupal-8.block-test-enabled.php b/core/modules/system/tests/fixtures/update/drupal-8.block-test-enabled.php new file mode 100644 index 0000000000..f3edf280bc --- /dev/null +++ b/core/modules/system/tests/fixtures/update/drupal-8.block-test-enabled.php @@ -0,0 +1,49 @@ +insert('key_value') + ->fields([ + 'collection' => 'system.schema', + 'name' => 'block_test', + 'value' => 'i:8000;', + ]) + ->execute(); + +// Update core.extension. +$extensions = $connection->select('config') + ->fields('config', ['data']) + ->condition('collection', '') + ->condition('name', 'core.extension') + ->execute() + ->fetchField(); +$extensions = unserialize($extensions); +$extensions['module']['block_test'] = 8000; +$connection->update('config') + ->fields([ + 'data' => serialize($extensions), + ]) + ->condition('collection', '') + ->condition('name', 'core.extension') + ->execute(); + +// Install the block configuration. +$config = file_get_contents(__DIR__ . '/../../../../block/tests/modules/block_test/config/install/block.block.test_block.yml'); +$config = Yaml::parse($config); +$connection->insert('config') + ->fields(['data', 'name', 'collection']) + ->values([ + 'name' => 'block.block.test_block', + 'data' => serialize($config), + 'collection' => '', + ]) + ->execute(); diff --git a/core/modules/system/tests/fixtures/update/drupal-8.language-enabled.php b/core/modules/system/tests/fixtures/update/drupal-8.language-enabled.php new file mode 100644 index 0000000000000000000000000000000000000000..6be5c24f5c101bc7fea607af617b4bc135a4401e GIT binary patch literal 6316 zcmeHLZEM?B6z=Ez3SkOzMq|fG+I8}h(IqV_lx;K}VB&-;1K%k}p^yXE7&FP~Vm`^z z1!(4Zmg=-R|3l3U|2N*+dK_hGs-r5&Qt!}nB7$J5tK;URzYWUa&^y(YSIx9nMl(HE z-jyy&@D18Rc8=z{nCiZNsTbjuGPU-%w>)p>Xp(3Xm;E!mc%CmO-r9l)$Sz9j1f!ayj+x(o)5$rCVDTb;8L8BM}5D=^ThMJ9CwIWHOLyp zLZPp9R9D&s;kP_imG&Zpe4wu@o!S^Q&m{uc3hT~MsmX3KCY>bHZamz_C*GM4xys+< zgJo~|=*;d~Wa%2?B?-EUX0Ip{v9uPa?B9Q4ERaxlf>vSNhjI1cLUFp2?(2SJ4Yzxmky`>ZSU~V^A~gD3$e#gg-qB>eIW>PRg}8V z{NN0s5g4z^RgrJCGQX;7*5BTSg;dlX%-b#?_A(ZUWakJUTy0w1u9*5GIvAbw{Q+A^ zHF$@$g$UGZOMIux5StX$3dF>!ZGjh4HBj1MO^c;vLmQPAd17)?eH5YFt=mq&UE3;K zF={D+qsT*2Ee5fkBq=wza$r%SzDj7w(AjR#vm_UF8XLr_`36eLZj{CRb>)?k0pO_GR15+~w(ffq z-7;t%5lYFH^$KB?^B&5AngK7l)SN9 z0qYQeWkoVgQe}=s)Xz)pGet2f7&iwDNucHJ7c3R$m_QxeD^rC-2cE~^g*lYn(L!(as8_;Ev z^pdmB(I!mB?A6Z1hVmHzF=V}N?iPBAT2p4|Oc)Bw@aA5u-;y%8MG09-g)^I^62n6> zN06~>|D0=>zd@=rL!^p)r$&QbWz2<&E_-9D3)=~$cZ8jgaoHdm;IzltM3`)Ev|nxi zVsgNj$T6}*+&!opu@aHu+Ez$gUi*9`_BH1%){#iO!yy2ukoD5gHHTEmkg$1{riw|0 z_x7YZt%@X_zO#%-?0M_?_d?|W73LMyqF}RR28$q9d-OUIuT(Lu=Lj65O2!Li3Sr1{ zx^pz&3GQNcT_h`M5TmC>R_81lUN_((A^cJ13KOAY^U(OD{!y%@Y|&X8tsmhfCNZ}K zm|o#3!A2vsQuZDdqGw&aMKJb6GH+;MorH`UM1Z;xqehx}l+EW^8e&<{7{(C+3-?I~ zmvmbx+{1Yc%Yu5{$%m_b^m(DF)Rgnm><;@)#DgaA?e!=m1yW3s22cSRD(NJidKMBd zkZIwH9J;;lma=IPTXW%&I$g8(wJtlYb+daFTXQFeQ)oiK+v-L6L4_Od&F;<+mb$7? zedWKoY|?(i0L9+s>|vxzZT{c(&SzAUsI-;66BXgwEjbU|(jSE83)mu&2sdi)Acr&c z(VHavTHS1D1X+iga7TF%1*zp z+eY&f>_6BxXveka^c+0t2iGM&KVmXdX1?wpU-JHeqQO+c&nCgz-uGE{khR)6Gy2o* GA%6izQ~1>Y literal 0 HcmV?d00001 diff --git a/core/modules/system/tests/fixtures/update/drupal-8.update-test-schema-enabled.php b/core/modules/system/tests/fixtures/update/drupal-8.update-test-schema-enabled.php new file mode 100644 index 0000000000..7250741cf8 --- /dev/null +++ b/core/modules/system/tests/fixtures/update/drupal-8.update-test-schema-enabled.php @@ -0,0 +1,54 @@ +schema()->createTable('update_test_schema_table', array( + 'fields' => array( + 'a' => array( + 'type' => 'int', + 'not null' => TRUE, + 'size' => 'normal', + ), + 'b' => array( + 'type' => 'blob', + 'not null' => FALSE, + 'size' => 'normal', + ), + ), +)); + +// Set the schema version. +$connection->merge('key_value') + ->condition('collection', 'system.schema') + ->condition('name', 'update_test_schema') + ->fields([ + 'collection' => 'system.schema', + 'name' => 'update_test_schema', + 'value' => 'i:8000;', + ]) + ->execute(); + +// Update core.extension. +$extensions = $connection->select('config') + ->fields('config', ['data']) + ->condition('collection', '') + ->condition('name', 'core.extension') + ->execute() + ->fetchField(); +$extensions = unserialize($extensions); +$extensions['module']['update_test_schema'] = 8000; +$connection->update('config') + ->fields([ + 'data' => serialize($extensions), + ]) + ->condition('collection', '') + ->condition('name', 'core.extension') + ->execute(); -- GitLab