public function BEF_TestSecondaryFilters::test_befSecondaryFilters in Better Exposed Filters 7.3
Basic coverage for filters rendered in secondary options fieldsets. See
@todo near the end of this test.
File
- tests/
better_exposed_filters.test, line 737 - Simpletest tests for the Better Exposed Filters module.
Class
Code
public function test_befSecondaryFilters() {
// Create a page display to validate rendering.
$this
->createDisplay('Page', array(
'path' => array(
'path' => 'bef_test_page',
),
));
// Add the node.type filter as a multi-select filter.
$this
->addFilter('node.type', array(
'options[expose][multiple]' => TRUE,
));
$this
->setBefSettings(array(
'exposed_form_options[bef][general][allow_secondary]' => 1,
'exposed_form_options[bef][general][secondary_label]' => 'Custom Label',
'exposed_form_options[bef][general][secondary_collapse_override]' => 0,
'exposed_form_options[bef][type][more_options][is_secondary]' => 1,
));
$this
->saveView();
$this
->drupalGet('bef_test_page');
// Verify a collapsed fieldset exists with the correct label.
$this
->assertFieldByXpath('//div[@id="edit-secondary-wrapper"]//fieldset[contains(@class, "collapsible") and contains(@class, "collapsed")]', NULL, 'Collapsible fieldset for secondary options starts collapsed/');
$this
->assertFieldByXpath('//div[@id="edit-secondary-wrapper"]//fieldset/legend/span', 'Custom Label', 'Collapsible fieldset has the correct custom label');
$this
->assertFieldByXpath('//div[@id="edit-secondary-wrapper"]//fieldset//select[@name="type[]"]', NULL, 'The node.type filter is within the secondary fieldset');
// Select an option and make sure the fieldset is expanded when rendered.
$this
->drupalGet('bef_test_page', array(
'query' => array(
'type' => 'page',
),
));
$this
->assertFieldByXpath('//div[@id="edit-secondary-wrapper"]//fieldset[contains(@class, "collapsible") and not(contains(@class, "collapsed"))]', NULL, 'Collapsible fieldset starts open');
// Verify force-open and force-closed fieldset options.
$this
->setBefSettings(array(
// Always render opened.
'exposed_form_options[bef][general][secondary_collapse_override]' => 1,
));
$this
->saveView();
$this
->drupalGet('bef_test_page');
$this
->assertFieldByXpath('//div[@id="edit-secondary-wrapper"]//fieldset[contains(@class, "collapsible") and not(contains(@class, "collapsed"))]', NULL, 'Collapsible fieldset starts open');
$this
->setBefSettings(array(
// Always render closed.
'exposed_form_options[bef][general][secondary_collapse_override]' => 2,
));
$this
->saveView();
$this
->drupalGet('bef_test_page', array(
'query' => array(
'type' => 'page',
),
));
$this
->assertFieldByXpath('//div[@id="edit-secondary-wrapper"]//fieldset[contains(@class, "collapsible") and contains(@class, "collapsed")]', NULL, 'Collapsible fieldset starts closed');
// https://drupal.org/node/2189321
// Verify fieldset is collapsed/expanded when a custom filter ID is set.
// @TODO: Consider refactoring so we can leverage all existing tests to use
// custom filter ID's...
$this
->editFilter('node.type', array(
'options[expose][identifier]' => 'custom_id',
));
$this
->setBefSettings(array(
// Use default open/closed rendering.
'exposed_form_options[bef][general][secondary_collapse_override]' => 0,
));
$this
->saveView();
$this
->drupalGet('bef_test_page');
// Verify a collapsed fieldset exists with the correct label.
$this
->assertFieldByXpath('//div[@id="edit-secondary-wrapper"]//fieldset[contains(@class, "collapsible") and contains(@class, "collapsed")]', NULL, 'Collapsible fieldset for secondary options, starts collapsed.');
$this
->assertFieldByXpath('//div[@id="edit-secondary-wrapper"]//fieldset//select[@name="custom_id[]"]', NULL, 'The node.type filter is within the secondary fieldset');
// Select an option and make sure the fieldset is expanded when rendered.
$this
->drupalGet('bef_test_page', array(
'query' => array(
'custom_id' => 'page',
),
));
$this
->assertFieldByXpath('//div[@id="edit-secondary-wrapper"]//fieldset[contains(@class, "collapsible") and not(contains(@class, "collapsed"))]', NULL, 'Collapsible fieldset starts open');
// Add an in-between filter and verify it renders correctly.
$this
->addFilter('field_data_field_bef_test_integer.field_bef_test_integer_value', array(
'options[operator]' => 'between',
));
$this
->setBefSettings(array(
'exposed_form_options[bef][general][allow_secondary]' => 1,
'exposed_form_options[bef][general][secondary_label]' => 'Custom Label',
'exposed_form_options[bef][general][secondary_collapse_override]' => 0,
'exposed_form_options[bef][field_bef_test_integer_value][more_options][is_secondary]' => 1,
));
$this
->saveView();
$this
->drupalGet('bef_test_page');
// Verify labels for the min and max fields.
// Note: Both labels have a trailing space which is added by Views... I
// assume to provide some visual whitespace between the label and widget if
// they are arranged horizontally. I imagine that'll change at some point as
// it's a terrible way to add some padding to an element!
$this
->assertFieldByXpath('//label[@for="edit-field-bef-test-integer-value-min"]', 'Integer (field_bef_test_integer) ', 'Label appears for in-between filters in secondary fieldsets.');
$this
->assertFieldByXpath('//label[@for="edit-field-bef-test-integer-value-max"]', 'And ', 'In-between filter has correct label between min and max inputs');
$this
->assertFieldByXpath('//label[@for="edit-custom-id"]', 'Type ', 'Single input filter has correct label');
}