views_argument_default.test 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. /**
  3. * @file
  4. * Definition of ViewsArgumentDefaultTest.
  5. */
  6. /**
  7. * Basic test for pluggable argument default.
  8. */
  9. class ViewsArgumentDefaultTest extends ViewsSqlTest {
  10. public static function getInfo() {
  11. return array(
  12. 'name' => 'Argument_default',
  13. 'description' => 'Tests pluggable argument_default for views.',
  14. 'group' => 'Views Plugins',
  15. );
  16. }
  17. public function setUp() {
  18. parent::setUp('views');
  19. $this->random = $this->randomString();
  20. }
  21. /**
  22. * Tests the use of a default argument plugin that provides no options.
  23. */
  24. function testArgumentDefaultNoOptions() {
  25. module_enable(array('views_ui', 'views_test'));
  26. $admin_user = $this->drupalCreateUser(array('administer views', 'administer site configuration'));
  27. $this->drupalLogin($admin_user);
  28. // The current_user plugin has no options form, and should pass validation.
  29. $argument_type = 'current_user';
  30. $edit = array(
  31. 'options[default_argument_type]' => $argument_type,
  32. );
  33. $this->drupalPost('admin/structure/views/nojs/config-item/test_argument_default_current_user/default/argument/uid', $edit, t('Apply'));
  34. // Note, the undefined index error has two spaces after it.
  35. $error = array(
  36. '%type' => 'Notice',
  37. '!message' => 'Undefined index: ' . $argument_type,
  38. '%function' => 'views_handler_argument->options_validate()',
  39. );
  40. $message = t('%type: !message in %function', $error);
  41. $this->assertNoRaw($message, t('Did not find error message: !message.', array('!message' => $message)));
  42. }
  43. /**
  44. * Tests fixed default argument.
  45. */
  46. function testArgumentDefaultFixed() {
  47. $view = $this->view_argument_default_fixed();
  48. $view->set_display('default');
  49. $view->pre_execute();
  50. $view->init_handlers();
  51. $this->assertEqual($view->argument['null']->get_default_argument(), $this->random, 'Fixed argument should be used by default.');
  52. $view->destroy();
  53. // Make sure that a normal argument provided is used.
  54. $view = $this->view_argument_default_fixed();
  55. $view->set_display('default');
  56. $random_string = $this->randomString();
  57. $view->execute_display('default', array($random_string));
  58. $this->assertEqual($view->args[0], $random_string, 'Provided argument should be used.');
  59. }
  60. /**
  61. * @todo Test php default argument.
  62. */
  63. function testArgumentDefaultPhp() {
  64. }
  65. /**
  66. * @todo Test node default argument.
  67. */
  68. function testArgumentDefaultNode() {
  69. }
  70. function view_argument_default_fixed() {
  71. $view = new view();
  72. $view->name = 'test_argument_default_fixed';
  73. $view->description = '';
  74. $view->tag = '';
  75. $view->view_php = '';
  76. $view->base_table = 'node';
  77. $view->is_cacheable = FALSE;
  78. $view->api_version = 2;
  79. $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
  80. /* Display: Master */
  81. $handler = $view->new_display('default', 'Master', 'default');
  82. $handler->display->display_options['access']['type'] = 'none';
  83. $handler->display->display_options['cache']['type'] = 'none';
  84. $handler->display->display_options['exposed_form']['type'] = 'basic';
  85. $handler->display->display_options['pager']['type'] = 'full';
  86. $handler->display->display_options['pager']['options']['items_per_page'] = '10';
  87. $handler->display->display_options['pager']['options']['offset'] = '0';
  88. $handler->display->display_options['pager']['options']['id'] = '0';
  89. $handler->display->display_options['style_plugin'] = 'default';
  90. $handler->display->display_options['row_plugin'] = 'fields';
  91. /* Field: Content: Title */
  92. $handler->display->display_options['fields']['title']['id'] = 'title';
  93. $handler->display->display_options['fields']['title']['table'] = 'node';
  94. $handler->display->display_options['fields']['title']['field'] = 'title';
  95. $handler->display->display_options['fields']['title']['alter']['alter_text'] = 0;
  96. $handler->display->display_options['fields']['title']['alter']['make_link'] = 0;
  97. $handler->display->display_options['fields']['title']['alter']['trim'] = 0;
  98. $handler->display->display_options['fields']['title']['alter']['word_boundary'] = 1;
  99. $handler->display->display_options['fields']['title']['alter']['ellipsis'] = 1;
  100. $handler->display->display_options['fields']['title']['alter']['strip_tags'] = 0;
  101. $handler->display->display_options['fields']['title']['alter']['html'] = 0;
  102. $handler->display->display_options['fields']['title']['hide_empty'] = 0;
  103. $handler->display->display_options['fields']['title']['empty_zero'] = 0;
  104. $handler->display->display_options['fields']['title']['link_to_node'] = 0;
  105. /* Argument: Global: Null */
  106. $handler->display->display_options['arguments']['null']['id'] = 'null';
  107. $handler->display->display_options['arguments']['null']['table'] = 'views';
  108. $handler->display->display_options['arguments']['null']['field'] = 'null';
  109. $handler->display->display_options['arguments']['null']['default_action'] = 'default';
  110. $handler->display->display_options['arguments']['null']['style_plugin'] = 'default_summary';
  111. $handler->display->display_options['arguments']['null']['default_argument_type'] = 'fixed';
  112. $handler->display->display_options['arguments']['null']['default_argument_options']['argument'] = $this->random;
  113. $handler->display->display_options['arguments']['null']['must_not_be'] = 0;
  114. return $view;
  115. }
  116. }