View source
<?php
namespace Drupal\Tests\webform\Functional;
use Drupal\webform\Entity\Webform;
class WebformThirdPartySettingsTest extends WebformBrowserTestBase {
public static $modules = [
'node',
'webform',
];
public function testThirdPartySettings() {
$webform = Webform::load('contact');
$this
->drupalLogin($this->rootUser);
$this
->assertNull($webform
->getThirdPartySetting('honeypot', 'honeypot'));
$webform = $this
->reloadWebform('contact');
$webform
->setThirdPartySetting('honeypot', 'honeypot', TRUE);
$webform
->save();
$webform = $this
->reloadWebform('contact');
$this
->assertTrue($webform
->getThirdPartySetting('honeypot', 'honeypot'));
$this
->drupalGet('/admin/structure/webform/config');
$this
->assertRaw('There are no third party settings available.');
$this
->drupalGet('/admin/structure/webform/manage/contact/settings');
$this
->assertNoRaw('Third party settings');
$this
->drupalPostForm('admin/modules', [
'modules[webform_test_third_party_settings][enable]' => TRUE,
], 'Install');
$this
->drupalGet('/admin/structure/webform/config');
$this
->assertNoRaw('There are no third party settings available.');
$this
->drupalGet('/admin/structure/webform/manage/contact/settings');
$this
->assertRaw('Third party settings');
$edit = [
'third_party_settings[webform_test_third_party_settings][message]' => 'Message for all webforms',
];
$this
->drupalPostForm('/admin/structure/webform/config', $edit, 'Save configuration');
$this
->drupalGet('/webform/contact');
$this
->assertRaw('Message for all webforms');
$this
->assertEqual('Message for all webforms', $this
->config('webform.settings')
->get('third_party_settings.webform_test_third_party_settings.message'));
$edit = [
'third_party_settings[webform_test_third_party_settings][message]' => 'Message for only this webform',
];
$this
->drupalPostForm('/admin/structure/webform/manage/contact/settings', $edit, 'Save');
$this
->drupalGet('/webform/contact');
$this
->assertRaw('Message for only this webform');
$webform = $this
->reloadWebform('contact');
$this
->assertTrue($webform
->getThirdPartySetting('honeypot', 'honeypot'));
$this
->assertNotNull($this
->config('webform.webform.contact')
->get('third_party_settings.webform_test_third_party_settings'));
$edit = [
'third_party_settings[webform_test_third_party_settings][message]' => '',
];
$this
->drupalPostForm('/admin/structure/webform/manage/contact/settings', $edit, 'Save');
$webform = $this
->reloadWebform('contact');
$this
->assertEqual([], $webform
->getThirdPartySettings('webform_test_third_party_settings'));
$this
->assertNull($this
->config('webform.webform.contact')
->get('third_party_settings.webform_test_third_party_settings'));
$this
->drupalPostForm('admin/modules/uninstall', [
'uninstall[webform_test_third_party_settings]' => TRUE,
], 'Uninstall');
$this
->drupalPostForm(NULL, [], 'Uninstall');
$this
->drupalGet('/webform/contact');
$this
->assertNoRaw('Message for only this webform');
$this
->assertNull($this
->config('webform.settings')
->get('third_party_settings.webform_test_third_party_settings.message'));
$this
->assertNull($this
->config('webform.settings')
->get('third_party_settings.webform_test_third_party_settings'));
}
}