function DrupalSolrNodeTestCase::testApacheSolrNodeAddDelete in Apache Solr Search 7
Same name and namespace in other branches
- 8 tests/apachesolr_base.test \DrupalSolrNodeTestCase::testApacheSolrNodeAddDelete()
- 6.3 tests/apachesolr_base.test \DrupalSolrNodeTestCase::testApacheSolrNodeAddDelete()
File
- tests/apachesolr_base.test, line 406
- 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 testApacheSolrNodeAddDelete() {
$permissions = array(
'access content',
'search content',
'administer nodes',
'administer search',
'access content overview',
'bypass node access',
);
$admin_user = $this
->drupalCreateUser($permissions);
$this
->drupalLogin($admin_user);
apachesolr_index_set_bundles('solr', 'node', array(
'page',
'article',
));
entity_info_cache_clear();
apachesolr_environments_clear_cache();
$types = array(
'page',
'article',
);
foreach ($types as $type) {
$edit = array();
$edit['uid'] = $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,
)));
$node = $this
->drupalGetNodeByTitle($edit['title']);
$this
->assertTrue($node, t('Created article @type found in database.', array(
'@type' => $type,
)));
$indexer_table = apachesolr_get_indexer_table('node');
$query = db_select($indexer_table, 'aien')
->condition('entity_id', $node->nid)
->fields('aien', array(
'entity_id',
'status',
));
$db_node = $query
->execute()
->fetchObject();
$this
->assertEqual($db_node->status, 1, t('Node @entity_id has status 1', array(
'@entity_id' => $db_node->entity_id,
)));
$this
->drupalPost('node/' . $node->nid . '/delete', array(), t('Delete'));
$indexer_table = apachesolr_get_indexer_table('node');
$nodes_in_tracking_table = db_select($indexer_table, 'aien')
->condition('entity_id', $node->nid)
->countQuery()
->execute()
->fetchField();
if ($nodes_in_tracking_table > 0) {
$db_node = db_select($indexer_table, 'aien')
->condition('entity_id', $node->nid)
->fields('aien', array(
'entity_id',
'status',
))
->execute()
->fetchObject();
$this
->assertEqual($db_node->status, 0, t('Node @entity_id has status 0', array(
'@entity_id' => $db_node->entity_id,
)));
}
else {
$this
->assertEqual($nodes_in_tracking_table, 0, t('No more nodes in the tracking table'));
}
$count = db_select('node', 'n')
->condition('n.nid', $node->nid)
->countQuery()
->execute()
->fetchField();
$this
->assertEqual($count, 0, t('No more nodes left in the node table.'));
}
}