SymfonyComponentTranslationTestsDataCollectorTranslatorTest

The Simple Calendar Symfony Component Translation Tests DataCollectorTranslatorTest class.

Defined (1)

The class is defined in the following location(s).

/vendor/symfony/translation/Tests/DataCollectorTranslatorTest.php  
  1. class DataCollectorTranslatorTest extends \PHPUnit_Framework_TestCase 
  2. public function testCollectMessages() 
  3. $collector = $this->createCollector(); 
  4. $collector->setFallbackLocales(array('fr', 'ru')); 
  5.  
  6. $collector->trans('foo'); 
  7. $collector->trans('bar'); 
  8. $collector->transChoice('choice', 0); 
  9. $collector->trans('bar_ru'); 
  10. $collector->trans('bar_ru', array('foo' => 'bar')); 
  11.  
  12. $expectedMessages = array(); 
  13. $expectedMessages[] = array( 
  14. 'id' => 'foo',  
  15. 'translation' => 'foo (en)',  
  16. 'locale' => 'en',  
  17. 'domain' => 'messages',  
  18. 'state' => DataCollectorTranslator::MESSAGE_DEFINED,  
  19. 'parameters' => array(),  
  20. 'transChoiceNumber' => null,  
  21. ); 
  22. $expectedMessages[] = array( 
  23. 'id' => 'bar',  
  24. 'translation' => 'bar (fr)',  
  25. 'locale' => 'fr',  
  26. 'domain' => 'messages',  
  27. 'state' => DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK,  
  28. 'parameters' => array(),  
  29. 'transChoiceNumber' => null,  
  30. ); 
  31. $expectedMessages[] = array( 
  32. 'id' => 'choice',  
  33. 'translation' => 'choice',  
  34. 'locale' => 'en',  
  35. 'domain' => 'messages',  
  36. 'state' => DataCollectorTranslator::MESSAGE_MISSING,  
  37. 'parameters' => array(),  
  38. 'transChoiceNumber' => 0,  
  39. ); 
  40. $expectedMessages[] = array( 
  41. 'id' => 'bar_ru',  
  42. 'translation' => 'bar (ru)',  
  43. 'locale' => 'ru',  
  44. 'domain' => 'messages',  
  45. 'state' => DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK,  
  46. 'parameters' => array(),  
  47. 'transChoiceNumber' => null,  
  48. ); 
  49. $expectedMessages[] = array( 
  50. 'id' => 'bar_ru',  
  51. 'translation' => 'bar (ru)',  
  52. 'locale' => 'ru',  
  53. 'domain' => 'messages',  
  54. 'state' => DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK,  
  55. 'parameters' => array('foo' => 'bar'),  
  56. 'transChoiceNumber' => null,  
  57. ); 
  58.  
  59. $this->assertEquals($expectedMessages, $collector->getCollectedMessages()); 
  60.  
  61. private function createCollector() 
  62. $translator = new Translator('en'); 
  63. $translator->addLoader('array', new ArrayLoader()); 
  64. $translator->addResource('array', array('foo' => 'foo (en)'), 'en'); 
  65. $translator->addResource('array', array('bar' => 'bar (fr)'), 'fr'); 
  66. $translator->addResource('array', array('bar_ru' => 'bar (ru)'), 'ru'); 
  67.  
  68. $collector = new DataCollectorTranslator($translator); 
  69.  
  70. return $collector;