annotate core/modules/language/tests/src/Functional/LanguagePathMonolingualTest.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 4c8ae668cc8c
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\Tests\language\Functional;
Chris@0 4
Chris@0 5 use Drupal\Tests\BrowserTestBase;
Chris@0 6
Chris@0 7 /**
Chris@0 8 * Confirm that paths are not changed on monolingual non-English sites.
Chris@0 9 *
Chris@0 10 * @group language
Chris@0 11 */
Chris@0 12 class LanguagePathMonolingualTest extends BrowserTestBase {
Chris@0 13
Chris@0 14 /**
Chris@0 15 * Modules to enable.
Chris@0 16 *
Chris@0 17 * @var array
Chris@0 18 */
Chris@0 19 public static $modules = ['block', 'language', 'path'];
Chris@0 20
Chris@0 21 protected function setUp() {
Chris@0 22 parent::setUp();
Chris@0 23
Chris@0 24 // Create and log in user.
Chris@0 25 $web_user = $this->drupalCreateUser(['administer languages', 'access administration pages', 'administer site configuration']);
Chris@0 26 $this->drupalLogin($web_user);
Chris@0 27
Chris@0 28 // Enable French language.
Chris@0 29 $edit = [];
Chris@0 30 $edit['predefined_langcode'] = 'fr';
Chris@0 31 $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
Chris@0 32
Chris@0 33 // Make French the default language.
Chris@0 34 $edit = [
Chris@0 35 'site_default_language' => 'fr',
Chris@0 36 ];
Chris@0 37 $this->drupalPostForm('admin/config/regional/language', $edit, t('Save configuration'));
Chris@0 38
Chris@0 39 // Delete English.
Chris@0 40 $this->drupalPostForm('admin/config/regional/language/delete/en', [], t('Delete'));
Chris@0 41
Chris@0 42 // Changing the default language causes a container rebuild. Therefore need
Chris@0 43 // to rebuild the container in the test environment.
Chris@0 44 $this->rebuildContainer();
Chris@0 45
Chris@0 46 // Verify that French is the only language.
Chris@0 47 $this->container->get('language_manager')->reset();
Chris@0 48 $this->assertFalse(\Drupal::languageManager()->isMultilingual(), 'Site is mono-lingual');
Chris@0 49 $this->assertEqual(\Drupal::languageManager()->getDefaultLanguage()->getId(), 'fr', 'French is the default language');
Chris@0 50
Chris@0 51 // Set language detection to URL.
Chris@0 52 $edit = ['language_interface[enabled][language-url]' => TRUE];
Chris@0 53 $this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings'));
Chris@0 54 $this->drupalPlaceBlock('local_actions_block');
Chris@0 55 }
Chris@0 56
Chris@0 57 /**
Chris@0 58 * Verifies that links do not have language prefixes in them.
Chris@0 59 */
Chris@0 60 public function testPageLinks() {
Chris@0 61 // Navigate to 'admin/config' path.
Chris@0 62 $this->drupalGet('admin/config');
Chris@0 63
Chris@0 64 // Verify that links in this page do not have a 'fr/' prefix.
Chris@0 65 $this->assertNoLinkByHref('/fr/', 'Links do not contain language prefix');
Chris@0 66
Chris@0 67 // Verify that links in this page can be followed and work.
Chris@0 68 $this->clickLink(t('Languages'));
Chris@0 69 $this->assertResponse(200, 'Clicked link results in a valid page');
Chris@0 70 $this->assertText(t('Add language'), 'Page contains the add language text');
Chris@0 71 }
Chris@0 72
Chris@0 73 }