@@ -103,7 +103,6 @@ public function testSetFallbackLocalesMultiple()
103
103
$ this ->assertEquals ('bar (fr) ' , $ translator ->trans ('bar ' ));
104
104
}
105
105
106
-
107
106
/**
108
107
* @dataProvider getInvalidLocalesTests
109
108
* @expectedException \InvalidArgumentException
@@ -329,7 +328,6 @@ public function testTransChoiceValidLocale($locale)
329
328
// no assertion. this method just asserts that no exception is thrown
330
329
}
331
330
332
-
333
331
public function getTransFileTests ()
334
332
{
335
333
return array (
@@ -463,6 +461,120 @@ public function testTransChoiceFallbackWithNoTranslation()
463
461
// unchanged if it can't be found
464
462
$ this ->assertEquals ('some_message2 ' , $ translator ->transChoice ('some_message2 ' , 10 , array ('%count% ' => 10 )));
465
463
}
464
+
465
+ /**
466
+ * @dataProvider dataProviderGetMessages
467
+ */
468
+ public function testGetMessages ($ resources , $ locale , $ expected )
469
+ {
470
+ $ locales = array_keys ($ resources );
471
+ $ _locale = !is_null ($ locale ) ? $ locale : reset ($ locales );
472
+ $ locales = array_slice ($ locales , 0 , array_search ($ _locale , $ locales ));
473
+
474
+ $ translator = new Translator ($ _locale , new MessageSelector ());
475
+ $ translator ->setFallbackLocales (array_reverse ($ locales ));
476
+ $ translator ->addLoader ('array ' , new ArrayLoader ());
477
+ foreach ($ resources as $ _locale => $ domainMessages ) {
478
+ foreach ($ domainMessages as $ domain => $ messages ) {
479
+ $ translator ->addResource ('array ' , $ messages , $ _locale , $ domain );
480
+ }
481
+ }
482
+ $ result = $ translator ->getMessages ($ locale );
483
+
484
+ $ this ->assertEquals ($ expected , $ result );
485
+ }
486
+
487
+ public function dataProviderGetMessages ()
488
+ {
489
+ $ resources = array (
490
+ 'en ' => array (
491
+ 'jsmessages ' => array (
492
+ 'foo ' => 'foo (EN) ' ,
493
+ 'bar ' => 'bar (EN) ' ,
494
+ ),
495
+ 'messages ' => array (
496
+ 'foo ' => 'foo messages (EN) ' ,
497
+ ),
498
+ 'validators ' => array (
499
+ 'int ' => 'integer (EN) ' ,
500
+ ),
501
+ ),
502
+ 'pt-PT ' => array (
503
+ 'messages ' => array (
504
+ 'foo ' => 'foo messages (PT) ' ,
505
+ ),
506
+ 'validators ' => array (
507
+ 'str ' => 'integer (PT) ' ,
508
+ ),
509
+ ),
510
+ 'pt_BR ' => array (
511
+ 'validators ' => array (
512
+ 'int ' => 'integer (BR) ' ,
513
+ ),
514
+ ),
515
+ );
516
+
517
+ return array (
518
+ array ($ resources , null ,
519
+ array (
520
+ 'jsmessages ' => array (
521
+ 'foo ' => 'foo (EN) ' ,
522
+ 'bar ' => 'bar (EN) ' ,
523
+ ),
524
+ 'messages ' => array (
525
+ 'foo ' => 'foo messages (EN) ' ,
526
+ ),
527
+ 'validators ' => array (
528
+ 'int ' => 'integer (EN) ' ,
529
+ ),
530
+ ),
531
+ ),
532
+ array ($ resources , 'en ' ,
533
+ array (
534
+ 'jsmessages ' => array (
535
+ 'foo ' => 'foo (EN) ' ,
536
+ 'bar ' => 'bar (EN) ' ,
537
+ ),
538
+ 'messages ' => array (
539
+ 'foo ' => 'foo messages (EN) ' ,
540
+ ),
9E7A
div>
541
+ 'validators ' => array (
542
+ 'int ' => 'integer (EN) ' ,
543
+ ),
544
+ ),
545
+ ),
546
+ array ($ resources , 'pt-PT ' ,
547
+ array (
548
+ 'jsmessages ' => array (
549
+ 'foo ' => 'foo (EN) ' ,
550
+ 'bar ' => 'bar (EN) ' ,
551
+ ),
552
+ 'messages ' => array (
553
+ 'foo ' => 'foo messages (PT) ' ,
554
+ ),
555
+ 'validators ' => array (
556
+ 'int ' => 'integer (EN) ' ,
557
+ 'str ' => 'integer (PT) ' ,
558
+ ),
559
+ ),
560
+ ),
561
+ array ($ resources , 'pt_BR ' ,
562
+ array (
563
+ 'jsmessages ' => array (
564
+ 'foo ' => 'foo (EN) ' ,
565
+ 'bar ' => 'bar (EN) ' ,
566
+ ),
567
+ 'messages ' => array (
568
+ 'foo ' => 'foo messages (PT) ' ,
569
+ ),
570
+ 'validators ' => array (
571
+ 'int ' => 'integer (BR) ' ,
572
+ 'str ' => 'integer (PT) ' ,
573
+ ),
574
+ ),
575
+ ),
576
+ );
577
+ }
466
578
}
467
579
468
580
class String
0 commit comments