View source
<?php
namespace Drupal\Tests\webform\Functional\Settings;
use Drupal\Core\Serialization\Yaml;
use Drupal\webform\Entity\Webform;
use Drupal\Tests\webform\Functional\WebformBrowserTestBase;
use Drupal\webform\WebformInterface;
class WebformSettingsPathTest extends WebformBrowserTestBase {
public static $modules = [
'path',
'webform',
'node',
];
public function testPaths() {
$path_alias_repository = $this->container
->get('path_alias.repository');
$node = $this
->drupalCreateNode();
$webform = Webform::create([
'langcode' => 'en',
'status' => WebformInterface::STATUS_OPEN,
'id' => 'test_paths',
'title' => 'test_paths',
'elements' => Yaml::encode([
'test' => [
'#markup' => 'test',
],
]),
]);
$webform
->setSetting('draft', WebformInterface::DRAFT_ALL);
$webform
->save();
$webform_path = '/webform/' . $webform
->id();
$form_path = '/form/' . str_replace('_', '-', $webform
->id());
$this
->drupalLogin($this->rootUser);
$this
->assertIsArray($path_alias_repository
->lookupByAlias($form_path, 'en'));
$this
->assertIsArray($path_alias_repository
->lookupByAlias("{$form_path}/confirmation", 'en'));
$this
->assertIsArray($path_alias_repository
->lookupByAlias("{$form_path}/drafts", 'en'));
$this
->assertIsArray($path_alias_repository
->lookupByAlias("{$form_path}/submissions", 'en'));
$this
->drupalGet($webform_path);
$this
->assertResponse(200, 'Submit system path exists');
$this
->drupalGet($form_path);
$this
->assertResponse(200, 'Submit URL alias exists');
$this
->drupalGet("{$form_path}/confirmation");
$this
->assertResponse(200, 'Confirm URL alias exists');
$this
->drupalGet("{$form_path}/drafts");
$this
->assertResponse(200, 'Drafts URL alias exists');
$this
->drupalGet("{$form_path}/submissions");
$this
->assertResponse(200, 'Submissions URL alias exists');
$this
->drupalLogout();
$webform
->setSettings([
'page' => FALSE,
])
->save();
$this
->assertNull($path_alias_repository
->lookupByAlias($form_path, 'en'));
$this
->assertNull($path_alias_repository
->lookupByAlias("{$form_path}/confirmation", 'en'));
$this
->assertNull($path_alias_repository
->lookupByAlias("{$form_path}/drafts", 'en'));
$this
->assertNull($path_alias_repository
->lookupByAlias("{$form_path}/submissions", 'en'));
$this
->drupalGet($webform_path);
$this
->assertResponse(403, 'Submit system path access denied');
$this
->assertNoRaw('Only webform administrators are allowed to access this page and create new submissions.');
$this
->drupalGet($form_path);
$this
->assertResponse(404, 'Submit URL alias does not exist');
$this
->drupalGet($webform_path, [
'query' => [
'source_entity_type' => 'node',
'source_entity_id' => $node
->id(),
],
]);
$this
->assertResponse(403, 'Submit system path access denied');
$webform
->setSettings([
'form_prepopulate_source_entity' => TRUE,
])
->save();
$this
->drupalGet($webform_path, [
'query' => [
'source_entity_type' => 'node',
'source_entity_id' => $node
->id(),
],
]);
$this
->assertResponse(200, 'Submit system path exists');
$this
->drupalLogin($this->rootUser);
$this
->drupalGet($webform_path);
$this
->assertResponse(200, 'Submit system path access permitted');
$this
->assertRaw('Only webform administrators are allowed to access this page and create new submissions.');
$this
->drupalLogout();
$webform
->setSettings([
'page' => TRUE,
'page_submit_path' => 'page_submit_path',
'page_confirm_path' => 'page_confirm_path',
])
->save();
$this
->drupalGet('/page_submit_path');
$this
->assertResponse(200, 'Submit system path access permitted');
$this
->drupalGet('/page_confirm_path');
$this
->assertResponse(200, 'Submit URL alias access permitted');
$webform
->setSettings([
'page_submit_path' => '',
'page_confirm_path' => '',
])
->save();
$this
->drupalLogin($this->rootUser);
$this
->drupalPostForm('/admin/structure/webform/config', [
'page_settings[default_page_base_path]' => 'base/path',
], 'Save configuration');
$this
->drupalGet('/base/path/' . str_replace('_', '-', $webform
->id()));
$this
->assertResponse(200, 'Submit URL alias with custom base path exists');
$this
->drupalGet('/base/path/' . str_replace('_', '-', $webform
->id()) . '/confirmation');
$this
->assertResponse(200, 'Confirm URL alias with custom base path exists');
$webform
->setSettings([
'page' => FALSE,
])
->save();
$this
->drupalGet('/base/path/' . str_replace('_', '-', $webform
->id()));
$this
->assertResponse(404, 'Submit URL alias does not exist.');
$this
->drupalGet('/base/path/' . str_replace('_', '-', $webform
->id()) . '/confirmation');
$this
->assertResponse(404, 'Confirm URL alias does not exist.');
\Drupal::configFactory()
->getEditable('webform.settings')
->set('settings.default_page_base_path', '')
->save();
$webform = Webform::create([
'langcode' => 'en',
'status' => WebformInterface::STATUS_OPEN,
'id' => 'test_no_paths',
'title' => 'test_no_paths',
'elements' => Yaml::encode([
'test' => [
'#markup' => 'test',
],
]),
]);
$webform
->save();
$webform_path = '/webform/' . $webform
->id();
$form_path = '/form/' . str_replace('_', '-', $webform
->id());
$this
->drupalGet($webform_path);
$this
->assertResponse(200, 'Submit system path exists');
$this
->drupalGet($form_path);
$this
->assertResponse(404, 'Submit URL alias does not exist');
$this
->drupalLogin($this->rootUser);
$webform = Webform::create([
'langcode' => 'en',
'status' => WebformInterface::STATUS_OPEN,
'id' => 'test_admin_theme',
'title' => 'test_admin_theme',
'elements' => Yaml::encode([
'test' => [
'#markup' => 'test',
],
]),
]);
$webform
->save();
$this
->drupalGet('/webform/test_admin_theme');
$this
->assertNoRaw('seven');
\Drupal::service('theme_installer')
->install([
'seven',
]);
$edit = [
'admin_theme' => 'seven',
'use_admin_theme' => TRUE,
];
$this
->drupalPostForm('/admin/appearance', $edit, 'Save configuration');
$webform
->setSetting('page_theme_name', 'seven')
->save();
$this
->drupalGet('/webform/test_admin_theme');
$this
->assertRaw('seven');
}
}