You are here

public function YamlFormElementTableTest::test in YAML Form 8

Tests building of options elements.

File

src/Tests/YamlFormElementTableTest.php, line 24

Class

YamlFormElementTableTest
Tests for table elements.

Namespace

Drupal\yamlform\Tests

Code

public function test() {
  $yamlform = YamlForm::load('test_element_table');

  /**************************************************************************/

  // Table select sort.

  /**************************************************************************/

  // Check processing.
  $edit = [
    'yamlform_tableselect_sort_custom[one][weight]' => '4',
    'yamlform_tableselect_sort_custom[two][weight]' => '3',
    'yamlform_tableselect_sort_custom[three][weight]' => '2',
    'yamlform_tableselect_sort_custom[four][weight]' => '1',
    'yamlform_tableselect_sort_custom[five][weight]' => '0',
    'yamlform_tableselect_sort_custom[one][checkbox]' => TRUE,
    'yamlform_tableselect_sort_custom[two][checkbox]' => TRUE,
    'yamlform_tableselect_sort_custom[three][checkbox]' => TRUE,
    'yamlform_tableselect_sort_custom[four][checkbox]' => TRUE,
    'yamlform_tableselect_sort_custom[five][checkbox]' => TRUE,
  ];
  $this
    ->drupalPostForm('yamlform/test_element_table', $edit, t('Submit'));
  $this
    ->assertRaw("yamlform_tableselect_sort_custom:\n  - five\n  - four\n  - three\n  - two\n  - one");

  /**************************************************************************/

  // Table sort.

  /**************************************************************************/

  // Check processing.
  $edit = [
    'yamlform_table_sort_custom[one][weight]' => '4',
    'yamlform_table_sort_custom[two][weight]' => '3',
    'yamlform_table_sort_custom[three][weight]' => '2',
    'yamlform_table_sort_custom[four][weight]' => '1',
    'yamlform_table_sort_custom[five][weight]' => '0',
  ];
  $this
    ->drupalPostForm('yamlform/test_element_table', $edit, t('Submit'));
  $this
    ->assertRaw("yamlform_table_sort_custom:\n  - five\n  - four\n  - three\n  - two\n  - one");

  /**************************************************************************/

  // Export results.

  /**************************************************************************/
  $this
    ->drupalLogin($this->adminFormUser);
  $excluded_columns = $this
    ->getExportColumns($yamlform);
  unset($excluded_columns['yamlform_tableselect_sort_custom']);
  $this
    ->getExport($yamlform, [
    'options_format' => 'separate',
    'excluded_columns' => $excluded_columns,
  ]);
  $this
    ->assertRaw('"yamlform_tableselect_sort (custom): one","yamlform_tableselect_sort (custom): two","yamlform_tableselect_sort (custom): three","yamlform_tableselect_sort (custom): four","yamlform_tableselect_sort (custom): five"');
  $this
    ->assertRaw('5,4,3,2,1');
}