ArrayConverterTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Translation\Tests\Util;
  11. use Symfony\Component\Translation\Util\ArrayConverter;
  12. class ArrayConverterTest extends \PHPUnit_Framework_TestCase
  13. {
  14. /**
  15. * @dataProvider messsagesData
  16. */
  17. public function testDump($input, $expectedOutput)
  18. {
  19. $this->assertEquals($expectedOutput, ArrayConverter::expandToTree($input));
  20. }
  21. public function messsagesData()
  22. {
  23. return array(
  24. array(
  25. // input
  26. array(
  27. 'foo1' => 'bar',
  28. 'foo.bar' => 'value',
  29. ),
  30. // expected output
  31. array(
  32. 'foo1' => 'bar',
  33. 'foo' => array('bar' => 'value'),
  34. ),
  35. ),
  36. array(
  37. // input
  38. array(
  39. 'foo.bar' => 'value1',
  40. 'foo.bar.test' => 'value2',
  41. ),
  42. // expected output
  43. array(
  44. 'foo' => array(
  45. 'bar' => 'value1',
  46. 'bar.test' => 'value2',
  47. ),
  48. ),
  49. ),
  50. array(
  51. // input
  52. array(
  53. 'foo.level2.level3.level4' => 'value1',
  54. 'foo.level2' => 'value2',
  55. 'foo.bar' => 'value3',
  56. ),
  57. // expected output
  58. array(
  59. 'foo' => array(
  60. 'level2' => 'value2',
  61. 'level2.level3.level4' => 'value1',
  62. 'bar' => 'value3',
  63. ),
  64. ),
  65. ),
  66. );
  67. }
  68. }