diff --git a/core/modules/views/tests/src/Kernel/ViewExecutableTest.php b/core/modules/views/tests/src/Kernel/ViewExecutableTest.php index 4c1f3a1..b49d0c3 100644 --- a/core/modules/views/tests/src/Kernel/ViewExecutableTest.php +++ b/core/modules/views/tests/src/Kernel/ViewExecutableTest.php @@ -198,8 +198,9 @@ public function testSetDisplayWithInvalidDisplay() { // Error is triggered while calling the wrong display. try { $view->setDisplay('invalid'); + $this->fail('Expected error, when setDisplay() called with invalid display ID'); } - catch (\PHPUnit_Framework_Error $e) { + catch (\PHPUnit_Framework_Error_Warning $e) { $this->assertEquals('setDisplay() called with invalid display ID "invalid".', $e->getMessage()); } 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); + } + }