Projet

Général

Profil

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

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

1
<?php
2
/**
3
 * @file
4
 * Test language selection modes
5
 */
6

    
7
class i18nSelectTestCase extends Drupali18nTestCase {
8

    
9
  public static function getInfo() {
10
    return array(
11
      'name' => 'Content Selection',
12
      'group' => 'Internationalization',
13
      'description' => 'Internationalization Content Selection'
14
    );
15
  }
16

    
17
  function setUp() {
18
    parent::setUp('translation', 'i18n_variable', 'i18n_select');
19
    parent::setUpLanguages();
20
    parent::setUpContentTranslation();
21
  }
22

    
23
  function testIi18nSelect() {
24
    drupal_static_reset('language_list');
25
    $language_list = language_list();
26
    $language_count = count($language_list);
27
    // Set site name for each language and check pages later
28
    variable_set('i18n_variable_list', array('site_name'));
29
    foreach (i18n_language_list() as $langcode => $name) {
30
      i18n_variable_set('site_name', "Drupal-$name", $langcode);
31
    }
32

    
33
    // Enable tags field for page content type.
34
    $edit = array(
35
      'fields[_add_existing_field][label]' => t('Tags'),
36
      'fields[_add_existing_field][field_name]' => 'field_tags',
37
      'fields[_add_existing_field][widget_type]' => 'taxonomy_autocomplete',
38
    );
39
    $this->drupalPost('admin/structure/types/manage/page/fields', $edit, t('Save'));
40
    $this->drupalPost(NULL, array(), t('Save settings'));
41

    
42
    // Create some content and check selection modes
43
    $this->drupalLogin($this->content_editor);
44

    
45
    // variable_set('language_content_type_story', 1);
46
    $neutral = $this->drupalCreateNode(array('type' => 'page', 'promote' => 1));
47
    $source = $this->createNode('page', $this->randomName(), $this->randomString(20), language_default('language'), array('field_tags[und]' => $tag_name = $this->randomName()));
48
    $translations = $this->createNodeTranslationSet($source);
49

    
50
    drupal_static_reset('translation_node_get_translations');
51
    $this->assertEqual(count(translation_node_get_translations($source->tnid)), $language_count, "Created $language_count $source->type translations.");
52

    
53
    // Log in user with access content permission
54
    $user = $this->drupalCreateUser(array('access comments', 'access content'));
55
    $this->drupalLogin($user);
56
    // Default selection mode, only language neutral and current
57
    variable_set('i18n_select_nodes', TRUE);
58
    foreach (i18n_language_list() as $langcode => $name) {
59
      $this->i18nGet($langcode);
60
      $this->assertText("Drupal-$name", 'Checked translated site name: Drupal-' . $name);
61
      $display = array($translations[$langcode], $neutral);
62
      $hide = $translations;
63
      unset($hide[$langcode]);
64
      $this->assertContent($display, $hide);
65
      // Visit the taxonomy page of that node and try again. Only the translated
66
      // pages are tagged.
67
      unset($display[1]);
68
      $this->i18nGet($langcode, 'taxonomy/term/' . $source->field_tags[LANGUAGE_NONE][0]['tid']);
69
      $this->assertContent($display, $hide);
70
    }
71

    
72
  }
73

    
74
  /**
75
   * Check some nodes are displayed, some are not
76
   */
77
  function assertContent($display, $hide = array()) {
78
    $languages = language_list();
79
    foreach ($display as $node) {
80
      $this->assertText($node->title, 'Content displayed for ' . i18n_language_name($node->language));
81
    }
82
    foreach ($hide as $node) {
83
      $this->assertNoText($node->title, 'Content not displayed for ' . i18n_language_name($node->language));
84
    }
85
  }
86
}