You are here

public function JoinTest::testExamplePlugin in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views/src/Tests/Plugin/JoinTest.php \Drupal\views\Tests\Plugin\JoinTest::testExamplePlugin()

Tests an example join plugin.

File

core/modules/views/src/Tests/Plugin/JoinTest.php, line 48
Contains \Drupal\views\Tests\Plugin\JoinTest.

Class

JoinTest
Tests the join plugin.

Namespace

Drupal\views\Tests\Plugin

Code

public function testExamplePlugin() {

  // Setup a simple join and test the result sql.
  $view = Views::getView('test_view');
  $view
    ->initDisplay();
  $view
    ->initQuery();
  $configuration = array(
    'left_table' => 'views_test_data',
    'left_field' => 'uid',
    'table' => 'users_field_data',
    'field' => 'uid',
  );
  $join = $this->manager
    ->createInstance('join_test', $configuration);
  $this
    ->assertTrue($join instanceof JoinTestPlugin, 'The correct join class got loaded.');
  $rand_int = rand(0, 1000);
  $join
    ->setJoinValue($rand_int);
  $query = db_select('views_test_data');
  $table = array(
    'alias' => 'users_field_data',
  );
  $join
    ->buildJoin($query, $table, $view->query);
  $tables = $query
    ->getTables();
  $join_info = $tables['users_field_data'];
  $this
    ->assertTrue(strpos($join_info['condition'], "views_test_data.uid = {$rand_int}") !== FALSE, 'Make sure that the custom join plugin can extend the join base and alter the result.');
}