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. $r2 = $this->getMock('Symfony\Component\Config\Resource\ResourceInterface'); 
  81. $r2->expects($this->any())->method('__toString')->will($this->returnValue('r2')); 
  82.  
  83. $catalogue = new MessageCatalogue('fr_FR', array('domain1' => array('foo' => 'foo'), 'domain2' => array('bar' => 'bar'))); 
  84. $catalogue->addResource($r); 
  85.  
  86. $catalogue1 = new MessageCatalogue('fr', array('domain1' => array('foo' => 'bar', 'foo1' => 'foo1'))); 
  87. $catalogue1->addResource($r1); 
  88.  
  89. $catalogue2 = new MessageCatalogue('en'); 
  90. $catalogue2->addResource($r2); 
  91.  
  92. $catalogue->addFallbackCatalogue($catalogue1); 
  93. $catalogue1->addFallbackCatalogue($catalogue2); 
  94.  
  95. $this->assertEquals('foo', $catalogue->get('foo', 'domain1')); 
  96. $this->assertEquals('foo1', $catalogue->get('foo1', 'domain1')); 
  97.  
  98. $this->assertEquals(array($r, $r1, $r2), $catalogue->getResources()); 
  99.  
  100. /** 
  101. * @expectedException \Symfony\Component\Translation\Exception\LogicException 
  102. */ 
  103. public function testAddFallbackCatalogueWithParentCircularReference() 
  104. $main = new MessageCatalogue('en_US'); 
  105. $fallback = new MessageCatalogue('fr_FR'); 
  106.  
  107. $fallback->addFallbackCatalogue($main); 
  108. $main->addFallbackCatalogue($fallback); 
  109.  
  110. /** 
  111. * @expectedException \Symfony\Component\Translation\Exception\LogicException 
  112. */ 
  113. public function testAddFallbackCatalogueWithFallbackCircularReference() 
  114. $fr = new MessageCatalogue('fr'); 
  115. $en = new MessageCatalogue('en'); 
  116. $es = new MessageCatalogue('es'); 
  117.  
  118. $fr->addFallbackCatalogue($en); 
  119. $es->addFallbackCatalogue($en); 
  120. $en->addFallbackCatalogue($fr); 
  121.  
  122. /** 
  123. * @expectedException \Symfony\Component\Translation\Exception\LogicException 
  124. */ 
  125. public function testAddCatalogueWhenLocaleIsNotTheSameAsTheCurrentOne() 
  126. $catalogue = new MessageCatalogue('en'); 
  127. $catalogue->addCatalogue(new MessageCatalogue('fr', array())); 
  128.  
  129. public function testGetAddResource() 
  130. $catalogue = new MessageCatalogue('en'); 
  131. $r = $this->getMock('Symfony\Component\Config\Resource\ResourceInterface'); 
  132. $r->expects($this->any())->method('__toString')->will($this->returnValue('r')); 
  133. $catalogue->addResource($r); 
  134. $catalogue->addResource($r); 
  135. $r1 = $this->getMock('Symfony\Component\Config\Resource\ResourceInterface'); 
  136. $r1->expects($this->any())->method('__toString')->will($this->returnValue('r1')); 
  137. $catalogue->addResource($r1); 
  138.  
  139. $this->assertEquals(array($r, $r1), $catalogue->getResources()); 
  140.  
  141. public function testMetadataDelete() 
  142. $catalogue = new MessageCatalogue('en'); 
  143. $this->assertEquals(array(), $catalogue->getMetadata('', ''), 'Metadata is empty'); 
  144. $catalogue->deleteMetadata('key', 'messages'); 
  145. $catalogue->deleteMetadata('', 'messages'); 
  146. $catalogue->deleteMetadata(); 
  147.  
  148. public function testMetadataSetGetDelete() 
  149. $catalogue = new MessageCatalogue('en'); 
  150. $catalogue->setMetadata('key', 'value'); 
  151. $this->assertEquals('value', $catalogue->getMetadata('key', 'messages'), "Metadata 'key' = 'value'"); 
  152.  
  153. $catalogue->setMetadata('key2', array()); 
  154. $this->assertEquals(array(), $catalogue->getMetadata('key2', 'messages'), 'Metadata key2 is array'); 
  155.  
  156. $catalogue->deleteMetadata('key2', 'messages'); 
  157. $this->assertNull($catalogue->getMetadata('key2', 'messages'), 'Metadata key2 should is deleted.'); 
  158.  
  159. $catalogue->deleteMetadata('key2', 'domain'); 
  160. $this->assertNull($catalogue->getMetadata('key2', 'domain'), 'Metadata key2 should is deleted.'); 
  161.  
  162. public function testMetadataMerge() 
  163. $cat1 = new MessageCatalogue('en'); 
  164. $cat1->setMetadata('a', 'b'); 
  165. $this->assertEquals(array('messages' => array('a' => 'b')), $cat1->getMetadata('', ''), 'Cat1 contains messages metadata.'); 
  166.  
  167. $cat2 = new MessageCatalogue('en'); 
  168. $cat2->setMetadata('b', 'c', 'domain'); 
  169. $this->assertEquals(array('domain' => array('b' => 'c')), $cat2->getMetadata('', ''), 'Cat2 contains domain metadata.'); 
  170.  
  171. $cat1->addCatalogue($cat2); 
  172. $this->assertEquals(array('messages' => array('a' => 'b'), 'domain' => array('b' => 'c')), $cat1->getMetadata('', ''), 'Cat1 contains merged metadata.');