You are here

public function ArgumentDefaultTest::testArgumentDefaultPlugin in Zircon Profile 8

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

Tests the argument default test plugin.

See also

\Drupal\views_test_data\Plugin\views\argument_default\ArgumentDefaultTest

File

core/modules/views/src/Tests/Plugin/ArgumentDefaultTest.php, line 46
Contains \Drupal\views\Tests\Plugin\ArgumentDefaultTest.

Class

ArgumentDefaultTest
Tests pluggable argument_default for views.

Namespace

Drupal\views\Tests\Plugin

Code

public function testArgumentDefaultPlugin() {
  $view = Views::getView('test_view');

  // Add a new argument and set the test plugin for the argument_default.
  $options = array(
    'default_argument_type' => 'argument_default_test',
    'default_argument_options' => array(
      'value' => 'John',
    ),
    'default_action' => 'default',
  );
  $id = $view
    ->addHandler('default', 'argument', 'views_test_data', 'name', $options);
  $view
    ->initHandlers();
  $plugin = $view->argument[$id]
    ->getPlugin('argument_default');
  $this
    ->assertTrue($plugin instanceof ArgumentDefaultTestPlugin, 'The correct argument default plugin is used.');

  // Check that the value of the default argument is as expected.
  $this
    ->assertEqual($view->argument[$id]
    ->getDefaultArgument(), 'John', 'The correct argument default value is returned.');

  // Don't pass in a value for the default argument and make sure the query
  // just returns John.
  $this
    ->executeView($view);
  $this
    ->assertEqual($view->argument[$id]
    ->getValue(), 'John', 'The correct argument value is used.');
  $expected_result = array(
    array(
      'name' => 'John',
    ),
  );
  $this
    ->assertIdenticalResultset($view, $expected_result, array(
    'views_test_data_name' => 'name',
  ));

  // Pass in value as argument to be sure that not the default value is used.
  $view
    ->destroy();
  $this
    ->executeView($view, array(
    'George',
  ));
  $this
    ->assertEqual($view->argument[$id]
    ->getValue(), 'George', 'The correct argument value is used.');
  $expected_result = array(
    array(
      'name' => 'George',
    ),
  );
  $this
    ->assertIdenticalResultset($view, $expected_result, array(
    'views_test_data_name' => 'name',
  ));
}