public function AlterHooksTest::testAlterHooks in Simple Facebook Pixel 8
Tests alter hooks.
File
- tests/
src/ Functional/ AlterHooksTest.php, line 51
Class
- AlterHooksTest
- Tests the alter hooks.
Namespace
Drupal\Tests\simple_facebook_pixel\FunctionalCode
public function testAlterHooks() {
$edit['pixel_enabled'] = TRUE;
$edit['pixel_id'] = '567123';
$edit['view_content_entities[node:page]'] = TRUE;
$this
->drupalPostForm('admin/config/system/simple-facebook-pixel', $edit, 'Save configuration');
$this
->assertSession()
->responseContains('The configuration options have been saved.');
/** @var \Drupal\simple_facebook_pixel\PixelBuilderServiceInterface $pixel_builder */
$pixel_builder = \Drupal::service('simple_facebook_pixel.pixel_builder');
$this
->drupalGet('/node/1');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->responseContains('"content_name":"Test page #1"');
$this
->assertSession()
->responseContains($pixel_builder
->getPixelScriptCode());
$this
->assertSession()
->responseContains($pixel_builder
->getPixelNoScriptCode());
$this->container
->get('module_installer')
->install([
'simple_facebook_pixel_test_hooks',
]);
// @todo Remove invalidation once https://www.drupal.org/project/drupal/issues/2783791 is fixed.
Cache::invalidateTags([
'rendered',
]);
$altered_events_code = 'Altered title';
$altered_pixel_script_code = 'Appended script code text';
$altered_pixel_noscript_code = 'Appended noscript code text';
$this
->drupalGet('/node/1');
$this
->assertSession()
->responseNotContains('"content_name":"Test page #1"');
$this
->assertSession()
->responseContains($altered_events_code);
$this
->assertSession()
->responseContains($altered_pixel_script_code);
$this
->assertSession()
->responseContains($altered_pixel_noscript_code);
$this
->drupalLogout();
$this
->drupalGet('/node/1');
$this
->assertSession()
->responseContains($altered_events_code);
$this
->assertSession()
->responseContains($altered_pixel_script_code);
$this
->assertSession()
->responseContains($altered_pixel_noscript_code);
}