public function AreaEntityTest::testEntityArea

Tests the area handler.

File

drupal/core/modules/views/lib/Drupal/views/Tests/Handler/AreaEntityTest.php, line 79
Contains \Drupal\views\Tests\Handler\AreaEntityTest.

Class

AreaEntityTest
Tests the generic entity area handler.

Namespace

Drupal\views\Tests\Handler

Code

public function testEntityArea() {
  $entities = array();
  for ($i = 0; $i < 2; $i++) {
    $random_label = $this
      ->randomName();
    $data = array(
      'bundle' => 'entity_test_render',
      'name' => $random_label,
    );
    $entity_test = $this->container
      ->get('plugin.manager.entity')
      ->getStorageController('entity_test_render')
      ->create($data);
    $entity_test
      ->save();
    $entities[] = $entity_test;
  }
  $view = views_get_view('test_entity_area');
  $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.');
  $this
    ->assertTrue(strpos(trim((string) $result[0]), 'full') !== FALSE, 'The rendered entity appeared in the right view mode.');
  $result = $this
    ->xpath('//div[@class = "view-footer"]');
  $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.');

  // Change the view mode of the area handler.
  $view = views_get_view('test_entity_area');
  $item = $view
    ->getItem('default', 'header', 'entity_entity_test_render');
  $item['view_mode'] = 'test';
  $view
    ->setItem('default', 'header', 'entity_entity_test_render', $item);
  $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.');
  $this
    ->assertTrue(strpos(trim((string) $result[0]), 'test') !== FALSE, 'The rendered entity appeared in the right view mode.');
}