Projet

Général

Profil

Paste
Télécharger (3,65 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / i18n / i18n_variable / i18n_variable.test @ 76df55b7

1
<?php
2
/**
3
 * @file
4
 * Test case for multilingual variables
5
 */
6

    
7

    
8
class i18nVariableTestCase extends Drupali18nTestCase {
9

    
10
  public static function getInfo() {
11
    return array(
12
      'name' => 'Variable translation',
13
      'group' => 'Internationalization',
14
      'description' => 'Variable translation functions'
15
    );
16
  }
17

    
18
  function setUp() {
19
    parent::setUp('i18n_variable', 'translation');
20
    parent::setUpLanguages(array('administer site configuration'));
21
  }
22

    
23
  /**
24
   * Set up translation for content type (page)
25
   */
26
  function setUpContentTranslation($settings = array()) {
27
    $this->translator = $this->drupalCreateUser(array('create page content', 'edit own page content', 'translate content'));
28
    $this->drupalLogin($this->admin_user);
29
    // Set "Basic page" content type to use multilingual support with
30
    // translation.
31
    $this->drupalGet('admin/structure/types/manage/page');
32
    $edit = array();
33
    $edit['language_content_type'] = 2;
34
    // Mark status and promoted
35
    $edit['node_options[status]'] = 1;
36
    $this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type'));
37
    $this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Basic page')), t('Basic page content type has been updated.'));
38

    
39
    // Enable the language switcher block.
40
    $language_type = LANGUAGE_TYPE_INTERFACE;
41
    $edit = array("blocks[locale_$language_type][region]" => 'sidebar_first');
42
    $this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
43
  }
44

    
45
  function testVariableLocalize() {
46
    $this->setUpContentTranslation();
47

    
48
    // Create 2 nodes in different languages.
49
    $first_title = $this->randomName(10);
50
    $first_body = $this->randomString(50);
51
    $first_node = $this->createNode('page', $first_title, $first_body, $this->default_language);
52

    
53
    $secondary_title = $this->randomName(10);
54
    $secondary_body = $this->randomString(50);
55
    $secondary_node = $this->createNode('page', $secondary_title, $secondary_body, $this->secondary_language);
56

    
57
    $this->drupalGet('<front>', array('language' => i18n_language_object($this->default_language)));
58
    $this->assertText(t('No front page content has been created yet.'));
59

    
60
    $this->drupalGet('<front>', array('language' => i18n_language_object($this->secondary_language)));
61
    $this->assertText(t('No front page content has been created yet.'));
62

    
63
    $edit = array(
64
      'variables[site_name]' => 1,
65
      'variables[site_frontpage]' => 1,
66
    );
67
    $this->drupalPost('admin/config/regional/i18n/variable', $edit, t('Save configuration'));
68

    
69
    $edit_first = array(
70
      'site_frontpage' => 'node/' . $first_node->nid,
71
      'site_name' => $this->randomName(10),
72
    );
73
    $this->drupalPost('admin/config/system/site-information', $edit_first, t('Save configuration'), array('language' => i18n_language_object($this->default_language)));
74

    
75
    $edit_secondary = array(
76
      'site_frontpage' => 'node/' . $secondary_node->nid,
77
      'site_name' => $this->randomName(10),
78
    );
79
    $this->drupalPost('admin/config/system/site-information', $edit_secondary, t('Save configuration'), array('language' => i18n_language_object($this->secondary_language)));
80

    
81
    $this->drupalGet('<front>', array('language' => i18n_language_object($this->default_language)));
82
    $this->assertText($edit_first['site_name']);
83
    $this->assertNoText(t('No front page content has been created yet.'));
84
    $this->assertText($first_title);
85

    
86
    $this->drupalGet('<front>', array('language' => i18n_language_object($this->secondary_language)));
87
    $this->assertText($edit_secondary['site_name']);
88
    $this->assertNoText(t('No front page content has been created yet.'));
89
    $this->assertText($secondary_title);
90
  }
91
}