Verified Commit f4a02958 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3275530 by danflanagan8: Language Tests should not rely on Classy

(cherry picked from commit 446bc5dd)
parent a3562c9e
Loading
Loading
Loading
Loading
+22 −37
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@

use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\system\Functional\Menu\AssertBreadcrumbTrait;

/**
 * Tests breadcrumbs functionality.
@@ -12,6 +13,8 @@
 */
class LanguageBreadcrumbTest extends BrowserTestBase {

  use AssertBreadcrumbTrait;

  /**
   * Modules to enable.
   *
@@ -22,7 +25,7 @@ class LanguageBreadcrumbTest extends BrowserTestBase {
  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'classy';
  protected $defaultTheme = 'stark';

  /**
   * {@inheritdoc}
@@ -38,51 +41,33 @@ protected function setUp(): void {
   * Tests breadcrumbs with URL prefixes.
   */
  public function testBreadCrumbs() {
    // Prepare common base breadcrumb elements.
    $home = ['' => 'Home'];
    $admin = $home + ['admin' => 'Administration'];

    $page = $this->getSession()->getPage();

    // /user/login is the default frontpage which only works for an anonymous
    // user. Access the frontpage in different languages, ensure that no
    // breadcrumb is displayed.
    $this->drupalGet('user/login');
    $breadcrumbs = $page->find('css', '.block-system-breadcrumb-block');
    $this->assertNull($breadcrumbs);

    $this->drupalGet('de/user/login');
    $breadcrumbs = $page->find('css', '.block-system-breadcrumb-block');
    $this->assertNull($breadcrumbs);

    $this->drupalGet('gsw-berne/user/login');
    $breadcrumbs = $page->find('css', '.block-system-breadcrumb-block');
    $this->assertNull($breadcrumbs);
    $this->assertBreadcrumb('user/login', []);
    $this->assertBreadcrumb('de/user/login', []);
    $this->assertBreadcrumb('gsw-berne/user/login', []);

    $admin_user = $this->drupalCreateUser(['access administration pages']);
    $this->drupalLogin($admin_user);

    // Use administration routes to assert that breadcrumb is displayed
    // correctly on pages other than the frontpage.
    $this->drupalGet('admin');
    $breadcrumbs = $page->find('css', '.block-system-breadcrumb-block');
    $this->assertEquals(1, substr_count($breadcrumbs->getText(), 'Home'));
    $this->assertEquals(0, substr_count($breadcrumbs->getText(), 'Administration'));

    $this->drupalGet('de/admin');
    $breadcrumbs = $page->find('css', '.block-system-breadcrumb-block');
    $this->assertEquals(1, substr_count($breadcrumbs->getText(), 'Home'));
    $this->assertEquals(0, substr_count($breadcrumbs->getText(), 'Administration'));

    $this->drupalGet('admin/structure', $admin);
    $breadcrumbs = $page->find('css', '.block-system-breadcrumb-block');
    $this->assertEquals(1, substr_count($breadcrumbs->getText(), 'Home'));
    $this->assertEquals(1, substr_count($breadcrumbs->getText(), 'Administration'));

    $this->drupalGet('de/admin/structure', $admin);
    $breadcrumbs = $page->find('css', '.block-system-breadcrumb-block');
    $this->assertEquals(1, substr_count($breadcrumbs->getText(), 'Home'));
    $this->assertEquals(1, substr_count($breadcrumbs->getText(), 'Administration'));
    $this->assertBreadcrumb('admin', [
      '' => 'Home',
    ]);
    $this->assertBreadcrumb('de/admin', [
      'de' => 'Home',
    ]);

    $this->assertBreadcrumb('admin/structure', [
      '' => 'Home',
      'admin' => 'Administration',
    ]);
    $this->assertBreadcrumb('de/admin/structure', [
      'de' => 'Home',
      'de/admin' => 'Administration',
    ]);
  }

}
+3 −3
Original line number Diff line number Diff line
@@ -50,7 +50,7 @@ public function testUIBrowserLanguageMappings() {
    $this->drupalGet('admin/config/regional/language/detection/browser/delete/' . $browser_langcode);
    $this->submitForm($edit, 'Confirm');

    $this->assertSession()->pageTextContains("The mapping for the {$browser_langcode} browser language code has been deleted.");
    $this->assertSession()->statusMessageContains("The mapping for the {$browser_langcode} browser language code has been deleted.", 'status');

    // Check we went back to the browser negotiation mapping overview.
    $this->assertSession()->addressEquals(Url::fromRoute('language.negotiation_browser'));
@@ -71,7 +71,7 @@ public function testUIBrowserLanguageMappings() {
    // Add the same custom mapping again.
    $this->drupalGet('admin/config/regional/language/detection/browser');
    $this->submitForm($edit, 'Save configuration');
    $this->assertSession()->pageTextContains('Browser language codes must be unique.');
    $this->assertSession()->statusMessageContains('Browser language codes must be unique.', 'error');

    // Change browser language code of our custom mapping to zh-sg.
    $edit = [
@@ -80,7 +80,7 @@ public function testUIBrowserLanguageMappings() {
    ];
    $this->drupalGet('admin/config/regional/language/detection/browser');
    $this->submitForm($edit, 'Save configuration');
    $this->assertSession()->pageTextContains('Browser language codes must be unique.');
    $this->assertSession()->statusMessageContains('Browser language codes must be unique.', 'error');

    // Change Drupal language code of our custom mapping to zh-hans.
    $edit = [
+4 −4
Original line number Diff line number Diff line
@@ -101,7 +101,7 @@ public function testLanguageConfiguration() {
      'prefix[fr]' => '',
    ];
    $this->submitForm($edit, 'Save configuration');
    $this->assertSession()->pageTextNotContains('The prefix may only be left blank for the selected detection fallback language.');
    $this->assertSession()->statusMessageNotContains('The prefix may only be left blank for the selected detection fallback language.');

    // Change default negotiation language.
    $this->config('language.negotiation')->set('selected_langcode', 'fr')->save();
@@ -111,21 +111,21 @@ public function testLanguageConfiguration() {
      'prefix[en]' => '',
    ];
    $this->submitForm($edit, 'Save configuration');
    $this->assertSession()->pageTextContains('The prefix may only be left blank for the selected detection fallback language.');
    $this->assertSession()->statusMessageContains('The prefix may only be left blank for the selected detection fallback language.', 'error');

    // Check that prefix cannot be changed to contain a slash.
    $edit = [
      'prefix[en]' => 'foo/bar',
    ];
    $this->submitForm($edit, 'Save configuration');
    $this->assertSession()->pageTextContains('The prefix may not contain a slash.');
    $this->assertSession()->statusMessageContains('The prefix may not contain a slash.', 'error');

    // Remove English language and add a new Language to check if langcode of
    // Language entity is 'en'.
    $this->drupalGet('admin/config/regional/language/delete/en');
    $this->submitForm([], 'Delete');
    $this->rebuildContainer();
    $this->assertSession()->pageTextContains("The English (en) language has been removed.");
    $this->assertSession()->statusMessageContains('The English (en) language has been removed.', 'status');

    // Ensure that French language has a weight of 1 after being created through
    // the UI.
+7 −7
Original line number Diff line number Diff line
@@ -45,8 +45,8 @@ public function testLanguageConfiguration() {
    $this->drupalGet('admin/config/regional/language/add');
    $this->submitForm($edit, 'Add custom language');
    // Test validation on missing values.
    $this->assertSession()->pageTextContains('Language code field is required.');
    $this->assertSession()->pageTextContains('Language name field is required.');
    $this->assertSession()->statusMessageContains('Language code field is required.', 'error');
    $this->assertSession()->statusMessageContains('Language name field is required.', 'error');
    $empty_language = new Language();
    $this->assertSession()->checkboxChecked('edit-direction-' . $empty_language->getDirection());
    $this->assertSession()->addressEquals(Url::fromRoute('language.add'));
@@ -61,10 +61,10 @@ public function testLanguageConfiguration() {
    $this->drupalGet('admin/config/regional/language/add');
    $this->submitForm($edit, 'Add custom language');

    $this->assertSession()->pageTextContains("Language code must be a valid language tag as defined by the W3C.");
    $this->assertSession()->statusMessageContains('Language code must be a valid language tag as defined by the W3C.', 'error');
    $this->assertSession()->linkExists("defined by the W3C");
    $this->assertSession()->linkByHrefExists("http://www.w3.org/International/articles/language-tags/");
    $this->assertSession()->pageTextContains("Language name cannot contain any markup.");
    $this->assertSession()->statusMessageContains('Language name cannot contain any markup.', 'error');
    $this->assertSession()->addressEquals(Url::fromRoute('language.add'));

    // Test adding a custom language with a numeric region code.
@@ -77,7 +77,7 @@ public function testLanguageConfiguration() {

    $this->drupalGet('admin/config/regional/language/add');
    $this->submitForm($edit, 'Add custom language');
    $this->assertSession()->pageTextContains("The language {$edit['label']} has been created and can now be used.");
    $this->assertSession()->statusMessageContains("The language {$edit['label']} has been created and can now be used.", 'status');
    $this->assertSession()->addressEquals(Url::fromRoute('entity.configurable_language.collection'));

    // Test validation of existing language values.
@@ -91,13 +91,13 @@ public function testLanguageConfiguration() {
    // Add the language the first time.
    $this->drupalGet('admin/config/regional/language/add');
    $this->submitForm($edit, 'Add custom language');
    $this->assertSession()->pageTextContains("The language {$edit['label']} has been created and can now be used.");
    $this->assertSession()->statusMessageContains("The language {$edit['label']} has been created and can now be used.", 'status');
    $this->assertSession()->addressEquals(Url::fromRoute('entity.configurable_language.collection'));

    // Add the language a second time and confirm that this is not allowed.
    $this->drupalGet('admin/config/regional/language/add');
    $this->submitForm($edit, 'Add custom language');
    $this->assertSession()->pageTextContains("The language {$edit['label']} ({$edit['langcode']}) already exists.");
    $this->assertSession()->statusMessageContains("The language {$edit['label']} ({$edit['langcode']}) already exists.", 'error');
    $this->assertSession()->addressEquals(Url::fromRoute('language.add'));
  }

+4 −4
Original line number Diff line number Diff line
@@ -130,7 +130,7 @@ public function testLanguageList() {
    // fields changed.
    $this->drupalGet('admin/config/regional/language/delete/' . $langcode);
    $this->submitForm([], 'Delete');
    $this->assertSession()->pageTextContains("The {$name} ({$langcode}) language has been removed.");
    $this->assertSession()->statusMessageContains("The {$name} ({$langcode}) language has been removed.", 'status');
    $this->assertSession()->addressEquals(Url::fromRoute('entity.configurable_language.collection', [], ['language' => $english]));
    // Verify that language is no longer found.
    $this->drupalGet('admin/config/regional/language/delete/' . $langcode);
@@ -141,7 +141,7 @@ public function testLanguageList() {
    $this->submitForm([], 'Delete');
    // Make sure the "language_count" state has been updated correctly.
    $this->rebuildContainer();
    $this->assertSession()->pageTextContains("The French (fr) language has been removed.");
    $this->assertSession()->statusMessageContains('The French (fr) language has been removed.', 'status');
    $this->assertSession()->addressEquals(Url::fromRoute('entity.configurable_language.collection'));
    // Verify that language is no longer found.
    $this->drupalGet('admin/config/regional/language/delete/fr');
@@ -179,7 +179,7 @@ public function testLanguageList() {

    $this->drupalGet('admin/config/regional/language/delete/en');
    $this->submitForm([], 'Delete');
    $this->assertSession()->pageTextContains("The English (en) language has been removed.");
    $this->assertSession()->statusMessageContains('The English (en) language has been removed.', 'status');
    $this->rebuildContainer();

    // Ensure we can't delete a locked language.
@@ -202,7 +202,7 @@ public function testLanguageList() {
    $language_storage->load('nl')->delete();

    $this->submitForm(['site_default_language' => 'nl'], 'Save configuration');
    $this->assertSession()->pageTextContains('Selected default language no longer exists.');
    $this->assertSession()->statusMessageContains('Selected default language no longer exists.', 'error');
    $this->assertSession()->checkboxNotChecked('edit-site-default-language-xx');
  }

Loading