RendererLegacyTest.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace Drupal\KernelTests\Core\Render;
  3. use Drupal\Core\Form\FormHelper;
  4. use Drupal\Core\Render\HtmlResponseAttachmentsProcessor;
  5. use Drupal\KernelTests\KernelTestBase;
  6. /**
  7. * Deprecation tests cases for the render layer.
  8. *
  9. * @group legacy
  10. */
  11. class RendererLegacyTest extends KernelTestBase {
  12. /**
  13. * Tests deprecation of the drupal_http_header_attributes() function.
  14. *
  15. * @dataProvider providerAttributes
  16. *
  17. * @expectedDeprecation drupal_http_header_attributes() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Render\HtmlResponseAttachmentsProcessor::formatHttpHeaderAttributes() instead. See https://www.drupal.org/node/3000051
  18. */
  19. public function testHeaderAttributes($expected, $attributes) {
  20. $this->assertSame($expected, drupal_http_header_attributes($attributes));
  21. $this->assertSame($expected, HtmlResponseAttachmentsProcessor::formatHttpHeaderAttributes($attributes));
  22. }
  23. /**
  24. * Provides a list of attributes to test.
  25. */
  26. public function providerAttributes() {
  27. return [
  28. [' foo=""', ['foo' => '']],
  29. [' foo=""', ['foo' => []]],
  30. [' foo="bar"', ['foo' => 'bar']],
  31. [' foo="bar"', ['foo' => ['bar']]],
  32. [' foo="bar baz"', ['foo' => ['bar', 'baz']]],
  33. ];
  34. }
  35. /**
  36. * Tests deprecation of the drupal_process_states() function.
  37. *
  38. * @dataProvider providerElements
  39. *
  40. * @expectedDeprecation drupal_process_states() is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Form\FormHelper::processStates() instead. See https://www.drupal.org/node/3000069
  41. */
  42. public function testDrupalProcessStates($elements) {
  43. // Clone elements because processing changes array.
  44. $expected = $elements;
  45. drupal_process_states($expected);
  46. FormHelper::processStates($elements);
  47. $this->assertEquals($expected, $elements);
  48. }
  49. /**
  50. * Provides a list of elements to test.
  51. */
  52. public function providerElements() {
  53. return [
  54. [
  55. [
  56. '#type' => 'date',
  57. '#states' => [
  58. 'visible' => [
  59. ':input[name="toggle_me"]' => ['checked' => TRUE],
  60. ],
  61. ],
  62. ],
  63. ],
  64. [
  65. [
  66. '#type' => 'item',
  67. '#states' => [
  68. 'visible' => [
  69. ':input[name="foo"]' => ['value' => 'bar'],
  70. ],
  71. ],
  72. ],
  73. ],
  74. ];
  75. }
  76. }