DbLogFormInjectionTest.php in Drupal 10
File
core/modules/dblog/tests/src/Kernel/DbLogFormInjectionTest.php
View source
<?php
namespace Drupal\Tests\dblog\Kernel;
use Drupal\Core\DependencyInjection\DependencySerializationTrait;
use Drupal\Core\Form\FormInterface;
use Drupal\Core\Form\FormState;
use Drupal\Core\Form\FormStateInterface;
use Drupal\KernelTests\KernelTestBase;
use Drupal\user\Entity\User;
class DbLogFormInjectionTest extends KernelTestBase implements FormInterface {
use DependencySerializationTrait;
protected $logger;
protected static $modules = [
'system',
'dblog',
'user',
];
public function getFormId() {
return 'dblog_test_injection_form';
}
public function process($element) {
return $element;
}
public function buildForm(array $form, FormStateInterface $form_state) {
$form['#process'][] = [
$this,
'process',
];
return $form;
}
public function validateForm(array &$form, FormStateInterface $form_state) {
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$form_state
->setRebuild();
}
protected function setUp() : void {
parent::setUp();
$this
->installSchema('dblog', [
'watchdog',
]);
$this
->installSchema('system', [
'sequences',
]);
$this
->installEntitySchema('user');
$this->logger = \Drupal::logger('test_logger');
$test_user = User::create([
'name' => 'foobar',
'mail' => 'foobar@example.com',
]);
$test_user
->save();
\Drupal::service('current_user')
->setAccount($test_user);
}
public function testLoggerSerialization() {
$form_state = new FormState();
$form_state
->setRequestMethod('POST');
$form_state
->setCached();
$form_builder = $this->container
->get('form_builder');
$form_id = $form_builder
->getFormId($this, $form_state);
$form = $form_builder
->retrieveForm($form_id, $form_state);
$form_builder
->prepareForm($form_id, $form, $form_state);
$form_builder
->processForm($form_id, $form, $form_state);
}
}