function StatisticsAdminTest::testDeleteNode in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/statistics/src/Tests/StatisticsAdminTest.php \Drupal\statistics\Tests\StatisticsAdminTest::testDeleteNode()
Tests that when a node is deleted, the node counter is deleted too.
File
- core/
modules/ statistics/ src/ Tests/ StatisticsAdminTest.php, line 110 - Contains \Drupal\statistics\Tests\StatisticsAdminTest.
Class
- StatisticsAdminTest
- Tests the statistics admin.
Namespace
Drupal\statistics\TestsCode
function testDeleteNode() {
$this
->config('statistics.settings')
->set('count_content_views', 1)
->save();
$this
->drupalGet('node/' . $this->testNode
->id());
// Manually calling statistics.php, simulating ajax behavior.
$nid = $this->testNode
->id();
$post = array(
'nid' => $nid,
);
global $base_url;
$stats_path = $base_url . '/' . drupal_get_path('module', 'statistics') . '/statistics.php';
$this->client
->post($stats_path, array(
'form_params' => $post,
));
$result = db_select('node_counter', 'n')
->fields('n', array(
'nid',
))
->condition('n.nid', $this->testNode
->id())
->execute()
->fetchAssoc();
$this
->assertEqual($result['nid'], $this->testNode
->id(), 'Verifying that the node counter is incremented.');
$this->testNode
->delete();
$result = db_select('node_counter', 'n')
->fields('n', array(
'nid',
))
->condition('n.nid', $this->testNode
->id())
->execute()
->fetchAssoc();
$this
->assertFalse($result, 'Verifying that the node counter is deleted.');
}