Commit 32cda049 authored by dawehner's avatar dawehner Committed by tim.plunkett

Issue #1754232 by dawehner: Add a generic testcase for the argument_default base.

parent 4abfc832
......@@ -7,6 +7,9 @@
namespace Drupal\views\Tests\Plugin;
use Drupal\views_test_data\Plugin\views\argument_default\ArgumentDefaultTest as ArgumentDefaultTestPlugin;
/**
* Basic test for pluggable argument default.
*/
......@@ -42,6 +45,45 @@ protected function setUp() {
$this->enableViewsTestModule();
}
/**
* Tests the argument default test plugin.
*
* @see Drupal\views_test_data\Plugin\views\argument_default\ArgumentDefaultTest
*/
public function testArgumentDefaultPlugin() {
$view = views_get_view('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->addItem('default', 'argument', 'views_test_data', 'name', $options);
$view->initHandlers();
$plugin = $view->argument[$id]->get_plugin('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]->get_default_argument(), '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]->get_value(), '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]->get_value(), 'George', 'The correct argument value is used.');
$expected_result = array(array('name' => 'George'));
$this->assertIdenticalResultset($view, $expected_result, array('views_test_data_name' => 'name'));
}
/**
* Tests the use of a default argument plugin that provides no options.
*/
......
<?php
/**
* @file
* Definition of Drupal\views_test_data\Plugin\views\argument_default\ArgumentDefaultTest.
*/
namespace Drupal\views_test_data\Plugin\views\argument_default;
use Drupal\views\Plugin\views\argument_default\ArgumentDefaultPluginBase;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
/**
* Defines a argument default test plugin.
*
* @Plugin(
* id = "argument_default_test",
* title = @Translation("Argument default test")
* )
*/
class ArgumentDefaultTest extends ArgumentDefaultPluginBase {
/**
* Overrides Drupal\views\Plugin\views\argument_default\ArgumentDefaultPluginBase::defineOptions().
*/
protected function defineOptions() {
$options = parent::defineOptions();
$options['value'] = array('default' => '');
return $options;
}
/**
* Overrides Drupal\views\Plugin\views\argument_default\ArgumentDefaultPluginBase::get_argument().
*/
public function get_argument() {
return $this->options['value'];
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment