views_plugin_display.test 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <?php
  2. /**
  3. * @file
  4. * Definition of ViewsPluginDisplayTestCase.
  5. */
  6. /**
  7. *
  8. */
  9. class ViewsPluginDisplayTestCase extends ViewsSqlTest {
  10. /**
  11. *
  12. */
  13. public static function getInfo() {
  14. return array(
  15. 'name' => 'Display plugin',
  16. 'description' => 'Tests the basic display plugin.',
  17. 'group' => 'Views Plugins',
  18. );
  19. }
  20. /**
  21. * Tests the overriding of filter_groups.
  22. */
  23. function testFilterGroupsOverriding() {
  24. $view = $this->viewFilterGroupsUpdating();
  25. $view->init_display();
  26. // mark is as overridden, yes FALSE, means overridden.
  27. $view->display['page']->handler->set_override('filter_groups', FALSE);
  28. $this->assertFalse($view->display['page']->handler->is_defaulted('filter_groups'), "Take sure that 'filter_groups' is marked as overridden.");
  29. $this->assertFalse($view->display['page']->handler->is_defaulted('filters'), "Take sure that 'filters'' is marked as overridden.");
  30. }
  31. /**
  32. * Returns a test view for testFilterGroupsOverriding.
  33. *
  34. * @see testFilterGroupsOverriding
  35. *
  36. * @return view
  37. */
  38. function viewFilterGroupsOverriding() {
  39. $view = new view();
  40. $view->name = 'test_filter_group_override';
  41. $view->description = '';
  42. $view->tag = 'default';
  43. $view->base_table = 'node';
  44. $view->human_name = 'test_filter_group_override';
  45. $view->core = 7;
  46. $view->api_version = '3.0';
  47. $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
  48. /* Display: Master */
  49. $handler = $view->new_display('default', 'Master', 'default');
  50. $handler->display->display_options['access']['type'] = 'perm';
  51. $handler->display->display_options['cache']['type'] = 'none';
  52. $handler->display->display_options['query']['type'] = 'views_query';
  53. $handler->display->display_options['exposed_form']['type'] = 'basic';
  54. $handler->display->display_options['pager']['type'] = 'full';
  55. $handler->display->display_options['style_plugin'] = 'default';
  56. $handler->display->display_options['row_plugin'] = 'fields';
  57. /* Field: Content: Title */
  58. $handler->display->display_options['fields']['title']['id'] = 'title';
  59. $handler->display->display_options['fields']['title']['table'] = 'node';
  60. $handler->display->display_options['fields']['title']['field'] = 'title';
  61. $handler->display->display_options['fields']['title']['label'] = '';
  62. $handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
  63. $handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
  64. /* Filter criterion: Content: Published */
  65. $handler->display->display_options['filters']['status']['id'] = 'status';
  66. $handler->display->display_options['filters']['status']['table'] = 'node';
  67. $handler->display->display_options['filters']['status']['field'] = 'status';
  68. $handler->display->display_options['filters']['status']['value'] = 1;
  69. $handler->display->display_options['filters']['status']['group'] = 1;
  70. $handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
  71. /* Display: Page */
  72. $handler = $view->new_display('page', 'Page', 'page_1');
  73. $handler->display->display_options['path'] = 'test';
  74. return $view;
  75. }
  76. /**
  77. * Based on a bug some filter_groups landed in the overridden display.
  78. *
  79. * Even the filters weren't overridden.
  80. * This caused multiple issues.
  81. * Take sure that the value from the default display are used.
  82. *
  83. * @see http://drupal.org/node/1259608
  84. * @see views_plugin_display::init()
  85. */
  86. function testFilterGroupsUpdating() {
  87. $view = $this->viewFilterGroupsUpdating();
  88. $view->init_display();
  89. $this->assertFalse($view->display['page']->handler->options['defaults']['filter_groups']);
  90. $this->assertEqual($view->display['default']->handler->options['filter_groups'], $view->display['page']->handler->options['filter_groups'], 'Take sure the default options are used for the filter_groups');
  91. }
  92. /**
  93. * Returns a test view for testFilterGroupUpdating.
  94. *
  95. * @see testFilterGroupUpdating
  96. *
  97. * @return view
  98. */
  99. function viewFilterGroupsUpdating() {
  100. $view = new view();
  101. $view->name = 'test_filter_groups';
  102. $view->description = '';
  103. $view->tag = 'default';
  104. $view->base_table = 'node';
  105. $view->human_name = 'test_filter_groups';
  106. $view->core = 7;
  107. $view->api_version = '3.0';
  108. $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
  109. /* Display: Master */
  110. $handler = $view->new_display('default', 'Master', 'default');
  111. $handler->display->display_options['title'] = 'test_filter_groups';
  112. $handler->display->display_options['access']['type'] = 'perm';
  113. $handler->display->display_options['cache']['type'] = 'none';
  114. $handler->display->display_options['query']['type'] = 'views_query';
  115. $handler->display->display_options['exposed_form']['type'] = 'basic';
  116. $handler->display->display_options['pager']['type'] = 'full';
  117. $handler->display->display_options['pager']['options']['items_per_page'] = '10';
  118. $handler->display->display_options['style_plugin'] = 'default';
  119. $handler->display->display_options['row_plugin'] = 'node';
  120. /* Field: Content: Title */
  121. $handler->display->display_options['fields']['title']['id'] = 'title';
  122. $handler->display->display_options['fields']['title']['table'] = 'node';
  123. $handler->display->display_options['fields']['title']['field'] = 'title';
  124. $handler->display->display_options['fields']['title']['label'] = '';
  125. $handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
  126. $handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
  127. /* Sort criterion: Content: Post date */
  128. $handler->display->display_options['sorts']['created']['id'] = 'created';
  129. $handler->display->display_options['sorts']['created']['table'] = 'node';
  130. $handler->display->display_options['sorts']['created']['field'] = 'created';
  131. $handler->display->display_options['sorts']['created']['order'] = 'DESC';
  132. $handler->display->display_options['filter_groups']['groups'] = array(
  133. 1 => 'AND',
  134. 2 => 'AND',
  135. );
  136. /* Filter criterion: Content: Published */
  137. $handler->display->display_options['filters']['status']['id'] = 'status';
  138. $handler->display->display_options['filters']['status']['table'] = 'node';
  139. $handler->display->display_options['filters']['status']['field'] = 'status';
  140. $handler->display->display_options['filters']['status']['value'] = 1;
  141. $handler->display->display_options['filters']['status']['group'] = 1;
  142. $handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
  143. /* Filter criterion: Content: Nid */
  144. $handler->display->display_options['filters']['nid']['id'] = 'nid';
  145. $handler->display->display_options['filters']['nid']['table'] = 'node';
  146. $handler->display->display_options['filters']['nid']['field'] = 'nid';
  147. $handler->display->display_options['filters']['nid']['value']['value'] = '1';
  148. $handler->display->display_options['filters']['nid']['group'] = 2;
  149. /* Filter criterion: Content: Nid */
  150. $handler->display->display_options['filters']['nid_1']['id'] = 'nid_1';
  151. $handler->display->display_options['filters']['nid_1']['table'] = 'node';
  152. $handler->display->display_options['filters']['nid_1']['field'] = 'nid';
  153. $handler->display->display_options['filters']['nid_1']['value']['value'] = '2';
  154. $handler->display->display_options['filters']['nid_1']['group'] = 2;
  155. /* Display: Page */
  156. $handler = $view->new_display('page', 'Page', 'page');
  157. $handler->display->display_options['filter_groups']['operator'] = 'OR';
  158. $handler->display->display_options['filter_groups']['groups'] = array(
  159. 1 => 'OR',
  160. 2 => 'OR',
  161. );
  162. $handler->display->display_options['defaults']['filters'] = FALSE;
  163. /* Filter criterion: Content: Published */
  164. $handler->display->display_options['filters']['status']['id'] = 'status';
  165. $handler->display->display_options['filters']['status']['table'] = 'node';
  166. $handler->display->display_options['filters']['status']['field'] = 'status';
  167. $handler->display->display_options['filters']['status']['value'] = 1;
  168. $handler->display->display_options['filters']['status']['group'] = 1;
  169. $handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
  170. /* Filter criterion: Content: Nid */
  171. $handler->display->display_options['filters']['nid']['id'] = 'nid';
  172. $handler->display->display_options['filters']['nid']['table'] = 'node';
  173. $handler->display->display_options['filters']['nid']['field'] = 'nid';
  174. $handler->display->display_options['filters']['nid']['value']['value'] = '1';
  175. $handler->display->display_options['filters']['nid']['group'] = 2;
  176. /* Filter criterion: Content: Nid */
  177. $handler->display->display_options['filters']['nid_1']['id'] = 'nid_1';
  178. $handler->display->display_options['filters']['nid_1']['table'] = 'node';
  179. $handler->display->display_options['filters']['nid_1']['field'] = 'nid';
  180. $handler->display->display_options['filters']['nid_1']['value']['value'] = '2';
  181. $handler->display->display_options['filters']['nid_1']['group'] = 2;
  182. $handler->display->display_options['path'] = 'test-filter-groups';
  183. return $view;
  184. }
  185. }