Projet

Général

Profil

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

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

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
  public function setUp($modules = array(), $permissions = array()) {
28
    $modules = array_merge($modules, array(
29
      'locale',
30
    ));
31
    $permissions = array_merge(array(
32
      'administer languages',
33
    ));
34
    parent::setUp($modules, $permissions);
35

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

    
48
    // Include FeedsProcessor.inc to make its constants available.
49
    module_load_include('inc', 'feeds', 'plugins/FeedsProcessor');
50

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

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

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

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

    
80
    // Change processor's language to Dutch.
81
    $this->setSettings('i18n', $this->processorName, array('language' => 'nl'));
82

    
83
    // Re-import content.
84
    $this->importFile('i18n', $this->absolutePath() . '/tests/feeds/content.csv');
85

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

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

    
104
    // Import content.
105
    $this->importFile('i18n', $this->absolutePath() . '/tests/feeds/content.csv');
106

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

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

    
123
    // Import content.
124
    $this->importFile('i18n', $this->absolutePath() . '/tests/feeds/content.csv');
125

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