You are here

public function JoinTest::testExamplePlugin in Views (for Drupal 7) 8.3

Tests an example join plugin.

File

lib/Drupal/views/Tests/Plugin/JoinTest.php, line 45
Definition of Drupal\views\Tests\Plugin\JoinTest.

Class

JoinTest
Tests a generic join plugin and the join plugin base.

Namespace

Drupal\views\Tests\Plugin

Code

public function testExamplePlugin() {

  // Setup a simple join and test the result sql.
  $view = views_get_view('frontpage');
  $view
    ->initDisplay();
  $view
    ->initQuery();
  $configuration = array(
    'left_table' => 'node',
    'left_field' => 'uid',
    'table' => 'users',
    '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('node');
  $table = array(
    'alias' => 'users',
  );
  $join
    ->buildJoin($query, $table, $view->query);
  $tables = $query
    ->getTables();
  $join_info = $tables['users'];
  debug($join_info);
  $this
    ->assertTrue(strpos($join_info['condition'], "node.uid = {$rand_int}") !== FALSE, 'Make sure that the custom join plugin can extend the join base and alter the result.');
}