Chris@0: container->get('renderer'); Chris@0: $view = Views::getView('test_view_embed'); Chris@0: Chris@0: // Get the render array, #embed must be FALSE since this is the default Chris@0: // display. Chris@0: $render = $view->buildRenderable(); Chris@0: $this->assertEqual($render['#embed'], FALSE); Chris@0: $this->setRawContent($renderer->renderRoot($render)); Chris@0: Chris@0: $xpath = $this->xpath('//div[@class="views-element-container"]'); Chris@0: $this->assertTrue($xpath, 'The view container has been found in the rendered output.'); Chris@0: Chris@0: // There should be 5 rows in the results. Chris@0: $xpath = $this->xpath('//div[@class="views-row"]'); Chris@0: $this->assertEqual(count($xpath), 5); Chris@0: Chris@0: // Add an argument and save the view. Chris@0: $view->displayHandlers->get('default')->overrideOption('arguments', [ Chris@0: 'age' => [ Chris@0: 'default_action' => 'ignore', Chris@0: 'title' => '', Chris@0: 'default_argument_type' => 'fixed', Chris@0: 'validate' => [ Chris@0: 'type' => 'none', Chris@0: 'fail' => 'not found', Chris@0: ], Chris@0: 'break_phrase' => FALSE, Chris@0: 'not' => FALSE, Chris@0: 'id' => 'age', Chris@0: 'table' => 'views_test_data', Chris@0: 'field' => 'age', Chris@0: 'plugin_id' => 'numeric', Chris@0: ], Chris@0: ]); Chris@0: $view->save(); Chris@0: Chris@0: // Test the render array again. Chris@0: $view = Views::getView('test_view_embed'); Chris@0: $render = $view->buildRenderable(NULL, [25]); Chris@0: $this->setRawContent($renderer->renderRoot($render)); Chris@0: // There should be 1 row in the results, 'John' arg 25. Chris@0: $xpath = $this->xpath('//div[@class="views-row"]'); Chris@0: $this->assertEqual(count($xpath), 1); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests the rendered output and form output of a view element, using the Chris@0: * embed display plugin. Chris@0: */ Chris@0: public function testViewElementEmbed() { Chris@0: /** @var \Drupal\Core\Render\RendererInterface $renderer */ Chris@0: $renderer = $this->container->get('renderer'); Chris@0: $view = Views::getView('test_view_embed'); Chris@0: Chris@0: // Get the render array, #embed must be TRUE since this is an embed display. Chris@0: $render = $view->buildRenderable('embed_1'); Chris@0: $this->assertEqual($render['#embed'], TRUE); Chris@0: $this->setRawContent($renderer->renderRoot($render)); Chris@0: Chris@17: // Ensure that the render array can be serialized. Chris@17: serialize($render); Chris@17: Chris@0: $xpath = $this->xpath('//div[@class="views-element-container"]'); Chris@0: $this->assertTrue($xpath, 'The view container has been found in the rendered output.'); Chris@0: Chris@0: // There should be 5 rows in the results. Chris@0: $xpath = $this->xpath('//div[@class="views-row"]'); Chris@0: $this->assertEqual(count($xpath), 5); Chris@0: Chris@0: // Add an argument and save the view. Chris@0: $view->displayHandlers->get('default')->overrideOption('arguments', [ Chris@0: 'age' => [ Chris@0: 'default_action' => 'ignore', Chris@0: 'title' => '', Chris@0: 'default_argument_type' => 'fixed', Chris@0: 'validate' => [ Chris@0: 'type' => 'none', Chris@0: 'fail' => 'not found', Chris@0: ], Chris@0: 'break_phrase' => FALSE, Chris@0: 'not' => FALSE, Chris@0: 'id' => 'age', Chris@0: 'table' => 'views_test_data', Chris@0: 'field' => 'age', Chris@0: 'plugin_id' => 'numeric', Chris@0: ], Chris@0: ]); Chris@0: $view->save(); Chris@0: Chris@0: // Test the render array again. Chris@0: $view = Views::getView('test_view_embed'); Chris@0: $render = $view->buildRenderable('embed_1', [25]); Chris@0: $this->setRawContent($renderer->renderRoot($render)); Chris@0: // There should be 1 row in the results, 'John' arg 25. Chris@0: $xpath = $this->xpath('//div[@class="views-row"]'); Chris@0: $this->assertEqual(count($xpath), 1); Chris@0: Chris@0: // Tests the render array with an exposed filter. Chris@0: $view = Views::getView('test_view_embed'); Chris@0: $render = $view->buildRenderable('embed_2'); Chris@0: $this->setRawContent($renderer->renderRoot($render)); Chris@0: Chris@0: // Ensure that the exposed form is rendered. Chris@0: $this->assertEqual(1, count($this->xpath('//form[@class="views-exposed-form"]'))); Chris@0: } Chris@0: Chris@0: }