WebformShareNodeTest.php in Webform 8.5
File
modules/webform_share/tests/src/Functional/WebformShareNodeTest.php
View source
<?php
namespace Drupal\Tests\webform_share\Functional;
use Drupal\Tests\webform_node\Functional\WebformNodeBrowserTestBase;
use Drupal\webform\Entity\Webform;
class WebformShareNodeTest extends WebformNodeBrowserTestBase {
public static $modules = [
'webform',
'webform_node',
'webform_share',
];
public function testShare() {
global $base_url;
$config = \Drupal::configFactory()
->getEditable('webform.settings');
$webform = Webform::load('contact');
$node = $this
->createWebformNode('contact');
$nid = $node
->id();
$renderer = \Drupal::service('renderer');
$this
->drupalLogin($this->rootUser);
$this
->drupalGet('/webform/contact/share');
$this
->assertResponse(403);
$this
->drupalGet("/node/{$nid}/webform/share");
$this
->assertResponse(403);
$this
->drupalGet("/node/{$nid}/webform/share/preview");
$this
->assertResponse(403);
$config
->set('settings.default_share_node', TRUE)
->save();
$this
->drupalGet('/webform/contact/share');
$this
->assertResponse(200);
$this
->drupalGet("/node/{$nid}/webform/share");
$this
->assertResponse(200);
$this
->drupalGet("/node/{$nid}/webform/share/preview");
$this
->assertResponse(200);
$config
->set('settings.default_share_node', FALSE)
->save();
$webform
->setSetting('share_node', TRUE)
->save();
$this
->drupalGet('/webform/contact/share');
$this
->assertResponse(200);
$this
->drupalGet("/node/{$nid}/webform/share");
$this
->assertResponse(200);
$this
->drupalGet("/node/{$nid}/webform/share/preview");
$this
->assertResponse(200);
$build = [
'#type' => 'webform_share_script',
'#webform' => $webform,
'#source_entity' => $node,
];
$actual_script_tag = $renderer
->renderPlain($build);
$src = $base_url . "/webform/contact/share.js?source_entity_type=node&source_entity_id={$nid}";
$src = preg_replace('#^https?:#', '', $src);
$expected_script_tag = '<script src="' . $src . '"></script>' . PHP_EOL;
$this
->assertEqual($expected_script_tag, $actual_script_tag);
}
}