function DrupalSolrQueryTests::testRemoveTerm in Apache Solr Search 5
Same name and namespace in other branches
- 6.2 tests/solr_base_query.test \DrupalSolrQueryTests::testRemoveTerm()
File
- tests/
solr_base_query.test, line 50
Class
Code
function testRemoveTerm() {
$result = TRUE;
$string = 'foo';
$query =& apachesolr_drupal_query($string, TRUE);
$query
->remove_field('', 'foo');
if (!$this
->assertEqual('foo', $query
->get_query())) {
$result = FALSE;
}
$string = 'foo bar';
$query =& apachesolr_drupal_query($string, TRUE);
$query
->remove_field('', 'foo');
if (!$this
->assertEqual('foo bar', $query
->get_query())) {
$result = FALSE;
}
$string = 'foo uid:1 bar';
$query =& apachesolr_drupal_query($string, TRUE);
$query
->remove_field('uid', '1');
if (!$this
->assertEqual('foo bar', $query
->get_query())) {
$result = FALSE;
}
$string = 'foo uid:1 bar';
$query =& apachesolr_drupal_query($string, TRUE);
$query
->remove_field('uid');
if (!$this
->assertEqual('foo bar', $query
->get_query())) {
$result = FALSE;
}
$string = 'foo uid:1 bar uid:2 tid:3';
$query =& apachesolr_drupal_query($string, TRUE);
$query
->remove_field('uid', '1');
/*// May not work because query doesn't necessarily get rebuilt in same order
if (!$this->assertEqual('foo bar uid:2 tid:3', $query->get_query())) {
$result = FALSE;
}*/
// Not very beautiful, but probably best way there is:
$pass = TRUE;
$components = array(
'foo',
'bar',
'uid:2',
'tid:3',
);
$q = $query
->get_query();
if (count($components) != count(explode(' ', $q))) {
$pass = FALSE;
}
else {
foreach ($components as $s) {
if (strpos($q, $s) === FALSE) {
$pass = false;
break;
}
}
}
if ($pass) {
$this
->assertEqual($q, $q);
}
else {
$this
->assertEqual('foo bar tid:3 uid:2', $q);
$result = FALSE;
}
$string = 'foo uid:1 bar uid:2 tid:3';
$query =& apachesolr_drupal_query($string, TRUE);
$query
->remove_field('uid');
if (!$this
->assertEqual('foo bar tid:3', $query
->get_query())) {
$result = FALSE;
}
return $result;
}