function DrupalSolrNodeTestCase::testApacheSolrNodeReindex in Apache Solr Search 6.3
Same name and namespace in other branches
- 7 tests/apachesolr_base.test \DrupalSolrNodeTestCase::testApacheSolrNodeReindex()
File
- tests/apachesolr_base.test, line 519
- Unit test class that provides tests for base functionality of the Apachesolr
Module without having the need of a Solr Server
Class
- DrupalSolrNodeTestCase
Code
function testApacheSolrNodeReindex() {
$this
->drupalLogin($this->admin_user);
$types = array(
'page',
'story',
);
apachesolr_index_set_bundles('solr', 'node', $types);
content_clear_type_cache();
apachesolr_environments_clear_cache();
foreach ($types as $type) {
for ($i = 0; $i < 5; $i++) {
$edit = array();
$edit['uid'] = $this->admin_user->uid;
$edit['type'] = $type;
$edit['title'] = $this
->randomName(16);
$node = $this
->drupalCreateNode($edit);
}
}
$timestamp = 1382019301;
$env_id = apachesolr_default_environment();
apachesolr_environment_variable_set($env_id, 'apachesolr_index_last', array());
$table = apachesolr_get_indexer_table('node');
db_query("UPDATE {{$table}} SET changed = %d, status = 1", $timestamp);
apachesolr_set_last_index_position($env_id, 'node', $timestamp + 1, 10);
db_query("UPDATE {{$table}} SET changed = %d + 10, status = 1 WHERE entity_id <= 9", $timestamp);
$set = apachesolr_index_get_entities_to_index($env_id, 'node', 5);
$count = count($set);
$this
->assertEqual($count, 5, t('We found 5 entities to index.'));
$last_row = end($set);
apachesolr_set_last_index_position($env_id, 'node', $last_row->changed, $last_row->entity_id);
$set = apachesolr_index_get_entities_to_index($env_id, 'node', 4);
$count = count($set);
$this
->assertEqual($count, 4, t('We found 4 entities to index.'));
$last_row = end($set);
apachesolr_set_last_index_position($env_id, 'node', $last_row->changed, $last_row->entity_id);
$set = apachesolr_index_get_entities_to_index($env_id, 'node', 5);
$count = count($set);
$this
->assertEqual($count, 0, t('We found 0 entities to index.'));
}