/vendor/solarium/solarium/tests/Solarium/Tests/QueryType/Select/Query/Component/MoreLikeThisTest.php

https://gitlab.com/Blueprint-Marketing/solr-power · PHP · 229 lines · 163 code · 34 blank · 32 comment · 0 complexity · bdc85a5af6487f08a60dccd193be53b2 MD5 · raw file

  1. <?php
  2. /**
  3. * Copyright 2011 Bas de Nooijer. All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice,
  9. * this list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this listof conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  19. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  20. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  21. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  22. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  23. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  24. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  25. * POSSIBILITY OF SUCH DAMAGE.
  26. *
  27. * The views and conclusions contained in the software and documentation are
  28. * those of the authors and should not be interpreted as representing official
  29. * policies, either expressed or implied, of the copyright holder.
  30. */
  31. namespace Solarium\Tests\QueryType\Select\Query\Component;
  32. use Solarium\QueryType\Select\Query\Component\MoreLikeThis;
  33. use Solarium\QueryType\Select\Query\Query;
  34. class MoreLikeThisTest extends \PHPUnit_Framework_TestCase
  35. {
  36. /**
  37. * @var MoreLikeThis
  38. */
  39. protected $mlt;
  40. public function setUp()
  41. {
  42. $this->mlt = new MoreLikeThis;
  43. }
  44. public function testConfigMode()
  45. {
  46. $options = array(
  47. 'fields' => 'fieldA,fieldB',
  48. 'minimumtermfrequency' => 10,
  49. 'minimumdocumentfrequency' => 2,
  50. 'minimumwordlength' => 3,
  51. 'maximumwordlength' => 10,
  52. 'maximumqueryterms' => 4,
  53. 'maximumnumberoftokens' => 20,
  54. 'boost' => 1.5,
  55. 'queryfields' => 'fieldC,fieldD',
  56. 'count' => 5,
  57. );
  58. $this->mlt->setOptions($options);
  59. $this->assertEquals($options['fields'], $this->mlt->getFields());
  60. $this->assertEquals($options['minimumtermfrequency'], $this->mlt->getMinimumTermFrequency());
  61. $this->assertEquals($options['minimumdocumentfrequency'], $this->mlt->getMinimumDocumentFrequency());
  62. $this->assertEquals($options['minimumwordlength'], $this->mlt->getMinimumWordLength());
  63. $this->assertEquals($options['maximumwordlength'], $this->mlt->getMaximumWordLength());
  64. $this->assertEquals($options['maximumqueryterms'], $this->mlt->getMaximumQueryTerms());
  65. $this->assertEquals($options['boost'], $this->mlt->getBoost());
  66. $this->assertEquals($options['queryfields'], $this->mlt->getQueryFields());
  67. $this->assertEquals($options['count'], $this->mlt->getCount());
  68. }
  69. public function testGetType()
  70. {
  71. $this->assertEquals(Query::COMPONENT_MORELIKETHIS, $this->mlt->getType());
  72. }
  73. public function testGetResponseParser()
  74. {
  75. $this->assertInstanceOf(
  76. 'Solarium\QueryType\Select\ResponseParser\Component\MoreLikeThis',
  77. $this->mlt->getResponseParser()
  78. );
  79. }
  80. public function testGetRequestBuilder()
  81. {
  82. $this->assertInstanceOf(
  83. 'Solarium\QueryType\Select\RequestBuilder\Component\MoreLikeThis',
  84. $this->mlt->getRequestBuilder()
  85. );
  86. }
  87. public function testSetAndGetFields()
  88. {
  89. $value = 'name,description';
  90. $this->mlt->setFields($value);
  91. $this->assertEquals(
  92. array('name', 'description'),
  93. $this->mlt->getFields()
  94. );
  95. }
  96. public function testSetAndGetFieldsWithArray()
  97. {
  98. $value = array('name', 'description');
  99. $this->mlt->setFields($value);
  100. $this->assertEquals(
  101. $value,
  102. $this->mlt->getFields()
  103. );
  104. }
  105. public function testSetAndGetMinimumTermFrequency()
  106. {
  107. $value = 2;
  108. $this->mlt->setMinimumTermFrequency($value);
  109. $this->assertEquals(
  110. $value,
  111. $this->mlt->getMinimumTermFrequency()
  112. );
  113. }
  114. public function testMinimumDocumentFrequency()
  115. {
  116. $value = 4;
  117. $this->mlt->setMinimumDocumentFrequency($value);
  118. $this->assertEquals(
  119. $value,
  120. $this->mlt->getMinimumDocumentFrequency()
  121. );
  122. }
  123. public function testSetAndGetMinimumWordLength()
  124. {
  125. $value = 3;
  126. $this->mlt->setMinimumWordLength($value);
  127. $this->assertEquals(
  128. $value,
  129. $this->mlt->getMinimumWordLength()
  130. );
  131. }
  132. public function testSetAndGetMaximumWordLength()
  133. {
  134. $value = 15;
  135. $this->mlt->setMaximumWordLength($value);
  136. $this->assertEquals(
  137. $value,
  138. $this->mlt->getMaximumWordLength()
  139. );
  140. }
  141. public function testSetAndGetMaximumQueryTerms()
  142. {
  143. $value = 5;
  144. $this->mlt->setMaximumQueryTerms($value);
  145. $this->assertEquals(
  146. $value,
  147. $this->mlt->getMaximumQueryTerms()
  148. );
  149. }
  150. public function testSetAndGetMaximumNumberOfTokens()
  151. {
  152. $value = 5;
  153. $this->mlt->setMaximumNumberOfTokens($value);
  154. $this->assertEquals(
  155. $value,
  156. $this->mlt->getMaximumNumberOfTokens()
  157. );
  158. }
  159. public function testSetAndGetBoost()
  160. {
  161. $value = true;
  162. $this->mlt->setBoost($value);
  163. $this->assertEquals(
  164. $value,
  165. $this->mlt->getBoost()
  166. );
  167. }
  168. public function testSetAndGetQueryFields()
  169. {
  170. $value = 'content,name';
  171. $this->mlt->setQueryFields($value);
  172. $this->assertEquals(
  173. array('content', 'name'),
  174. $this->mlt->getQueryFields()
  175. );
  176. }
  177. public function testSetAndGetQueryFieldsWithArray()
  178. {
  179. $value = array('content', 'name');
  180. $this->mlt->setQueryFields($value);
  181. $this->assertEquals(
  182. $value,
  183. $this->mlt->getQueryFields()
  184. );
  185. }
  186. public function testSetAndGetCount()
  187. {
  188. $value = 8;
  189. $this->mlt->setCount($value);
  190. $this->assertEquals(
  191. $value,
  192. $this->mlt->getCount()
  193. );
  194. }
  195. }