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
Code
function testApacheSolrNodeReindex() {
// Login as admin user to perform initial content creation.
$this
->drupalLogin($this->admin_user);
// Define types of node bundles that we want to index
$types = array(
'page',
'story',
);
// enable our bundles to be indexed, and clear caches
apachesolr_index_set_bundles('solr', 'node', $types);
content_clear_type_cache();
apachesolr_environments_clear_cache();
// Create 10 nodes (5 times 2)
foreach ($types as $type) {
for ($i = 0; $i < 5; $i++) {
$edit = array();
// Create a node of the type $type.
$edit['uid'] = $this->admin_user->uid;
$edit['type'] = $type;
$edit['title'] = $this
->randomName(16);
$node = $this
->drupalCreateNode($edit);
}
}
// Set a static timestamp
$timestamp = 1382019301;
$env_id = apachesolr_default_environment();
// Clear the last timestamp so we know that our nodes have to be indexed.
apachesolr_environment_variable_set($env_id, 'apachesolr_index_last', array());
// Set apachesolr_index_entities_node.changed to the same value
// (REQUEST_TIME).
$table = apachesolr_get_indexer_table('node');
db_query("UPDATE {{$table}} SET changed = %d, status = 1", $timestamp);
// Fake that we actually indexed before
apachesolr_set_last_index_position($env_id, 'node', $timestamp + 1, 10);
// Set the changed date to after our previous index cycle
db_query("UPDATE {{$table}} SET changed = %d + 10, status = 1 WHERE entity_id <= 9", $timestamp);
// Get the next 5 entities to index.
$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.'));
// Mark the last item from that 5 as last indexed.
$last_row = end($set);
apachesolr_set_last_index_position($env_id, 'node', $last_row->changed, $last_row->entity_id);
// Get the next batch of 5 and this should be 4 items.
$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.'));
// Mark the last item from that 4 as last indexed.
$last_row = end($set);
apachesolr_set_last_index_position($env_id, 'node', $last_row->changed, $last_row->entity_id);
// Get the next batch of 5 and this should be 0 items
$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.'));
}