Révision 6331c987
Ajouté par Assos Assos il y a environ 10 ans
drupal7/sites/all/modules/i18n/i18n_string/i18n_string.test | ||
---|---|---|
24 | 24 |
|
25 | 25 |
function setUp() { |
26 | 26 |
// We can use any of the modules that define a text group, to use it for testing |
27 |
parent::setUp('i18n_string', 'i18n_menu'); |
|
27 |
parent::setUp('i18n_string', 'i18n_menu', 'i18n_test');
|
|
28 | 28 |
parent::setUpLanguages(); |
29 | 29 |
$this->translator = $this->drupalCreateUser(array('translate interface', 'translate user-defined strings')); |
30 | 30 |
} |
... | ... | |
55 | 55 |
} |
56 | 56 |
} |
57 | 57 |
|
58 |
/** |
|
59 |
* Test base i18n_string caching. |
|
60 |
*/ |
|
61 |
function testCaching() { |
|
62 |
// Create a bunch of strings for all languages. |
|
63 |
$textgroup = 'test_cached'; |
|
64 |
$strings = $this->stringCreateArray(2); |
|
65 |
$translations = array(); |
|
66 |
$textgroup_object = i18n_string_textgroup($textgroup); |
|
67 |
// Save source strings and store translations. |
|
68 |
foreach ($strings as $key => $string) { |
|
69 |
$name = "$textgroup:item:$key:title"; |
|
70 |
i18n_string_update($name, $string); |
|
71 |
$translations[$key] = $this->createStringTranslation($textgroup, $string); |
|
72 |
} |
|
73 |
|
|
74 |
// Now fetch the strings to fill the cache. |
|
75 |
foreach ($textgroup_object->strings as $context => $string_object) { |
|
76 |
$this->drupalGet('tests/i18n/i18n_string_build/' . $textgroup . ':' . $context); |
|
77 |
} |
|
78 |
foreach ($strings as $key => $string) { |
|
79 |
$this->drupalGet('tests/i18n/i18n_string_translation_search/' . $textgroup . ':item:' . $key . ':*/es'); |
|
80 |
} |
|
81 |
|
|
82 |
// Check the persistent cache for contents. |
|
83 |
$cache = cache_get('i18n:string:tgroup:' . $textgroup . ':strings'); |
|
84 |
if ($this->assertNotEqual($cache, FALSE, 'Textgroup strings cache found')) { |
|
85 |
foreach ($textgroup_object->strings as $context => $string_object) { |
|
86 |
if ($this->assertTrue(isset($cache->data[$context]), format_string('Cached string %context found', array('%context' => $context)))) { |
|
87 |
$this->assertEqual($cache->data[$context], $context, 'Cached string is a string and not an object'); |
|
88 |
} |
|
89 |
// Check if the string object cache is also available. |
|
90 |
$string_cache = cache_get($string_object->get_cid()); |
|
91 |
if ($this->assertNotEqual($string_cache, FALSE, format_string('Cached string object %cid found', array('%cid' => $string_object->get_cid())))) { |
|
92 |
$this->assertTrue(is_array($string_cache->data), 'Cached string object is an array.'); |
|
93 |
} |
|
94 |
} |
|
95 |
} |
|
96 |
$cache = cache_get('i18n:string:tgroup:' . $textgroup . ':cache_multiple'); |
|
97 |
if ($this->assertNotEqual($cache, FALSE, 'Textgroup cache_multiple cache found')) { |
|
98 |
foreach ($strings as $key => $string) { |
|
99 |
$pattern = 'item:' . $key . ':*:es'; |
|
100 |
if ($this->assertTrue(isset($cache->data[$pattern]), format_string('Cached multiple cache for pattern %pattern found', array('%pattern_key' => $pattern)))) { |
|
101 |
$property_pattern = 'item:' . $key . ':title'; |
|
102 |
if ($this->assertTrue(isset($cache->data[$pattern][$property_pattern]), format_string('Cached multiple property title found', array('%pattern_key' => $pattern)))) { |
|
103 |
$this->assertEqual($cache->data[$pattern][$property_pattern], $property_pattern); |
|
104 |
} |
|
105 |
} |
|
106 |
} |
|
107 |
} |
|
108 |
|
|
109 |
// Test cache injection. |
|
110 |
foreach ($textgroup_object->strings as $context => $string_object) { |
|
111 |
// Check if the string object cache is also available. |
|
112 |
$string_cache = cache_get($string_object->get_cid()); |
|
113 |
if (isset($string_cache->data)) { |
|
114 |
// Modify cache. |
|
115 |
$string_cache->data['string'] = "Injected value."; |
|
116 |
cache_set($string_object->get_cid(), $string_cache->data, 'cache', CACHE_TEMPORARY); |
|
117 |
|
|
118 |
// Check if modification is reflected on the next page call. |
|
119 |
$this->drupalGet('tests/i18n/i18n_string_build/' . $textgroup . ':' . $context); |
|
120 |
$this->assertText($string_cache->data['string']); |
|
121 |
} |
|
122 |
} |
|
123 |
} |
|
124 |
|
|
125 |
|
|
58 | 126 |
/** |
59 | 127 |
* Create strings for all languages |
60 | 128 |
*/ |
... | ... | |
76 | 144 |
/** |
77 | 145 |
* Create and store one translation into the db |
78 | 146 |
*/ |
79 |
public static function stringCreateTranslation($name, $lang, $length = 20) {
|
|
147 |
public function stringCreateTranslation($name, $lang, $length = 20) { |
|
80 | 148 |
$translation = $this->randomName($length); |
81 | 149 |
if (self::stringSaveTranslation($name, $lang, $translation)) { |
82 | 150 |
return $translation; |
Formats disponibles : Unified diff
Weekly update of contrib modules