cms/drupal/modules/simpletest/tests/upgrade/upgrade.locale.test
changeset 541 e756a8c72c3d
equal deleted inserted replaced
540:07239de796bb 541:e756a8c72c3d
       
     1 <?php
       
     2 
       
     3 /**
       
     4  * Upgrade test for locale.module.
       
     5  */
       
     6 class LocaleUpgradePathTestCase extends UpgradePathTestCase {
       
     7   public static function getInfo() {
       
     8     return array(
       
     9       'name'  => 'Locale upgrade path',
       
    10       'description'  => 'Upgrade path tests for the Locale module.',
       
    11       'group' => 'Upgrade path',
       
    12     );
       
    13   }
       
    14 
       
    15   public function setUp() {
       
    16     // Path to the database dump files.
       
    17     $this->databaseDumpFiles = array(
       
    18       drupal_get_path('module', 'simpletest') . '/tests/upgrade/drupal-6.filled.database.php',
       
    19       drupal_get_path('module', 'simpletest') . '/tests/upgrade/drupal-6.locale.database.php',
       
    20     );
       
    21     parent::setUp();
       
    22 
       
    23     $this->uninstallModulesExcept(array('locale', 'comment'));
       
    24   }
       
    25 
       
    26   /**
       
    27    * Test a successful upgrade (no negotiation).
       
    28    */
       
    29   public function testLocaleUpgrade() {
       
    30     $this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.');
       
    31 
       
    32     // The home page should be in French.
       
    33     $this->assertPageInLanguage('', 'fr');
       
    34 
       
    35     // No prefixed page should exist.
       
    36     $this->drupalGet('en');
       
    37     $this->assertResponse(404);
       
    38     $this->drupalGet('fr');
       
    39     $this->assertResponse(404);
       
    40   }
       
    41 
       
    42   /**
       
    43    * Test an upgrade with path-based negotiation.
       
    44    */
       
    45   public function testLocaleUpgradePathDefault() {
       
    46     // LANGUAGE_NEGOTIATION_PATH_DEFAULT.
       
    47     $this->variable_set('language_negotiation', 1);
       
    48 
       
    49     $this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.');
       
    50 
       
    51     // The home page should be in French.
       
    52     $this->assertPageInLanguage('', 'fr');
       
    53 
       
    54     // The language switcher block should be displayed.
       
    55     $this->assertRaw('block-locale-language', 'The language switcher block is displayed.');
       
    56 
       
    57     // The French prefix should not be active because French is the default language.
       
    58     $this->drupalGet('fr');
       
    59     $this->assertResponse(404);
       
    60 
       
    61     // The English prefix should be active.
       
    62     $this->assertPageInLanguage('en', 'en');
       
    63   }
       
    64 
       
    65   /**
       
    66    * Test an upgrade with path-based (with fallback) negotiation.
       
    67    */
       
    68   public function testLocaleUpgradePathFallback() {
       
    69     // LANGUAGE_NEGOTIATION_PATH.
       
    70     $this->variable_set('language_negotiation', 2);
       
    71 
       
    72     // Set the language of the admin user to English.
       
    73     db_update('users')
       
    74       ->fields(array('language' => 'en'))
       
    75       ->condition('uid', 1)
       
    76       ->execute();
       
    77 
       
    78     $this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.');
       
    79 
       
    80     // Both prefixes should be active.
       
    81     $this->assertPageInLanguage('fr', 'fr');
       
    82     $this->assertPageInLanguage('en', 'en');
       
    83 
       
    84     // The home page should be in the admin user language.
       
    85     $this->assertPageInLanguage('', 'en');
       
    86 
       
    87     // The language switcher block should be displayed.
       
    88     $this->assertRaw('block-locale-language', 'The language switcher block is displayed.');
       
    89   }
       
    90 
       
    91   /**
       
    92    * Test an upgrade with domain-based negotiation.
       
    93    */
       
    94   public function testLocaleUpgradeDomain() {
       
    95     // LANGUAGE_NEGOTIATION_DOMAIN.
       
    96     $this->variable_set('language_negotiation', 3);
       
    97 
       
    98     $this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.');
       
    99 
       
   100     // The home page should be in French.
       
   101     $this->assertPageInLanguage('', 'fr');
       
   102 
       
   103     // The language switcher block should be displayed.
       
   104     $this->assertRaw('block-locale-language', 'The language switcher block is displayed.');
       
   105 
       
   106     // The language switcher block should point to http://en.example.com.
       
   107     $language_links = $this->xpath('//ul[contains(@class, :class)]/li/a', array(':class' => 'language-switcher-locale-url'));
       
   108     $found_english_link = FALSE;
       
   109     foreach ($language_links as $link) {
       
   110       if ((string) $link['href'] == 'http://en.example.com/') {
       
   111         $found_english_link = TRUE;
       
   112       }
       
   113     }
       
   114     $this->assertTrue($found_english_link, 'The English link points to the correct domain.');
       
   115 
       
   116     // Both prefixes should be inactive.
       
   117     $this->drupalGet('en');
       
   118     $this->assertResponse(404);
       
   119     $this->drupalGet('fr');
       
   120     $this->assertResponse(404);
       
   121 
       
   122   }
       
   123 
       
   124   /**
       
   125    * Asserts that a page exists and is in the specified language.
       
   126    */
       
   127   public function assertPageInLanguage($path = NULL, $langcode) {
       
   128     if (isset($path)) {
       
   129       $this->drupalGet($path);
       
   130     }
       
   131 
       
   132     if (!$this->assertResponse(200)) {
       
   133       return FALSE;
       
   134     }
       
   135 
       
   136     if ($this->parse()) {
       
   137       return $this->assertIdentical($langcode, (string) $this->elements['xml:lang']);
       
   138     }
       
   139     else {
       
   140       return FALSE;
       
   141     }
       
   142   }
       
   143 }