Commit 36745dd0 authored by dawehner's avatar dawehner Committed by tim.plunkett

Issue #1754240 by dawehner: Add a generic testcase for the display_extender base.

parent 6cc9fd2b
......@@ -624,7 +624,7 @@ protected function defineOptions() {
}
foreach ($this->extender as $extender) {
$extender->options_definition_alter($options);
$extender->defineOptionsAlter($options);
}
return $options;
......
......@@ -21,13 +21,13 @@ abstract class DisplayExtenderPluginBase extends PluginBase {
public function init(ViewExecutable $view, &$display) {
$this->setOptionDefaults($this->options, $this->defineOptions());
$this->view = $view;
$this->display = $display;
$this->displayHandler = $display;
}
/**
* Provide a form to edit options for this plugin.
*/
public function options_definition_alter(&$options) { }
public function defineOptionsAlter(&$options) { }
/**
* Provide a form to edit options for this plugin.
......
<?php
/**
* @file
* Definition of Drupal\views\Tests\Plugin\DisplayExtenderTest.
*/
namespace Drupal\views\Tests\Plugin;
use Drupal\views\Tests\Plugin\PluginTestBase;
/**
* Tests the display extender plugins.
*
* @see Drupal\views_test_data\Plugin\views\display_extender\DisplayExtenderTest
*/
class DisplayExtenderTest extends PluginTestBase {
public static function getInfo() {
return array(
'name' => 'Display extender',
'description' => 'Tests the display extender plugins.',
'group' => 'Views Plugins',
);
}
protected function setUp() {
parent::setUp();
$this->enableViewsTestModule();
}
/**
* Test display extenders.
*/
public function testDisplayExtenders() {
config('views.settings')->set('display_extenders', array('display_extender_test'))->save();
$this->assertEqual(count(views_get_enabled_display_extenders()), 1, 'Make sure that there is only one enabled display extender.');
$view = $this->getBasicView();
$view->initDisplay();
$this->assertEqual(count($view->display_handler->extender), 1, 'Make sure that only one extender is initialized.');
$display_extender = $view->display_handler->extender['display_extender_test'];
$this->assertTrue($display_extender instanceof \Drupal\views_test_data\Plugin\views\display_extender\DisplayExtenderTest, 'Make sure the right class got initialized.');
$view->preExecute();
$this->assertTrue($display_extender->testState['pre_execute'], 'Make sure the display extender was able to react on preExecute.');
$view->execute();
$this->assertTrue($display_extender->testState['query'], 'Make sure the display extender was able to react on query.');
}
}
<?php
/**
* @file
* Definition of Drupal\views\Tests\UI\DisplayExtenderUITest.
*/
namespace Drupal\views\Tests\UI;
/**
* Tests the display extender UI.
*/
class DisplayExtenderUITest extends UITestBase {
public static function getInfo() {
return array(
'name' => 'Display extender: UI',
'description' => 'Tests the display extender UI.',
'group' => 'Views UI',
);
}
/**
* Tests the display extender UI.
*/
public function testDisplayExtenderUI() {
config('views.settings')->set('display_extenders', array('display_extender_test'))->save();
$view = $this->getView();
$view_edit_url = "admin/structure/views/view/{$view->storage->name}/edit";
$display_option_url = 'admin/structure/views/nojs/display/test_view/default/test_extender_test_option';
$this->drupalGet($view_edit_url);
$this->assertLinkByHref($display_option_url, 0, 'Make sure the option defined by the test display extender appears in the UI.');
$random_text = $this->randomName();
$this->drupalPost($display_option_url, array('test_extender_test_option' => $random_text), t('Apply'));
$this->assertLink($random_text);
$this->drupalPost(NULL, array(), t('Save'));
$view = views_get_view($view->storage->name);
$view->initDisplay();
$this->assertEqual($view->display_handler->getOption('test_extender_test_option'), $random_text, 'Make sure that the display extender option got saved.');
}
}
<?php
/**
* @file
* Definition of Drupal\views_test_data\Plugin\views\display_extender\DisplayExtenderTest.
*/
namespace Drupal\views_test_data\Plugin\views\display_extender;
use Drupal\views\Plugin\views\display_extender\DisplayExtenderPluginBase;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
/**
* Defines a display extender test plugin.
*
* @Plugin(
* id = "display_extender_test",
* title = @Translation("Display extender test")
* )
*/
class DisplayExtenderTest extends DisplayExtenderPluginBase {
/**
* Stores some state booleans to be sure a certain method got called.
*
* @var array
*/
public $testState;
/**
* Overrides Drupal\views\Plugin\views\display_extender\DisplayExtenderPluginBase::defineOptionsAlter().
*/
public function defineOptionsAlter(&$options) {
$options['test_extender_test_option'] = array('default' => '');
return $options;
}
/**
* Overrides Drupal\views\Plugin\views\display\DisplayPluginBase::optionsSummary().
*/
public function optionsSummary(&$categories, &$options) {
parent::optionsSummary($categories, $options);
$categories['display_extender_test'] = array(
'title' => t('Display extender test settings'),
'column' => 'second',
'build' => array(
'#weight' => -100,
),
);
$test_option = $this->displayHandler->getOption('test_extender_test_option') ?: t('Empty');
$options['test_extender_test_option'] = array(
'category' => 'display_extender_test',
'title' => t('Test option'),
'value' => views_ui_truncate($test_option, 24),
);
}
/**
* Overrides Drupal\views\Plugin\views\display_extender\DisplayExtenderPluginBase::buildOptionsForm().
*/
public function buildOptionsForm(&$form, &$form_state) {
switch ($form_state['section']) {
case 'test_extender_test_option':
$form['#title'] .= t('Test option');
$form['test_extender_test_option'] = array(
'#type' => 'textfield',
'#description' => t('This is a textfield for test_option.'),
'#default_value' => $this->displayHandler->getOption('test_extender_test_option'),
);
}
}
/**
* Overrides Drupal\views\Plugin\views\display\DisplayExtenderPluginBase::submitOptionsForm().
*/
public function submitOptionsForm(&$form, &$form_state) {
parent::submitOptionsForm($form, $form_state);
switch ($form_state['section']) {
case 'test_extender_test_option':
$this->displayHandler->setOption('test_extender_test_option', $form_state['values']['test_extender_test_option']);
break;
}
}
/**
* Overrides Drupal\views\Plugin\views\display\DisplayExtenderPluginBase::defaultableSections().
*/
public function defaultableSections(&$sections, $section = NULL) {
$sections['test_extender_test_option'] = array('test_extender_test_option');
}
/**
* Overrides Drupal\views\Plugin\views\display\DisplayExtenderPluginBase::query().
*/
public function query() {
$this->testState['query'] = TRUE;
}
/**
* Overrides Drupal\views\Plugin\views\display\DisplayExtenderPluginBase::pre_execute().
*/
public function pre_execute() {
$this->testState['pre_execute'] = TRUE;
}
}
<?php
/**
* @file
* Definition of Drupal\views_test_data\Plugin\views\display_extender\DisplayExtenderTest2.
*/
namespace Drupal\views_test_data\Plugin\views\display_extender;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
/**
* Defines another display extender test plugin.
*
* @Plugin(
* id = "display_extender_test_2",
* title = @Translation("Display extender test number two")
* )
*/
class DisplayExtenderTest2 extends DisplayExtenderTest {
}
......@@ -1502,12 +1502,8 @@ function views_get_plugin_definition($type, $plugin_id) {
*/
function views_get_enabled_display_extenders() {
$enabled = array_filter((array) config('views.settings')->get('display_extenders'));
$options = views_fetch_plugin_names('display_extender');
foreach ($options as $name => $plugin) {
$enabled[$name] = $name;
}
return array_filter($enabled);
return drupal_map_assoc($enabled);
}
// -----------------------------------------------------------------------
......
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