AutosaveIntegrationTest.php in Lightning Workflow 8.3
File
tests/src/Functional/AutosaveIntegrationTest.php
View source
<?php
namespace Drupal\Tests\lightning_workflow\Functional;
use Drupal\Component\Serialization\Json;
use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay;
use Drupal\Tests\BrowserTestBase;
class AutosaveIntegrationTest extends BrowserTestBase {
protected $defaultTheme = 'stark';
protected static $modules = [
'layout_builder',
'lightning_workflow',
];
protected function setUp() {
parent::setUp();
$this
->drupalPlaceBlock('local_tasks_block');
}
private function createContentTypes() {
$this
->drupalCreateContentType([
'type' => 'alpha',
'third_party_settings' => [
'lightning_workflow' => [
'autosave' => FALSE,
],
],
]);
$this
->drupalCreateContentType([
'type' => 'beta',
]);
$this
->drupalCreateContentType([
'type' => 'charlie',
'third_party_settings' => [
'lightning_workflow' => [
'autosave' => TRUE,
],
],
]);
}
private function assertExpectedConfig() {
$config = $this
->config('autosave_form.settings');
$this
->assertSame(20000, $config
->get('interval'));
$node_types = $config
->get('allowed_content_entity_types.node.bundles');
$this
->assertArrayNotHasKey('alpha', $node_types);
$this
->assertSame('beta', $node_types['beta']);
$this
->assertSame('charlie', $node_types['charlie']);
}
public function testNewNodeTypeIntegration() {
$this->container
->get('module_installer')
->install([
'autosave_form',
]);
$this
->createContentTypes();
$this
->assertExpectedConfig();
}
public function testPreExistingNodeTypeIntegration() {
$this
->createContentTypes();
$this->container
->get('module_installer')
->install([
'autosave_form',
]);
$this
->assertExpectedConfig();
}
public function testAutosaveDisabledInLayoutBuilder() {
$page = $this
->getSession()
->getPage();
$assert_session = $this
->assertSession();
$this
->testPreExistingNodeTypeIntegration();
LayoutBuilderEntityViewDisplay::load('node.charlie.default')
->enableLayoutBuilder()
->setOverridable(TRUE)
->save();
$this
->drupalLogin($this->rootUser);
$node = $this
->drupalCreateNode([
'type' => 'charlie',
]);
$this
->drupalGet($node
->toUrl('edit-form'));
$assert_session
->statusCodeEquals(200);
$this
->assertArrayHasKey('autosaveForm', $this
->getJsSettings());
$page
->clickLink('Layout');
$assert_session
->statusCodeEquals(200);
$this
->assertArrayNotHasKey('autosaveForm', $this
->getJsSettings());
}
private function getJsSettings() {
$settings = $this
->assertSession()
->elementExists('css', '[data-drupal-selector="drupal-settings-json"]')
->getText();
return Json::decode($settings);
}
}