views_basic.test

Definition of ViewsBasicTest.

File

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