Commit 40d534a0 authored by alexpott's avatar alexpott

Issue #2941494 by jhedstrom, Lendude: Deprecate SystemConfigFormTestBase and...

Issue #2941494 by jhedstrom, Lendude: Deprecate SystemConfigFormTestBase and create kernel test version
parent d9f93782
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
namespace Drupal\system\Tests\System; namespace Drupal\system\Tests\System;
@trigger_error('\Drupal\system\Tests\System\SystemConfigFormTestBase is deprecated in Drupal 8.6.0 and will be removed before Drupal 9.0.0. Use \Drupal\KernelTests\ConfigFormTestBase instead.', E_USER_DEPRECATED);
use Drupal\Core\Form\FormState; use Drupal\Core\Form\FormState;
use Drupal\simpletest\WebTestBase; use Drupal\simpletest\WebTestBase;
...@@ -10,6 +12,11 @@ ...@@ -10,6 +12,11 @@
* *
* @see UserAdminSettingsFormTest * @see UserAdminSettingsFormTest
* For a full working implementation. * For a full working implementation.
*
* @deprecated in Drupal 8.6.x and will be removed before Drupal 9.0.0. Use
* \Drupal\KernelTests\ConfigFormTestBase instead.
*
* @see https://www.drupal.org/node/2941907
*/ */
abstract class SystemConfigFormTestBase extends WebTestBase { abstract class SystemConfigFormTestBase extends WebTestBase {
/** /**
......
...@@ -2,15 +2,14 @@ ...@@ -2,15 +2,14 @@
namespace Drupal\Tests\system\Functional\Form; namespace Drupal\Tests\system\Functional\Form;
use Drupal\system\Tests\System\SystemConfigFormTestBase; use Drupal\Tests\BrowserTestBase;
use Drupal\form_test\FormTestObject;
/** /**
* Tests building a form from an object. * Tests building a form from an object.
* *
* @group Form * @group Form
*/ */
class FormObjectTest extends SystemConfigFormTestBase { class FormObjectTest extends BrowserTestBase {
/** /**
* Modules to enable. * Modules to enable.
...@@ -19,19 +18,6 @@ class FormObjectTest extends SystemConfigFormTestBase { ...@@ -19,19 +18,6 @@ class FormObjectTest extends SystemConfigFormTestBase {
*/ */
public static $modules = ['form_test']; public static $modules = ['form_test'];
protected function setUp() {
parent::setUp();
$this->form = new FormTestObject($this->container->get('config.factory'));
$this->values = [
'bananas' => [
'#value' => $this->randomString(10),
'#config_name' => 'form_test.object',
'#config_key' => 'bananas',
],
];
}
/** /**
* Tests using an object as the form callback. * Tests using an object as the form callback.
* *
......
<?php
namespace Drupal\Tests\system\Kernel\Form;
use Drupal\form_test\FormTestObject;
use Drupal\KernelTests\ConfigFormTestBase;
/**
* Tests building a form from an object.
*
* @group Form
*/
class FormObjectTest extends ConfigFormTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['form_test'];
protected function setUp() {
parent::setUp();
$this->form = new FormTestObject($this->container->get('config.factory'));
$this->values = [
'bananas' => [
'#value' => $this->randomString(10),
'#config_name' => 'form_test.object',
'#config_key' => 'bananas',
],
];
}
}
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
namespace Drupal\user\Tests; namespace Drupal\user\Tests;
use Drupal\system\Tests\System\SystemConfigFormTestBase; use Drupal\KernelTests\ConfigFormTestBase;
use Drupal\user\AccountSettingsForm; use Drupal\user\AccountSettingsForm;
/** /**
...@@ -10,8 +10,16 @@ ...@@ -10,8 +10,16 @@
* *
* @group user * @group user
*/ */
class UserAdminSettingsFormTest extends SystemConfigFormTestBase { class UserAdminSettingsFormTest extends ConfigFormTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['user', 'system'];
/**
* {@inheritdoc}
*/
protected function setUp() { protected function setUp() {
parent::setUp(); parent::setUp();
......
<?php
namespace Drupal\KernelTests;
use Drupal\Core\Form\FormState;
/**
* Full generic test suite for any form that data with the configuration system.
*
* @see UserAdminSettingsFormTest
* For a full working implementation.
*/
abstract class ConfigFormTestBase extends KernelTestBase {
/**
* Form ID to use for testing.
*
* @var \Drupal\Core\Form\FormInterface.
*/
protected $form;
/**
* Values to use for testing.
*
* Contains details for form key, configuration object name, and config key.
* Example:
* @code
* array(
* 'user_mail_cancel_confirm_body' => array(
* '#value' => $this->randomString(),
* '#config_name' => 'user.mail',
* '#config_key' => 'cancel_confirm.body',
* ),
* );
* @endcode
*
* @var array
*/
protected $values;
/**
* Submit the system_config_form ensure the configuration has expected values.
*/
public function testConfigForm() {
// Programmatically submit the given values.
$values = [];
foreach ($this->values as $form_key => $data) {
$values[$form_key] = $data['#value'];
}
$form_state = (new FormState())->setValues($values);
\Drupal::formBuilder()->submitForm($this->form, $form_state);
// Check that the form returns an error when expected, and vice versa.
$errors = $form_state->getErrors();
$valid_form = empty($errors);
$args = [
'%values' => print_r($values, TRUE),
'%errors' => $valid_form ? t('None') : implode(' ', $errors),
];
$this->assertTrue($valid_form, format_string('Input values: %values<br/>Validation handler errors: %errors', $args));
foreach ($this->values as $data) {
$this->assertEqual($data['#value'], $this->config($data['#config_name'])->get($data['#config_key']));
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment