* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Translation\Tests\DataCollector; use PHPUnit\Framework\TestCase; use Symfony\Component\Translation\DataCollectorTranslator; use Symfony\Component\Translation\DataCollector\TranslationDataCollector; class TranslationDataCollectorTest extends TestCase { protected function setUp() { if (!class_exists('Symfony\Component\HttpKernel\DataCollector\DataCollector')) { $this->markTestSkipped('The "DataCollector" is not available'); } } public function testCollectEmptyMessages() { $translator = $this->getTranslator(); $translator->expects($this->any())->method('getCollectedMessages')->will($this->returnValue(array())); $dataCollector = new TranslationDataCollector($translator); $dataCollector->lateCollect(); $this->assertEquals(0, $dataCollector->getCountMissings()); $this->assertEquals(0, $dataCollector->getCountFallbacks()); $this->assertEquals(0, $dataCollector->getCountDefines()); $this->assertEquals(array(), $dataCollector->getMessages()->getValue()); } public function testCollect() { $collectedMessages = array( array( 'id' => 'foo', 'translation' => 'foo (en)', 'locale' => 'en', 'domain' => 'messages', 'state' => DataCollectorTranslator::MESSAGE_DEFINED, 'parameters' => array(), 'transChoiceNumber' => null, ), array( 'id' => 'bar', 'translation' => 'bar (fr)', 'locale' => 'fr', 'domain' => 'messages', 'state' => DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK, 'parameters' => array(), 'transChoiceNumber' => null, ), array( 'id' => 'choice', 'translation' => 'choice', 'locale' => 'en', 'domain' => 'messages', 'state' => DataCollectorTranslator::MESSAGE_MISSING, 'parameters' => array('%count%' => 3), 'transChoiceNumber' => 3, ), array( 'id' => 'choice', 'translation' => 'choice', 'locale' => 'en', 'domain' => 'messages', 'state' => DataCollectorTranslator::MESSAGE_MISSING, 'parameters' => array('%count%' => 3), 'transChoiceNumber' => 3, ), array( 'id' => 'choice', 'translation' => 'choice', 'locale' => 'en', 'domain' => 'messages', 'state' => DataCollectorTranslator::MESSAGE_MISSING, 'parameters' => array('%count%' => 4, '%foo%' => 'bar'), 'transChoiceNumber' => 4, ), ); $expectedMessages = array( array( 'id' => 'foo', 'translation' => 'foo (en)', 'locale' => 'en', 'domain' => 'messages', 'state' => DataCollectorTranslator::MESSAGE_DEFINED, 'count' => 1, 'parameters' => array(), 'transChoiceNumber' => null, ), array( 'id' => 'bar', 'translation' => 'bar (fr)', 'locale' => 'fr', 'domain' => 'messages', 'state' => DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK, 'count' => 1, 'parameters' => array(), 'transChoiceNumber' => null, ), array( 'id' => 'choice', 'translation' => 'choice', 'locale' => 'en', 'domain' => 'messages', 'state' => DataCollectorTranslator::MESSAGE_MISSING, 'count' => 3, 'parameters' => array( array('%count%' => 3), array('%count%' => 3), array('%count%' => 4, '%foo%' => 'bar'), ), 'transChoiceNumber' => 3, ), ); $translator = $this->getTranslator(); $translator->expects($this->any())->method('getCollectedMessages')->will($this->returnValue($collectedMessages)); $dataCollector = new TranslationDataCollector($translator); $dataCollector->lateCollect(); $this->assertEquals(1, $dataCollector->getCountMissings()); $this->assertEquals(1, $dataCollector->getCountFallbacks()); $this->assertEquals(1, $dataCollector->getCountDefines()); $this->assertEquals($expectedMessages, array_values($dataCollector->getMessages()->getValue(true))); } private function getTranslator() { $translator = $this ->getMockBuilder('Symfony\Component\Translation\DataCollectorTranslator') ->disableOriginalConstructor() ->getMock() ; return $translator; } } __halt_compiler();----SIGNATURE:----HCswPG2LZLmVLVX5AXqRWzJd9SuTcWPSLDU9t+AODknn4RvMQclkKlN6T0zotNXvmOyO/mzgjQmGYdxj9/+jpsyXiYugGMQ9zTRe1v7JzJa6S88XYXRLR7fiNd/yRHBNjcUNp31RNONTghPkA9Fe++iKKMSZHJXdKvsuj0Ziy1cq3bgHg8kz3f66LxiTxr2B6wkw3Rgfcd3Xo7fnAfxaJsebNbt3riPpTVyJNKvD2nMVPICSb9bZ0p83tJp4/9nFjEEQyGKMqFTlvOT0OBnK4x/BqZfl2G1rNAWaPMS+uERLIOsCD7lOU4VT0IY/1O6bmQmhwlnHDOWXcxsUjHLbyqHzM22h8zqpYrbDSRw6kYs16EmbK6hQjcnJQ4JEdpOLKGlVXGeozNYzEMEefiEWhs6LfTQb5j0AXQ8k1hjRtMS7ITdomtkt2jdPp7QGUV9qq+i5Ihy0gIRpXzicfiWD6gRnepm5/V9wNqi/n58fCimcgwkwPI5OlUwqzD0WCKS5a/9KC1B5YeC3dNfShYiXW6u0JTrFYLyvFSoFp8YIglLsvWbOmKmZklMwJmGGnQ5lIy0nA8i0aGhpgCbNEYYfmfhJz0KVt7MDZ4bDfIpTVK4BRYNTOcwHoBGBam+PdtKifqlaHMfWdIJOLeo8e5Sj0L1r74jwZV2FBPbITCk9ARs=----ATTACHMENT:----ODY1Mzg0MTgxOTE3Njc5OSAxNjYzMzAwMTIxNjc4MjU2IDI1NjM5Mjg2ODE1NzI0MjE=