You are here

public function WebformTemplatesTest::testTemplates in Webform 6.x

Same name and namespace in other branches
  1. 8.5 modules/webform_templates/tests/src/Functional/WebformTemplatesTest.php \Drupal\Tests\webform_templates\Functional\WebformTemplatesTest::testTemplates()

Tests webform templates.

File

modules/webform_templates/tests/src/Functional/WebformTemplatesTest.php, line 33

Class

WebformTemplatesTest
Tests for webform submission webform settings.

Namespace

Drupal\Tests\webform_templates\Functional

Code

public function testTemplates() {
  $user_account = $this
    ->drupalCreateUser([
    'access webform overview',
    'administer webform',
  ]);
  $admin_account = $this
    ->drupalCreateUser([
    'access webform overview',
    'administer webform',
    'administer webform templates',
  ]);

  // Login the user.
  $this
    ->drupalLogin($user_account);
  $template_webform = Webform::load('test_form_template');

  // Check the templates always will remain closed.
  $this
    ->assertTrue($template_webform
    ->isClosed());
  $template_webform
    ->setStatus(WebformInterface::STATUS_OPEN)
    ->save();
  $this
    ->assertTrue($template_webform
    ->isClosed());

  // Check template is included in the 'Templates' list display.
  $this
    ->drupalGet('/admin/structure/webform/templates');
  $this
    ->assertRaw('Test: Webform: Template');
  $this
    ->assertRaw('Test using a webform as a template.');

  // Check template is accessible to user with create webform access.
  $this
    ->drupalGet('/webform/test_form_template');
  $this
    ->assertResponse(200);
  $this
    ->assertRaw('You are previewing the below template,');

  // Check select template clears the description.
  $this
    ->drupalGet('/admin/structure/webform/manage/test_form_template/duplicate');
  $this
    ->assertFieldByName('description[value]', '');

  // Check that admin can not access manage templates.
  $this
    ->drupalGet('/admin/structure/webform/templates/manage');
  $this
    ->assertResponse(403);

  // Login the admin.
  $this
    ->drupalLogin($admin_account);

  // Check that admin can access manage templates.
  $this
    ->drupalGet('/admin/structure/webform/templates/manage');
  $this
    ->assertResponse(200);

  // Check select template clears the description.
  $this
    ->drupalGet('/admin/structure/webform/manage/test_form_template/duplicate', [
    'query' => [
      'template' => 1,
    ],
  ]);
  $this
    ->assertFieldByName('description[value]', 'Test using a webform as a template.');
}