[ Index ] |
PHP Cross Reference of GlotPress |
[Summary view] [Print] [Text view]
1 <?php 2 3 class GP_Import extends GP_UnitTestCase { 4 5 /** 6 * @ticket gh-377 7 */ 8 private function _verify_multiple_imports( $originals, $runs ) { 9 $object_type = GP::$validator_permission->object_type; 10 $user = $this->factory->user->create(); 11 wp_set_current_user( $user ); 12 13 $set = $this->factory->translation_set->create_with_project_and_locale(); 14 GP::$validator_permission->create( array( 'user_id' => $user, 'action' => 'approve', 15 'project_id' => $set->project_id, 'locale_slug' => $set->locale, 'set_slug' => $set->slug ) ); 16 17 if ( isset( $originals['singular'] ) ) { 18 $originals = array( $originals ); 19 } 20 21 foreach ( $originals as $original ) { 22 $o = $this->factory->original->create( array_merge( array( 23 'project_id' => $set->project_id, 24 'status' => '+active', 25 ), $original ) ); 26 } 27 28 $this->assertEquals( count( $originals ), $set->all_count() ); 29 $this->assertEquals( 0, $set->current_count() ); 30 $this->assertEquals( count( $originals ), $set->untranslated_count() ); 31 32 $status_sequence = ''; 33 foreach ( $runs as $run ) { 34 $status_sequence .= $run['status'] . '|'; 35 $set->import( $run['translations'], $run['status'] ); 36 37 wp_cache_flush(); 38 $set->update_status_breakdown(); 39 40 foreach ( $run['counts'] as $function => $count ) { 41 $this->assertEquals( $count, $set->$function(), $status_sequence . $function . '()' ); 42 } 43 } 44 } 45 46 function test_multiple_imports_singular() { 47 $original = array( 48 'singular' => 'Good morning', 49 ); 50 51 $translations = new Translations(); 52 $translations->add_entry( new Translation_Entry( array( 53 'singular' => $original['singular'], 54 'translations' => array( 'Guten Morgen' ), 55 ))); 56 57 $this->_verify_multiple_imports( $original, array( 58 array( 59 'status' => 'current', 60 'translations' => $translations, 61 'counts' => array( 62 'all_count' => 1, 63 'current_count' => 1, 64 'untranslated_count' => 0, 65 'waiting_count' => 0, 66 ), 67 ), 68 array( 69 'status' => 'current', 70 'translations' => $translations, 71 'counts' => array( 72 'all_count' => 1, 73 'current_count' => 1, 74 'untranslated_count' => 0, 75 'waiting_count' => 0, 76 ), 77 ), 78 )); 79 80 $this->_verify_multiple_imports( $original, array( 81 array( 82 'status' => 'current', 83 'translations' => $translations, 84 'counts' => array( 85 'all_count' => 1, 86 'current_count' => 1, 87 'untranslated_count' => 0, 88 'waiting_count' => 0, 89 ), 90 ), 91 array( 92 'status' => 'waiting', 93 'translations' => $translations, 94 'counts' => array( 95 'all_count' => 1, 96 'current_count' => 1, 97 'untranslated_count' => 0, 98 'waiting_count' => 0, 99 ), 100 ), 101 )); 102 103 $this->_verify_multiple_imports( $original, array( 104 array( 105 'status' => 'waiting', 106 'translations' => $translations, 107 'counts' => array( 108 'all_count' => 1, 109 'current_count' => 0, 110 'untranslated_count' => 0, 111 'waiting_count' => 1, 112 ), 113 ), 114 array( 115 'status' => 'current', 116 'translations' => $translations, 117 'counts' => array( 118 'all_count' => 1, 119 'current_count' => 1, 120 'untranslated_count' => 0, 121 'waiting_count' => 0, 122 ), 123 ), 124 )); 125 126 $this->_verify_multiple_imports( $original, array( 127 array( 128 'status' => 'waiting', 129 'translations' => $translations, 130 'counts' => array( 131 'all_count' => 1, 132 'current_count' => 0, 133 'untranslated_count' => 0, 134 'waiting_count' => 1, 135 ), 136 ), 137 array( 138 'status' => 'waiting', 139 'translations' => $translations, 140 'counts' => array( 141 'all_count' => 1, 142 'current_count' => 0, 143 'untranslated_count' => 0, 144 'waiting_count' => 1, 145 ), 146 ), 147 )); 148 } 149 150 function test_multiple_imports_plural() { 151 $original = array( 152 'singular' => '%d apple', 153 'plural' => '%d apples', 154 ); 155 156 $translations = new Translations(); 157 $translations->add_entry( new Translation_Entry( array( 158 'singular' => $original['singular'], 159 'plural' => $original['plural'], 160 'translations' => array( '%d Apfel', '%d Äpfel' ), 161 ))); 162 163 $this->_verify_multiple_imports( $original, array( 164 array( 165 'status' => 'current', 166 'translations' => $translations, 167 'counts' => array( 168 'all_count' => 1, 169 'current_count' => 1, 170 'untranslated_count' => 0, 171 'waiting_count' => 0, 172 ), 173 ), 174 array( 175 'status' => 'current', 176 'translations' => $translations, 177 'counts' => array( 178 'all_count' => 1, 179 'current_count' => 1, 180 'untranslated_count' => 0, 181 'waiting_count' => 0, 182 ), 183 ), 184 )); 185 186 $this->_verify_multiple_imports( $original, array( 187 array( 188 'status' => 'current', 189 'translations' => $translations, 190 'counts' => array( 191 'all_count' => 1, 192 'current_count' => 1, 193 'untranslated_count' => 0, 194 'waiting_count' => 0, 195 ), 196 ), 197 array( 198 'status' => 'waiting', 199 'translations' => $translations, 200 'counts' => array( 201 'all_count' => 1, 202 'current_count' => 1, 203 'untranslated_count' => 0, 204 'waiting_count' => 0, 205 ), 206 ), 207 )); 208 209 $this->_verify_multiple_imports( $original, array( 210 array( 211 'status' => 'waiting', 212 'translations' => $translations, 213 'counts' => array( 214 'all_count' => 1, 215 'current_count' => 0, 216 'untranslated_count' => 0, 217 'waiting_count' => 1, 218 ), 219 ), 220 array( 221 'status' => 'current', 222 'translations' => $translations, 223 'counts' => array( 224 'all_count' => 1, 225 'current_count' => 1, 226 'untranslated_count' => 0, 227 'waiting_count' => 0, 228 ), 229 ), 230 )); 231 232 $this->_verify_multiple_imports( $original, array( 233 array( 234 'status' => 'waiting', 235 'translations' => $translations, 236 'counts' => array( 237 'all_count' => 1, 238 'current_count' => 0, 239 'untranslated_count' => 0, 240 'waiting_count' => 1, 241 ), 242 ), 243 array( 244 'status' => 'waiting', 245 'translations' => $translations, 246 'counts' => array( 247 'all_count' => 1, 248 'current_count' => 0, 249 'untranslated_count' => 0, 250 'waiting_count' => 1, 251 ), 252 ), 253 )); 254 } 255 256 257 function test_multiple_imports_multiple_singulars() { 258 $originals = array( 259 array( 260 'singular' => 'Good morning', 261 ), 262 array( 263 'singular' => 'Good evening', 264 ), 265 ); 266 267 $translations1 = new Translations(); 268 $translations1->add_entry( new Translation_Entry( array( 269 'singular' => $originals[0]['singular'], 270 'translations' => array( 'Guten Morgen' ), 271 ))); 272 273 $translations2 = new Translations(); 274 $translations2->add_entry( new Translation_Entry( array( 275 'singular' => $originals[1]['singular'], 276 'translations' => array( 'Guten Abend' ), 277 ))); 278 279 $this->_verify_multiple_imports( $originals, array( 280 array( 281 'status' => 'current', 282 'translations' => $translations1, 283 'counts' => array( 284 'all_count' => 2, 285 'current_count' => 1, 286 'untranslated_count' => 1, 287 'waiting_count' => 0, 288 ), 289 ), 290 array( 291 'status' => 'current', 292 'translations' => $translations2, 293 'counts' => array( 294 'all_count' => 2, 295 'current_count' => 2, 296 'untranslated_count' => 0, 297 'waiting_count' => 0, 298 ), 299 ), 300 )); 301 302 $this->_verify_multiple_imports( $originals, array( 303 array( 304 'status' => 'current', 305 'translations' => $translations1, 306 'counts' => array( 307 'all_count' => 2, 308 'current_count' => 1, 309 'untranslated_count' => 1, 310 'waiting_count' => 0, 311 ), 312 ), 313 array( 314 'status' => 'waiting', 315 'translations' => $translations2, 316 'counts' => array( 317 'all_count' => 2, 318 'current_count' => 1, 319 'untranslated_count' => 0, 320 'waiting_count' => 1, 321 ), 322 ), 323 )); 324 325 $this->_verify_multiple_imports( $originals, array( 326 array( 327 'status' => 'waiting', 328 'translations' => $translations1, 329 'counts' => array( 330 'all_count' => 2, 331 'current_count' => 0, 332 'untranslated_count' => 1, 333 'waiting_count' => 1, 334 ), 335 ), 336 array( 337 'status' => 'waiting', 338 'translations' => $translations2, 339 'counts' => array( 340 'all_count' => 2, 341 'current_count' => 0, 342 'untranslated_count' => 0, 343 'waiting_count' => 2, 344 ), 345 ), 346 )); 347 348 $this->_verify_multiple_imports( $originals, array( 349 array( 350 'status' => 'waiting', 351 'translations' => $translations1, 352 'counts' => array( 353 'all_count' => 2, 354 'current_count' => 0, 355 'untranslated_count' => 1, 356 'waiting_count' => 1, 357 ), 358 ), 359 array( 360 'status' => 'current', 361 'translations' => $translations1, 362 'counts' => array( 363 'all_count' => 2, 364 'current_count' => 1, 365 'untranslated_count' => 1, 366 'waiting_count' => 0, 367 ), 368 ), 369 )); 370 } 371 372 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Nov 21 01:01:07 2024 | Cross-referenced by PHPXref 0.7.1 |