public function FacebookTrackingPixelTestTrackingCase::testFacebookTrackingPixelDeleteNode in Facebook Tracking Pixel 8
Same name and namespace in other branches
- 7 tests/facebook_tracking_pixel.tracking.test \FacebookTrackingPixelTestTrackingCase::testFacebookTrackingPixelDeleteNode()
Test path tracking when nodes are deleted.
Scenarios tested: 1. Node created without alias 2. Add tracking to node/XX. 3. Node deleted. 4. Check status of tracking.
1. Node created with alias 2. Add trackign to alias 3. Node deleted. 4. Check status of tracking.
File
- tests/
facebook_tracking_pixel.tracking.test, line 231
Class
- FacebookTrackingPixelTestTrackingCase
- Test case.
Code
public function testFacebookTrackingPixelDeleteNode() {
// Create node to add tracking and then delete the node.
$node = $this
->drupalCreateNode();
$this
->assertTrue(!empty($node->nid), t('A basic page has been created with node ID %nid and title %title and path alias', [
'%nid' => $node->nid,
'%title' => $node->title,
]), t('FBTrkPx'));
$nid = $node->nid;
// Add a path tracking to the node created above.
$edit = [];
$edit['event_name'] = $this
->randomName(8);
$edit['event_path'] = 'node/' . $node->nid;
$edit['event_base_code_id'] = $this->baseCodeID;
$edit['event_type[addtocart]'] = TRUE;
$edit['event_type[lead]'] = TRUE;
$this
->drupalPost('admin/config/system/facebook_tracking_pixel/path/add', $edit, t('Save'));
$this
->assertText(t('Path tracking entry added.'), t('Path tracking text confirmation on page displayed after form submit. Path name %name added', [
'%name' => $edit['event_name'],
]), 'FBTrkPx');
// Delete node.
$this
->drupalGet('node/' . $node->nid . '/edit');
// Activate the delete button.
$this
->drupalPost(NULL, NULL, t('Delete'));
// Activate the confirmation delete button.
$this
->drupalPost(NULL, NULL, t('Delete'));
$this
->assertText(t('Basic page @title has been deleted.', [
'@title' => $node->title,
]), t('Test node deleted'), 'FBTrkPx');
// Check DB to see if tracking item is now showing as disabled.
$result = db_select('facebook_tracking_pixel_events_path', 'c')
->fields('c', [
'event_path_system',
'event_enable',
'event_id',
'event_uid',
])
->condition('event_path_system', 'node/' . $nid, '=')
->execute()
->fetchAssoc();
$this
->assertEqual($result['event_enable'], 0, t('Tracking event is disabled in database after node delete'), 'FBTrkPx');
// Check edit page to see if tracking item is now showing as disabled.
$this
->drupalGet('admin/config/system/facebook_tracking_pixel/path/edit/' . $result['event_id']);
$this
->assertText(t('This event is disabled because the path being tracked no longer exists. You may only update the path of this item to provide a new valid path.'), t('Tracking event is disabled in the UI after node delete.'), 'FBTrkPx');
// Make sure that the tracking code does not appear on any page.
$this
->drupalGet('');
$this
->assertNoRaw($result['event_uid'], t('Disabled tracking code does not appear on any page.'));
// Create node, add an alias, add tracking, and then delete the node.
$node = $this
->drupalCreateNode();
$this
->assertTrue(!empty($node->nid), t('A basic page has been created with node ID %nid and title %title and path alias', [
'%nid' => $node->nid,
'%title' => $node->title,
]), t('FBTrkPx'));
// Create alias for the node just created above.
$edit = [];
$edit['source'] = 'node/' . $node->nid;
$edit['alias'] = 'testernode';
$this
->drupalPost('admin/config/search/path/add', $edit, t('Save'));
$nid = $node->nid;
// Add a path tracking to the node created above.
$edit = [];
$edit['event_name'] = $this
->randomName(8);
$edit['event_path'] = 'node/' . $node->nid;
$edit['event_base_code_id'] = $this->baseCodeID;
$edit['event_type[addtocart]'] = TRUE;
$edit['event_type[lead]'] = TRUE;
$this
->drupalPost('admin/config/system/facebook_tracking_pixel/path/add', $edit, t('Save'));
$this
->assertText(t('Path tracking entry added.'), t('Path tracking text confirmation on page displayed after form submit. Path name %name added', [
'%name' => $edit['event_name'],
]), 'FBTrkPx');
// Delete node.
$this
->drupalGet('node/' . $node->nid . '/edit');
// Activate the delete button.
$this
->drupalPost(NULL, NULL, t('Delete'));
// Activate the confirmation delete button.
$this
->drupalPost(NULL, NULL, t('Delete'));
$this
->assertText(t('Basic page @title has been deleted.', [
'@title' => $node->title,
]), t('Test node deleted'), 'FBTrkPx');
// Check DB to see if tracking item is now showing as disabled.
$result = db_select('facebook_tracking_pixel_events_path', 'c')
->fields('c', [
'event_path_system',
'event_enable',
'event_id',
'event_uid',
])
->condition('event_path_system', 'node/' . $nid, '=')
->execute()
->fetchAssoc();
$this
->assertEqual($result['event_enable'], 0, t('Tracking event is disabled in database after node delete'), 'FBTrkPx');
// Check edit page to see if tracking item is now showing as disabled.
$this
->drupalGet('admin/config/system/facebook_tracking_pixel/path/edit/' . $result['event_id']);
$this
->assertText(t('This event is disabled because the path being tracked no longer exists. You may only update the path of this item to provide a new valid path.'), t('Tracking event is disabled in the UI after node delete.'), 'FBTrkPx');
// Make sure that the tracking code does not appear on any page.
$this
->drupalGet('');
$this
->assertNoRaw($result['event_uid'], t('Disabled tracking code does not appear on any page.'));
}