function DrupalSolrNodeTestCase::testApacheSolrNodeAddDelete in Apache Solr Search 6.3
Same name and namespace in other branches
- 8 tests/apachesolr_base.test \DrupalSolrNodeTestCase::testApacheSolrNodeAddDelete()
- 7 tests/apachesolr_base.test \DrupalSolrNodeTestCase::testApacheSolrNodeAddDelete()
File
- tests/
apachesolr_base.test, line 472 - Unit test class that provides tests for base functionality of the Apachesolr Module without having the need of a Solr Server
Class
Code
function testApacheSolrNodeAddDelete() {
$this
->drupalLogin($this->admin_user);
// enable our bundles to be indexed, and clear caches
apachesolr_index_set_bundles('solr', 'node', array(
'page',
'story',
));
content_clear_type_cache();
apachesolr_environments_clear_cache();
// Define types of node bundles that we want to index
$types = array(
'page',
'story',
);
$table = apachesolr_get_indexer_table('node');
foreach ($types as $type) {
$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);
$this
->assertTrue(is_object($node) && isset($node->nid), t('Article type @type has been created.', array(
'@type' => $type,
)));
// Check that the node has been created.
$node = $this
->drupalGetNodeByTitle($edit['title']);
$this
->assertTrue($node, t('Created story @type found in database.', array(
'@type' => $type,
)));
// Check that the node has status 1
$query = "SELECT status FROM {{$table}} WHERE entity_id = %d";
$db_node_status = db_result(db_query($query, $node->nid));
$this
->assertEqual($db_node_status, 1, t('Node @entity_id has status 1', array(
'@entity_id' => $node->nid,
)));
// Delete the node
$this
->drupalPost('node/' . $node->nid . '/delete', array(), t('Delete'));
// check if the entity delete does its work. It should have set the
// status to 0 so it will be deleted when solr comes online
$query = "SELECT status FROM {{$table}} WHERE entity_id = %d";
$db_node_status = db_result(db_query($query, $node->nid));
$this
->assertEqual($db_node_status, 0, t('Node @entity_id has status 0', array(
'@entity_id' => $node->nid,
)));
// Check that all the nodes have been deleted.
$query = "SELECT count(*) as count FROM {node} WHERE nid = %d";
$count = db_result(db_query($query));
$this
->assertEqual($count, 0, t('No more nodes left in the node table.'));
}
}