public function BlockLanguageTest::testLanguageBlockVisibilityLanguageDelete

Tests if the visibility settings are removed if the language is deleted.

File

drupal/core/modules/block/lib/Drupal/block/Tests/BlockLanguageTest.php, line 94
Definition of Drupal\block\Tests\BlockLanguageTest.

Class

BlockLanguageTest
Functional tests for the language list configuration forms.

Namespace

Drupal\block\Tests

Code

public function testLanguageBlockVisibilityLanguageDelete() {

  // 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.');

  // 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[fr]' => TRUE,
  );
  $this
    ->drupalPost('admin/structure/block/manage/block/1/configure', $edit, t('Save block'));

  // Check that we have an entry in the database after saving the setting.
  $count = db_query('SELECT COUNT(langcode) FROM {block_language} WHERE module = :module AND delta = :delta', array(
    ':module' => 'block',
    ':delta' => '1',
  ))
    ->fetchField();
  $this
    ->assertTrue($count == 1, 'The block language visibility has an entry in the database.');

  // Delete the language.
  $this
    ->drupalPost('admin/config/regional/language/delete/fr', array(), t('Delete'));

  // Check that the setting related to this language has been deleted.
  $count = db_query('SELECT COUNT(langcode) FROM {block_language} WHERE module = :module AND delta = :delta', array(
    ':module' => 'block',
    ':delta' => '1',
  ))
    ->fetchField();
  $this
    ->assertTrue($count == 0, 'The block language visibility do not have an entry in the database.');
}