View source
<?php
namespace Drupal\system\Tests\Form;
use Drupal\Component\Serialization\Json;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\simpletest\WebTestBase;
class StateValuesCleanTest extends WebTestBase {
public static $modules = array(
'form_test',
);
function testFormStateValuesClean() {
$values = Json::decode($this
->drupalPostForm('form_test/form-state-values-clean', array(), t('Submit')));
$result = array(
'beer' => 1000,
'baz' => array(
'beer' => 2000,
),
);
$this
->assertFalse(isset($values['form_id']), format_string('%element was removed.', array(
'%element' => 'form_id',
)));
$this
->assertFalse(isset($values['form_token']), format_string('%element was removed.', array(
'%element' => 'form_token',
)));
$this
->assertFalse(isset($values['form_build_id']), format_string('%element was removed.', array(
'%element' => 'form_build_id',
)));
$this
->assertFalse(isset($values['op']), format_string('%element was removed.', array(
'%element' => 'op',
)));
$this
->assertFalse(isset($values['foo']), format_string('%element was removed.', array(
'%element' => 'foo',
)));
$this
->assertFalse(isset($values['bar']), format_string('%element was removed.', array(
'%element' => 'bar',
)));
$this
->assertFalse(isset($values['baz']['foo']), format_string('%element was removed.', array(
'%element' => 'foo',
)));
$this
->assertFalse(isset($values['baz']['baz']), format_string('%element was removed.', array(
'%element' => 'baz',
)));
$this
->assertFalse(isset($values['wine']), SafeMarkup::format('%element was removed.', [
'%element' => 'wine',
]));
$this
->assertTrue(isset($values['baz']['beer']), 'Nested form value still exists.');
$this
->assertEqual($values, $result, 'Expected form values equal actual form values.');
}
}