views_handler_sort.test 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /**
  3. * @file
  4. * Definition of ViewsHandlerSortTest.
  5. */
  6. /**
  7. * Tests for core views_handler_sort handler.
  8. */
  9. class ViewsHandlerSortTest extends ViewsSqlTest {
  10. public static function getInfo() {
  11. return array(
  12. 'name' => 'Sort: generic',
  13. 'description' => 'Test the core views_handler_sort handler.',
  14. 'group' => 'Views Handlers',
  15. );
  16. }
  17. /**
  18. * Tests numeric ordering of the result set.
  19. */
  20. public function testNumericOrdering() {
  21. $view = $this->getBasicView();
  22. // Change the ordering
  23. $view->display['default']->handler->override_option('sorts', array(
  24. 'age' => array(
  25. 'order' => 'ASC',
  26. 'id' => 'age',
  27. 'table' => 'views_test',
  28. 'field' => 'age',
  29. 'relationship' => 'none',
  30. ),
  31. ));
  32. // Execute the view.
  33. $this->executeView($view);
  34. // Verify the result.
  35. $this->assertEqual(count($this->dataSet()), count($view->result), t('The number of returned rows match.'));
  36. $this->assertIdenticalResultset($view, $this->orderResultSet($this->dataSet(), 'age'), array(
  37. 'views_test_name' => 'name',
  38. 'views_test_age' => 'age',
  39. ));
  40. $view = $this->getBasicView();
  41. // Reverse the ordering
  42. $view->display['default']->handler->override_option('sorts', array(
  43. 'age' => array(
  44. 'order' => 'DESC',
  45. 'id' => 'age',
  46. 'table' => 'views_test',
  47. 'field' => 'age',
  48. 'relationship' => 'none',
  49. ),
  50. ));
  51. // Execute the view.
  52. $this->executeView($view);
  53. // Verify the result.
  54. $this->assertEqual(count($this->dataSet()), count($view->result), t('The number of returned rows match.'));
  55. $this->assertIdenticalResultset($view, $this->orderResultSet($this->dataSet(), 'age', TRUE), array(
  56. 'views_test_name' => 'name',
  57. 'views_test_age' => 'age',
  58. ));
  59. }
  60. /**
  61. * Tests string ordering of the result set.
  62. */
  63. public function testStringOrdering() {
  64. $view = $this->getBasicView();
  65. // Change the ordering
  66. $view->display['default']->handler->override_option('sorts', array(
  67. 'name' => array(
  68. 'order' => 'ASC',
  69. 'id' => 'name',
  70. 'table' => 'views_test',
  71. 'field' => 'name',
  72. 'relationship' => 'none',
  73. ),
  74. ));
  75. // Execute the view.
  76. $this->executeView($view);
  77. // Verify the result.
  78. $this->assertEqual(count($this->dataSet()), count($view->result), t('The number of returned rows match.'));
  79. $this->assertIdenticalResultset($view, $this->orderResultSet($this->dataSet(), 'name'), array(
  80. 'views_test_name' => 'name',
  81. 'views_test_age' => 'age',
  82. ));
  83. $view = $this->getBasicView();
  84. // Reverse the ordering
  85. $view->display['default']->handler->override_option('sorts', array(
  86. 'name' => array(
  87. 'order' => 'DESC',
  88. 'id' => 'name',
  89. 'table' => 'views_test',
  90. 'field' => 'name',
  91. 'relationship' => 'none',
  92. ),
  93. ));
  94. // Execute the view.
  95. $this->executeView($view);
  96. // Verify the result.
  97. $this->assertEqual(count($this->dataSet()), count($view->result), t('The number of returned rows match.'));
  98. $this->assertIdenticalResultset($view, $this->orderResultSet($this->dataSet(), 'name', TRUE), array(
  99. 'views_test_name' => 'name',
  100. 'views_test_age' => 'age',
  101. ));
  102. }
  103. }