Commit 45270552 authored by webchick's avatar webchick

Issue #1938380 by damiankloip, dawehner: Let ViewExecutable->preview() return a render array.

parent 9685483c
......@@ -76,7 +76,7 @@ public function testHandlers() {
$this->executeView($view);
$this->assertEqual(count($view->result), 2);
$output = $view->preview();
$this->drupalSetContent($output);
$this->drupalSetContent(drupal_render($output));
$result = $this->xpath('//span[@class=:class]', array(':class' => 'marker'));
$this->assertEqual(count($result), 1, 'Just one node is marked as new');
......
......@@ -202,20 +202,24 @@ public function optionsSummary(&$categories, &$options) {
public function execute() {
parent::execute();
return new Response($this->view->render(), 200, array('Content-type' => $this->getMimeType()));
$output = $this->view->render();
return new Response(drupal_render($output), 200, array('Content-type' => $this->getMimeType()));
}
/**
* Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::render().
*/
public function render() {
$output = $this->view->style_plugin->render();
$build = array();
$build['#markup'] = $this->view->style_plugin->render();
// Wrap the output in a pre tag if this is for a live preview.
if (!empty($this->view->live_preview)) {
return '<pre>' . $output . '</pre>';
$build['#prefix'] = '<pre>';
$build['#suffix'] = '</pre>';
}
return $output;
return $build;
}
/**
......
......@@ -100,7 +100,8 @@ public function testSerializerResponses() {
$view->setDisplay('rest_export_1');
// Mock the request content type by setting it on the display handler.
$view->display_handler->setContentType('json');
$this->assertIdentical($actual_json, $view->preview(), 'The expected JSON preview output was found.');
$output = $view->preview();
$this->assertIdentical($actual_json, drupal_render($output), 'The expected JSON preview output was found.');
// Test a 403 callback.
$this->drupalGet('test/serialize/denied');
......
......@@ -80,7 +80,8 @@ function views_ajax() {
// Reuse the same DOM id so it matches that in Drupal.settings.
$view->dom_id = $dom_id;
$response->addCommand(new ReplaceCommand(".view-dom-id-$dom_id", $view->preview($display_id, $args)));
$preview = $view->preview($display_id, $args);
$response->addCommand(new ReplaceCommand(".view-dom-id-$dom_id", drupal_render($preview)));
}
return $response;
}
......
......@@ -78,17 +78,11 @@ function render($empty = FALSE) {
drupal_set_message(t("Recursion detected in view @view display @display.", array('@view' => $view_name, '@display' => $display_id)), 'error');
}
else {
// Current $view->preview() does not return a render array, so we have
// to build a markup out if it.
if (!empty($this->options['inherit_arguments']) && !empty($this->view->args)) {
return array(
'#markup' => $view->preview($display_id, $this->view->args),
);
return $view->preview($display_id, $this->view->args);
}
else {
return array(
'#markup' => $view->preview($display_id),
);
return $view->preview($display_id);
}
}
}
......
......@@ -2549,8 +2549,7 @@ public function execute() { }
* some other AJAXy reason.
*/
function preview() {
$element = $this->view->render();
return drupal_render($element);
return $this->view->render();
}
/**
......
......@@ -88,7 +88,8 @@ public function testEntityArea() {
}
$view = views_get_view('test_entity_area');
$this->drupalSetContent($view->preview('default', array($entities[1]->id())));
$preview = $view->preview('default', array($entities[1]->id()));
$this->drupalSetContent(drupal_render($preview));
$result = $this->xpath('//div[@class = "view-header"]');
$this->assertTrue(strpos(trim((string) $result[0]), $entities[0]->label()) !== FALSE, 'The rendered entity appears in the header of the view.');
......@@ -104,7 +105,8 @@ public function testEntityArea() {
$item['view_mode'] = 'test';
$view->setItem('default', 'header', 'entity_entity_test_render', $item);
$this->drupalSetContent($view->preview('default', array($entities[1]->id())));
$preview = $view->preview('default', array($entities[1]->id()));
$this->drupalSetContent(drupal_render($preview));
$result = $this->xpath('//div[@class = "view-header"]');
$this->assertTrue(strpos(trim((string) $result[0]), $entities[0]->label()) !== FALSE, 'The rendered entity appears in the header of the view.');
......
......@@ -111,6 +111,7 @@ public function testRenderArea() {
// Check whether the strings exists in the output.
$output = $view->preview();
$output = drupal_render($output);
$this->assertTrue(strpos($output, $header_string) !== FALSE);
$this->assertTrue(strpos($output, $footer_string) !== FALSE);
$this->assertTrue(strpos($output, $empty_string) !== FALSE);
......@@ -149,6 +150,7 @@ public function testRenderAreaToken() {
// Test we have the site:name token in the output.
$output = $view->preview();
$output = drupal_render($output);
$expected = token_replace('[site:name]');
$this->assertTrue(strpos($output, $expected) !== FALSE);
}
......
......@@ -218,6 +218,7 @@ public function testExclude() {
$view->field['name']->options['exclude'] = TRUE;
$output = $view->preview();
$output = drupal_render($output);
foreach ($this->dataSet() as $entry) {
$this->assertNotSubString($output, $entry['name']);
}
......@@ -226,6 +227,7 @@ public function testExclude() {
$view->field['name']->options['exclude'] = FALSE;
$output = $view->preview();
$output = drupal_render($output);
foreach ($this->dataSet() as $entry) {
$this->assertSubString($output, $entry['name']);
}
......
......@@ -331,11 +331,13 @@ public function testFieldClasses() {
$id_field->options['element_default_classes'] = FALSE;
$output = $view->preview();
$output = drupal_render($output);
$this->assertFalse($this->xpathContent($output, '//div[contains(@class, :class)]', array(':class' => 'field-content')));
$this->assertFalse($this->xpathContent($output, '//div[contains(@class, :class)]', array(':class' => 'field-label')));
$id_field->options['element_default_classes'] = TRUE;
$output = $view->preview();
$output = drupal_render($output);
// Per default the label and the element of the field are spans.
$this->assertTrue($this->xpathContent($output, '//span[contains(@class, :class)]', array(':class' => 'field-content')));
$this->assertTrue($this->xpathContent($output, '//span[contains(@class, :class)]', array(':class' => 'views-label')));
......@@ -351,11 +353,13 @@ public function testFieldClasses() {
// Set a custom wrapper element css class.
$id_field->options['element_wrapper_class'] = $random_class;
$output = $view->preview();
$output = drupal_render($output);
$this->assertTrue($this->xpathContent($output, "//{$element_type}[contains(@class, :class)]", array(':class' => $random_class)));
// Set no custom css class.
$id_field->options['element_wrapper_class'] = '';
$output = $view->preview();
$output = drupal_render($output);
$this->assertFalse($this->xpathContent($output, "//{$element_type}[contains(@class, :class)]", array(':class' => $random_class)));
$this->assertTrue($this->xpathContent($output, "//li[contains(@class, views-row)]/{$element_type}"));
}
......@@ -369,11 +373,13 @@ public function testFieldClasses() {
// Set a custom label element css class.
$id_field->options['element_label_class'] = $random_class;
$output = $view->preview();
$output = drupal_render($output);
$this->assertTrue($this->xpathContent($output, "//li[contains(@class, views-row)]//{$element_type}[contains(@class, :class)]", array(':class' => $random_class)));
// Set no custom css class.
$id_field->options['element_label_class'] = '';
$output = $view->preview();
$output = drupal_render($output);
$this->assertFalse($this->xpathContent($output, "//li[contains(@class, views-row)]//{$element_type}[contains(@class, :class)]", array(':class' => $random_class)));
$this->assertTrue($this->xpathContent($output, "//li[contains(@class, views-row)]//{$element_type}"));
}
......@@ -387,11 +393,13 @@ public function testFieldClasses() {
// Set a custom label element css class.
$id_field->options['element_class'] = $random_class;
$output = $view->preview();
$output = drupal_render($output);
$this->assertTrue($this->xpathContent($output, "//li[contains(@class, views-row)]//div[contains(@class, views-field)]//{$element_type}[contains(@class, :class)]", array(':class' => $random_class)));
// Set no custom css class.
$id_field->options['element_class'] = '';
$output = $view->preview();
$output = drupal_render($output);
$this->assertFalse($this->xpathContent($output, "//li[contains(@class, views-row)]//div[contains(@class, views-field)]//{$element_type}[contains(@class, :class)]", array(':class' => $random_class)));
$this->assertTrue($this->xpathContent($output, "//li[contains(@class, views-row)]//div[contains(@class, views-field)]//{$element_type}"));
}
......
......@@ -139,14 +139,16 @@ function testHeaderStorage() {
)
));
$view->preview();
$output = $view->preview();
drupal_render($output);
unset($view->pre_render_called);
drupal_static_reset('drupal_add_css');
drupal_static_reset('drupal_add_js');
$view->destroy();
$view->setDisplay();
$view->preview();
$output = $view->preview();
drupal_render($output);
$css = drupal_add_css();
$css_path = drupal_get_path('module', 'views_test_data') . '/views_cache.test.css';
$js_path = drupal_get_path('module', 'views_test_data') . '/views_cache.test.js';
......@@ -166,14 +168,14 @@ function testHeaderStorage() {
drupal_add_js($system_js_path);
$view->destroy();
$view->setDisplay();
$view->preview();
$output = $view->preview();
drupal_render($output);
drupal_static_reset('drupal_add_css');
drupal_static_reset('drupal_add_js');
$view->destroy();
$view->setDisplay();
$view->preview();
$output = $view->preview();
drupal_render($output);
$css = drupal_add_css();
$js = drupal_add_js();
......
......@@ -82,6 +82,7 @@ function testDisplayPlugin() {
$this->assertIdentical($view->display_handler->getOption('test_option'), '');
$output = $view->preview();
$output = drupal_render($output);
$this->assertTrue(strpos($output, '<h1></h1>') !== FALSE, 'An empty value for test_option found in output.');
......@@ -90,6 +91,7 @@ function testDisplayPlugin() {
$view->save();
$output = $view->preview();
$output = drupal_render($output);
// Test we have our custom <h1> tag in the output of the view.
$this->assertTrue(strpos($output, '<h1>Test option title</h1>') !== FALSE, 'The test_option value found in display output title.');
......
......@@ -54,7 +54,8 @@ public function testMappedOutput() {
* The view rendered as HTML.
*/
protected function mappedOutputHelper($view) {
$rendered_output = $view->preview();
$output = $view->preview();
$rendered_output = drupal_render($output);
$this->storeViewPreview($rendered_output);
$rows = $this->elements->body->div->div->div;
$data_set = $this->dataSet();
......
......@@ -64,6 +64,7 @@ public function testStyle() {
// rendered.
$view->style_plugin->setOutput($random_text);
$output = $view->preview();
$output = drupal_render($output);
$this->assertTrue(strpos($output, $random_text) !== FALSE, 'Take sure that the rendering of the style plugin appears in the output of the view.');
// This run use the test row plugin and render with it.
......@@ -86,6 +87,7 @@ public function testStyle() {
$view->rowPlugin->setOutput($random_text);
$output = $view->preview();
$output = drupal_render($output);
$this->assertTrue(strpos($output, $random_text) !== FALSE, 'Take sure that the rendering of the row plugin appears in the output of the view.');
}
......@@ -225,8 +227,8 @@ function testCustomRowClasses() {
$random_name = $this->randomName();
$view->style_plugin->options['row_class'] = $random_name . " test-token-[name]";
$rendered_output = $view->preview();
$this->storeViewPreview($rendered_output);
$output = $view->preview();
$this->storeViewPreview(drupal_render($output));
$rows = $this->elements->body->div->div->div;
$count = 0;
......
......@@ -33,8 +33,8 @@ public static function getInfo() {
function testDefaultRowClasses() {
$view = views_get_view('test_view');
$view->setDisplay();
$rendered_output = $view->preview();
$this->storeViewPreview($rendered_output);
$output = $view->preview();
$this->storeViewPreview(drupal_render($output));
$rows = $this->elements->body->div->div->div;
$count = 0;
......
......@@ -103,6 +103,7 @@ public function testCustomOption() {
$view = views_get_view('test_view');
$output = $view->preview();
$output = drupal_render($output);
$replacements = array('%type' => $type);
$this->{$values['test']}(strpos($output, $values['true']), format_string('Expected custom boolean TRUE value in output for %type.', $replacements));
......
......@@ -41,7 +41,8 @@ public function testRender() {
// Make sure that the rendering just calls the preprocess function once.
$view = views_get_view('test_view_render');
$view->preview();
$output = $view->preview();
drupal_render($output);
$this->assertEqual(state()->get('views_render.test'), 1);
}
......
......@@ -127,8 +127,7 @@ public function execute() {
* Override so preview and execute are the same output.
*/
public function preview() {
$element = $this->execute();
return drupal_render($element);
return $this->execute();
}
}
......@@ -69,7 +69,7 @@ function views_pre_render_view_element($element) {
$view = views_get_view($element['#name']);
if ($view && $view->access($element['#display_id'])) {
$element['view']['#markup'] = $view->preview($element['#display_id'], $element['#arguments']);
$element['view'] = $view->preview($element['#display_id'], $element['#arguments']);
}
return $element;
......
......@@ -585,6 +585,7 @@ public function renderPreview($display_id, $args = array()) {
// Execute/get the view preview.
$preview = $this->executable->preview($display_id, $args);
$preview = drupal_render($preview);
if ($show_additional_queries) {
$this->endQueryCapture();
......
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