Commit 0c24732c authored by alexpott's avatar alexpott

Issue #2711973 by Berdir: buildRenderable() does not work with display plugin embed

parent ef6c84db
......@@ -20,6 +20,13 @@
*/
class Embed extends DisplayPluginBase {
// This display plugin does nothing apart from exist.
/**
* {@inheritdoc}
*/
public function buildRenderable(array $args = [], $cache = TRUE) {
$build = parent::buildRenderable($args, $cache);
$build['#embed'] = TRUE;
return $build;
}
}
......@@ -18,29 +18,10 @@ class ViewElementTest extends ViewTestBase {
*/
public static $testViews = array('test_view_embed');
/**
* The raw render data array to use in tests.
*
* @var array
*/
protected $render;
protected function setUp() {
parent::setUp();
$this->enableViewsTestModule();
// Set up a render array to use. We need to copy this as drupal_render
// passes by reference.
$this->render = array(
'view' => array(
'#type' => 'view',
'#name' => 'test_view_embed',
'#display_id' => 'default',
'#arguments' => array(25),
'#embed' => FALSE,
),
);
}
/**
......@@ -50,10 +31,11 @@ public function testViewElement() {
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = $this->container->get('renderer');
$view = Views::getView('test_view_embed');
$view->setDisplay();
// Set the content as our rendered array.
$render = $this->render;
// Get the render array, #embed must be FALSE since this is the default
// display.
$render = $view->buildRenderable();
$this->assertEqual($render['#embed'], FALSE);
$this->setRawContent($renderer->renderRoot($render));
$xpath = $this->xpath('//div[@class="views-element-container"]');
......@@ -98,7 +80,8 @@ public function testViewElement() {
$view->save();
// Test the render array again.
$render = $this->render;
$view = Views::getView('test_view_embed');
$render = $view->buildRenderable(NULL, [25]);
$this->setRawContent($renderer->renderRoot($render));
// There should be 1 row in the results, 'John' arg 25.
$xpath = $this->xpath('//div[@class="view-content"]/div');
......@@ -118,11 +101,10 @@ public function testViewElementEmbed() {
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = $this->container->get('renderer');
$view = Views::getView('test_view_embed');
$view->setDisplay('embed_1');
// Set the content as our rendered array.
$render = $this->render;
$render['view']['#embed'] = TRUE;
// Get the render array, #embed must be TRUE since this is an embed display.
$render = $view->buildRenderable('embed_1');
$this->assertEqual($render['#embed'], TRUE);
$this->setRawContent($renderer->renderRoot($render));
$xpath = $this->xpath('//div[@class="views-element-container"]');
......@@ -167,8 +149,8 @@ public function testViewElementEmbed() {
$view->save();
// Test the render array again.
$render = $this->render;
$render['view']['#embed'] = TRUE;
$view = Views::getView('test_view_embed');
$render = $view->buildRenderable('embed_1', [25]);
$this->setRawContent($renderer->renderRoot($render));
// There should be 1 row in the results, 'John' arg 25.
$xpath = $this->xpath('//div[@class="view-content"]/div');
......@@ -180,9 +162,8 @@ public function testViewElementEmbed() {
$this->assertEqual(count($xpath), 1);
// Tests the render array with an exposed filter.
$render = $this->render;
$render['view']['#display_id'] = 'embed_2';
$render['view']['#embed'] = TRUE;
$view = Views::getView('test_view_embed');
$render = $view->buildRenderable('embed_2');
$this->setRawContent($renderer->renderRoot($render));
// Ensure that the exposed form is rendered.
......
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