WebformNodeReferencesTest.php in Webform 8.5
File
modules/webform_node/tests/src/Functional/WebformNodeReferencesTest.php
View source
<?php
namespace Drupal\Tests\webform_node\Functional;
class WebformNodeReferencesTest extends WebformNodeBrowserTestBase {
public static $modules = [
'block',
'help',
'webform',
'webform_node',
];
protected static $testWebforms = [
'test_variant_multiple',
];
public function testReferences() {
global $base_path;
$this
->drupalLogin($this->rootUser);
$this
->drupalPlaceBlock('help_block');
$this
->drupalGet('/admin/structure/webform/manage/contact/references');
$this
->assertRaw('There are no webform node references.');
$this
->assertLink('Add Webform');
$this
->assertLinkByHref($base_path . 'node/add/webform?webform_id=contact');
$node = $this
->drupalCreateNode([
'type' => 'webform',
]);
$node->webform->target_id = 'contact';
$node
->save();
$this
->drupalGet('/admin/structure/webform/manage/contact/references');
$this
->assertNoRaw('There are no webform node references.');
$this
->assertLink($node
->label());
$this
->assertRaw('<li><a href="' . $base_path . 'node/add/webform?webform_id=contact" class="button button-action" data-drupal-link-query="{"webform_id":"contact"}" data-drupal-link-system-path="node/add/webform">Add Webform</a></li>');
$this
->drupalGet('/node/add/webform', [
'query' => [
'webform_id' => 'contact',
],
]);
$this
->assertFieldByName('webform[0][target_id]', 'contact');
$this
->drupalGet('/node/add/webform');
$this
->assertRaw('Webforms must first be <a href="' . $base_path . 'admin/structure/webform">created</a> before referencing them.');
$this
->drupalGet('/admin/structure/webform/manage/test_variant_multiple/references');
$this
->assertNoLinkByHref($base_path . 'node/add/webform?webform_id=test_variant_multiple');
$this
->assertLink('Add reference');
$this
->assertLinkByHref($base_path . 'admin/structure/webform/manage/test_variant_multiple/references/add');
$edit = [
'bundle' => 'webform',
'webform_title' => 'Testing 123',
'webform_default_data[letter]' => 'a',
'webform_default_data[number]' => '1',
];
$this
->drupalPostForm('/admin/structure/webform/manage/test_variant_multiple/references/add', $edit, 'Create content');
$this
->assertFieldByName('title[0][value]', 'Testing 123');
$this
->assertOptionSelected('edit-webform-0-target-id', 'test_variant_multiple');
$this
->assertRaw('>letter: a
number: '1'
</textarea>');
}
}