diff --git a/core/modules/views/src/ViewExecutable.php b/core/modules/views/src/ViewExecutable.php index 7ca902906cb9ec75b4f3d0a0ce0656b3915a9c7a..b8e7346b7ce63d29a0a765251a29d31653d5751d 100644 --- a/core/modules/views/src/ViewExecutable.php +++ b/core/modules/views/src/ViewExecutable.php @@ -2,6 +2,7 @@ namespace Drupal\views; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Component\Utility\Html; use Drupal\Component\Utility\Tags; use Drupal\Core\Routing\RouteProviderInterface; @@ -799,7 +800,7 @@ public function setDisplay($display_id = NULL) { // Ensure the requested display exists. if (!$this->displayHandlers->has($display_id)) { - debug(format_string('setDisplay() called with invalid display ID "@display".', ['@display' => $display_id])); + trigger_error(new FormattableMarkup('setDisplay() called with invalid display ID "@display".', ['@display' => $display_id]), E_USER_WARNING); return FALSE; } diff --git a/core/modules/views/tests/src/Kernel/ViewExecutableTest.php b/core/modules/views/tests/src/Kernel/ViewExecutableTest.php index a568363bb90ef0aae68bfe547b703a2047dd6f15..b49d0c32fb7b3d30c2644b6cd07fe6b00a030341 100644 --- a/core/modules/views/tests/src/Kernel/ViewExecutableTest.php +++ b/core/modules/views/tests/src/Kernel/ViewExecutableTest.php @@ -196,8 +196,13 @@ public function testSetDisplayWithInvalidDisplay() { $view->initDisplay(); // Error is triggered while calling the wrong display. - $this->setExpectedException(\PHPUnit_Framework_Error::class); - $view->setDisplay('invalid'); + try { + $view->setDisplay('invalid'); + $this->fail('Expected error, when setDisplay() called with invalid display ID'); + } + catch (\PHPUnit_Framework_Error_Warning $e) { + $this->assertEquals('setDisplay() called with invalid display ID "invalid".', $e->getMessage()); + } $this->assertEqual($view->current_display, 'default', 'If setDisplay is called with an invalid display id the default display should be used.'); $this->assertEqual(spl_object_hash($view->display_handler), spl_object_hash($view->displayHandlers->get('default'))); diff --git a/core/modules/views_ui/src/Tests/ViewEditTest.php b/core/modules/views_ui/src/Tests/ViewEditTest.php index 819a4391bb6566ed9910564c7bac9e8caada5efa..a939f97ae6e387538d3b832a77ab24c4f125a648 100644 --- a/core/modules/views_ui/src/Tests/ViewEditTest.php +++ b/core/modules/views_ui/src/Tests/ViewEditTest.php @@ -75,8 +75,13 @@ public function testOtherOptions() { $error_text = t('Display name must be letters, numbers, or underscores only.'); // Test that potential invalid display ID requests are detected - $this->drupalGet('admin/structure/views/ajax/handler/test_view/fake_display_name/filter/title'); - $this->assertText('Invalid display id fake_display_name'); + try { + $this->drupalGet('admin/structure/views/ajax/handler/test_view/fake_display_name/filter/title'); + $this->fail('Expected error, when setDisplay() called with invalid display ID'); + } + catch (\Exception $e) { + $this->assertEqual('setDisplay() called with invalid display ID "fake_display_name".', $e->getMessage()); + } $edit = ['display_id' => 'test 1']; $this->drupalPostForm($machine_name_edit_url, $edit, 'Apply'); @@ -239,4 +244,16 @@ public function testRelationRepresentativeNode() { $this->drupalPostForm('admin/structure/views/nojs/handler/test_groupwise_term_ui/default/relationship/tid_representative', $edit, 'Apply'); } + /** + * Override the error method so we can test for the expected exception. + * + * @todo Remove as part of https://www.drupal.org/node/2864613 + */ + protected function error($message = '', $group = 'Other', array $caller = NULL) { + if ($group === 'User warning') { + throw new \Exception($message); + } + return parent::error($message, $group, $caller); + } + }