Projet

Général

Profil

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

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

1
<?php
2

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

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

    
13
  /**
14
   * The entity type to be tested.
15
   *
16
   * @var string
17
   */
18
  protected $entityType;
19

    
20
  /**
21
   * The processor being used.
22
   *
23
   * @var string
24
   */
25
  protected $processorName;
26

    
27
  /**
28
   * {@inheritdoc}
29
   */
30
  public function setUp($modules = array(), $permissions = array()) {
31
    $modules = array_merge($modules, array(
32
      'locale',
33
    ));
34
    $permissions = array_merge(array(
35
      'administer languages',
36
    ));
37
    parent::setUp($modules, $permissions);
38

    
39
    // Setup other languages.
40
    $edit = array(
41
      'langcode' => 'nl',
42
    );
43
    $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language'));
44
    $this->assertText(t('The language Dutch has been created and can now be used.'));
45
    $edit = array(
46
      'langcode' => 'de',
47
    );
48
    $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language'));
49
    $this->assertText(t('The language German has been created and can now be used.'));
50

    
51
    // Include FeedsProcessor.inc to make its constants available.
52
    module_load_include('inc', 'feeds', 'plugins/FeedsProcessor');
53

    
54
    // Create and configure importer.
55
    $this->createImporterConfiguration('Multilingual term importer', 'i18n');
56
    $this->setPlugin('i18n', 'FeedsFileFetcher');
57
    $this->setPlugin('i18n', 'FeedsCSVParser');
58
    $this->setPlugin('i18n', $this->processorName);
59
  }
60

    
61
  /**
62
   * Tests if entities get the language assigned that is set in the processor.
63
   */
64
  public function testImport() {
65
    // Import content in German.
66
    $this->importFile('i18n', $this->absolutePath() . '/tests/feeds/content.csv');
67

    
68
    // Assert that the entity's language is in German.
69
    $entities = entity_load($this->entityType, array(1, 2));
70
    foreach ($entities as $entity) {
71
      $this->assertEqual('de', entity_language($this->entityType, $entity));
72
    }
73
  }
74

    
75
  /**
76
   * Tests if entities get a different language assigned when the processor's language
77
   * is changed.
78
   */
79
  public function testChangedLanguageImport() {
80
    // Import content in German.
81
    $this->importFile('i18n', $this->absolutePath() . '/tests/feeds/content.csv');
82

    
83
    // Change processor's language to Dutch.
84
    $this->setSettings('i18n', $this->processorName, array('language' => 'nl'));
85

    
86
    // Re-import content.
87
    $this->importFile('i18n', $this->absolutePath() . '/tests/feeds/content.csv');
88

    
89
    // Assert that the entity's language is now in Dutch.
90
    $entities = entity_load($this->entityType, array(1, 2));
91
    foreach ($entities as $entity) {
92
      $this->assertEqual('nl', entity_language($this->entityType, $entity));
93
    }
94
  }
95

    
96
  /**
97
   * Tests if items are imported in LANGUAGE_NONE if the processor's language is disabled.
98
   */
99
  public function testDisabledLanguage() {
100
    // Disable the German language.
101
    $path = 'admin/config/regional/language';
102
    $edit = array(
103
      'enabled[de]' => FALSE,
104
    );
105
    $this->drupalPost($path, $edit, t('Save configuration'));
106

    
107
    // Import content.
108
    $this->importFile('i18n', $this->absolutePath() . '/tests/feeds/content.csv');
109

    
110
    // Assert that the entities have no language assigned.
111
    $entities = entity_load($this->entityType, array(1, 2));
112
    foreach ($entities as $entity) {
113
      $language = entity_language($this->entityType, $entity);
114
      $this->assertEqual(LANGUAGE_NONE, $language, format_string('The entity is language neutral (actual: !language).', array('!language' => $language)));
115
    }
116
  }
117

    
118
  /**
119
   * Tests if items are imported in LANGUAGE_NONE if the processor's language is removed.
120
   */
121
  public function testRemovedLanguage() {
122
    // Remove the German language.
123
    $path = 'admin/config/regional/language/delete/de';
124
    $this->drupalPost($path, array(), t('Delete'));
125

    
126
    // Import content.
127
    $this->importFile('i18n', $this->absolutePath() . '/tests/feeds/content.csv');
128

    
129
    // Assert that the entities have no language assigned.
130
    $entities = entity_load($this->entityType, array(1, 2));
131
    foreach ($entities as $entity) {
132
      $language = entity_language($this->entityType, $entity);
133
      $this->assertEqual(LANGUAGE_NONE, $language, format_string('The entity is language neutral (actual: !language).', array('!language' => $language)));
134
    }
135
  }
136

    
137
}