GridStackSettingsFormTest.php in GridStack 8.2
File
tests/src/Kernel/Form/GridStackSettingsFormTest.php
View source
<?php
namespace Drupal\Tests\gridstack\Kernel\Form;
use Drupal\Core\Form\FormInterface;
use Drupal\Core\Form\FormState;
use Drupal\KernelTests\KernelTestBase;
use Drupal\gridstack_ui\Form\GridStackSettingsForm;
class GridStackSettingsFormTest extends KernelTestBase {
protected $gridstackSettingsForm;
protected $libraryDiscovery;
public static $modules = [
'system',
'file',
'image',
'media',
'blazy',
'gridstack',
'gridstack_ui',
];
protected function setUp() {
parent::setUp();
$this
->installConfig(static::$modules);
$this->manager = $this->container
->get('gridstack.manager');
$this->libraryDiscovery = $this->container
->get('library.discovery');
$this->gridstackSettingsForm = GridStackSettingsForm::create($this->container);
$this->manager
->getConfigFactory()
->getEditable('gridstack.settings')
->set('framework', 'bootstrap')
->save();
}
public function testGridStackSettingsForm() {
$form_state = (new FormState())
->setValues([
'optimized' => TRUE,
]);
$this
->assertInstanceOf(FormInterface::class, $this->gridstackSettingsForm);
$this
->assertEquals('bootstrap', $this->manager
->getConfigFactory()
->get('gridstack.settings')
->get('framework'));
$id = $this->gridstackSettingsForm
->getFormId();
$this
->assertEquals('gridstack_settings_form', $id);
$method = new \ReflectionMethod(GridStackSettingsForm::class, 'getEditableConfigNames');
$method
->setAccessible(TRUE);
$name = $method
->invoke($this->gridstackSettingsForm);
$this
->assertEquals([
'gridstack.settings',
], $name);
$form = $this->gridstackSettingsForm
->buildForm([], $form_state);
$this->gridstackSettingsForm
->submitForm($form, $form_state);
}
}