XmlReferenceDumperTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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\Config\Tests\Definition\Dumper;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Config\Definition\Dumper\XmlReferenceDumper;
  13. use Symfony\Component\Config\Tests\Fixtures\Configuration\ExampleConfiguration;
  14. class XmlReferenceDumperTest extends TestCase
  15. {
  16. public function testDumper()
  17. {
  18. $configuration = new ExampleConfiguration();
  19. $dumper = new XmlReferenceDumper();
  20. $this->assertEquals($this->getConfigurationAsString(), $dumper->dump($configuration));
  21. }
  22. public function testNamespaceDumper()
  23. {
  24. $configuration = new ExampleConfiguration();
  25. $dumper = new XmlReferenceDumper();
  26. $this->assertEquals(str_replace('http://example.org/schema/dic/acme_root', 'http://symfony.com/schema/dic/symfony', $this->getConfigurationAsString()), $dumper->dump($configuration, 'http://symfony.com/schema/dic/symfony'));
  27. }
  28. private function getConfigurationAsString()
  29. {
  30. return str_replace("\n", PHP_EOL, <<<'EOL'
  31. <!-- Namespace: http://example.org/schema/dic/acme_root -->
  32. <!-- scalar-required: Required -->
  33. <!-- scalar-deprecated: Deprecated (The child node "scalar_deprecated" at path "acme_root" is deprecated.) -->
  34. <!-- scalar-deprecated-with-message: Deprecated (Deprecation custom message for "scalar_deprecated_with_message" at "acme_root") -->
  35. <!-- enum-with-default: One of "this"; "that" -->
  36. <!-- enum: One of "this"; "that" -->
  37. <config
  38. boolean="true"
  39. scalar-empty=""
  40. scalar-null="null"
  41. scalar-true="true"
  42. scalar-false="false"
  43. scalar-default="default"
  44. scalar-array-empty=""
  45. scalar-array-defaults="elem1,elem2"
  46. scalar-required=""
  47. scalar-deprecated=""
  48. scalar-deprecated-with-message=""
  49. node-with-a-looong-name=""
  50. enum-with-default="this"
  51. enum=""
  52. >
  53. <!-- some info -->
  54. <!--
  55. child3: this is a long
  56. multi-line info text
  57. which should be indented;
  58. Example: example setting
  59. -->
  60. <array
  61. child1=""
  62. child2=""
  63. child3=""
  64. />
  65. <!-- prototype -->
  66. <scalar-prototyped>scalar value</scalar-prototyped>
  67. <!-- prototype: Parameter name -->
  68. <parameter name="parameter name">scalar value</parameter>
  69. <!-- prototype -->
  70. <connection
  71. user=""
  72. pass=""
  73. />
  74. <!-- prototype -->
  75. <cms-page page="cms page page">
  76. <!-- prototype -->
  77. <!-- title: Required -->
  78. <!-- path: Required -->
  79. <page
  80. locale="page locale"
  81. title=""
  82. path=""
  83. />
  84. </cms-page>
  85. <!-- prototype -->
  86. <pipou name="pipou name">
  87. <!-- prototype -->
  88. <name didou="" />
  89. </pipou>
  90. </config>
  91. EOL
  92. );
  93. }
  94. }