diff --git a/core/modules/views/src/ViewExecutable.php b/core/modules/views/src/ViewExecutable.php index f13c0e7..0db9c3b 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 a568363..b49d0c3 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 819a439..bb56b9e 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); + } + }