View source
<?php
namespace Drupal\Tests\plugin\Functional\Plugin\PluginSelector;
use Drupal\Tests\BrowserTestBase;
class RadiosTest extends BrowserTestBase {
public static $modules = [
'filter',
'plugin_test_helper',
];
protected $defaultTheme = 'stark';
public function testElement() {
$this
->doTestElement(FALSE);
$this
->doTestElement(TRUE);
}
public function buildFormPath(array $allowed_selectable_plugin_ids, $tree, $always_show_selector = FALSE) {
return sprintf('plugin_test_helper-plugin_selector-advanced_plugin_selector_base/%s/plugin_radios/%d/%d', implode(',', $allowed_selectable_plugin_ids), (int) $tree, (int) $always_show_selector);
}
public function doTestElement($tree) {
$name_prefix = $tree ? 'tree[plugin][container]' : 'container';
$change_button_name = $tree ? 'tree__plugin__container__select__container__change' : 'container__select__container__change';
$path = $this
->buildFormPath([
'none',
], $tree);
$this
->drupalGet($path);
$this
->assertNoFieldByName($name_prefix . '[select][container][container][plugin_id]');
$this
->assertEmpty($this
->getSession()
->getDriver()
->find(sprintf('//input[@name="%s"]', $change_button_name)));
$this
->assertText(t('There are no available options.'));
$path = $this
->buildFormPath([
'plugin_test_helper_configurable_plugin',
], $tree, TRUE);
$this
->drupalGet($path);
$path = $this
->buildFormPath([
'plugin_test_helper_configurable_plugin',
], $tree);
$this
->drupalGet($path);
$this
->assertNoFieldByName($name_prefix . '[select][container][plugin_id]');
$this
->assertEmpty($this
->getSession()
->getDriver()
->find(sprintf('//input[@name="%s"]', $change_button_name)));
$this
->assertNoText(t('There are no available options.'));
$path = $this
->buildFormPath([
'plugin_test_helper_plugin',
'plugin_test_helper_configurable_plugin',
], $tree);
$this
->drupalGet($path);
$this
->assertFieldByName($name_prefix . '[select][container][plugin_id]');
$this
->assertNotEmpty($this
->getSession()
->getDriver()
->find(sprintf('//input[@name="%s"]', $change_button_name)));
$this
->assertNoText(t('There are no available options.'));
$this
->drupalPostForm(NULL, [
$name_prefix . '[select][container][plugin_id]' => 'plugin_test_helper_plugin',
], t('Choose'));
$this
->assertFieldByName($name_prefix . '[select][container][plugin_id]');
$this
->assertNotEmpty($this
->getSession()
->getDriver()
->find(sprintf('//input[@name="%s"]', $change_button_name)));
$this
->drupalPostForm(NULL, [
$name_prefix . '[select][container][plugin_id]' => 'plugin_test_helper_configurable_plugin',
], t('Choose'));
$this
->assertFieldByName($name_prefix . '[select][container][plugin_id]');
$this
->assertNotEmpty($this
->getSession()
->getDriver()
->find(sprintf('//input[@name="%s"]', $change_button_name)));
$foo = $this
->randomString();
$this
->drupalPostForm(NULL, [
$name_prefix . '[select][container][plugin_id]' => 'plugin_test_helper_configurable_plugin',
$name_prefix . '[plugin_form][foo]' => $foo,
], t('Submit'));
$state = \Drupal::state();
$selected_plugin = $state
->get('plugin_test_helper_advanced_plugin_selector_base');
$this
->assertEqual($selected_plugin
->getPluginId(), 'plugin_test_helper_configurable_plugin');
$this
->assertEqual($selected_plugin
->getConfiguration(), [
'foo' => $foo,
]);
}
}