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 WebformSettingsFormTitleTest extends WebformBrowserTestBase {
public static $modules = [
'webform',
'node',
];
public function testTitle() {
$node = $this
->drupalCreateNode([
'title' => 'test_node',
]);
$webform = Webform::create([
'langcode' => 'en',
'status' => WebformInterface::STATUS_OPEN,
'id' => 'test_webform',
'title' => 'test_webform',
'elements' => Yaml::encode([
'test' => [
'#markup' => 'test',
],
]),
'settings' => [
'form_prepopulate_source_entity' => TRUE,
],
]);
$webform
->save();
$options = [
'query' => [
'source_entity_type' => 'node',
'source_entity_id' => $node
->id(),
],
];
$this
->drupalGet('/webform/test_webform');
$this
->assertRaw('<title>test_webform | Drupal</title>');
$this
->drupalGet('/webform/test_webform', $options);
$this
->assertRaw('<title>test_node: test_webform | Drupal</title>');
$webform
->setSetting('form_title', WebformInterface::TITLE_WEBFORM_SOURCE_ENTITY)
->save();
$this
->drupalGet('/webform/test_webform', $options);
$this
->assertRaw('<title>test_webform: test_node | Drupal</title>');
$webform
->setSetting('form_title', WebformInterface::TITLE_SOURCE_ENTITY)
->save();
$this
->drupalGet('/webform/test_webform', $options);
$this
->assertRaw('<title>test_node | Drupal</title>');
$webform
->setSetting('form_title', WebformInterface::TITLE_WEBFORM)
->save();
$this
->drupalGet('/webform/test_webform', $options);
$this
->assertRaw('<title>test_webform | Drupal</title>');
$webform
->setSetting('form_title', WebformInterface::TITLE_SOURCE_ENTITY_WEBFORM)
->save();
$this
->drupalGet('/webform/test_webform', $options);
$this
->assertRaw('<title>test_node: test_webform | Drupal</title>');
$webform
->set('title', 'test_node')
->save();
$this
->drupalGet('/webform/test_webform', $options);
$this
->assertRaw('<title>test_node | Drupal</title>');
}
}