Projet

Général

Profil

Paste
Télécharger (4,43 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / feeds / tests / feeds_i18n_node.test @ ed9a13f1

1
<?php
2

    
3
/**
4
 * @file
5
 * Contains Feedsi18nNodeTestCase.
6
 */
7

    
8
/**
9
 * Tests importing nodes in a language.
10
 */
11
class Feedsi18nNodeTestCase extends Feedsi18nTestCase {
12

    
13
  /**
14
   * Name of created content type.
15
   *
16
   * @var string
17
   */
18
  private $contentType;
19

    
20
  /**
21
   * {@inheritdoc}
22
   */
23
  public static function getInfo() {
24
    return array(
25
      'name' => 'Multilingual content',
26
      'description' => 'Tests Feeds multilingual support for nodes.',
27
      'group' => 'Feeds',
28
      'dependencies' => array('locale'),
29
    );
30
  }
31

    
32
  /**
33
   * {@inheritdoc}
34
   */
35
  public function setUp($modules = array(), $permissions = array()) {
36
    $this->entityType = 'node';
37
    $this->processorName = 'FeedsNodeProcessor';
38

    
39
    parent::setUp($modules, $permissions);
40

    
41
    // Create content type.
42
    $this->contentType = $this->createContentType();
43

    
44
    // Configure importer.
45
    $this->setSettings('i18n', $this->processorName, array(
46
      'bundle' => $this->contentType,
47
      'language' => 'de',
48
      'update_existing' => FEEDS_UPDATE_EXISTING,
49
      'skip_hash_check' => TRUE,
50
    ));
51
    $this->addMappings('i18n', array(
52
      0 => array(
53
        'source' => 'guid',
54
        'target' => 'guid',
55
        'unique' => '1',
56
      ),
57
      1 => array(
58
        'source' => 'title',
59
        'target' => 'title',
60
      ),
61
    ));
62
  }
63

    
64
  /**
65
   * Tests if the language setting is available on the processor.
66
   */
67
  public function testAvailableProcessorLanguageSetting() {
68
    // Check if the language setting is available when the locale module is enabled.
69
    $this->drupalGet('admin/structure/feeds/i18n/settings/FeedsNodeProcessor');
70
    $this->assertField('language', 'Language field is available on the node processor settings when the locale module is enabled.');
71

    
72
    // Disable the locale module and check if the language setting is no longer available.
73
    module_disable(array('locale'));
74
    $this->drupalGet('admin/structure/feeds/i18n/settings/FeedsNodeProcessor');
75
    $this->assertNoField('language', 'Language field is not available on the node processor settings when the locale module is disabled.');
76
  }
77

    
78
  /**
79
   * Tests processor language setting in combination with language mapping target.
80
   */
81
  public function testWithLanguageMappingTarget() {
82
    $this->addMappings('i18n', array(
83
      2 => array(
84
        'source' => 'language',
85
        'target' => 'language',
86
      ),
87
    ));
88

    
89
    // Import csv file. The first item has a language specified (Dutch), the second
90
    // one has no language specified and should be imported in the processor's language (German).
91
    $this->importFile('i18n', $this->absolutePath() . '/tests/feeds/content_i18n.csv');
92

    
93
    // The first node should be Dutch.
94
    $node = node_load(1);
95
    $this->assertEqual('nl', entity_language('node', $node), 'Item 1 has the Dutch language assigned.');
96

    
97
    // The second node should be German.
98
    $node = node_load(2);
99
    $this->assertEqual('de', entity_language('node', $node), 'Item 2 has the German language assigned.');
100
  }
101

    
102
  /**
103
   * Tests if nodes get imported in LANGUAGE_NONE when the locale module gets disabled.
104
   */
105
  public function testDisabledLocaleModule() {
106
    module_disable(array('locale'));
107
    // Make sure that entity info is reset.
108
    drupal_flush_all_caches();
109
    drupal_static_reset();
110

    
111
    // Import content.
112
    $this->importFile('i18n', $this->absolutePath() . '/tests/feeds/content.csv');
113

    
114
    // Assert that the content has no language assigned.
115
    for ($i = 1; $i <= 2; $i++) {
116
      $node = node_load($i);
117
      $language = entity_language('node', $node);
118
      $this->assertEqual(LANGUAGE_NONE, $language, format_string('The node is language neutral (actual: !language).', array('!language' => $language)));
119
    }
120
  }
121

    
122
  /**
123
   * Tests if nodes get imported in LANGUAGE_NONE when the locale module gets uninstalled.
124
   */
125
  public function testUninstalledLocaleModule() {
126
    module_disable(array('locale'));
127
    drupal_uninstall_modules(array('locale'));
128
    // Make sure that entity info is reset.
129
    drupal_flush_all_caches();
130
    drupal_static_reset();
131

    
132
    // Import content.
133
    $this->importFile('i18n', $this->absolutePath() . '/tests/feeds/content.csv');
134

    
135
    // Assert that the content has no language assigned.
136
    for ($i = 1; $i <= 2; $i++) {
137
      $node = node_load($i);
138
      $language = entity_language('node', $node);
139
      $this->assertEqual(LANGUAGE_NONE, $language, format_string('The node is language neutral (actual: !language).', array('!language' => $language)));
140
    }
141
  }
142

    
143
}