You are here

ds.forms.test in Display Suite 7

Same filename and directory in other branches
  1. 7.2 tests/ds.forms.test

Form layout tests.

File

tests/ds.forms.test
View source
<?php

/**
 * @file
 * Form layout tests.
 */
class dsFormTests extends dsBaseTest {

  /**
   * Implements getInfo().
   */
  public static function getInfo() {
    return array(
      'name' => t('Forms'),
      'description' => t('Tests for managing layouts on forms.'),
      'group' => t('Display suite'),
    );
  }

  /**
   * Forms tests.
   */
  function testDSForms() {

    // Register the article form.
    $this
      ->drupalGet('node/add/article');
    $edit = array(
      'elements[actions]' => TRUE,
      'elements[additional_settings]' => TRUE,
    );
    $this
      ->drupalPost('rel-register/nojs/article_node_form', $edit, t('Save'), array(
      'query' => array(
        'destination' => 'node/add/article',
      ),
    ));

    // Create a node.
    $node = $this
      ->drupalCreateNode(array(
      'type' => 'article',
      'promote' => FALSE,
    ));

    // Configure teaser layout.
    $form = array(
      'additional_settings[layout]' => 'ds_form',
    );
    $form_assert = array(
      'regions' => array(
        'header' => '<td colspan="8">' . t('Header') . '</td>',
        'left' => '<td colspan="8">' . t('Left') . '</td>',
        'right' => '<td colspan="8">' . t('Right') . '</td>',
        'footer' => '<td colspan="8">' . t('Footer') . '</td>',
      ),
    );
    $this
      ->dsSelectLayout($form, $form_assert, 'admin/structure/types/manage/article/fields');
    $fields = array(
      'fields[title][region]' => 'header',
      'fields[body][region]' => 'left',
      'fields[additional_settings][region]' => 'left',
      'fields[actions][region]' => 'right',
      'fields[field_image][region]' => 'right',
      'fields[field_tags][region]' => 'right',
      'fields[additional_settings][region]' => 'footer',
    );
    $this
      ->dsConfigureUI($fields, 'admin/structure/types/manage/article/fields');

    // Inspect the node.
    $this
      ->drupalGet('node/' . $node->nid . '/edit');
    $this
      ->assertRaw('ds-form"', 'ds-form class added');
    $this
      ->assertRaw('group-header', 'Template found (region header)');
    $this
      ->assertRaw('group-left', 'Template found (region left)');
    $this
      ->assertRaw('group-right', 'Template found (region right)');
    $this
      ->assertRaw('group-footer', 'Template found (region footer)');
    $this
      ->assertRaw('edit-title', 'Title field found');
    $this
      ->assertRaw('edit-submit', 'Submit field found');
    $this
      ->assertRaw('edit-field-tags-und', 'Tags field found');
    $this
      ->assertRaw('edit-log', 'Revision log found');

    // Hide the additional settings field.
    $fields = array(
      'fields[additional_settings][region]' => 'hidden',
    );
    $this
      ->dsConfigureUI($fields, 'admin/structure/types/manage/article/fields');
    $this
      ->drupalGet('node/' . $node->nid . '/edit');
    $this
      ->assertNoRaw('edit-log', 'Revision log hidden');

    // Check layout configuration.
    $layout_id = 'node|article|form';
    $this
      ->drupalPost('rel-unregister/nojs/article_node_form', array(), t('Confirm'), array(
      'query' => array(
        'destination' => 'admin/structure/rel',
      ),
    ));
    $record = db_query('SELECT id FROM {ds_layout_settings} WHERE  id = :id', array(
      ':id' => $layout_id,
    ))
      ->fetchField();
    $this
      ->assertTrue($record, 'Layout is not gone for node form after unregistration.');

    // Test on a non entity form - view modes form is registered in ds_test.
    $form = array(
      'additional_settings[layout]' => 'ds_form',
    );
    $form_assert = array(
      'regions' => array(
        'header' => '<td colspan="8">' . t('Header') . '</td>',
        'left' => '<td colspan="8">' . t('Left') . '</td>',
        'right' => '<td colspan="8">' . t('Right') . '</td>',
        'footer' => '<td colspan="8">' . t('Footer') . '</td>',
      ),
    );
    $this
      ->dsSelectLayout($form, $form_assert, 'admin/structure/rel/manage/ds_edit_view_mode_form');
    $fields = array(
      'fields[name][region]' => 'left',
      'fields[view_mode][region]' => 'left',
      'fields[entities][region]' => 'right',
      'fields[submit][region]' => 'right',
    );
    $this
      ->dsConfigureUI($fields, 'admin/structure/rel/manage/ds_edit_view_mode_form');

    // Inspect the view mode form.
    $this
      ->drupalGet('admin/structure/ds/view_modes/manage');
    $this
      ->assertRaw('ds-form"', 'ds-form class added');
    $this
      ->assertRaw('group-header', 'Template found (region header)');
    $this
      ->assertRaw('group-left', 'Template found (region left)');
    $this
      ->assertRaw('group-right', 'Template found (region right)');
    $this
      ->assertRaw('group-footer', 'Template found (region footer)');
    $this
      ->assertRaw('edit-view-mode', 'Label field found');
    $this
      ->assertRaw('edit-name', 'Machine field found');
    $this
      ->assertRaw('edit-submit', 'Submit button found');
    $this
      ->assertRaw('edit-entities', 'Entities checkboxes found');

    // Use the onsite registration of rel functionality.
    $this
      ->drupalGet('admin/structure/ds/fields/manage_custom');
    $edit = array(
      'elements[name]' => TRUE,
      'elements[field]' => TRUE,
      'elements[entities]' => TRUE,
      'elements[submit]' => TRUE,
      'elements[code]' => TRUE,
      'elements[use_token]' => TRUE,
    );
    $this
      ->drupalPost('rel-register/nojs/ds_edit_custom_field_form', $edit, t('Save'), array(
      'query' => array(
        'destination' => 'admin/structure/ds/fields/manage_custom',
      ),
    ));
    $form = array(
      'additional_settings[layout]' => 'ds_form',
    );
    $form_assert = array(
      'regions' => array(
        'header' => '<td colspan="8">' . t('Header') . '</td>',
        'left' => '<td colspan="8">' . t('Left') . '</td>',
        'right' => '<td colspan="8">' . t('Right') . '</td>',
        'footer' => '<td colspan="8">' . t('Footer') . '</td>',
      ),
    );
    $this
      ->dsSelectLayout($form, $form_assert, 'admin/structure/rel/manage/ds_edit_custom_field_form');
    $fields = array(
      'fields[name][region]' => 'left',
      'fields[field][region]' => 'left',
      'fields[submit][region]' => 'right',
      'fields[code][region]' => 'right',
      'fields[use_token][region]' => 'right',
      'fields[entities][region]' => 'right',
    );
    $this
      ->dsConfigureUI($fields, 'admin/structure/rel/manage/ds_edit_custom_field_form');

    // Inspect the code field form.
    $this
      ->drupalGet('admin/structure/ds/fields/manage_custom');
    $this
      ->assertRaw('ds-form"', 'ds-form class added');
    $this
      ->assertRaw('group-header', 'Template found (region header)');
    $this
      ->assertRaw('group-left', 'Template found (region left)');
    $this
      ->assertRaw('group-right', 'Template found (region right)');
    $this
      ->assertRaw('group-footer', 'Template found (region footer)');
    $this
      ->assertRaw('edit-field', 'Label field found');
    $this
      ->assertRaw('edit-name', 'Machine field found');
    $this
      ->assertRaw('edit-submit', 'Submit button found');
    $this
      ->assertRaw('edit-entities', 'Entities checkboxes found');
    $this
      ->assertRaw('edit-use-token', 'Token button found');
    $this
      ->assertRaw('edit-code', 'Code textarea found');

    // Check layout configuration.
    $layout_id = 'rel_build|ds_edit_custom_field_form|form';
    $record = db_query('SELECT id FROM {ds_layout_settings} WHERE  id = :id', array(
      ':id' => $layout_id,
    ))
      ->fetchField();
    $this
      ->assertTrue($record, 'Layout found for DS');
    $this
      ->drupalPost('rel-unregister/nojs/ds_edit_custom_field_form', array(), t('Confirm'), array(
      'query' => array(
        'destination' => 'admin/structure/ds/fields/manage_custom',
      ),
    ));
    $record = db_query('SELECT id FROM {ds_layout_settings} WHERE  id = :id', array(
      ':id' => $layout_id,
    ))
      ->fetchField();
    $this
      ->assertFalse($record, 'Layout is gone for contact form');
  }

}

Classes

Namesort descending Description
dsFormTests @file Form layout tests.