CompleteRegistrationTest.php in Simple Facebook Pixel 8
File
tests/src/Functional/CompleteRegistrationTest.php
View source
<?php
namespace Drupal\Tests\simple_facebook_pixel\Functional;
use Drupal\Tests\BrowserTestBase;
class CompleteRegistrationTest extends BrowserTestBase {
public static $modules = [
'simple_facebook_pixel',
];
protected $defaultTheme = 'stark';
protected $configFactory;
protected function setUp() {
parent::setUp();
$this->configFactory = \Drupal::configFactory();
}
public function testUserCreationWhenEnabled() {
$this->configFactory
->getEditable('simple_facebook_pixel.settings')
->set('pixel_enabled', TRUE)
->set('pixel_id', '1234567890')
->set('complete_registration_enabled', TRUE)
->save();
$edit['name'] = $this
->randomMachineName();
$edit['mail'] = $edit['name'] . '@example.com';
$this
->drupalPostForm('user/register', $edit, 'Create new account');
$this
->assertText('A welcome message with further instructions has been sent to your email address.');
$pixel_builder = \Drupal::service('simple_facebook_pixel.pixel_builder');
$this
->assertSession()
->responseContains($pixel_builder
->getPixelScriptCode());
$this
->assertSession()
->responseContains('CompleteRegistration');
$this
->drupalGet('<front>');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->responseNotContains('CompleteRegistration');
}
public function testUserCreationWhenDisabled() {
$this->configFactory
->getEditable('simple_facebook_pixel.settings')
->set('pixel_enabled', TRUE)
->set('pixel_id', '1234567890')
->set('complete_registration_enabled', FALSE)
->save();
$edit['name'] = $this
->randomMachineName();
$edit['mail'] = $edit['name'] . '@example.com';
$this
->drupalPostForm('user/register', $edit, 'Create new account');
$this
->assertText('A welcome message with further instructions has been sent to your email address.');
$pixel_builder = \Drupal::service('simple_facebook_pixel.pixel_builder');
$this
->assertSession()
->responseContains($pixel_builder
->getPixelScriptCode());
$this
->assertSession()
->responseNotContains('CompleteRegistration');
}
}