Tests the visibility settings for the blocks based on language.
public function testLanguageBlockVisibility() {
// Create a new user, allow him to manage the blocks and the languages.
$admin_user = $this
->drupalCreateUser(array(
'administer languages',
'administer blocks',
));
$this
->drupalLogin($admin_user);
// Add predefined language.
$edit = array(
'predefined_langcode' => 'fr',
);
$this
->drupalPost('admin/config/regional/language/add', $edit, t('Add language'));
$this
->assertText('French', 'Language added successfully.');
// Check if the visibility setting is available.
$this
->drupalGet('admin/structure/block/add');
$this
->assertField('langcodes[en]', 'Language visibility field is visible.');
// Create a new block.
$info_name = $this
->randomString(10);
$body = '';
for ($i = 0; $i <= 100; $i++) {
$body .= chr(rand(97, 122));
}
$edit = array(
'regions[stark]' => 'sidebar_first',
'info' => $info_name,
'title' => 'test',
'body[value]' => $body,
);
$this
->drupalPost('admin/structure/block/add', $edit, t('Save block'));
// Set visibility setting for one language.
$edit = array(
'langcodes[en]' => TRUE,
);
$this
->drupalPost('admin/structure/block/manage/block/1/configure', $edit, t('Save block'));
// Change the default language.
$edit = array(
'site_default' => 'fr',
);
$this
->drupalPost('admin/config/regional/language', $edit, t('Save configuration'));
// Reset the static cache of the language list.
drupal_static_reset('language_list');
// Check that a page has a block
$this
->drupalGet('', array(
'language' => language_load('en'),
));
$this
->assertText($body, 'The body of the custom block appears on the page.');
// Check that a page doesn't has a block for the current language anymore
$this
->drupalGet('', array(
'language' => language_load('fr'),
));
$this
->assertNoText($body, 'The body of the custom block does not appear on the page.');
}