public function WebformNodeAccessClosedTest::testAccessClosedT in Webform 8.5
Same name and namespace in other branches
- 6.x modules/webform_node/tests/src/Functional/Access/WebformNodeAccessClosedTest.php \Drupal\Tests\webform_node\Functional\Access\WebformNodeAccessClosedTest::testAccessClosedT()
Tests webform node closed access.
File
- modules/
webform_node/ tests/ src/ Functional/ Access/ WebformNodeAccessClosedTest.php, line 25
Class
- WebformNodeAccessClosedTest
- Tests for webform node closed access.
Namespace
Drupal\Tests\webform_node\Functional\AccessCode
public function testAccessClosedT() {
$node = $this
->createWebformNode('contact');
$nid = $node
->id();
$account = $this
->drupalCreateUser([
'access content',
]);
/**************************************************************************/
$this
->drupalLogin($account);
// Check webform node access allowed.
$this
->drupalGet('/node/' . $node
->id());
$this
->assertResponse(200);
$this
->assertFieldByName('name', $account
->getAccountName());
$this
->assertFieldByName('email', $account
->getEmail());
// Check webform access allowed with source entity.
$this
->drupalGet('/webform/contact', [
'query' => [
'source_entity_type' => 'node',
'source_entity_id' => $nid,
],
]);
$this
->assertResponse(200);
$this
->assertFieldByName('name', $account
->getAccountName());
$this
->assertFieldByName('email', $account
->getEmail());
// Close the webform via the node.
$node->webform->status = FALSE;
$node
->save();
// Check webform node access denied.
$this
->drupalGet('/node/' . $node
->id());
$this
->assertResponse(200);
$this
->assertNoFieldByName('name', $account
->getAccountName());
$this
->assertNoFieldByName('email', $account
->getEmail());
$this
->assertRaw('Sorry… This form is closed to new submissions.');
// Check webform access denied with source entity.
$this
->drupalGet('/webform/contact', [
'query' => [
'source_entity_type' => 'node',
'source_entity_id' => $nid,
],
]);
$this
->assertResponse(200);
$this
->assertNoFieldByName('name', $account
->getAccountName());
$this
->assertNoFieldByName('email', $account
->getEmail());
$this
->assertRaw('Sorry… This form is closed to new submissions.');
}