views_basic.test 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. /**
  3. * @file
  4. */
  5. /**
  6. * Basic test class for Views query builder tests.
  7. */
  8. /**
  9. *
  10. */
  11. class ViewsBasicTest extends ViewsSqlTest {
  12. public static function getInfo() {
  13. return array(
  14. 'name' => 'Basic query test',
  15. 'description' => 'A basic query test for Views.',
  16. 'group' => 'Views',
  17. );
  18. }
  19. /**
  20. * Tests a trivial result set.
  21. */
  22. public function testSimpleResultSet() {
  23. $view = $this->getBasicView();
  24. // Execute the view.
  25. $this->executeView($view);
  26. // Verify the result.
  27. $this->assertEqual(5, count($view->result), t('The number of returned rows match.'));
  28. $this->assertIdenticalResultset($view, $this->dataSet(), array(
  29. 'views_test_name' => 'name',
  30. 'views_test_age' => 'age',
  31. ));
  32. }
  33. /**
  34. * Tests filtering of the result set.
  35. */
  36. public function testSimpleFiltering() {
  37. $view = $this->getBasicView();
  38. // Add a filter.
  39. $view->display['default']->handler->override_option('filters', array(
  40. 'age' => array(
  41. 'operator' => '<',
  42. 'value' => array(
  43. 'value' => '28',
  44. 'min' => '',
  45. 'max' => '',
  46. ),
  47. 'group' => '0',
  48. 'exposed' => FALSE,
  49. 'expose' => array(
  50. 'operator' => FALSE,
  51. 'label' => '',
  52. ),
  53. 'id' => 'age',
  54. 'table' => 'views_test',
  55. 'field' => 'age',
  56. 'relationship' => 'none',
  57. ),
  58. ));
  59. // Execute the view.
  60. $this->executeView($view);
  61. // Build the expected result.
  62. $dataset = array(
  63. array(
  64. 'id' => 1,
  65. 'name' => 'John',
  66. 'age' => 25,
  67. ),
  68. array(
  69. 'id' => 2,
  70. 'name' => 'George',
  71. 'age' => 27,
  72. ),
  73. array(
  74. 'id' => 4,
  75. 'name' => 'Paul',
  76. 'age' => 26,
  77. ),
  78. );
  79. // Verify the result.
  80. $this->assertEqual(3, count($view->result), t('The number of returned rows match.'));
  81. $this->assertIdenticalResultSet($view, $dataset, array(
  82. 'views_test_name' => 'name',
  83. 'views_test_age' => 'age',
  84. ));
  85. }
  86. /**
  87. * Tests simple argument.
  88. */
  89. public function testSimpleArgument() {
  90. $view = $this->getBasicView();
  91. // Add a argument.
  92. $view->display['default']->handler->override_option('arguments', array(
  93. 'age' => array(
  94. 'default_action' => 'ignore',
  95. 'style_plugin' => 'default_summary',
  96. 'style_options' => array(),
  97. 'wildcard' => 'all',
  98. 'wildcard_substitution' => 'All',
  99. 'title' => '',
  100. 'breadcrumb' => '',
  101. 'default_argument_type' => 'fixed',
  102. 'default_argument' => '',
  103. 'validate_type' => 'none',
  104. 'validate_fail' => 'not found',
  105. 'break_phrase' => 0,
  106. 'not' => 0,
  107. 'id' => 'age',
  108. 'table' => 'views_test',
  109. 'field' => 'age',
  110. 'validate_user_argument_type' => 'uid',
  111. 'validate_user_roles' => array(
  112. '2' => 0,
  113. ),
  114. 'relationship' => 'none',
  115. 'default_options_div_prefix' => '',
  116. 'default_argument_user' => 0,
  117. 'default_argument_fixed' => '',
  118. 'default_argument_php' => '',
  119. 'validate_argument_node_type' => array(
  120. 'page' => 0,
  121. 'story' => 0,
  122. ),
  123. 'validate_argument_node_access' => 0,
  124. 'validate_argument_nid_type' => 'nid',
  125. 'validate_argument_vocabulary' => array(),
  126. 'validate_argument_type' => 'tid',
  127. 'validate_argument_transform' => 0,
  128. 'validate_user_restrict_roles' => 0,
  129. 'validate_argument_php' => '',
  130. ),
  131. ));
  132. $saved_view = clone $view;
  133. // Execute with a view.
  134. $view->set_arguments(array(27));
  135. $this->executeView($view);
  136. // Build the expected result.
  137. $dataset = array(
  138. array(
  139. 'id' => 2,
  140. 'name' => 'George',
  141. 'age' => 27,
  142. ),
  143. );
  144. // Verify the result.
  145. $this->assertEqual(1, count($view->result), t('The number of returned rows match.'));
  146. $this->assertIdenticalResultSet($view, $dataset, array(
  147. 'views_test_name' => 'name',
  148. 'views_test_age' => 'age',
  149. ));
  150. // Test "show all" if no argument is present.
  151. $view = $saved_view;
  152. $this->executeView($view);
  153. // Build the expected result.
  154. $dataset = $this->dataSet();
  155. $this->assertEqual(5, count($view->result), t('The number of returned rows match.'));
  156. $this->assertIdenticalResultSet($view, $dataset, array(
  157. 'views_test_name' => 'name',
  158. 'views_test_age' => 'age',
  159. ));
  160. }
  161. }