GridStackSettingsFormTest.php in GridStack 8        
                          
                  
                        
  
  
  
  
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;
  
  protected $messenger;
  
  public static $modules = [
    'system',
    'file',
    'image',
    'blazy',
    'gridstack',
    'gridstack_ui',
  ];
  
  protected function setUp() {
    parent::setUp();
    $this
      ->installConfig(static::$modules);
    $this->blazyManager = $this->container
      ->get('blazy.manager');
    $this->libraryDiscovery = $this->container
      ->get('library.discovery');
    $this->messenger = $this->container
      ->get('messenger');
    $this->gridstackSettingsForm = new GridStackSettingsForm($this->blazyManager
      ->getConfigFactory(), $this->libraryDiscovery, $this->messenger);
    
    $this->blazyManager
      ->getConfigFactory()
      ->getEditable('gridstack.settings')
      ->set('framework', 'bootstrap')
      ->save();
  }
  
  public function testGridStackSettingsForm() {
    
    $form_state = (new FormState())
      ->setValues([
      'customized' => TRUE,
    ]);
    $this
      ->assertInstanceOf(FormInterface::class, $this->gridstackSettingsForm);
    $this
      ->assertEquals('bootstrap', $this->blazyManager
      ->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);
  }
}