You are here

public function SettingsFormTest::testConfiguration in Simple Facebook Pixel 8

Tests if configuration is possible.

File

tests/src/Functional/SettingsFormTest.php, line 90

Class

SettingsFormTest
Tests the settings form.

Namespace

Drupal\Tests\simple_facebook_pixel\Functional

Code

public function testConfiguration() {
  $this
    ->drupalGet('admin/modules');
  $this
    ->assertSession()
    ->responseContains('admin/config/system/simple-facebook-pixel');
  $this
    ->assertEquals(FALSE, $this
    ->config('simple_facebook_pixel.settings')
    ->get('pixel_enabled'));
  $this
    ->assertEquals('', $this
    ->config('simple_facebook_pixel.settings')
    ->get('pixel_id'));
  $this
    ->assertEquals([], $this
    ->config('simple_facebook_pixel.settings')
    ->get('excluded_roles'));
  $edit['pixel_enabled'] = FALSE;
  $edit['pixel_id'] = '456123';
  $edit['exclude_admin_pages'] = FALSE;
  $edit['excluded_roles[anonymous]'] = TRUE;
  $edit['excluded_roles[authenticated]'] = FALSE;
  $edit['complete_registration_enabled'] = FALSE;
  $this
    ->drupalPostForm('admin/config/system/simple-facebook-pixel', $edit, 'Save configuration');
  $this
    ->assertSession()
    ->responseContains('The configuration options have been saved.');
  $this
    ->assertEquals(FALSE, $this
    ->config('simple_facebook_pixel.settings')
    ->get('pixel_enabled'));
  $this
    ->assertEquals('456123', $this
    ->config('simple_facebook_pixel.settings')
    ->get('pixel_id'));
  $this
    ->assertEquals(FALSE, $this
    ->config('simple_facebook_pixel.settings')
    ->get('exclude_admin_pages'));
  $this
    ->assertEquals(FALSE, $this
    ->config('simple_facebook_pixel.settings')
    ->get('complete_registration_enabled'));
  $user_roles = $this->user
    ->getRoles(TRUE);
  $user_role = reset($user_roles);
  $roles = [
    'anonymous' => 'anonymous',
    'authenticated' => '0',
    $user_role => '0',
  ];
  $this
    ->assertSame($roles, $this
    ->config('simple_facebook_pixel.settings')
    ->get('excluded_roles'));
  $edit['pixel_enabled'] = TRUE;
  $edit['pixel_id'] = '876321';
  $edit['exclude_admin_pages'] = TRUE;
  $edit['excluded_roles[anonymous]'] = FALSE;
  $edit['excluded_roles[authenticated]'] = TRUE;
  $edit['complete_registration_enabled'] = TRUE;
  $this
    ->drupalPostForm('admin/config/system/simple-facebook-pixel', $edit, 'Save configuration');
  $this
    ->assertSession()
    ->responseContains('The configuration options have been saved.');
  $this
    ->assertEquals(TRUE, $this
    ->config('simple_facebook_pixel.settings')
    ->get('pixel_enabled'));
  $this
    ->assertEquals('876321', $this
    ->config('simple_facebook_pixel.settings')
    ->get('pixel_id'));
  $this
    ->assertEquals(TRUE, $this
    ->config('simple_facebook_pixel.settings')
    ->get('exclude_admin_pages'));
  $this
    ->assertEquals(TRUE, $this
    ->config('simple_facebook_pixel.settings')
    ->get('complete_registration_enabled'));
  $roles = [
    'authenticated' => 'authenticated',
    'anonymous' => '0',
    $user_role => '0',
  ];
  $this
    ->assertSame($roles, $this
    ->config('simple_facebook_pixel.settings')
    ->get('excluded_roles'));
  $edit['pixel_enabled'] = TRUE;
  $edit['pixel_id'] = '876321';
  $edit['view_content_entities[node:article]'] = TRUE;
  $edit['view_content_entities[node:page]'] = FALSE;
  $edit['view_content_entities[taxonomy_term:tags]'] = TRUE;
  $this
    ->drupalPostForm('admin/config/system/simple-facebook-pixel', $edit, 'Save configuration');
  $this
    ->assertSession()
    ->responseContains('The configuration options have been saved.');
  $this
    ->assertEquals(TRUE, $this
    ->config('simple_facebook_pixel.settings')
    ->get('pixel_enabled'));
  $this
    ->assertEquals('876321', $this
    ->config('simple_facebook_pixel.settings')
    ->get('pixel_id'));
  $view_content_entities = [
    'node:article' => 'node:article',
    'taxonomy_term:tags' => 'taxonomy_term:tags',
    'node:page' => '0',
  ];
  $this
    ->assertSame($view_content_entities, $this
    ->config('simple_facebook_pixel.settings')
    ->get('view_content_entities'));
}