diff options
Diffstat (limited to 'modules/system')
-rw-r--r-- | modules/system/system.module | 96 | ||||
-rw-r--r-- | modules/system/system.test | 52 |
2 files changed, 107 insertions, 41 deletions
diff --git a/modules/system/system.module b/modules/system/system.module index 8046f10ad..ad56aea37 100644 --- a/modules/system/system.module +++ b/modules/system/system.module @@ -836,51 +836,65 @@ function system_user_timezone(&$edit, &$form) { } /** - * Implementation of hook_block(). + * Implementation of hook_block_list(). + */ +function system_block_list() { + $image_path = 'misc/' . variable_get('drupal_badge_color', 'powered-blue') . '-' . variable_get('drupal_badge_size', '80x15') . '.png'; + $blocks['powered-by'] = array( + 'info' => t('Powered by Drupal'), + 'weight' => '10', + // Not worth caching. + 'cache' => BLOCK_NO_CACHE, + ); + return $blocks; +} + +/** + * Implementation of hook_block_configure(). + */ +function system_block_configure($delta = '') { + $image_path = 'misc/' . variable_get('drupal_badge_color', 'powered-blue') . '-' . variable_get('drupal_badge_size', '80x15') . '.png'; + drupal_add_js(drupal_get_path('module', 'system') .'/system.js'); + // Compile a list of fields to show + $form['wrapper']['color'] = array( + '#type' => 'select', + '#title' => t('Badge color'), + '#default_value' => variable_get('drupal_badge_color', 'powered-blue'), + '#options' => array('powered-black' => t('Black'), 'powered-blue' => t('Blue'), 'powered-gray' => t('Gray')), + ); + $form['wrapper']['size'] = array( + '#type' => 'select', + '#title' => t('Badge size'), + '#default_value' => variable_get('drupal_badge_size', '80x15'), + '#options' => array('80x15' => t('Small'), '88x31' => t('Medium'), '135x42' => t('Large')), + ); + $form['wrapper']['preview'] = array( + '#type' => 'item', + '#title' => 'Preview', + '#markup' => theme('image', $image_path, t('Powered by Drupal, an open source content management system'), t('Powered by Drupal, an open source content management system'), array('class' => 'powered-by-preview'), FALSE), + ); + return $form; +} + +/** + * Implementation of hook_block_save(). + */ +function system_block_save($delta = '', $edit = NULL) { + $image_path = 'misc/' . variable_get('drupal_badge_color', 'powered-blue') . '-' . variable_get('drupal_badge_size', '80x15') . '.png'; + variable_set('drupal_badge_color', $edit['color']); + variable_set('drupal_badge_size', $edit['size']); +} + +/** + * Implementation of hook_block_view(). * * Generate a block with a promotional link to Drupal.org. */ -function system_block($op = 'list', $delta = '', $edit = NULL) { +function system_block_view($delta = '') { $image_path = 'misc/' . variable_get('drupal_badge_color', 'powered-blue') . '-' . variable_get('drupal_badge_size', '80x15') . '.png'; - switch ($op) { - case 'list': - $blocks['powered-by'] = array( - 'info' => t('Powered by Drupal'), - 'weight' => '10', - // Not worth caching. - 'cache' => BLOCK_NO_CACHE, - ); - return $blocks; - case 'configure': - drupal_add_js(drupal_get_path('module', 'system') .'/system.js'); - // Compile a list of fields to show - $form['wrapper']['color'] = array( - '#type' => 'select', - '#title' => t('Badge color'), - '#default_value' => variable_get('drupal_badge_color', 'powered-blue'), - '#options' => array('powered-black' => t('Black'), 'powered-blue' => t('Blue'), 'powered-gray' => t('Gray')), - ); - $form['wrapper']['size'] = array( - '#type' => 'select', - '#title' => t('Badge size'), - '#default_value' => variable_get('drupal_badge_size', '80x15'), - '#options' => array('80x15' => t('Small'), '88x31' => t('Medium'), '135x42' => t('Large')), - ); - $form['wrapper']['preview'] = array( - '#type' => 'item', - '#title' => 'Preview', - '#markup' => theme('image', $image_path, t('Powered by Drupal, an open source content management system'), t('Powered by Drupal, an open source content management system'), array('class' => 'powered-by-preview'), FALSE), - ); - return $form; - case 'save': - variable_set('drupal_badge_color', $edit['color']); - variable_set('drupal_badge_size', $edit['size']); - break; - case 'view': - $block['subject'] = NULL; // Don't display a title - $block['content'] = theme('system_powered_by', $image_path); - return $block; - } + $block['subject'] = NULL; // Don't display a title + $block['content'] = theme('system_powered_by', $image_path); + return $block; } /** diff --git a/modules/system/system.test b/modules/system/system.test index 9b1b2cbdc..f07d8707e 100644 --- a/modules/system/system.test +++ b/modules/system/system.test @@ -631,3 +631,55 @@ class FrontPageTestCase extends DrupalWebTestCase { $this->assertText(t('On front page.'), t('Path is the front page.')); } } + +class SystemBlockTestCase extends DrupalWebTestCase { + function getInfo() { + return array( + 'name' => t('Block functionality'), + 'description' => t('Configure and move powered-by block.'), + 'group' => t('System'), + ); + } + + function setUp() { + parent::setUp(); + + // Create and login user + $admin_user = $this->drupalCreateUser(array('administer blocks')); + $this->drupalLogin($admin_user); + } + + /** + * Test displaying and hiding the powered-by block. + */ + function testPoweredByBlock() { + // Set block title and some settings to confirm that the interface is availble. + $this->drupalPost('admin/build/block/configure/system/powered-by', array('title' => $this->randomName(8), 'color' => 'powered-black', 'size' => '135x42'), t('Save block')); + $this->assertText(t('The block configuration has been saved.'), t('Block configuration set.')); + + // Set the powered-by block to the footer region. + $edit = array(); + $edit['system_powered-by[region]'] = 'footer'; + $this->drupalPost('admin/build/block', $edit, t('Save blocks')); + $this->assertText(t('The block settings have been updated.'), t('Block successfully move to footer region.')); + + // Confirm that the block is being displayed. + $this->assertRaw('id="block-system-powered-by"', t('Block successfully being displayed on the page.')); + + // Set the block to the disabled region. + $edit = array(); + $edit['system_powered-by[region]'] = '-1'; + $this->drupalPost('admin/build/block', $edit, t('Save blocks')); + + // Confirm that the block is hidden. + $this->assertNoRaw('id="block-system-powered-by"', t('Block no longer appears on page.')); + + // For convenience of developers, set the block to it's default settings. + $edit = array(); + $edit['system_powered-by[region]'] = 'footer'; + $this->drupalPost('admin/build/block', $edit, t('Save blocks')); + $this->drupalPost('admin/build/block/configure/system/powered-by', array('title' => '', 'color' => 'powered-blue', 'size' => '80x15'), t('Save block')); + } + +} + |