From 8923b60e60c1b9e98445134b493c57f363b6483e Mon Sep 17 00:00:00 2001 From: mmorris Date: Fri, 7 Aug 2015 22:12:34 -0400 Subject: [PATCH] #71 - adjust the tests as closely as possible to final form. --- .../src/Tests/Bootstrap/DrupalSetMessageTest.php | 17 ++-------- .../src/Controller/SystemTestController.php | 39 +++++++++++++--------- .../modules/system_test/system_test.routing.yml | 8 ----- 3 files changed, 26 insertions(+), 38 deletions(-) diff --git a/core/modules/system/src/Tests/Bootstrap/DrupalSetMessageTest.php b/core/modules/system/src/Tests/Bootstrap/DrupalSetMessageTest.php index 1d57018..e54e30a 100644 --- a/core/modules/system/src/Tests/Bootstrap/DrupalSetMessageTest.php +++ b/core/modules/system/src/Tests/Bootstrap/DrupalSetMessageTest.php @@ -59,21 +59,8 @@ function testDrupalSetMessage() { // Ensure that strings that are not marked as safe are escaped. $this->assertEscaped('Thismarkup will be escaped.'); - // Ensure render arrays fail with #attached when assertions are enabled. - $this->drupalGet('system-test/drupal-set-message-fail'); - $this->assertText('Render arrays passed to drupal_set_message() cannot have attachments.'); - } - - /** - * {@inheritdoc} - */ - protected function error($message = '', $group = 'Other', array $caller = NULL) { - // @todo Clean this up in https://www.drupal.org/node/2536560. - if (strpos($message, 'Render arrays passed to drupal_set_message() cannot have attachments.') !== FALSE) { - // We're expecting this error. - return FALSE; - } - return parent::error($message, $group, $caller); + // Ensure the runtime assertion fires on cue. + $this->assertUniqueText('Correct runtime assertion thrown when render array contains #attached.'); } } diff --git a/core/modules/system/tests/modules/system_test/src/Controller/SystemTestController.php b/core/modules/system/tests/modules/system_test/src/Controller/SystemTestController.php index ddb1a83..f4a566f 100644 --- a/core/modules/system/tests/modules/system_test/src/Controller/SystemTestController.php +++ b/core/modules/system/tests/modules/system_test/src/Controller/SystemTestController.php @@ -144,26 +144,35 @@ public function drupalSetMessageTest() { // Test auto-escape of non safe strings. drupal_set_message('Thismarkup will be escaped.'); - return []; - } + // Test setting messages with a render array containing #attached. - /** - * Tests setting messages with a render array containing #attached. - * - * @return array - * Empty array, we just test the setting of messages. - */ - public function drupalSetMessageFailTest() { - // Enable assert testing. - // @todo Clean this up in https://www.drupal.org/node/2536560. - $old_assert_active = assert_options(ASSERT_ACTIVE, 1); + // @todo Remove this after https://www.drupal.org/node/2536560 is finished. + assert_options(ASSERT_ACTIVE, TRUE); + assert_options(ASSERT_CALLBACK, function($file, $line, $code, $message) { + throw new \Exception($message); + }); + // End block to be removed. $array_with_attachments['foo']['bar']['#markup'] = t('Render array with assets'); $array_with_attachments['foo']['bar']['#attached']['drupalSettings'] = ['pecary' => TRUE]; - drupal_set_message($array_with_attachments); - // Reset assert settings. - assert_options(ASSERT_ACTIVE, $old_assert_active); + try { + drupal_set_message($array_with_attachments); + } + catch (\Exception $e) { + // @todo Switch to next line when #2536560 is finished. + # catch (\AssertionError $e) { + + // If the exception is the not the one we expect, rethrow causing a test + // failure. + if ($e->getMessage() !== 'Render arrays passed to drupal_set_message() cannot have attachments.') { + throw $e; + } + else { + drupal_set_message('Correct runtime assertion thrown when render array contains #attached.'); + } + } + return []; } diff --git a/core/modules/system/tests/modules/system_test/system_test.routing.yml b/core/modules/system/tests/modules/system_test/system_test.routing.yml index 8062111..ecb9921 100644 --- a/core/modules/system/tests/modules/system_test/system_test.routing.yml +++ b/core/modules/system/tests/modules/system_test/system_test.routing.yml @@ -21,14 +21,6 @@ system_test.drupal_set_message: requirements: _access: 'TRUE' -system_test.drupal_set_message.fail: - path: '/system-test/drupal-set-message-fail' - defaults: - _title: 'Uses #attached in render array with drupal_set_message()' - _controller: '\Drupal\system_test\Controller\SystemTestController::drupalSetMessageFailTest' - requirements: - _access: 'TRUE' - system_test.main_content_fallback: path: '/system-test/main-content-fallback' defaults: -- 1.8.4.2