BlockLanguageCacheTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace Drupal\Tests\block\Functional;
  3. use Drupal\language\Entity\ConfigurableLanguage;
  4. use Drupal\Tests\BrowserTestBase;
  5. /**
  6. * Tests display of menu blocks with multiple languages.
  7. *
  8. * @group block
  9. */
  10. class BlockLanguageCacheTest extends BrowserTestBase {
  11. /**
  12. * Modules to install.
  13. *
  14. * @var array
  15. */
  16. public static $modules = ['block', 'language', 'menu_ui'];
  17. /**
  18. * List of langcodes.
  19. *
  20. * @var array
  21. */
  22. protected $langcodes = [];
  23. protected function setUp() {
  24. parent::setUp();
  25. // Create test languages.
  26. $this->langcodes = [ConfigurableLanguage::load('en')];
  27. for ($i = 1; $i < 3; ++$i) {
  28. $language = ConfigurableLanguage::create([
  29. 'id' => 'l' . $i,
  30. 'label' => $this->randomString(),
  31. ]);
  32. $language->save();
  33. $this->langcodes[$i] = $language;
  34. }
  35. }
  36. /**
  37. * Creates a block in a language, check blocks page in all languages.
  38. */
  39. public function testBlockLinks() {
  40. // Create admin user to be able to access block admin.
  41. $admin_user = $this->drupalCreateUser([
  42. 'administer blocks',
  43. 'access administration pages',
  44. 'administer menu',
  45. ]);
  46. $this->drupalLogin($admin_user);
  47. // Create the block cache for all languages.
  48. foreach ($this->langcodes as $langcode) {
  49. $this->drupalGet('admin/structure/block', ['language' => $langcode]);
  50. $this->clickLink('Place block');
  51. }
  52. // Create a menu in the default language.
  53. $edit['label'] = $this->randomMachineName();
  54. $edit['id'] = mb_strtolower($edit['label']);
  55. $this->drupalPostForm('admin/structure/menu/add', $edit, t('Save'));
  56. $this->assertText(t('Menu @label has been added.', ['@label' => $edit['label']]));
  57. // Check that the block is listed for all languages.
  58. foreach ($this->langcodes as $langcode) {
  59. $this->drupalGet('admin/structure/block', ['language' => $langcode]);
  60. $this->clickLink('Place block');
  61. $this->assertText($edit['label']);
  62. }
  63. }
  64. }