function HandlerTest::testPlaceholder

Same name in other branches
  1. 9 core/modules/views/tests/src/Functional/Handler/HandlerTest.php \Drupal\Tests\views\Functional\Handler\HandlerTest::testPlaceholder()
  2. 8.9.x core/modules/views/tests/src/Functional/Handler/HandlerTest.php \Drupal\Tests\views\Functional\Handler\HandlerTest::testPlaceholder()
  3. 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 335

Class

HandlerTest
Tests abstract handler definitions.

Namespace

Drupal\Tests\views\Functional\Handler

Code

public function testPlaceholder() : void {
    $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());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.