YamlTestBase.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace Drupal\Tests\Component\Serialization;
  3. use PHPUnit\Framework\TestCase;
  4. /**
  5. * Provides standard data to validate different YAML implementations.
  6. */
  7. abstract class YamlTestBase extends TestCase {
  8. /**
  9. * Some data that should be able to be serialized.
  10. */
  11. public function providerEncodeDecodeTests() {
  12. return [
  13. [
  14. 'foo' => 'bar',
  15. 'id' => 'schnitzel',
  16. 'ponies' => ['nope', 'thanks'],
  17. 'how' => [
  18. 'about' => 'if',
  19. 'i' => 'ask',
  20. 'nicely',
  21. ],
  22. 'the' => [
  23. 'answer' => [
  24. 'still' => 'would',
  25. 'be' => 'Y',
  26. ],
  27. ],
  28. 'how_many_times' => 123,
  29. 'should_i_ask' => FALSE,
  30. 1,
  31. FALSE,
  32. [1, FALSE],
  33. [10],
  34. [0 => '123456'],
  35. ],
  36. [NULL],
  37. ];
  38. }
  39. /**
  40. * Some data that should be able to be de-serialized.
  41. */
  42. public function providerDecodeTests() {
  43. $data = [
  44. // NULL files.
  45. ['', NULL],
  46. ["\n", NULL],
  47. ["---\n...\n", NULL],
  48. // Node anchors.
  49. [
  50. "
  51. jquery.ui:
  52. version: &jquery_ui 1.10.2
  53. jquery.ui.accordion:
  54. version: *jquery_ui
  55. ",
  56. [
  57. 'jquery.ui' => [
  58. 'version' => '1.10.2',
  59. ],
  60. 'jquery.ui.accordion' => [
  61. 'version' => '1.10.2',
  62. ],
  63. ],
  64. ],
  65. ];
  66. // 1.2 Bool values.
  67. foreach ($this->providerBoolTest() as $test) {
  68. $data[] = ['bool: ' . $test[0], ['bool' => $test[1]]];
  69. }
  70. $data = array_merge($data, $this->providerBoolTest());
  71. return $data;
  72. }
  73. /**
  74. * Tests different boolean serialization and de-serialization.
  75. */
  76. public function providerBoolTest() {
  77. return [
  78. ['true', TRUE],
  79. ['TRUE', TRUE],
  80. ['True', TRUE],
  81. ['y', 'y'],
  82. ['Y', 'Y'],
  83. ['false', FALSE],
  84. ['FALSE', FALSE],
  85. ['False', FALSE],
  86. ['n', 'n'],
  87. ['N', 'N'],
  88. ];
  89. }
  90. }