diff --git a/linkchecker.module b/linkchecker.module index 9c13058..5445cc2 100644 --- a/linkchecker.module +++ b/linkchecker.module @@ -364,6 +364,14 @@ function _linkchecker_status_handling($link, $response) { } // Save changed block and update the block link list. + // Reformat the body as expected. + $block_custom['body'] = array( + 'value' => $block_custom['body'], + 'format' => $block_custom['format'] + ); + // Set these to ensure warning aren't raised. + $block_custom['module'] = 'block'; + $block_custom['delta'] = $row->bid; block_custom_block_save($block_custom, $block_custom['bid']); // There is no hook that fires on block_custom_block_save(), // therefore do link extraction programmatically. diff --git a/linkchecker.test b/linkchecker.test index d4ea142..2907724 100644 --- a/linkchecker.test +++ b/linkchecker.test @@ -380,3 +380,76 @@ EOT; return db_query('SELECT COUNT(1) FROM {linkchecker_link}')->fetchField(); } } + +/** + * Tests block updates + */ +class LinkCheckerBlockTest extends DrupalWebTestCase { + + public static function getInfo() { + return array( + 'name' => t('Block link checking and update tests'), + 'description' => t('Test Link checker module block integration functionality.'), + 'group' => 'Link checker', + ); + } + + public function setUp() { + parent::setUp('linkchecker'); + + $full_html_format = filter_format_load('full_html'); + $permissions = array( + 'administer blocks', + filter_permission_name($full_html_format), + ); + + $user = $this->drupalCreateUser($permissions); + $this->drupalLogin($user); + + } + + /** + * Tests block updates. + */ + function testBlockUpdates() { + // Set the ignore response codes and behaviour. + variable_set('linkchecker_check_links_types', 0); + variable_set('linkchecker_scan_blocks', 1); + // Repair after 1 fail. + variable_set('linkchecker_action_status_code_301', 1); + // check after 1 day. + variable_set('linkchecker_check_links_interval', 86400); + variable_set('linkchecker_ignore_response_codes', '200 +206 +302 +304 +401 +403'); + + // Create block. + $this->drupalGet('admin/structure/block/add'); + $edit = array( + 'info' => 'dummy_block', + 'body[value]' => 'something with google which will 301 back to www', + 'body[format]' => 'full_html' + ); + $this->drupalPost(NULL, $edit, t('Save block')); + + // Mark the last updated and fails to force an update. + db_update('linkchecker_link') + // 3 days ago. + ->fields(array( + 'last_checked' => REQUEST_TIME - (3 * 86400), + 'fail_count' => 2, + )) + ->execute(); + + // Run cron. + $this->cronRun(); + + // Load the block back up. + $block = block_custom_block_get(1); + // Verify that google.com rewritten to www.google.com. + $this->assertEqual($block['body'], 'something with google which will 301 back to www', format_string('Block body @body had link updated', array('@body' => $block['body']))); + } +}