ds.search.test 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. /**
  3. * @file
  4. * Search tests
  5. */
  6. class dsSearchTests extends dsBaseTest {
  7. /**
  8. * Implements getInfo().
  9. */
  10. public static function getInfo() {
  11. return array(
  12. 'name' => t('Search'),
  13. 'description' => t('Tests for display of search results for nodes and users.'),
  14. 'group' => t('Display Suite'),
  15. );
  16. }
  17. function testDSSearch() {
  18. // Create nodes.
  19. $i = 15;
  20. while ($i > 0) {
  21. $settings = array(
  22. 'title' => 'title' . $i,
  23. 'type' => 'article',
  24. 'promote' => 1,
  25. );
  26. $this->drupalCreateNode($settings);
  27. $i--;
  28. }
  29. // Set default search.
  30. $edit = array(
  31. 'search_default_module' => 'ds_search',
  32. );
  33. $this->drupalPost('admin/config/search/settings', $edit, t('Save configuration'));
  34. // Run cron.
  35. $this->cronRun();
  36. $this->drupalGet('admin/config/search/settings');
  37. $this->assertText(t('100% of the site has been indexed. There are 0 items left to index.'), 'Site has been indexed');
  38. // Configure search result view mode.
  39. $svm = array('additional_settings[modes][view_modes_custom][search_result]' => 'search_result');
  40. $this->dsConfigureUI($svm);
  41. $layout = array(
  42. 'additional_settings[layout]' => 'ds_2col_stacked',
  43. );
  44. $assert = array(
  45. 'regions' => array(
  46. 'header' => '<td colspan="8">' . t('Header') . '</td>',
  47. 'left' => '<td colspan="8">' . t('Left') . '</td>',
  48. 'right' => '<td colspan="8">' . t('Right') . '</td>',
  49. 'footer' => '<td colspan="8">' . t('Footer') . '</td>',
  50. ),
  51. );
  52. $this->dsSelectLayout($layout, $assert, 'admin/structure/types/manage/article/display/search_result');
  53. $fields = array(
  54. 'fields[title][region]' => 'header',
  55. 'fields[post_date][region]' => 'header',
  56. 'fields[author][region]' => 'left',
  57. 'fields[body][region]' => 'right',
  58. 'fields[node_link][region]' => 'footer',
  59. );
  60. $this->dsConfigureUI($fields, 'admin/structure/types/manage/article/display/search_result');
  61. // Configure ds search.
  62. $edit = array('ds_user_override_search_page' => '1');
  63. $this->drupalPost('admin/structure/ds/list/search', $edit, t('Save configuration'));
  64. // Let's search.
  65. $this->drupalGet('search/content/title1');
  66. $this->assertNoRaw('/search/node/title1');
  67. $this->assertRaw('view-mode-search_result', 'Search view mode found');
  68. $this->assertRaw('group-left', 'Search template found');
  69. $this->assertRaw('group-right', 'Search template found');
  70. $this->assertNoText(t('Advanced search'), 'No advanced search found');
  71. $edit = array('ds_search_node_form_alter' => '1');
  72. $this->drupalPost('admin/structure/ds/list/search', $edit, t('Save configuration'));
  73. $this->drupalGet('search/content/title1');
  74. $this->assertText(t('Advanced search'), 'Advanced search found');
  75. // Search on user.
  76. // Configure user. We'll just do default.
  77. $layout = array(
  78. 'additional_settings[layout]' => 'ds_2col_stacked',
  79. );
  80. $assert = array(
  81. 'regions' => array(
  82. 'header' => '<td colspan="8">' . t('Header') . '</td>',
  83. 'left' => '<td colspan="8">' . t('Left') . '</td>',
  84. 'right' => '<td colspan="8">' . t('Right') . '</td>',
  85. 'footer' => '<td colspan="8">' . t('Footer') . '</td>',
  86. ),
  87. );
  88. $this->dsSelectLayout($layout, $assert, 'admin/config/people/accounts/display');
  89. $fields = array(
  90. 'fields[name][region]' => 'left',
  91. 'fields[summary][region]' => 'right',
  92. );
  93. $this->dsConfigureUI($fields, 'admin/config/people/accounts/display');
  94. $this->drupalGet('search/user/' . $this->admin_user->name);
  95. $this->assertRaw('view-mode-search_result', 'Search view mode found');
  96. $this->assertRaw('group-left', 'Search template found');
  97. $this->assertRaw('group-right', 'Search template found');
  98. // Test the group by settings.
  99. $article = array(
  100. 'title' => 'group article 1',
  101. 'type' => 'article',
  102. 'promote' => 1,
  103. );
  104. $this->drupalCreateNode($article);
  105. $page = array(
  106. 'title' => 'group page 1',
  107. 'type' => 'page',
  108. 'promote' => 1,
  109. );
  110. $this->drupalCreateNode($page);
  111. $this->cronRun();
  112. $edit = array(
  113. 'ds_search_group_by_type' => '1'
  114. );
  115. $this->drupalPost('admin/structure/ds/list/search', $edit, t('Save configuration'));
  116. // Let's search.
  117. $this->drupalGet('search/content/group');
  118. $this->assertRaw('Results for article');
  119. $this->assertRaw('Results for basic page');
  120. $edit = array(
  121. 'ds_search_group_by_type_settings[article][label]' => 'Article results',
  122. );
  123. $this->drupalPost('admin/structure/ds/list/search', $edit, t('Save configuration'));
  124. $this->drupalGet('search/content/group');
  125. $this->assertNoRaw('Results for article');
  126. $this->assertRaw('Article results');
  127. $this->assertRaw('Results for basic page');
  128. $edit = array(
  129. 'ds_search_group_by_type_settings[page][status]' => FALSE,
  130. 'ds_search_group_by_type_settings[article][label]' => '',
  131. );
  132. $this->drupalPost('admin/structure/ds/list/search', $edit, t('Save configuration'));
  133. $this->drupalGet('search/content/group');
  134. $this->assertNoRaw('Article results');
  135. $this->assertNoRaw('Results for basic page');
  136. $this->assertRaw('Other');
  137. }
  138. }