Commit 3b2b644d authored by catch's avatar catch

Issue #2461017 by aerozeppelin, Berdir, Lendude: TaxonomyIndexTid doesn't...

Issue #2461017 by aerozeppelin, Berdir, Lendude: TaxonomyIndexTid doesn't check whether there are any values before trying to loop over it
parent f33c6be7
......@@ -271,8 +271,10 @@ protected function valueValidate($form, FormStateInterface $form_state) {
}
$tids = array();
foreach ($form_state->getValue(array('options', 'value')) as $value) {
$tids[] = $value['target_id'];
if ($values = $form_state->getValue(array('options', 'value'))) {
foreach ($values as $value) {
$tids[] = $value['target_id'];
}
}
$form_state->setValue(array('options', 'value'), $tids);
}
......@@ -335,8 +337,10 @@ public function validateExposed(&$form, FormStateInterface $form_state) {
return;
}
foreach ($form_state->getValue($identifier) as $value) {
$this->validated_exposed_input[] = $value['target_id'];
if ($values = $form_state->getValue($identifier)) {
foreach ($values as $value) {
$this->validated_exposed_input[] = $value['target_id'];
}
}
}
......
......@@ -28,14 +28,14 @@ class TaxonomyIndexTidUiTest extends UITestBase {
*
* @var array
*/
public static $testViews = array('test_filter_taxonomy_index_tid');
public static $testViews = array('test_filter_taxonomy_index_tid', 'test_taxonomy_term_name');
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['node', 'taxonomy', 'taxonomy_test_views'];
public static $modules = ['node', 'taxonomy', 'views', 'views_ui', 'taxonomy_test_views'];
/**
* A nested array of \Drupal\taxonomy\TermInterface objects.
......@@ -50,6 +50,9 @@ class TaxonomyIndexTidUiTest extends UITestBase {
protected function setUp() {
parent::setUp();
$this->adminUser = $this->drupalCreateUser(['administer taxonomy', 'administer views']);
$this->drupalLogin($this->adminUser);
Vocabulary::create([
'vid' => 'tags',
'name' => 'Tags',
......@@ -73,6 +76,11 @@ protected function setUp() {
}
}
ViewTestData::createTestViews(get_class($this), array('taxonomy_test_views'));
Vocabulary::create([
'vid' => 'empty_vocabulary',
'name' => 'Empty Vocabulary',
])->save();
}
/**
......@@ -189,6 +197,29 @@ public function testExposedFilter() {
$this->assertIdentical(1, count($xpath));
$xpath = $this->xpath('//div[@class="view-content"]//a[@href=:href]', [':href' => $node4->url()]);
$this->assertIdentical(1, count($xpath));
// Select 'Term ID' as the field to be displayed.
$edit = ['name[taxonomy_term_field_data.tid]' => TRUE];
$this->drupalPostForm('admin/structure/views/nojs/add-handler/test_taxonomy_term_name/default/field', $edit, 'Add and configure fields');
// Select 'Term' and 'Vocabulary' as filters.
$edit = [
'name[taxonomy_term_field_data.tid]' => TRUE,
'name[taxonomy_term_field_data.vid]' => TRUE
];
$this->drupalPostForm('admin/structure/views/nojs/add-handler/test_taxonomy_term_name/default/filter', $edit, 'Add and configure filter criteria');
// Select 'Empty Vocabulary' and 'Autocomplete' from the list of options.
$this->drupalPostForm('admin/structure/views/nojs/handler-extra/test_taxonomy_term_name/default/filter/tid', [], 'Apply and continue');
// Expose the filter.
$edit = ['options[expose_button][checkbox][checkbox]' => TRUE];
$this->drupalPostForm('admin/structure/views/nojs/handler/test_taxonomy_term_name/default/filter/tid', $edit, 'Expose filter');
$this->drupalPostForm('admin/structure/views/nojs/handler/test_taxonomy_term_name/default/filter/tid', $edit, 'Apply');
// Filter 'Taxonomy terms' belonging to 'Empty Vocabulary'.
$edit = ['options[value][empty_vocabulary]' => TRUE];
$this->drupalPostForm('admin/structure/views/nojs/handler/test_taxonomy_term_name/default/filter/vid', $edit, 'Apply');
$this->drupalPostForm('admin/structure/views/view/test_taxonomy_term_name/edit/default', [], 'Save');
$this->drupalPostForm(NULL, [], t('Update preview'));
$preview = $this->xpath("//div[@class='view-content']");
$this->assertTrue(empty($preview), 'No results.');
}
}
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