Project

General

Profile

Revision b0dc3a2e

Added by Julien Enselme over 7 years ago

Update to Drupal 7.52

View differences:

drupal7/modules/locale/locale.test
393 393
    // The indicator should not be here.
394 394
    $this->assertNoRaw($language_indicator, 'String is translated.');
395 395

  
396
    // Verify that a translation set which has an empty target string can be
397
    // updated without any database error.
398
    db_update('locales_target')
399
      ->fields(array('translation' => ''))
400
      ->condition('language', $langcode, '=')
401
      ->condition('lid', $lid, '=')
402
      ->execute();
403
    $this->drupalPost('admin/config/regional/translate/edit/' . $lid, $edit, t('Save translations'));
404
    $this->assertText(t('The string has been saved.'), 'The string has been saved.');
405

  
396 406
    // Try to edit a non-existent string and ensure we're redirected correctly.
397 407
    // Assuming we don't have 999,999 strings already.
398 408
    $random_lid = 999999;
......
2237 2247

  
2238 2248
    $this->drupalLogout();
2239 2249
  }
2250

  
2251
  /**
2252
   * Verifies that nodes may be created with different languages.
2253
   */
2254
  function testNodeCreationWithLanguage() {
2255
    // Create an admin user and log them in.
2256
    $perms = array(
2257
      // Standard node permissions.
2258
      'create page content',
2259
      'administer content types',
2260
      'administer nodes',
2261
      'bypass node access',
2262
      // Locale.
2263
      'administer languages',
2264
    );
2265
    $web_user = $this->drupalCreateUser($perms);
2266
    $this->drupalLogin($web_user);
2267

  
2268
    // Create some test nodes using different langcodes.
2269
    foreach (array(LANGUAGE_NONE, 'en', 'fr') as $langcode) {
2270
      $node_args = array(
2271
        'type' => 'page',
2272
        'promote' => 1,
2273
        'language' => $langcode,
2274
      );
2275
      $node = $this->drupalCreateNode($node_args);
2276
      $node_reloaded = node_load($node->nid, NULL, TRUE);
2277
      $this->assertEqual($node_reloaded->language, $langcode, format_string('The language code of the node was successfully set to @langcode.', array('@langcode' => $langcode)));
2278
    }
2279
  }
2280

  
2240 2281
}
2241 2282

  
2242 2283
/**
......
2629 2670
    $this->drupalGet("$prefix/$path");
2630 2671
    $this->assertResponse(404, $message2);
2631 2672
  }
2673

  
2674
  /**
2675
   * Check URL rewriting when using a domain name and a non-standard port.
2676
   */
2677
  function testDomainNameNegotiationPort() {
2678
    $language_domain = 'example.fr';
2679
    $edit = array(
2680
      'locale_language_negotiation_url_part' => 1,
2681
    );
2682
    $this->drupalPost('admin/config/regional/language/configure/url', $edit, t('Save configuration'));
2683
    $edit = array(
2684
      'prefix' => '',
2685
      'domain' => $language_domain
2686
    );
2687
    $this->drupalPost('admin/config/regional/language/edit/fr', $edit, t('Save language'));
2688

  
2689
    // Enable domain configuration.
2690
    variable_set('locale_language_negotiation_url_part', LOCALE_LANGUAGE_NEGOTIATION_URL_DOMAIN);
2691

  
2692
    // Reset static caching.
2693
    drupal_static_reset('language_list');
2694
    drupal_static_reset('language_url_outbound_alter');
2695
    drupal_static_reset('language_url_rewrite_url');
2696

  
2697
    // In case index.php is part of the URLs, we need to adapt the asserted
2698
    // URLs as well.
2699
    $index_php = strpos(url('', array('absolute' => TRUE)), 'index.php') !== FALSE;
2700

  
2701
    // Remember current HTTP_HOST.
2702
    $http_host = $_SERVER['HTTP_HOST'];
2703

  
2704
    // Fake a different port.
2705
    $_SERVER['HTTP_HOST'] .= ':88';
2706

  
2707
    // Create an absolute French link.
2708
    $languages = language_list();
2709
    $language = $languages['fr'];
2710
    $url = url('', array(
2711
      'absolute' => TRUE,
2712
      'language' => $language
2713
    ));
2714

  
2715
    $expected = 'http://example.fr:88/';
2716
    $expected .= $index_php ? 'index.php/' : '';
2717

  
2718
    $this->assertEqual($url, $expected, 'The right port is used.');
2719

  
2720
    // If we set the port explicitly in url(), it should not be overriden.
2721
    $url = url('', array(
2722
      'absolute' => TRUE,
2723
      'language' => $language,
2724
      'base_url' => $GLOBALS['base_url'] . ':90',
2725
    ));
2726

  
2727
    $expected = 'http://example.fr:90/';
2728
    $expected .= $index_php ? 'index.php/' : '';
2729

  
2730
    $this->assertEqual($url, $expected, 'A given port is not overriden.');
2731

  
2732
    // Restore HTTP_HOST.
2733
    $_SERVER['HTTP_HOST'] = $http_host;
2734
  }
2632 2735
}
2633 2736

  
2634 2737
/**
......
3141 3244
    $this->assertRaw('@import url("' . $base_url . '/modules/system/system.messages.css' . $query_string . '");' . "\n" . '@import url("' . $base_url . '/modules/system/system.messages-rtl.css' . $query_string . '");' . "\n", 'CSS: system.messages-rtl.css is added directly after system.messages.css.');
3142 3245
  }
3143 3246
}
3247

  
3248
/**
3249
 * Tests locale translation safe string handling.
3250
 */
3251
class LocaleStringIsSafeTest extends DrupalWebTestCase {
3252
  public static function getInfo() {
3253
    return array(
3254
      'name' => 'Test if a string is safe',
3255
      'description' => 'Tests locale translation safe string handling.',
3256
      'group' => 'Locale',
3257
    );
3258
  }
3259

  
3260
  function setUp() {
3261
    parent::setUp('locale');
3262
  }
3263

  
3264
  /**
3265
   * Tests for locale_string_is_safe().
3266
   */
3267
  public function testLocaleStringIsSafe() {
3268
    // Check a translatable string without HTML.
3269
    $string = 'Hello world!';
3270
    $result = locale_string_is_safe($string);
3271
    $this->assertTrue($result);
3272

  
3273
    // Check a translatable string which includes trustable HTML.
3274
    $string = 'Hello <strong>world</strong>!';
3275
    $result = locale_string_is_safe($string);
3276
    $this->assertTrue($result);
3277

  
3278
    // Check an untranslatable string which includes untrustable HTML (according
3279
    // to the locale_string_is_safe() function definition).
3280
    $string = 'Hello <img src="world.png" alt="world" />!';
3281
    $result = locale_string_is_safe($string);
3282
    $this->assertFalse($result);
3283

  
3284
    // Check a translatable string which includes a token in an href attribute.
3285
    $string = 'Hi <a href="[current-user:url]">user</a>';
3286
    $result = locale_string_is_safe($string);
3287
    $this->assertTrue($result);
3288
  }
3289
}

Also available in: Unified diff