From c5faa7e487d24fc34e902e7912308dec752eb517 Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Tue, 16 Jan 2018 10:51:39 +0200 Subject: [PATCH] Test post-updates. --- tests/UpdateDBTest.php | 69 +++++++++++++++++-- tests/resources/modules/d8/woot/woot.install | 7 ++ .../modules/d8/woot/woot.post_update.php | 12 +++- 3 files changed, 80 insertions(+), 8 deletions(-) diff --git a/tests/UpdateDBTest.php b/tests/UpdateDBTest.php index 810b999e83..5d0c410421 100644 --- a/tests/UpdateDBTest.php +++ b/tests/UpdateDBTest.php @@ -72,13 +72,14 @@ public function testFailedUpdate() $this->drush('updatedb', [], $options, null, null, self::EXIT_ERROR); $expected_output = <<assertErrorOutputEquals(preg_replace('# *#', ' ', $this->simplifyOutput($expected_error_output))); } + /** + * Tests that a failed post-update is handled correctly. + */ + public function testFailedPostUpdate() + { + $sites = $this->setUpDrupal(1, true); + $options = [ + 'yes' => null, + 'root' => $root = $this->webroot(), + 'uri' => key($sites), + ]; + $this->setupModulesForTests($root); + $this->drush('pm-enable', ['woot'], $options); + + // Force re-run of woot_update_8101(). + $this->drush('php:eval', array('drupal_set_installed_schema_version("woot", 8102)'), $options); + + // Force re-run of post-update hooks. + $this->forcePostUpdate('woot_post_update_a', $options); + $this->forcePostUpdate('woot_post_update_failing', $options); + + // Run updates. + $this->drush('updatedb', [], $options, null, null, self::EXIT_ERROR); + + $expected_output = <<assertOutputEquals(preg_replace('# *#', ' ', $this->simplifyOutput($expected_output))); + + $expected_error_output = <<assertErrorOutputEquals(preg_replace('# *#', ' ', $this->simplifyOutput($expected_error_output))); + } + /** * Tests that the updatedb command works when new services are introduced. * diff --git a/tests/resources/modules/d8/woot/woot.install b/tests/resources/modules/d8/woot/woot.install index 163a99447e..be9dd39cc4 100644 --- a/tests/resources/modules/d8/woot/woot.install +++ b/tests/resources/modules/d8/woot/woot.install @@ -13,3 +13,10 @@ function woot_update_8101() { function woot_update_8102() { throw new \Exception('This is the exception message thrown in woot_update_8102'); } + +/** + * Another good update. + */ +function woot_update_8103() { + return t('This is the update message from woot_update_8103'); +} diff --git a/tests/resources/modules/d8/woot/woot.post_update.php b/tests/resources/modules/d8/woot/woot.post_update.php index f256be0bd0..289cd14ed0 100644 --- a/tests/resources/modules/d8/woot/woot.post_update.php +++ b/tests/resources/modules/d8/woot/woot.post_update.php @@ -1,11 +1,21 @@