BlazySettingsFormTest.php in Blazy 8.2
File
tests/src/Kernel/Form/BlazySettingsFormTest.php
View source
<?php
namespace Drupal\Tests\blazy\Kernel\Form;
use Drupal\Core\Form\FormInterface;
use Drupal\Core\Form\FormState;
use Drupal\KernelTests\KernelTestBase;
use Drupal\blazy_ui\Form\BlazySettingsForm;
class BlazySettingsFormTest extends KernelTestBase {
protected $defaultTheme = 'stark';
protected $blazySettingsForm;
protected static $modules = [
'system',
'file',
'image',
'media',
'blazy',
'blazy_ui',
];
protected function setUp() {
parent::setUp();
$this
->installConfig(static::$modules);
$this->blazyManager = $this->container
->get('blazy.manager');
$this->blazySettingsForm = BlazySettingsForm::create($this->container);
}
public function testBlazySettingsForm() {
$form_state = (new FormState())
->setValues([
'admin_css' => TRUE,
'responsive_image' => FALSE,
]);
$this
->assertInstanceOf(FormInterface::class, $this->blazySettingsForm);
$this
->assertTrue($this->blazyManager
->getConfigFactory()
->get('blazy.settings')
->get('admin_css'));
$id = $this->blazySettingsForm
->getFormId();
$this
->assertEquals('blazy_settings_form', $id);
$method = new \ReflectionMethod(BlazySettingsForm::class, 'getEditableConfigNames');
$method
->setAccessible(TRUE);
$name = $method
->invoke($this->blazySettingsForm);
$this
->assertEquals([
'blazy.settings',
], $name);
$form = $this->blazySettingsForm
->buildForm([], $form_state);
$this->blazySettingsForm
->submitForm($form, $form_state);
}
}