Issue #2012502 by damiankloip: Fixed Tab options form cannot be submitted.

8.0.x
Alex Pott 2013-06-13 21:50:46 +01:00
parent b0113327fa
commit 4b815b31e9
3 changed files with 71 additions and 3 deletions

View File

@ -811,13 +811,20 @@ abstract class DisplayPluginBase extends PluginBase {
public function getPlugin($type) {
// Look up the plugin name to use for this instance.
$options = $this->getOption($type);
$name = $options['type'];
// Return now if no options have been loaded.
if (empty($options) || !isset($options['type'])) {
return;
}
// Query plugins allow specifying a specific query class per base table.
if ($type == 'query') {
$views_data = Views::viewsData()->get($this->view->storage->get('base_table'));
$name = isset($views_data['table']['base']['query_id']) ? $views_data['table']['base']['query_id'] : 'views_query';
}
else {
$name = $options['type'];
}
// Plugin instances are stored on the display for re-use.
if (!isset($this->plugins[$type][$name])) {

View File

@ -7,7 +7,13 @@
namespace Drupal\views\Tests\Plugin;
use Drupal\views\Tests\ViewUnitTestBase;
use Drupal\views\ViewExecutable;
use Drupal\views\Plugin\views\style\StylePluginBase;
use Drupal\views\Plugin\views\access\AccessPluginBase;
use Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase;
use Drupal\views\Plugin\views\pager\PagerPluginBase;
use Drupal\views\Plugin\views\query\QueryPluginBase;
use Drupal\views\Plugin\views\cache\CachePluginBase;
use Drupal\views\Plugin\views\row\RowPluginBase;
/**
* Drupal unit tests for the DisplayPluginBase class.
@ -87,7 +93,35 @@ class DisplayUnitTest extends ViewUnitTestBase {
$this->assertIdentical($display_data[$id]['display_options'][$type], $options);
}
}
}
/**
* Tests the \Drupal\views\Plugin\views\display\DisplayPluginBase::getPlugin() method.
*/
public function testGetPlugin() {
$view = views_get_view('test_display_defaults');
$view->initDisplay();
$display_handler = $view->display_handler;
$this->assertTrue($display_handler->getPlugin('access') instanceof AccessPluginBase, 'An access plugin instance was returned.');
$this->assertTrue($display_handler->getPlugin('cache') instanceof CachePluginBase, 'A cache plugin instance was returned.');
$this->assertTrue($display_handler->getPlugin('exposed_form') instanceof ExposedFormPluginBase, 'An exposed_form plugin instance was returned.');
$this->assertTrue($display_handler->getPlugin('pager') instanceof PagerPluginBase, 'A pager plugin instance was returned.');
$this->assertTrue($display_handler->getPlugin('query') instanceof QueryPluginBase, 'A query plugin instance was returned.');
$this->assertTrue($display_handler->getPlugin('row') instanceof RowPluginBase, 'A row plugin instance was returned.');
$this->assertTrue($display_handler->getPlugin('style') instanceof StylePluginBase, 'A style plugin instance was returned.');
// Test that nothing is returned when an invalid type is requested.
$this->assertNull($display_handler->getPlugin('invalid'), 'NULL was returned for an invalid instance');
// Test that nothing was returned for an instance with no 'type' in options.
unset($display_handler->options['access']);
$this->assertNull($display_handler->getPlugin('access'), 'NULL was returned for a plugin type with no "type" option');
// Get a plugin twice, and make sure the same instance is returned.
$view->destroy();
$view->initDisplay();
$first = spl_object_hash($display_handler->getPlugin('style'));
$second = spl_object_hash($display_handler->getPlugin('style'));
$this->assertIdentical($first, $second, 'The same plugin instance was returned.');
}
}

View File

@ -39,7 +39,7 @@ class DisplayPath extends UITestBase {
// Save a path and make sure the summary appears as expected.
$random_path = $this->randomName();
$this->drupalPost("admin/structure/views/nojs/display/test_view/page_1/path", array('path' => $random_path), t('Apply'));
$this->drupalPost('admin/structure/views/nojs/display/test_view/page_1/path', array('path' => $random_path), t('Apply'));
$this->assertText('/' . $random_path, 'The custom path appears in the summary.');
$this->assertLink(t('View @display', array('@display' => 'Page')), 0, 'view page link found on the page.');
}
@ -55,4 +55,31 @@ class DisplayPath extends UITestBase {
$this->assertRaw(t('The view %view has been saved.', array('%view' => 'Test view')));
}
/**
* Tests the menu and tab option form.
*/
public function testMenuOptions() {
$this->container->get('module_handler')->enable(array('menu'));
$this->drupalGet('admin/structure/views/view/test_view');
// Add a new page display.
$this->drupalPost(NULL, array(), 'Add Page');
// Save a path.
$this->drupalPost('admin/structure/views/nojs/display/test_view/page_1/path', array('path' => $this->randomString()), t('Apply'));
$this->drupalGet('admin/structure/views/view/test_view');
$this->drupalPost('admin/structure/views/nojs/display/test_view/page_1/menu', array('menu[type]' => 'default tab', 'menu[title]' => 'Test tab title'), t('Apply'));
$this->assertResponse(200);
$this->assertUrl('admin/structure/views/nojs/display/test_view/page_1/tab_options');
$this->drupalPost(NULL, array('tab_options[type]' => 'tab', 'tab_options[title]' => $this->randomString()), t('Apply'));
$this->assertResponse(200);
$this->assertUrl('admin/structure/views/view/test_view/edit/page_1');
$this->drupalGet('admin/structure/views/view/test_view');
$this->assertLink(t('Tab: @title', array('@title' => 'Test tab title')));
// If it's a default tab, it should also have an additional settings link.
$this->assertLinkByHref('admin/structure/views/nojs/display/test_view/page_1/tab_options');
}
}