BlockLanguageCacheTest.php 2.03 KB
Newer Older
1 2 3 4
<?php

/**
 * @file
5
 * Contains \Drupal\block\Tests\BlockLanguageCacheTest.
6 7
 */

8
namespace Drupal\block\Tests;
9

10
use Drupal\Component\Utility\Unicode;
11
use Drupal\language\Entity\ConfigurableLanguage;
12
use Drupal\simpletest\WebTestBase;
13 14

/**
15 16 17
 * Tests display of menu blocks with multiple languages.
 *
 * @group block
18
 */
19
class BlockLanguageCacheTest extends WebTestBase {
20 21 22 23 24 25

  /**
   * Modules to enable.
   *
   * @var array
   */
26
  public static $modules = array('block', 'language', 'menu_ui');
27 28 29 30 31 32 33 34

  /**
   * List of langcodes.
   *
   * @var array
   */
  protected $langcodes = array();

35
  protected function setUp() {
36 37 38
    parent::setUp();

    // Create test languages.
39
    $this->langcodes = array(ConfigurableLanguage::load('en'));
40
    for ($i = 1; $i < 3; ++$i) {
41
      $language = ConfigurableLanguage::create(array(
42
        'id' => 'l' . $i,
43
        'label' => $this->randomString(),
44
      ));
45
      $language->save();
46 47 48 49 50 51 52 53 54 55 56 57
      $this->langcodes[$i] = $language;
    }
  }

  /**
   * Creates a block in a language, check blocks page in all languages.
   */
  public function testBlockLinks() {
    // Create admin user to be able to access block admin.
    $admin_user = $this->drupalCreateUser(array(
      'administer blocks',
      'access administration pages',
58
      'administer menu',
59 60 61 62 63 64 65 66
    ));
    $this->drupalLogin($admin_user);

    // Create the block cache for all languages.
    foreach ($this->langcodes as $langcode) {
      $this->drupalGet('admin/structure/block', array('language' => $langcode));
    }

67
    // Create a menu in the default language.
68
    $edit['label'] = $this->randomMachineName();
69 70 71
    $edit['id'] = Unicode::strtolower($edit['label']);
    $this->drupalPostForm('admin/structure/menu/add', $edit, t('Save'));
    $this->assertText(t('Menu @label has been added.', array('@label' => $edit['label'])));
72 73 74 75

    // Check that the block is listed for all languages.
    foreach ($this->langcodes as $langcode) {
      $this->drupalGet('admin/structure/block', array('language' => $langcode));
76
      $this->assertText($edit['label']);
77 78 79
    }
  }
}