Commit a7abcdb5 authored by Perignon's avatar Perignon Committed by Rick Hawkins
Browse files

Issue #2901064 by Perignon: Fix line endings

parent 57ce0341
<?php
/**
* @file
* Install/Uninstall code for the Better Exposed Filters module.
*/
/**
* Implements hook_disable.
*/
function better_exposed_filters_disable() {
// Check any views have their exposed form plugin set to BEF. If so, offer
// a warning about disabling the module.
$warnings = array();
foreach (views_get_all_views() as $view) {
foreach ($view->display as $display) {
if (!empty($display->display_options['exposed_form']['type']) && 'better_exposed_filters' == $display->display_options['exposed_form']['type']) {
$warnings[] = t('The %display_title display in the %view_name view. (<a href="@link" target="_blank">Update this display</a>)',
array(
'%display_title' => $display->display_title,
'%view_name' => $view->human_name,
'@link' => url('admin/structure/views/view/' . $view->name . '/edit/' . $display->id),
)
);
}
}
}
if (!empty($warnings)) {
$message = t('The following Views displays are using the Better Exposed Filters plugin, which is no longer enabled. It is recommended that you update these displays (links open in a new window) before removing the code associated with this module. Not doing so may cause unexpected results.');
$message .= '<ul><li>' . join('</li></li>', $warnings) . '</li></ul>';
drupal_set_message($message, 'warning');
}
}
/*
* Implementations of hook_update_N.
*
* Comments above each function appear in the update database message.
*/
/**
* Rebuild the theme registry to discover new theme_bef_checkbox() function.
*/
function better_exposed_filters_update_7000() {
drupal_theme_rebuild();
return t('Theme registry has been rebuilt.');
}
<?php
/**
* @file
* Install/Uninstall code for the Better Exposed Filters module.
*/
/**
* Implements hook_disable.
*/
function better_exposed_filters_disable() {
// Check any views have their exposed form plugin set to BEF. If so, offer
// a warning about disabling the module.
$warnings = array();
foreach (views_get_all_views() as $view) {
foreach ($view->display as $display) {
if (!empty($display->display_options['exposed_form']['type']) && 'better_exposed_filters' == $display->display_options['exposed_form']['type']) {
$warnings[] = t('The %display_title display in the %view_name view. (<a href="@link" target="_blank">Update this display</a>)',
array(
'%display_title' => $display->display_title,
'%view_name' => $view->human_name,
'@link' => url('admin/structure/views/view/' . $view->name . '/edit/' . $display->id),
)
);
}
}
}
if (!empty($warnings)) {
$message = t('The following Views displays are using the Better Exposed Filters plugin, which is no longer enabled. It is recommended that you update these displays (links open in a new window) before removing the code associated with this module. Not doing so may cause unexpected results.');
$message .= '<ul><li>' . join('</li></li>', $warnings) . '</li></ul>';
drupal_set_message($message, 'warning');
}
}
/*
* Implementations of hook_update_N.
*
* Comments above each function appear in the update database message.
*/
/**
* Rebuild the theme registry to discover new theme_bef_checkbox() function.
*/
function better_exposed_filters_update_7000() {
drupal_theme_rebuild();
return t('Theme registry has been rebuilt.');
}
<?php
/**
* Provides install hooks for the BEF Test Content module.
*/
/**
* Adds terms to the hierarchical vocabulary.
*/
function bef_test_content_update_7001() {
// Set up an example hierarchical terms in the "Location" vocab.
$locations = array(
'United States' => array(
'California' => array(
'San Francisco',
'San Diego',
'Santa Barbara',
),
'Oregon' => array(
'Portland',
'Eugene',
),
'Washington' => array(
'Seattle',
'Spokane',
'Walla Walla',
),
),
'Canada' => array(
'British Columbia' => array(
'Vancouver',
'Victoria',
'Whistler',
),
'Alberta' => array(
'Calgary',
'Edmonton',
'Lake Louise',
),
),
'Mexico' => array(),
);
foreach ($locations as $country => $states) {
$country_tid = _bef_test_content_add_term($country);
if ($country_tid && !empty($states)) {
foreach ($states as $state => $cities) {
$state_tid = _bef_test_content_add_term($state, $country_tid);
if ($state_tid && !empty($cities)) {
foreach ($cities as $city) {
_bef_test_content_add_term($city, $state_tid);
}
}
}
}
}
}
/**
* Adds a new term to the bef_test-location vocabulary. If a TID is specified
* in $parent, the new term is added as a child of that term.
*
* @param string $name
* The name of the new term.
* @param int $parent
* The (optional) TID of the parent term.
*
* @return int
* TID of the newly created term or 0 on an error.
*/
function _bef_test_content_add_term($name, $parent = 0) {
$term = new stdClass();
// Features manages to create a vocab machine name that includes illegal
// characters (taxonomy-bef_test-location -- the hyphen is not allowed). So
// we use the VID of the vocab instead.
$term->vid = 2;
$term->parent = $parent;
$term->name = $name;
if (taxonomy_term_save($term) == SAVED_NEW) {
return $term->tid;
}
return 0;
}
<?php
/**
* Provides install hooks for the BEF Test Content module.
*/
/**
* Adds terms to the hierarchical vocabulary.
*/
function bef_test_content_update_7001() {
// Set up an example hierarchical terms in the "Location" vocab.
$locations = array(
'United States' => array(
'California' => array(
'San Francisco',
'San Diego',
'Santa Barbara',
),
'Oregon' => array(
'Portland',
'Eugene',
),
'Washington' => array(
'Seattle',
'Spokane',
'Walla Walla',
),
),
'Canada' => array(
'British Columbia' => array(
'Vancouver',
'Victoria',
'Whistler',
),
'Alberta' => array(
'Calgary',
'Edmonton',
'Lake Louise',
),
),
'Mexico' => array(),
);
foreach ($locations as $country => $states) {
$country_tid = _bef_test_content_add_term($country);
if ($country_tid && !empty($states)) {
foreach ($states as $state => $cities) {
$state_tid = _bef_test_content_add_term($state, $country_tid);
if ($state_tid && !empty($cities)) {
foreach ($cities as $city) {
_bef_test_content_add_term($city, $state_tid);
}
}
}
}
}
}
/**
* Adds a new term to the bef_test-location vocabulary. If a TID is specified
* in $parent, the new term is added as a child of that term.
*
* @param string $name
* The name of the new term.
* @param int $parent
* The (optional) TID of the parent term.
*
* @return int
* TID of the newly created term or 0 on an error.
*/
function _bef_test_content_add_term($name, $parent = 0) {
$term = new stdClass();
// Features manages to create a vocab machine name that includes illegal
// characters (taxonomy-bef_test-location -- the hyphen is not allowed). So
// we use the VID of the vocab instead.
$term->vid = 2;
$term->parent = $parent;
$term->name = $name;
if (taxonomy_term_save($term) == SAVED_NEW) {
return $term->tid;
}
return 0;
}
<?php
/**
* @file Base class for testing the Better Exposed Filters module.
* @author mikeker
*/
/**
* Helper functions for Better Exposed Filters tests.
*/
class BEF_TestBase extends DrupalWebTestCase {
/**
* User with 'Administrator' role.
*/
protected $admin_user;
/**
* Stores information about the view used in these tests.
*/
protected $view = array();
public static function getInfo() {
return array(
'name' => 'BEF Basic functionality tests',
'description' => 'Basic tests for Better Exposed Filters.',
'group' => 'Better Exposed Filters',
);
}
public function setUp() {
// For benchmarking.
$this->start = time();
// Enable any modules required for the test.
parent::setUp(
'better_exposed_filters',
'date',
'date_views',
'list',
'number',
'taxonomy',
'text',
'views',
'views_ui'
);
// One of these days I'll figure out why Features is breaking all my tests.
module_enable(array('bef_test_content'));
// User with edit views perms
$this->admin_user = $this->drupalCreateUser();
$role = user_role_load_by_name('administrator');
$this->assertTrue(!empty($role->rid), 'Found the "administrator" role.');
user_save($this->admin_user, array('roles' => array($role->rid => $role->rid)));
$this->drupalLogin($this->admin_user);
// Build a basic view for use in tests.
$this->createView();
// $this->createDisplay('Page', array('path' => array('path' => 'bef_test_page')));
// Add field to default display
// $this->addField('node.title');
// Turn of Better Exposed Filters
$this->setBefExposedForm();
}
public function tearDown() {
debug('This test run took ' . (time() - $this->start) . ' seconds.');
unset($this->view);
parent::tearDown();
}
/*******************************************************************************
* Helper functions
******************************************************************************/
/**
* Returns the URL for the BEF exposed form settings page.
*/
protected function getBefSettingsUrl() {
return 'admin/structure/views/nojs/display/' . $this->view['machine_name'] . '/default/exposed_form_options';
}
protected function createView($name = '') {
if (!empty($this->view)) {
debug('WARNING: createView called after view has already been created.');
return;
}
if (empty($name)) {
$name = $this->randomName(8);
}
$this->view['name'] = $name;
$this->view['machine_name'] = strtolower($name);
$edit = array(
'human_name' => $this->view['name'],
'name' => $this->view['machine_name'],
// Default is to create a page display.
'page[create]' => FALSE,
);
$this->drupalPost('admin/structure/views/add', $edit, 'Save & exit');
// URL to edit this view.
$this->view['edit_url'] = 'admin/structure/views/view/' . $this->view['machine_name'] . '/edit';
}
/**
* Creates a display of $type. Currently supports:
* 'Page'
*
* @todo: support more types...
*/
protected function createDisplay($type = 'Page', $settings = NULL) {
if (!isset($this->view['displays'])) {
$this->view['displays'] = array();
}
// Add a display of $type to the view
$this->drupalPost($this->view['edit_url'], array(), "Add $type");
// Grab the name of the newly created display and store some info about it.
$url = $this->getUrl();
$display_name = substr($url, strrpos($url, '/') + 1);
$this->view['displays'][$display_name] = array(
'machine_name' => $display_name,
'edit_url' => 'admin/structure/views/view/' . $this->view['machine_name'] . '/edit/' . $display_name,
'settings_base_url' => 'admin/structure/views/nojs/display/' . $this->view['machine_name'] . '/' . $display_name,
);
// Settings should be in the form of 'path' => array_of_form_settings. Eg:
// to set the title for a new display as an override:
// 'title' => array(
// 'title' => 'This is an override title',
// 'override[dropdown]' => display_machine_name_goes_here,
// )
//
// If you navigate to
// admin/structure/views/nojs/display/<view_name>/<display_name>/title
// you will see the form in question.
foreach ($settings as $path => $values) {
$this->drupalPost($this->view['displays'][$display_name]['settings_base_url'] . "/$path", $values, 'Apply');
}
$this->saveView();
}
/**
* Adds a filter to a view display.
*
* $field: string in the form of node.status or
* field_data_field_example.field_example_value
* $settings: (array) Settings on the "Configure filter criterion" dialog.
* NOTE: called after the "Expose filter" button is pressed if $exposed
* is TRUE so you can set things like "Allow multiple items" or grouped
* filter options.
* $additional: (array) settings for any additional configuration forms such
* as taxonomy term settings.
* $display: machine name of the display to add this filter to. NOTE:
* Currently only allows filters on the master display, no overrides.
* @todo: fix that, if needed.
* $exposed: (bool) (optional, default: TRUE) Is this an exposed filter?
*
* Note: This routine expects the caller to save the view, as needed.
*/
protected function addFilter($field, $settings = array(), $additional = array(), $exposed = TRUE, $display = 'default') {
$edit = array(
"name[$field]" => TRUE,
);
$url = 'admin/structure/views/nojs/add-item/' . $this->view['machine_name'] . "/$display/filter";
$this->drupalPost($url, $edit, 'Add and configure filter criteria');
if (!empty($additional)) {
// Handle filter-specific options screen.
$this->drupalPost(NULL, $additional, 'Apply');
}
if ($exposed) {
$this->drupalPost(NULL, array(), 'Expose filter');
}
$this->drupalPost(NULL, $settings, 'Apply');
}
/**
* Edits an existing filter in the current view. See addFilter for param
* definitions.
*/
protected function editFilter($field, $settings, $additional = array(), $display = 'default') {
if (FALSE !== ($pos = strpos($field, '.'))) {
$field = substr($field, $pos + 1);
}
$url = 'admin/structure/views/nojs/config-item/' . $this->view['machine_name'] . "/$display/filter/$field";
$this->drupalPost($url, $settings, 'Apply');
if (!empty($additional)) {
// Handle filter-specific options screen.
$this->drupalPost(NULL, $additional, 'Apply');
}
}
/**
* Adds a sort to a view display. See addFilter for parameter options.
*
* Note: This routine expects the caller to save the view, as needed.
*/
protected function addSort($field, $settings = array(), $additional = array(), $exposed = TRUE, $display = 'default') {
$edit = array(
"name[$field]" => TRUE,
);
$url = 'admin/structure/views/nojs/add-item/' . $this->view['machine_name'] . "/$display/sort";
$this->drupalPost($url, $edit, 'Add and configure sort criteria');
if (!empty($additional)) {
// Handle filter-specific options screen.
$this->drupalPost(NULL, $additional, 'Apply');
}
if ($exposed) {
$this->drupalPost(NULL, array(), 'Expose sort');
}
$this->drupalPost(NULL, $settings, 'Apply');
}
/**
* Adds a field to a view display. See addFilter for parameter options.
*
* Note: This routine expects the caller to save the view, as needed.
*/
protected function addField($field, $settings = array(), $display = 'default') {
$edit = array(
"name[$field]" => TRUE,
);
$url = 'admin/structure/views/nojs/add-item/' . $this->view['machine_name'] . "/$display/field";
$this->drupalPost($url, $edit, 'Add and configure fields');
$this->drupalPost(NULL, $settings, 'Apply');
}
/**
* Ensures that BEF is selected as the exposed form option
*
* Note: This routine expects the caller to save the view, as needed.
*/
protected function setBefExposedForm($display = 'default') {
$edit = array(
"exposed_form[type]" => 'better_exposed_filters',
);
$url = 'admin/structure/views/nojs/display/' . $this->view['machine_name'] . "/$display/exposed_form";
$this->drupalPost($url, $edit, 'Apply');
// BEF settings is covered under setBefSettings() so we just accept the
// default values and move on.
$this->drupalPost(NULL, array(), 'Apply');
}
/**
* Sets various BEF exposed form settings. If $error is specified it also
* asserts that the error text apepars when trying to apply $settings.
*
* Note: This routine expects the caller to save the view, as needed.
*/
protected function setBefSettings($settings, $error = '') {
$this->drupalPost($this->getBefSettingsUrl(), $settings, 'Apply');
if (!empty($error)) {
$this->assertText($error);
}
}
/**
* Saves the view
*/
protected function saveView() {
$this->drupalPost($this->view['edit_url'], array(), 'Save');
}
}
<?php
/**
* @file Base class for testing the Better Exposed Filters module.
* @author mikeker
*/
/**
* Helper functions for Better Exposed Filters tests.
*/
class BEF_TestBase extends DrupalWebTestCase {
/**
* User with 'Administrator' role.
*/
protected $admin_user;
/**
* Stores information about the view used in these tests.
*/
protected $view = array();
public static function getInfo() {
return array(
'name' => 'BEF Basic functionality tests',
'description' => 'Basic tests for Better Exposed Filters.',
'group' => 'Better Exposed Filters',
);
}
public function setUp() {
// For benchmarking.
$this->start = time();
// Enable any modules required for the test.
parent::setUp(
'better_exposed_filters',
'date',
'date_views',
'list',
'number',
'taxonomy',
'text',
'views',
'views_ui'
);
// One of these days I'll figure out why Features is breaking all my tests.
module_enable(array('bef_test_content'));
// User with edit views perms
$this->admin_user = $this->drupalCreateUser();
$role = user_role_load_by_name('administrator');
$this->assertTrue(!empty($role->rid), 'Found the "administrator" role.');
user_save($this->admin_user, array('roles' => array($role->rid => $role->rid)));
$this->drupalLogin($this->admin_user);
// Build a basic view for use in tests.
$this->createView();
// $this->createDisplay('Page', array('path' => array('path' => 'bef_test_page')));
// Add field to default display
// $this->addField('node.title');
// Turn of Better Exposed Filters
$this->setBefExposedForm();
}
public function tearDown() {
debug('This test run took ' . (time() - $this->start) . ' seconds.');
unset($this->view);
parent::tearDown();
}