contrib modules security updates
This commit is contained in:
@@ -2,7 +2,8 @@
|
||||
Block Class
|
||||
http://drupal.org/project/block_class
|
||||
-----
|
||||
Block Class was developed and is maintained by Four Kitchens <http://fourkitchens.com>.
|
||||
Block Class was developed and is maintained by Four Kitchens
|
||||
<http://fourkitchens.com>.
|
||||
|
||||
|
||||
=====
|
||||
@@ -10,4 +11,5 @@ Installation
|
||||
-----
|
||||
|
||||
1. Enable the module
|
||||
2. To add a class to a block, simply visit that block's configuration page at Administration > Structure > Blocks
|
||||
2. To add a class to a block, simply visit that block's configuration page at
|
||||
Administration > Structure > Blocks
|
||||
|
@@ -1,74 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Implements hook_features_export_options().
|
||||
*/
|
||||
function block_class_features_export_options() {
|
||||
$query = db_select('block_class', 'bc');
|
||||
$query->addExpression("CONCAT(bc.module, ':', bc.delta)");
|
||||
$blocks = $query->execute()->fetchAllKeyed(0, 0);
|
||||
|
||||
natcasesort($blocks);
|
||||
return $blocks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_features_export().
|
||||
*/
|
||||
function block_class_features_export($data, &$export, $module_name = '') {
|
||||
$pipe = array();
|
||||
|
||||
$export['dependencies']['features'] = 'features';
|
||||
$export['dependencies']['block_class'] = 'block_class';
|
||||
|
||||
foreach ($data as $component) {
|
||||
$export['features']['block_class'][$component] = $component;
|
||||
}
|
||||
|
||||
return $pipe;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_features_export_render().
|
||||
*/
|
||||
function block_class_features_export_render($module, $data) {
|
||||
$query = db_select('block_class', 'bc');
|
||||
$query->addExpression("CONCAT(bc.module, ':', bc.delta)", 'id');
|
||||
$query->addField('bc', 'css_class');
|
||||
$classes = $query->execute()->fetchAllKeyed(1, 0);
|
||||
|
||||
$code = array();
|
||||
foreach ($data as $id) {
|
||||
if (isset($classes[$id])) {
|
||||
list($module, $delta) = explode(':', $id);
|
||||
$css_classes = $classes[$id];
|
||||
$code[$id] = compact('module', 'delta', 'css_classes');
|
||||
}
|
||||
}
|
||||
|
||||
$code = " return ". features_var_export($code, ' ') .";";
|
||||
|
||||
return array('block_class_features_default_class' => $code);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_features_revert().
|
||||
*/
|
||||
function block_class_features_revert($module) {
|
||||
block_class_features_rebuild($module);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_features_rebuild().
|
||||
*/
|
||||
function block_class_features_rebuild($module) {
|
||||
$blocks = module_invoke($module, 'block_class_features_default_class');
|
||||
if ($blocks) {
|
||||
foreach($blocks as $block) {
|
||||
db_delete('block_class')->condition('module', $block['module'])->condition('delta', $block['delta'])->execute();
|
||||
if (!empty($block['css_classes'])) {
|
||||
$id = db_insert('block_class')->fields(array('module' => $block['module'], 'delta' => $block['delta'], 'css_class' => $block['css_classes']))->execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -2,12 +2,15 @@ name = Block Class
|
||||
description = Allows assigning CSS classes to blocks.
|
||||
core = 7.x
|
||||
|
||||
files[] = block_class.install
|
||||
files[] = block_class.module
|
||||
dependencies[] = block
|
||||
files[] = block_class.test
|
||||
test_dependencies[] = context
|
||||
test_dependencies[] = features (2.x)
|
||||
test_dependencies[] = features_extra
|
||||
|
||||
; Information added by drupal.org packaging script on 2012-10-04
|
||||
version = "7.x-1.2+3-dev"
|
||||
; Information added by Drupal.org packaging script on 2015-12-18
|
||||
version = "7.x-2.3"
|
||||
core = "7.x"
|
||||
project = "block_class"
|
||||
datestamp = "1349309175"
|
||||
datestamp = "1450415951"
|
||||
|
||||
|
@@ -6,102 +6,146 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implementation of hook_schema().
|
||||
* Implements hook_install().
|
||||
*/
|
||||
function block_class_schema() {
|
||||
$schema['block_class'] = array(
|
||||
'fields' => array(
|
||||
'module' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 64,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'description' => 'The module to which the block belongs.',
|
||||
),
|
||||
'delta' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 32,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'description' => "The ID of the module's block.",
|
||||
),
|
||||
'css_class' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'description' => 'String containing the classes for the block.',
|
||||
),
|
||||
),
|
||||
'primary key' => array('module', 'delta'),
|
||||
);
|
||||
function block_class_install() {
|
||||
$schema['block'] = array();
|
||||
block_class_schema_alter($schema);
|
||||
foreach ($schema['block']['fields'] as $field => $spec) {
|
||||
if (db_field_exists('block', $field)) {
|
||||
watchdog('system', 'Module install: Attempt to recreate field: "%field", when it already exists.', array('%field' => $field), WATCHDOG_WARNING);
|
||||
}
|
||||
else {
|
||||
db_add_field('block', $field, $spec);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $schema;
|
||||
/**
|
||||
* Implements hook_uninstall().
|
||||
*/
|
||||
function block_class_uninstall() {
|
||||
$schema['block'] = array();
|
||||
block_class_schema_alter($schema);
|
||||
foreach ($schema['block']['fields'] as $field => $specs) {
|
||||
db_drop_field('block', $field);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_schema_alter().
|
||||
*
|
||||
* Other modules, such as i18n_block also modify the block database table.
|
||||
*/
|
||||
function block_class_schema_alter(&$schema) {
|
||||
if (isset($schema['block'])) {
|
||||
$schema['block']['fields']['css_class'] = array(
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'description' => 'String containing the classes for the block.',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Alters the structure of {block_class} schema.
|
||||
*/
|
||||
function block_class_update_7100() {
|
||||
// Update the schema.
|
||||
db_drop_primary_key('block_class');
|
||||
// Check if the block_class table exists to prevent installation profiles
|
||||
// from running this update for versions without the block_class table.
|
||||
if (db_table_exists('block_class')) {
|
||||
// Update the schema.
|
||||
db_drop_primary_key('block_class');
|
||||
|
||||
db_change_field('block_class', 'module', 'module',
|
||||
array(
|
||||
'type' => 'varchar',
|
||||
'length' => '255',
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'description' => 'The module to which the block belongs.',
|
||||
)
|
||||
);
|
||||
db_change_field('block_class', 'module', 'module',
|
||||
array(
|
||||
'type' => 'varchar',
|
||||
'length' => '64',
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'description' => 'The module to which the block belongs.',
|
||||
)
|
||||
);
|
||||
|
||||
db_change_field('block_class', 'delta', 'delta',
|
||||
array(
|
||||
'type' => 'varchar',
|
||||
'length' => '255',
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'description' => "The ID of the module's block.",
|
||||
)
|
||||
);
|
||||
db_change_field('block_class', 'delta', 'delta',
|
||||
array(
|
||||
'type' => 'varchar',
|
||||
'length' => '32',
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'description' => "The ID of the module's block.",
|
||||
)
|
||||
);
|
||||
|
||||
db_change_field('block_class', 'css_class', 'css_class',
|
||||
array(
|
||||
'type' => 'varchar',
|
||||
'length' => '255',
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'description' => 'String containing the classes for the block.',
|
||||
)
|
||||
);
|
||||
db_change_field('block_class', 'css_class', 'css_class',
|
||||
array(
|
||||
'type' => 'varchar',
|
||||
'length' => '255',
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'description' => 'String containing the classes for the block.',
|
||||
)
|
||||
);
|
||||
|
||||
// Restore the primary key.
|
||||
db_add_primary_key('block_class', array('module', 'delta'));
|
||||
// Restore the primary key.
|
||||
db_add_primary_key('block_class', array('module', 'delta'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix too long primary key length in {block_class}.
|
||||
*/
|
||||
function block_class_update_7101() {
|
||||
// Drop current primary key.
|
||||
db_drop_primary_key('block_class');
|
||||
// Ensure the block_class table exists, which is not true for all versions.
|
||||
if (db_table_exists('block_class')) {
|
||||
// Drop current primary key.
|
||||
db_drop_primary_key('block_class');
|
||||
|
||||
db_change_field('block_class', 'module', 'module', array(
|
||||
'type' => 'varchar',
|
||||
'length' => 64,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'description' => 'The module to which the block belongs.',
|
||||
));
|
||||
db_change_field('block_class', 'delta', 'delta', array(
|
||||
'type' => 'varchar',
|
||||
'length' => 32,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'description' => "The ID of the module's block.",
|
||||
));
|
||||
db_change_field('block_class', 'module', 'module', array(
|
||||
'type' => 'varchar',
|
||||
'length' => 64,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'description' => 'The module to which the block belongs.',
|
||||
));
|
||||
db_change_field('block_class', 'delta', 'delta', array(
|
||||
'type' => 'varchar',
|
||||
'length' => 32,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'description' => "The ID of the module's block.",
|
||||
));
|
||||
|
||||
// Create new primary key.
|
||||
db_add_primary_key('block_class', array('module', 'delta'));
|
||||
// Create new primary key.
|
||||
db_add_primary_key('block_class', array('module', 'delta'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Migration from block_class table to new field css_class in core block table.
|
||||
*/
|
||||
function block_class_update_7103() {
|
||||
if (!db_field_exists('block', 'block_class')) {
|
||||
$schema['block'] = array();
|
||||
block_class_schema_alter($schema);
|
||||
foreach ($schema['block']['fields'] as $field => $specs) {
|
||||
db_add_field('block', $field, $specs);
|
||||
}
|
||||
}
|
||||
|
||||
if (db_table_exists('block_class')) {
|
||||
// Migrate all existing records from block_class table to block table.
|
||||
$result = db_query('SELECT css_class, module, delta FROM {block_class}');
|
||||
while ($record = $result->fetchObject()) {
|
||||
db_update('block')
|
||||
->fields(array('css_class' => $record->css_class))
|
||||
->condition('module', $record->module)
|
||||
->condition('delta', $record->delta)
|
||||
->execute();
|
||||
}
|
||||
// Remove the block_class table.
|
||||
db_drop_table('block_class');
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,15 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Enhanced control over the CSS Classes of any Block.
|
||||
*
|
||||
* Block Class allows users to add classes to any block through the block's
|
||||
* configuration interface. This implementation is based on an alteration of
|
||||
* the Core block database table to leverage the Core Block API functions,
|
||||
* objects and structure.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_permission().
|
||||
*/
|
||||
@@ -12,37 +22,25 @@ function block_class_permission() {
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Implements theme_preprocess_block().
|
||||
*
|
||||
* Extend block's classes with any user defined classes.
|
||||
*/
|
||||
function block_class_preprocess_block(&$vars) {
|
||||
$block = $vars['block'];
|
||||
|
||||
/* The original code: */
|
||||
//$classes = block_class($block);
|
||||
//$vars['classes_array'] = array_merge($vars['classes_array'], explode(' ', $classes));
|
||||
|
||||
/* Replaced with the following so it doesn't fire that many queries if you have a lot of blocks */
|
||||
static $_block_class_blocks_classes;
|
||||
|
||||
if (! isset ($_block_class_blocks_classes)) {
|
||||
$_block_class_blocks_classes = array();
|
||||
$result = db_query('SELECT css_class, module, delta FROM {block_class}');
|
||||
while ($record = $result->fetchObject()) {
|
||||
$_block_class_blocks_classes[$record->module][$record->delta] = $record->css_class;
|
||||
if (!empty($block->css_class)) {
|
||||
$classes_array = explode(' ', $block->css_class);
|
||||
foreach ($classes_array as $class) {
|
||||
$vars['classes_array'][] = drupal_clean_css_identifier($class, array());
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_block_class_blocks_classes[$block->module][$block->delta])) {
|
||||
$classes = $_block_class_blocks_classes[$block->module][$block->delta];
|
||||
$vars['classes_array'] = array_merge($vars['classes_array'], explode(' ', $classes));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
/**
|
||||
* Implements hook_preprocess_HOOK().
|
||||
*
|
||||
* Extend panel block's classes with any user defined classes.
|
||||
* Implements hook_preprocess_hook()
|
||||
*/
|
||||
function block_class_preprocess_panels_pane(&$vars) {
|
||||
if ($vars['pane']->type != 'block') {
|
||||
@@ -52,42 +50,32 @@ function block_class_preprocess_panels_pane(&$vars) {
|
||||
$block_parts = explode('-', $vars['pane']->subtype);
|
||||
// Load the block based on the block parts.
|
||||
$block = block_load($block_parts[0], $block_parts[1]);
|
||||
// Return block_class classes as string.
|
||||
$css_class = block_class($block);
|
||||
// Add a generic 'module type' pane class.
|
||||
$vars['classes_array'][] = drupal_html_class('pane-' . $block->module);
|
||||
// Add $css_class to the $classes_array.
|
||||
$vars['classes_array'][] = $css_class;
|
||||
if (!empty($block->css_class)) {
|
||||
$classes_array = explode(' ', $block->css_class);
|
||||
foreach ($classes_array as $class) {
|
||||
$vars['classes_array'][] = drupal_clean_css_identifier($class, array());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return classes as string
|
||||
*/
|
||||
function block_class($block) {
|
||||
$ret = db_query('SELECT css_class FROM {block_class} WHERE module = :module AND delta = :delta', array(':module' => $block->module, ':delta' => $block->delta))->fetchField();
|
||||
return $ret ? check_plain ($ret) : '';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Alter block edit form
|
||||
* Implements hook_form_alter().
|
||||
*
|
||||
* Alter block edit form to add configuration field.
|
||||
*/
|
||||
function block_class_form_alter(&$form, &$form_state, $form_id) {
|
||||
if (user_access('administer block classes') && $form_id == 'block_admin_configure' || $form_id == 'block_add_block_form') {
|
||||
$block = new stdClass;
|
||||
$block->module = $form['module']['#value'];
|
||||
$block->delta = $form['delta']['#value'];
|
||||
$css_class = block_class($block);
|
||||
|
||||
// Create a more technical description for users with administer blocks permission.
|
||||
$description = t('Customize the styling of this block by adding CSS classes. Separate multiple classes by spaces.');
|
||||
if (user_access('administer block classes') && ($form_id == 'block_admin_configure' || $form_id == 'block_add_block_form')) {
|
||||
// Load statically cached block object used to display the form.
|
||||
$block = block_load($form['module']['#value'], $form['delta']['#value']);
|
||||
|
||||
$form['settings']['css_class'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('CSS class(es)'),
|
||||
'#default_value' => $css_class,
|
||||
'#description' => t('Separate classes with a space.'),
|
||||
'#default_value' => isset($block->css_class) ? $block->css_class : '',
|
||||
'#description' => t('Customize the styling of this block by adding CSS classes. Separate multiple classes by spaces.'),
|
||||
'#maxlength' => 255,
|
||||
);
|
||||
|
||||
@@ -95,34 +83,24 @@ function block_class_form_alter(&$form, &$form_state, $form_id) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save supplied class.
|
||||
* Helper function: additional submit callback for block configuration pages.
|
||||
*
|
||||
* Save supplied CSS classes.
|
||||
*/
|
||||
function block_class_form_submit($form, &$form_state) {
|
||||
if ($form_state['values']['form_id'] == 'block_admin_configure' || $form_state['values']['form_id'] == 'block_add_block_form') {
|
||||
if (isset($form_state['values']['css_class']) && user_access('administer blocks')) {
|
||||
$module = $form_state['values']['module'];
|
||||
$delta = $form_state['values']['delta'];
|
||||
$class = $form_state['values']['css_class'];
|
||||
db_delete('block_class')->condition('module', $module)->condition('delta', $delta)->execute();
|
||||
if (!empty($class)) {
|
||||
$id = db_insert('block_class')->fields(array('module' => $module, 'delta' => $delta, 'css_class' => $class))->execute();
|
||||
// Only save if value has changed.
|
||||
if (isset($form_state['values']['css_class']) && $form['settings']['css_class']['#default_value'] != $form_state['values']['css_class'] && user_access('administer blocks')) {
|
||||
db_update('block')
|
||||
->fields(array('css_class' => $form_state['values']['css_class']))
|
||||
->condition('module', $form_state['values']['module'])
|
||||
->condition('delta', $form_state['values']['delta'])
|
||||
->execute();
|
||||
// Flush all context module cache to use the updated css_class.
|
||||
if (module_exists('context')) {
|
||||
cache_clear_all('context', 'cache', TRUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_features_api().
|
||||
*/
|
||||
function block_class_features_api() {
|
||||
return array(
|
||||
'block_class' => array(
|
||||
'name' => t('Block class'),
|
||||
'feature_source' => TRUE,
|
||||
'default_hook' => 'block_class_features_default_class',
|
||||
'file' => drupal_get_path('module', 'block_class') . '/block_class.features.inc',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
329
sites/all/modules/block_class/block_class.test
Normal file
329
sites/all/modules/block_class/block_class.test
Normal file
@@ -0,0 +1,329 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Test the Block Class module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Provides common functionality for the Block Class test classes.
|
||||
*/
|
||||
class BlockClassTestCase extends DrupalWebTestCase {
|
||||
|
||||
/**
|
||||
* User object to perform site browsing
|
||||
* @var object
|
||||
*/
|
||||
protected $privilegedUser;
|
||||
|
||||
/**
|
||||
* Machine name of the module providing the block coupled with delta.
|
||||
* @var string
|
||||
*/
|
||||
protected $module = 'system';
|
||||
|
||||
/**
|
||||
* Block delta as provided by its module.
|
||||
* @var string
|
||||
*/
|
||||
protected $delta = 'main';
|
||||
|
||||
/**
|
||||
* Permissions required by the user to perform the tests.
|
||||
* @var array
|
||||
*/
|
||||
protected $permissions = array(
|
||||
'administer blocks',
|
||||
'administer block classes',
|
||||
);
|
||||
|
||||
/**
|
||||
* Enable modules and create user with specific permissions.
|
||||
*
|
||||
* By default Test Cases are carried on the "Main page content" Block.
|
||||
*/
|
||||
public function setUp() {
|
||||
// Merge inherited classes modules, see FieldUITestCase for an example.
|
||||
$modules = func_get_args();
|
||||
if (isset($modules[0]) && is_array($modules[0])) {
|
||||
$modules = $modules[0];
|
||||
}
|
||||
$modules[] = 'block_class';
|
||||
parent::setUp($modules);
|
||||
|
||||
// Authenticate test user.
|
||||
$this->privilegedUser = $this->drupalCreateUser($this->permissions);
|
||||
$this->drupalLogin($this->privilegedUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update Block CSS class and assert whether it is found when displayed.
|
||||
*
|
||||
* @param bool $anon
|
||||
* (optional) Set to TRUE to view block with anon user, defaults to TRUE.
|
||||
* @param string $module
|
||||
* (optional) Machine name of the module Defaults to
|
||||
* $this->module if set to NULL.
|
||||
* @param string $delta
|
||||
* (optional) Block delta as provided by its module. Defaults to
|
||||
* $this->delta if set to NULL.
|
||||
*/
|
||||
public function assertUpdateBlockClass($anon = FALSE, $module = NULL, $delta = NULL) {
|
||||
// Initialize $module and $delta by default if no value is provided.
|
||||
if (!isset($module)) {
|
||||
$module = $this->module;
|
||||
}
|
||||
if (!isset($delta)) {
|
||||
$delta = $this->delta;
|
||||
}
|
||||
// Test with three random class names.
|
||||
$css_classes = implode(' ', array(
|
||||
$this->randomName(8),
|
||||
$this->randomName(8),
|
||||
$this->randomName(8),
|
||||
));
|
||||
// Update Block CSS class field.
|
||||
$this->drupalPost("admin/structure/block/manage/$module/$delta/configure", array('css_class' => $css_classes), t('Save block'));
|
||||
// Check Block configuration was saved successfully.
|
||||
$this->assertText(t('The block configuration has been saved.'));
|
||||
// Browse to the homepage.
|
||||
$this->drupalGet('');
|
||||
// Log out if the test is for anonymous user.
|
||||
if ($anon) {
|
||||
$this->drupalLogout();
|
||||
// Browse back to the homepage.
|
||||
$this->drupalGet('');
|
||||
}
|
||||
// Check if the Block CSS classes could be found.
|
||||
$this->assertPattern('/class=\"(.*?)' . $css_classes . '(.*?)\"/', format_string('The CSS classes were found: @css_classes', array('@css_classes' => $css_classes)));
|
||||
// Login again after testing with the anonumous user.
|
||||
if ($anon) {
|
||||
$this->drupalLogin($this->privilegedUser);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the update and display of the CSS class for a Block.
|
||||
*/
|
||||
class BlockClassUpdateDisplayTestCase extends BlockClassTestCase {
|
||||
|
||||
/**
|
||||
* Implements DrupalWebTestCase::getInfo().
|
||||
*/
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Block CSS class update and display',
|
||||
'description' => 'Test the update of a Block CSS class field and the display for the Main Page Content Block.',
|
||||
'group' => 'Block Class',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update and display a Block multiple times to ensure CSS class is found.
|
||||
*
|
||||
* A Block is updated and displayed several times and with logged in or
|
||||
* anonymous user, with Block cache turned enabled or disabled.
|
||||
*/
|
||||
public function testUpdateDisplayClass() {
|
||||
// Edit the block, change the class and check if the CSS classes are found.
|
||||
$this->assertUpdateBlockClass();
|
||||
|
||||
// Now, turn on caching programmatically and set it to 15 min expiry.
|
||||
variable_set('block_cache', TRUE);
|
||||
variable_set('cache_lifetime', 900);
|
||||
variable_set('page_cache_maximum_age', 900);
|
||||
|
||||
// Edit the block, change the class and check with the anonymous user.
|
||||
$this->assertUpdateBlockClass(TRUE);
|
||||
|
||||
// Edit the block, change the class and check with the anonymous user.
|
||||
$this->assertUpdateBlockClass(TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Block Class permissions.
|
||||
*/
|
||||
class BlockClassPermissionTestCase extends BlockClassTestCase {
|
||||
|
||||
/**
|
||||
* Implements DrupalWebTestCase::getInfo().
|
||||
*/
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Administer block classes permission',
|
||||
'description' => 'Test the permission added by the module to administer block classes.',
|
||||
'group' => 'Block Class',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable modules and create user with specific permissions.
|
||||
*/
|
||||
public function setUp() {
|
||||
// Remove the 'administer block classes' permission from the base class.
|
||||
$this->permissions = array('administer blocks');
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure Block CSS classes field is only visible with the right permissions.
|
||||
*
|
||||
* Test if a user without 'administer block classes' permission has access to
|
||||
* the Block CSS classes field on the block configuration page.
|
||||
*/
|
||||
public function testPermission() {
|
||||
// Browse to the "Main page content" block editing form page.
|
||||
$this->drupalGet("admin/structure/block/manage/{$this->module}/{$this->delta}/configure");
|
||||
// Check that the css_class field couldn't be found.
|
||||
// If the field is not found, it can't be submitted through drupalPost.
|
||||
$this->assertNoFieldById('css_class', 'The Css classes field was not found on the page.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Block Class integration with Context.
|
||||
*/
|
||||
class BlockClassContextTestCase extends BlockClassUpdateDisplayTestCase {
|
||||
|
||||
/**
|
||||
* Implements DrupalWebTestCase::getInfo().
|
||||
*/
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Integration with Context',
|
||||
'description' => 'Test the integration of Block Class with the Context module and the update/display of a Block CSS class.',
|
||||
// Include required contributed modules context and ctools for the test.
|
||||
'dependencies' => array('context', 'ctools'),
|
||||
'group' => 'Block Class',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable modules and create user with specific permissions.
|
||||
*/
|
||||
public function setUp() {
|
||||
// Override default module and delta to test with the "Who's online" block.
|
||||
$this->module = 'user';
|
||||
$this->delta = 'online';
|
||||
// Include the Context module and its dependencies to be loaded.
|
||||
parent::setUp('context');
|
||||
// Initialize a test context with the test block.
|
||||
$this->initializeContext();
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to initialize a test Context with a test block.
|
||||
*/
|
||||
public function initializeContext() {
|
||||
// Import a basic context exported through the admin interface.
|
||||
$context = new stdClass();
|
||||
$context->disabled = FALSE;
|
||||
$context->api_version = 3;
|
||||
$context->name = 'front';
|
||||
$context->description = 'Frontpage Context';
|
||||
$context->tag = '';
|
||||
$context->conditions = array(
|
||||
'path' => array(
|
||||
'values' => array(
|
||||
'<front>' => '<front>',
|
||||
),
|
||||
),
|
||||
);
|
||||
$context->reactions = array(
|
||||
'block' => array(
|
||||
'blocks' => array(
|
||||
$this->module . '-' . $this->delta => array(
|
||||
'module' => $this->module,
|
||||
'delta' => $this->delta,
|
||||
'region' => 'content',
|
||||
'weight' => '-10',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
$context->condition_mode = 0;
|
||||
|
||||
// Translatables
|
||||
// Included for use with string extractors like potx.
|
||||
t('Frontpage Context');
|
||||
|
||||
// Save the context.
|
||||
context_save($context);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Block Class integration with Features through FE Block.
|
||||
*/
|
||||
class BlockClassFeaturesTestCase extends BlockClassTestCase {
|
||||
|
||||
/**
|
||||
* Implements DrupalWebTestCase::getInfo().
|
||||
*/
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Integration with Features',
|
||||
'description' => 'Test the integration of Block Class with Features through the FE Block module and the update/display of a Block CSS class.',
|
||||
// Include Features related modules required for this Test Case.
|
||||
'dependencies' => array('features', 'ctools', 'fe_block'),
|
||||
'group' => 'Block Class',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable modules and create user with specific permissions.
|
||||
*/
|
||||
public function setUp() {
|
||||
// Override default module and delta to test with the "Who's online" block.
|
||||
$this->module = 'user';
|
||||
$this->delta = 'online';
|
||||
// Include all Features related modules and Test Helper feature.
|
||||
parent::setUp('block_class_fe_block_test');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test how Block Class reacts when exported to a Feature with FE Block.
|
||||
*
|
||||
* Helper Feature's Block configuration settings are imported, updated and
|
||||
* the display is tested several times, before reverting the feature.
|
||||
*/
|
||||
public function testFeatureDisplayClass() {
|
||||
// Block classes exported to the Test Feature module.
|
||||
$test_classes = 'fe_block-class1 fe_block-class2 fe_block-class3';
|
||||
// Test helper feature machine name.
|
||||
$test_feature = 'block_class_fe_block_test';
|
||||
|
||||
// Browse to the front page and check Block's CSS classes configuration.
|
||||
$this->drupalGet('');
|
||||
// Check if feature's Block CSS classes could be found.
|
||||
$this->assertPattern('/class=\"(.*?)' . $test_classes . '(.*?)\"/', format_string('The CSS classes from exported feature were found: @css_classes', array('@css_classes' => $test_classes)));
|
||||
|
||||
// Check Block's configuration form css_class field value.
|
||||
$this->drupalGet("admin/structure/block/manage/{$this->module}/{$this->delta}/configure");
|
||||
$this->assertFieldByName('css_class', $test_classes, format_string('The CSS classes from exported feature were found for the field <em>css_class</em> in the Block\'s configuration page: @css_classes', array('@css_classes' => $test_classes)));
|
||||
|
||||
// Run a standard Update/Display Test check with Anon.
|
||||
$this->assertUpdateBlockClass(TRUE);
|
||||
|
||||
// Ensure Feature's state is overriden for 'fe_block_settings' component.
|
||||
module_load_include('inc', 'features', 'features.export');
|
||||
$test_feature_state = features_get_storage($test_feature);
|
||||
$this->assertFalse(empty($test_feature_state), 'The state of the <em>Block Class FE Block Integration Test Helper</em> feature is <strong>Overridden</strong>.');
|
||||
$test_feature_states = features_get_component_states(array($test_feature));
|
||||
$this->assertFalse(empty($test_feature_states[$test_feature]['fe_block_settings']), 'The state of the <em>fe_block_settings</em> component of the <em>Block Class FE Block Integration Test Helper</em> feature is <strong>Overridden</strong>.');
|
||||
|
||||
// Revert feature and check again.
|
||||
features_revert_module($test_feature);
|
||||
|
||||
// Browse to the front page and check Block's CSS classes configuration.
|
||||
$this->drupalGet('');
|
||||
// Check if feature's Block CSS classes could be found.
|
||||
$this->assertPattern('/class=\"(.*?)' . $test_classes . '(.*?)\"/', format_string('After reverting the feature, the CSS classes from exported feature were found: @css_classes', array('@css_classes' => $test_classes)));
|
||||
|
||||
// Check Block's configuration form css_class field value.
|
||||
$this->drupalGet("admin/structure/block/manage/{$this->module}/{$this->delta}/configure");
|
||||
$this->assertFieldByName('css_class', $test_classes, format_string('After reverting the feature, the CSS classes from exported feature were found for the field <em>css_class</em> in the Block\'s configuration page: @css_classes', array('@css_classes' => $test_classes)));
|
||||
}
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* block_class_fe_block_test.features.fe_block_settings.inc
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_default_fe_block_settings().
|
||||
*/
|
||||
function block_class_fe_block_test_default_fe_block_settings() {
|
||||
$export = array();
|
||||
|
||||
$export['version'] = '2.0';
|
||||
|
||||
$export['user-online'] = array(
|
||||
'cache' => -1,
|
||||
'css_class' => 'fe_block-class1 fe_block-class2 fe_block-class3',
|
||||
'custom' => 0,
|
||||
'delta' => 'online',
|
||||
'module' => 'user',
|
||||
'node_types' => array(),
|
||||
'pages' => '<front>',
|
||||
'roles' => array(),
|
||||
'themes' => array(
|
||||
'bartik' => array(
|
||||
'region' => 'content',
|
||||
'status' => 1,
|
||||
'theme' => 'bartik',
|
||||
'weight' => -7,
|
||||
),
|
||||
),
|
||||
'title' => 'Block Class Test Who\'s Online with FE Block',
|
||||
'visibility' => 1,
|
||||
);
|
||||
|
||||
return $export;
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
name = Block Class FE Block Integration Test Helper
|
||||
description = Helper module for testing the integration of Block Class with Features through the FE Block module.
|
||||
core = 7.x
|
||||
package = Features
|
||||
dependencies[] = fe_block
|
||||
features[fe_block_settings][] = user-online
|
||||
features[features_api][] = api:2
|
||||
hidden = TRUE
|
||||
|
||||
; Information added by Drupal.org packaging script on 2015-12-18
|
||||
version = "7.x-2.3"
|
||||
core = "7.x"
|
||||
project = "block_class"
|
||||
datestamp = "1450415951"
|
||||
|
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Drupal needs this blank file.
|
||||
*/
|
Reference in New Issue
Block a user