TableSortLegacyTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace Drupal\KernelTests\Core\Theme;
  3. use Drupal\Core\Utility\TableSort;
  4. use Drupal\KernelTests\KernelTestBase;
  5. /**
  6. * Deprecation tests cases for the tablesort.inc file functions.
  7. *
  8. * @package Drupal\KernelTests\Core\Theme
  9. *
  10. * @group legacy
  11. */
  12. class TableSortLegacyTest extends KernelTestBase {
  13. /**
  14. * Tests deprecation of the tablesort_init() function.
  15. *
  16. * @expectedDeprecation tablesort_init() is deprecated in Drupal 8.7.x and will be removed before Drupal 9.0.0. Use \Drupal\Core\Utility\TableSort::getContextFromRequest() instead. See https://www.drupal.org/node/3009182
  17. */
  18. public function testInit() {
  19. $context = tablesort_init([]);
  20. $this->assertArrayHasKey('query', $context);
  21. $this->assertArrayHasKey('sort', $context);
  22. }
  23. /**
  24. * Tests deprecation of the tablesort_header() function.
  25. *
  26. * @expectedDeprecation tablesort_header() is deprecated in Drupal 8.7.x and will be removed before Drupal 9.0.0. Use \Drupal\Core\Utility\TableSort::header() instead. See https://www.drupal.org/node/3009182
  27. */
  28. public function testHeader() {
  29. $cell_content = '';
  30. $cell_attributes = [];
  31. tablesort_header($cell_content, $cell_attributes, [], []);
  32. $this->assertEquals('', $cell_content);
  33. }
  34. /**
  35. * Tests deprecation of the tablesort_get_query_parameters() function.
  36. *
  37. * @expectedDeprecation tablesort_get_query_parameters() is deprecated in Drupal 8.7.x and will be removed before Drupal 9.0.0. Use \Drupal\Core\Utility\TableSort::getQueryParameters() instead. See https://www.drupal.org/node/3009182
  38. */
  39. public function testQueryParameters() {
  40. $parameters = tablesort_get_query_parameters();
  41. $this->assertArrayNotHasKey('sort', $parameters);
  42. $this->assertArrayNotHasKey('order', $parameters);
  43. }
  44. /**
  45. * Tests deprecation of the tablesort_get_order() function.
  46. *
  47. * @expectedDeprecation tablesort_get_order() is deprecated in Drupal 8.7.x and will be removed before Drupal 9.0.0. Use \Drupal\Core\Utility\TableSort::getOrder() instead. See https://www.drupal.org/node/3009182
  48. */
  49. public function testOrder() {
  50. $this->assertEquals(
  51. [
  52. 'name' => NULL,
  53. 'sql' => NULL,
  54. ],
  55. tablesort_get_order([])
  56. );
  57. }
  58. /**
  59. * Tests deprecation of the tablesort_get_sort() function.
  60. *
  61. * @expectedDeprecation tablesort_get_sort() is deprecated in Drupal 8.7.x and will be removed before Drupal 9.0.0. Use \Drupal\Core\Utility\TableSort::getSort() instead. See https://www.drupal.org/node/3009182
  62. */
  63. public function testSort() {
  64. $this->assertEquals(TableSort::ASC, tablesort_get_sort([]));
  65. }
  66. }