public function AreaEntityTest::doTestRender in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/views/src/Tests/Handler/AreaEntityTest.php \Drupal\views\Tests\Handler\AreaEntityTest::doTestRender()
Tests rendering the entity area handler.
Parameters
\Drupal\Core\Entity\EntityInterface[] $entities: The entities.
1 call to AreaEntityTest::doTestRender()
- AreaEntityTest::testEntityArea in core/
modules/ views/ src/ Tests/ Handler/ AreaEntityTest.php - Tests the area handler.
File
- core/
modules/ views/ src/ Tests/ Handler/ AreaEntityTest.php, line 124 - Contains \Drupal\views\Tests\Handler\AreaEntityTest.
Class
- AreaEntityTest
- Tests the generic entity area handler.
Namespace
Drupal\views\Tests\HandlerCode
public function doTestRender($entities) {
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = $this->container
->get('renderer');
$view = Views::getView('test_entity_area');
$preview = $view
->preview('default', [
$entities[1]
->id(),
]);
$this
->setRawContent(\Drupal::service('renderer')
->renderRoot($preview));
$view_class = 'js-view-dom-id-' . $view->dom_id;
$header_xpath = '//div[@class = "' . $view_class . '"]/header[1]';
$footer_xpath = '//div[@class = "' . $view_class . '"]/footer[1]';
$result = $this
->xpath($header_xpath);
$this
->assertTrue(strpos(trim((string) $result[0]), $entities[0]
->label()) !== FALSE, 'The rendered entity appears in the header of the view.');
$this
->assertTrue(strpos(trim((string) $result[0]), 'full') !== FALSE, 'The rendered entity appeared in the right view mode.');
$result = $this
->xpath($footer_xpath);
$this
->assertTrue(strpos(trim((string) $result[0]), $entities[1]
->label()) !== FALSE, 'The rendered entity appears in the footer of the view.');
$this
->assertTrue(strpos(trim((string) $result[0]), 'full') !== FALSE, 'The rendered entity appeared in the right view mode.');
$preview = $view
->preview('default', array(
$entities[1]
->id(),
));
$this
->setRawContent($renderer
->renderRoot($preview));
$result = $this
->xpath($header_xpath);
$this
->assertTrue(strpos(trim((string) $result[0]), $entities[0]
->label()) !== FALSE, 'The rendered entity appears in the header of the view.');
$this
->assertTrue(strpos(trim((string) $result[0]), 'full') !== FALSE, 'The rendered entity appeared in the right view mode.');
$result = $this
->xpath($footer_xpath);
$this
->assertTrue(strpos(trim((string) $result[0]), $entities[1]
->label()) !== FALSE, 'The rendered entity appears in the footer of the view.');
$this
->assertTrue(strpos(trim((string) $result[0]), 'full') !== FALSE, 'The rendered entity appeared in the right view mode.');
// Mark entity_test test view_mode as customizable.
$entity_view_mode = \Drupal::entityManager()
->getStorage('entity_view_mode')
->load('entity_test.test');
$entity_view_mode
->enable();
$entity_view_mode
->save();
// Change the view mode of the area handler.
$view = Views::getView('test_entity_area');
$item = $view
->getHandler('default', 'header', 'entity_entity_test');
$item['view_mode'] = 'test';
$view
->setHandler('default', 'header', 'entity_entity_test', $item);
$preview = $view
->preview('default', array(
$entities[1]
->id(),
));
$this
->setRawContent($renderer
->renderRoot($preview));
$view_class = 'js-view-dom-id-' . $view->dom_id;
$result = $this
->xpath('//div[@class = "' . $view_class . '"]/header[1]');
$this
->assertTrue(strpos(trim((string) $result[0]), $entities[0]
->label()) !== FALSE, 'The rendered entity appears in the header of the view.');
$this
->assertTrue(strpos(trim((string) $result[0]), 'test') !== FALSE, 'The rendered entity appeared in the right view mode.');
// Test entity access.
$view = Views::getView('test_entity_area');
$preview = $view
->preview('default', array(
$entities[2]
->id(),
));
$this
->setRawContent($renderer
->renderRoot($preview));
$view_class = 'js-view-dom-id-' . $view->dom_id;
$result = $this
->xpath('//div[@class = "' . $view_class . '"]/footer[1]');
$this
->assertTrue(strpos($result[0], $entities[2]
->label()) === FALSE, 'The rendered entity does not appear in the footer of the view.');
// Test the available view mode options.
$form = array();
$form_state = (new FormState())
->set('type', 'header');
$view->display_handler
->getHandler('header', 'entity_entity_test')
->buildOptionsForm($form, $form_state);
$this
->assertTrue(isset($form['view_mode']['#options']['test']), 'Ensure that the test view mode is available.');
$this
->assertTrue(isset($form['view_mode']['#options']['default']), 'Ensure that the default view mode is available.');
}