You are here

public function HandlerTest::testPlaceholder in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/views/tests/src/Functional/Handler/HandlerTest.php \Drupal\Tests\views\Functional\Handler\HandlerTest::testPlaceholder()
  2. 10 core/modules/views/tests/src/Functional/Handler/HandlerTest.php \Drupal\Tests\views\Functional\Handler\HandlerTest::testPlaceholder()

Tests the placeholder function.

See also

\Drupal\views\Plugin\views\HandlerBase::placeholder()

File

core/modules/views/tests/src/Functional/Handler/HandlerTest.php, line 344

Class

HandlerTest
Tests abstract handler definitions.

Namespace

Drupal\Tests\views\Functional\Handler

Code

public function testPlaceholder() {
  $view = Views::getView('test_view');
  $view
    ->initHandlers();
  $view
    ->initQuery();
  $handler = $view->field['name'];
  $table = $handler->table;
  $field = $handler->field;
  $string = ':' . $table . '_' . $field;

  // Make sure the placeholder variables are like expected.
  $this
    ->assertEquals($string, $handler
    ->getPlaceholder());
  $this
    ->assertEquals($string . 1, $handler
    ->getPlaceholder());
  $this
    ->assertEquals($string . 2, $handler
    ->getPlaceholder());

  // Set another table/field combination and make sure there are new
  // placeholders.
  $table = $handler->table = $this
    ->randomMachineName();
  $field = $handler->field = $this
    ->randomMachineName();
  $string = ':' . $table . '_' . $field;

  // Make sure the placeholder variables are like expected.
  $this
    ->assertEquals($string, $handler
    ->getPlaceholder());
  $this
    ->assertEquals($string . 1, $handler
    ->getPlaceholder());
  $this
    ->assertEquals($string . 2, $handler
    ->getPlaceholder());
}