SymfonyComponentTranslationTestsMessageCatalogueTest

The Simple Calendar Symfony Component Translation Tests MessageCatalogueTest class.

Defined (1)

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

/vendor/symfony/translation/Tests/MessageCatalogueTest.php  
  1. class MessageCatalogueTest extends \PHPUnit_Framework_TestCase 
  2. public function testGetLocale() 
  3. $catalogue = new MessageCatalogue('en'); 
  4.  
  5. $this->assertEquals('en', $catalogue->getLocale()); 
  6.  
  7. public function testGetDomains() 
  8. $catalogue = new MessageCatalogue('en', array('domain1' => array(), 'domain2' => array())); 
  9.  
  10. $this->assertEquals(array('domain1', 'domain2'), $catalogue->getDomains()); 
  11.  
  12. public function testAll() 
  13. $catalogue = new MessageCatalogue('en', $messages = array('domain1' => array('foo' => 'foo'), 'domain2' => array('bar' => 'bar'))); 
  14.  
  15. $this->assertEquals(array('foo' => 'foo'), $catalogue->all('domain1')); 
  16. $this->assertEquals(array(), $catalogue->all('domain88')); 
  17. $this->assertEquals($messages, $catalogue->all()); 
  18.  
  19. public function testHas() 
  20. $catalogue = new MessageCatalogue('en', array('domain1' => array('foo' => 'foo'), 'domain2' => array('bar' => 'bar'))); 
  21.  
  22. $this->assertTrue($catalogue->has('foo', 'domain1')); 
  23. $this->assertFalse($catalogue->has('bar', 'domain1')); 
  24. $this->assertFalse($catalogue->has('foo', 'domain88')); 
  25.  
  26. public function testGetSet() 
  27. $catalogue = new MessageCatalogue('en', array('domain1' => array('foo' => 'foo'), 'domain2' => array('bar' => 'bar'))); 
  28. $catalogue->set('foo1', 'foo1', 'domain1'); 
  29.  
  30. $this->assertEquals('foo', $catalogue->get('foo', 'domain1')); 
  31. $this->assertEquals('foo1', $catalogue->get('foo1', 'domain1')); 
  32.  
  33. public function testAdd() 
  34. $catalogue = new MessageCatalogue('en', array('domain1' => array('foo' => 'foo'), 'domain2' => array('bar' => 'bar'))); 
  35. $catalogue->add(array('foo1' => 'foo1'), 'domain1'); 
  36.  
  37. $this->assertEquals('foo', $catalogue->get('foo', 'domain1')); 
  38. $this->assertEquals('foo1', $catalogue->get('foo1', 'domain1')); 
  39.  
  40. $catalogue->add(array('foo' => 'bar'), 'domain1'); 
  41. $this->assertEquals('bar', $catalogue->get('foo', 'domain1')); 
  42. $this->assertEquals('foo1', $catalogue->get('foo1', 'domain1')); 
  43.  
  44. $catalogue->add(array('foo' => 'bar'), 'domain88'); 
  45. $this->assertEquals('bar', $catalogue->get('foo', 'domain88')); 
  46.  
  47. public function testReplace() 
  48. $catalogue = new MessageCatalogue('en', array('domain1' => array('foo' => 'foo'), 'domain2' => array('bar' => 'bar'))); 
  49. $catalogue->replace($messages = array('foo1' => 'foo1'), 'domain1'); 
  50.  
  51. $this->assertEquals($messages, $catalogue->all('domain1')); 
  52.  
  53. public function testAddCatalogue() 
  54. $r = $this->getMock('Symfony\Component\Config\Resource\ResourceInterface'); 
  55. $r->expects($this->any())->method('__toString')->will($this->returnValue('r')); 
  56.  
  57. $r1 = $this->getMock('Symfony\Component\Config\Resource\ResourceInterface'); 
  58. $r1->expects($this->any())->method('__toString')->will($this->returnValue('r1')); 
  59.  
  60. $catalogue = new MessageCatalogue('en', array('domain1' => array('foo' => 'foo'), 'domain2' => array('bar' => 'bar'))); 
  61. $catalogue->addResource($r); 
  62.  
  63. $catalogue1 = new MessageCatalogue('en', array('domain1' => array('foo1' => 'foo1'))); 
  64. $catalogue1->addResource($r1); 
  65.  
  66. $catalogue->addCatalogue($catalogue1); 
  67.  
  68. $this->assertEquals('foo', $catalogue->get('foo', 'domain1')); 
  69. $this->assertEquals('foo1', $catalogue->get('foo1', 'domain1')); 
  70.  
  71. $this->assertEquals(array($r, $r1), $catalogue->getResources()); 
  72.  
  73. public function testAddFallbackCatalogue() 
  74. $r = $this->getMock('Symfony\Component\Config\Resource\ResourceInterface'); 
  75. $r->expects($this->any())->method('__toString')->will($this->returnValue('r')); 
  76.  
  77. $r1 = $this->getMock('Symfony\Component\Config\Resource\ResourceInterface'); 
  78. $r1->expects($this->any())->method('__toString')->will($this->returnValue('r1')); 
  79.  
  80. $catalogue = new MessageCatalogue('en_US', array('domain1' => array('foo' => 'foo'), 'domain2' => array('bar' => 'bar'))); 
  81. $catalogue->addResource($r); 
  82.  
  83. $catalogue1 = new MessageCatalogue('en', array('domain1' => array('foo' => 'bar', 'foo1' => 'foo1'))); 
  84. $catalogue1->addResource($r1); 
  85.  
  86. $catalogue->addFallbackCatalogue($catalogue1); 
  87.  
  88. $this->assertEquals('foo', $catalogue->get('foo', 'domain1')); 
  89. $this->assertEquals('foo1', $catalogue->get('foo1', 'domain1')); 
  90.  
  91. $this->assertEquals(array($r, $r1), $catalogue->getResources()); 
  92.  
  93. /** 
  94. * @expectedException \LogicException 
  95. */ 
  96. public function testAddFallbackCatalogueWithParentCircularReference() 
  97. $main = new MessageCatalogue('en_US'); 
  98. $fallback = new MessageCatalogue('fr_FR'); 
  99.  
  100. $fallback->addFallbackCatalogue($main); 
  101. $main->addFallbackCatalogue($fallback); 
  102.  
  103. /** 
  104. * @expectedException \LogicException 
  105. */ 
  106. public function testAddFallbackCatalogueWithFallbackCircularReference() 
  107. $fr = new MessageCatalogue('fr'); 
  108. $en = new MessageCatalogue('en'); 
  109. $es = new MessageCatalogue('es'); 
  110.  
  111. $fr->addFallbackCatalogue($en); 
  112. $es->addFallbackCatalogue($en); 
  113. $en->addFallbackCatalogue($fr); 
  114.  
  115. /** 
  116. * @expectedException \LogicException 
  117. */ 
  118. public function testAddCatalogueWhenLocaleIsNotTheSameAsTheCurrentOne() 
  119. $catalogue = new MessageCatalogue('en'); 
  120. $catalogue->addCatalogue(new MessageCatalogue('fr', array())); 
  121.  
  122. public function testGetAddResource() 
  123. $catalogue = new MessageCatalogue('en'); 
  124. $r = $this->getMock('Symfony\Component\Config\Resource\ResourceInterface'); 
  125. $r->expects($this->any())->method('__toString')->will($this->returnValue('r')); 
  126. $catalogue->addResource($r); 
  127. $catalogue->addResource($r); 
  128. $r1 = $this->getMock('Symfony\Component\Config\Resource\ResourceInterface'); 
  129. $r1->expects($this->any())->method('__toString')->will($this->returnValue('r1')); 
  130. $catalogue->addResource($r1); 
  131.  
  132. $this->assertEquals(array($r, $r1), $catalogue->getResources()); 
  133.  
  134. public function testMetadataDelete() 
  135. $catalogue = new MessageCatalogue('en'); 
  136. $this->assertEquals(array(), $catalogue->getMetadata('', ''), 'Metadata is empty'); 
  137. $catalogue->deleteMetadata('key', 'messages'); 
  138. $catalogue->deleteMetadata('', 'messages'); 
  139. $catalogue->deleteMetadata(); 
  140.  
  141. public function testMetadataSetGetDelete() 
  142. $catalogue = new MessageCatalogue('en'); 
  143. $catalogue->setMetadata('key', 'value'); 
  144. $this->assertEquals('value', $catalogue->getMetadata('key', 'messages'), "Metadata 'key' = 'value'"); 
  145.  
  146. $catalogue->setMetadata('key2', array()); 
  147. $this->assertEquals(array(), $catalogue->getMetadata('key2', 'messages'), 'Metadata key2 is array'); 
  148.  
  149. $catalogue->deleteMetadata('key2', 'messages'); 
  150. $this->assertNull($catalogue->getMetadata('key2', 'messages'), 'Metadata key2 should is deleted.'); 
  151.  
  152. $catalogue->deleteMetadata('key2', 'domain'); 
  153. $this->assertNull($catalogue->getMetadata('key2', 'domain'), 'Metadata key2 should is deleted.'); 
  154.  
  155. public function testMetadataMerge() 
  156. $cat1 = new MessageCatalogue('en'); 
  157. $cat1->setMetadata('a', 'b'); 
  158. $this->assertEquals(array('messages' => array('a' => 'b')), $cat1->getMetadata('', ''), 'Cat1 contains messages metadata.'); 
  159.  
  160. $cat2 = new MessageCatalogue('en'); 
  161. $cat2->setMetadata('b', 'c', 'domain'); 
  162. $this->assertEquals(array('domain' => array('b' => 'c')), $cat2->getMetadata('', ''), 'Cat2 contains domain metadata.'); 
  163.  
  164. $cat1->addCatalogue($cat2); 
  165. $this->assertEquals(array('messages' => array('a' => 'b'), 'domain' => array('b' => 'c')), $cat1->getMetadata('', ''), 'Cat1 contains merged metadata.');