facetapi_test.plugins.inc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. /**
  3. * @file
  4. * Test adapter and plugins.
  5. */
  6. /**
  7. * Adapter for our test searcher.
  8. *
  9. * The test searcher does not connect to a backend, it just renders dummy data
  10. * every tom a search is executed. Facet API is not responsible for calculating
  11. * the facets, so for testing purposes this works just fine.
  12. */
  13. class FacetapiTestAdapter extends FacetapiAdapter {
  14. /**
  15. * The total number of results in the query.
  16. */
  17. protected $resultCount = 10;
  18. /**
  19. * Implements FacetapiAdapter::searchExecuted().
  20. */
  21. public function searchExecuted() {
  22. return !empty($this->keys);
  23. }
  24. /**
  25. * Implements FacetapiAdapter::suppressOutput().
  26. */
  27. public function suppressOutput($realm_name) {
  28. return FALSE;
  29. }
  30. /**
  31. * Overrides FacetapiAdapter::getSearchPath().
  32. */
  33. public function getSearchPath() {
  34. return 'facetapi_test/search';
  35. }
  36. /**
  37. * Sets the result count.
  38. *
  39. * The test searcher does not use the core pager APIs, so we use this method
  40. * to set a dummy value.
  41. *
  42. * @param int $count
  43. * The result count.
  44. *
  45. * @return FacetapiAdapter
  46. * An instance of this class.
  47. */
  48. public function setResultCount($count) {
  49. $this->resultCount = $count;
  50. return $this;
  51. }
  52. /**
  53. * Overrides FacetapiAdapter::getResultCount().
  54. */
  55. public function getResultCount() {
  56. return $this->resultCount;
  57. }
  58. }
  59. /**
  60. * Plugin for "term" query type.
  61. */
  62. class FacetapiTestTerm extends FacetapiQueryType implements FacetapiQueryTypeInterface {
  63. /**
  64. * Implements FacetapiQueryTypeInterface::getType().
  65. */
  66. static public function getType() {
  67. return 'term';
  68. }
  69. /**
  70. * Implements FacetapiQueryTypeInterface::execute().
  71. */
  72. public function execute($query) {
  73. // Nothing to do...
  74. }
  75. /**
  76. * Implements FacetapiQueryTypeInterface::build().
  77. */
  78. public function build() {
  79. $build = array();
  80. $build['testthree'] = array('#count' => 3);
  81. $build['testone'] = array('#count' => 1);
  82. $build['testtwo'] = array('#count' => 2);
  83. // Returns initialized build.
  84. return $build;
  85. }
  86. }
  87. /**
  88. * Plugin for "nonterm" query type.
  89. */
  90. class FacetapiTestNonterm extends FacetapiQueryType implements FacetapiQueryTypeInterface {
  91. /**
  92. * Implements FacetapiQueryTypeInterface::getType().
  93. */
  94. static public function getType() {
  95. return 'nonterm';
  96. }
  97. /**
  98. * Implements FacetapiQueryTypeInterface::execute().
  99. */
  100. public function execute($query) {
  101. // Nothing to do...
  102. }
  103. /**
  104. * Implements FacetapiQueryTypeInterface::build().
  105. */
  106. public function build() {
  107. $build = array();
  108. $build['testfour'] = array('#count' => 4);
  109. $build['testsix'] = array('#count' => 6);
  110. $build['testfive'] = array('#count' => 5);
  111. // Returns initialized build.
  112. return $build;
  113. }
  114. }
  115. /**
  116. * Plugin for dummy widget that only supports the "nonterm" query type.
  117. */
  118. class FacetapiTestWidgetNonterm extends FacetapiWidgetLinks {
  119. }