You are here

protected function FieldEntityLinkTest::doTestEntityLink in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views/src/Tests/Handler/FieldEntityLinkTest.php \Drupal\views\Tests\Handler\FieldEntityLinkTest::doTestEntityLink()

Tests whether entity links behave as expected.

Parameters

\Drupal\Core\Session\AccountInterface $account: The user account to be used to run the test;

bool[] $expected_results: An associative array of expected results keyed by link template name.

1 call to FieldEntityLinkTest::doTestEntityLink()
FieldEntityLinkTest::testEntityLink in core/modules/views/src/Tests/Handler/FieldEntityLinkTest.php
Tests entity link fields.

File

core/modules/views/src/Tests/Handler/FieldEntityLinkTest.php, line 91
Contains \Drupal\views\Tests\Handler\FieldEntityLinkTest.

Class

FieldEntityLinkTest
Tests the core Drupal\views\Plugin\views\field\EntityOperations handler.

Namespace

Drupal\views\Tests\Handler

Code

protected function doTestEntityLink(AccountInterface $account, $expected_results) {
  \Drupal::currentUser()
    ->setAccount($account);
  $view = Views::getView('test_entity_test_link');
  $view
    ->preview();
  $info = [
    'canonical' => [
      'label' => 'View entity test',
      'field_id' => 'view_entity_test',
      'destination' => FALSE,
    ],
    'edit-form' => [
      'label' => 'Edit entity test',
      'field_id' => 'edit_entity_test',
      'destination' => TRUE,
    ],
    'delete-form' => [
      'label' => 'Delete entity test',
      'field_id' => 'delete_entity_test',
      'destination' => TRUE,
    ],
  ];
  $index = 0;
  foreach (EntityTest::loadMultiple() as $entity) {
    foreach ($expected_results as $template => $expected_result) {
      $expected_link = '';
      if ($expected_result) {
        $path = $entity
          ->url($template);
        $destination = $info[$template]['destination'] ? '?destination=/' : '';
        $expected_link = '<a href="' . $path . $destination . '" hreflang="en">' . $info[$template]['label'] . '</a>';
      }
      $link = $view->style_plugin
        ->getField($index, $info[$template]['field_id']);
      $this
        ->assertEqual($link, $expected_link);
    }
    $index++;
  }
}