Commit 0fa72bde authored by catch's avatar catch

Issue #2853359 by vaplas, Lendude, tinny: Runtime debug statement in Views now prints out object

parent e630c782
......@@ -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;
}
......
......@@ -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')));
......
......@@ -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);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment