views_handler_argument_string.test

Definition of ViewsHandlerArgumentNullTest.

File

tests/handlers/views_handler_argument_string.test
View source
  1. <?php
  2. /**
  3. * @file
  4. * Definition of ViewsHandlerArgumentNullTest.
  5. */
  6. /**
  7. * Tests the core views_handler_argument_string handler.
  8. */
  9. class ViewsHandlerArgumentStringTest extends ViewsSqlTest {
  10. public static function getInfo() {
  11. return array(
  12. 'name' => 'Argument: String',
  13. 'description' => 'Test the core views_handler_argument_string handler.',
  14. 'group' => 'Views Handlers',
  15. );
  16. }
  17. /**
  18. * Tests the glossary feature.
  19. */
  20. function testGlossary() {
  21. // Setup some nodes, one with a, two with b and three with c.
  22. $counter = 1;
  23. foreach (array('a', 'b', 'c') as $char) {
  24. for ($i = 0; $i < $counter; $i++) {
  25. $edit = array(
  26. 'title' => $char . $this->randomName(),
  27. );
  28. $this->drupalCreateNode($edit);
  29. }
  30. }
  31. $view = $this->viewGlossary();
  32. $view->init_display();
  33. $this->executeView($view);
  34. $count_field = 'nid';
  35. foreach ($view->result as &$row) {
  36. if (strpos($row->node_title, 'a') === 0) {
  37. $this->assertEqual(1, $row->{$count_field});
  38. }
  39. if (strpos($row->node_title, 'b') === 0) {
  40. $this->assertEqual(2, $row->{$count_field});
  41. }
  42. if (strpos($row->node_title, 'c') === 0) {
  43. $this->assertEqual(3, $row->{$count_field});
  44. }
  45. }
  46. }
  47. /**
  48. * Provide a test view for testGlossary.
  49. *
  50. * @see testGlossary
  51. * @return view
  52. */
  53. function viewGlossary() {
  54. $view = new view();
  55. $view->name = 'test_glossary';
  56. $view->description = '';
  57. $view->tag = 'default';
  58. $view->base_table = 'node';
  59. $view->human_name = 'test_glossary';
  60. $view->core = 7;
  61. $view->api_version = '3.0';
  62. $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
  63. /* Display: Master */
  64. $handler = $view->new_display('default', 'Master', 'default');
  65. $handler->display->display_options['access']['type'] = 'perm';
  66. $handler->display->display_options['cache']['type'] = 'none';
  67. $handler->display->display_options['query']['type'] = 'views_query';
  68. $handler->display->display_options['exposed_form']['type'] = 'basic';
  69. $handler->display->display_options['pager']['type'] = 'full';
  70. $handler->display->display_options['style_plugin'] = 'default';
  71. $handler->display->display_options['row_plugin'] = 'fields';
  72. /* Field: Content: Title */
  73. $handler->display->display_options['fields']['title']['id'] = 'title';
  74. $handler->display->display_options['fields']['title']['table'] = 'node';
  75. $handler->display->display_options['fields']['title']['field'] = 'title';
  76. $handler->display->display_options['fields']['title']['label'] = '';
  77. /* Contextual filter: Content: Title */
  78. $handler->display->display_options['arguments']['title']['id'] = 'title';
  79. $handler->display->display_options['arguments']['title']['table'] = 'node';
  80. $handler->display->display_options['arguments']['title']['field'] = 'title';
  81. $handler->display->display_options['arguments']['title']['default_argument_type'] = 'fixed';
  82. $handler->display->display_options['arguments']['title']['summary']['number_of_records'] = '0';
  83. $handler->display->display_options['arguments']['title']['summary']['format'] = 'default_summary';
  84. $handler->display->display_options['arguments']['title']['summary_options']['items_per_page'] = '25';
  85. $handler->display->display_options['arguments']['title']['glossary'] = TRUE;
  86. $handler->display->display_options['arguments']['title']['limit'] = '1';
  87. return $view;
  88. }
  89. }