You are here

semantic_fields.test in Semantic Fields 7

File

semantic_fields.test
View source
<?php

/**
 * @file
 * Tests for semantic_fields.module.
 */
class SemanticFieldsPermissionsTestCase extends DrupalWebTestCase {
  protected $privileged_user;
  protected $simple_user;
  public static function getInfo() {
    return array(
      'name' => 'Semantic Fields permissions',
      'description' => 'Test for permissions to administer Semantic Fields.',
      'group' => 'Semantic Fields',
    );
  }
  function setUp() {
    parent::setUp(array(
      'semantic_fields',
      'php',
    ));
    $this->privileged_user = $this
      ->drupalCreateUser(array(
      'administer semantic fields',
      'use PHP for settings',
    ));
    $this->simple_user = $this
      ->drupalCreateUser(array());
  }

  /**
   * Tests access to Semantic fields configuration.
   */
  function testPermission() {
    $this
      ->drupalLogin($this->privileged_user);
    $this
      ->drupalGet('admin/structure/semantic_fields');
    $this
      ->assertResponse(200, t('User allowed.'));

    // Create preset.
    $preset = testPreset('Ipsum');
    $this
      ->drupalPost('admin/structure/semantic_fields/add', $preset, t('Save'));
    $this
      ->assertText('ipsum has been created.', t('The ipsum preset were created'));

    // Import preset. @todo: make this work ...
    // $preset_import['import'] = testImportPreset();

    //$this->drupalPost('admin/structure/semantic_fields/import', $preset_import, t('Continue'));
    $this
      ->drupalLogin($this->simple_user);
    $this
      ->drupalGet('admin/structure/semantic_fields');
    $this
      ->assertResponse(403, t('User denied.'));
  }

}
function testImportPreset() {
  $preset = new stdClass();
  $preset->disabled = FALSE;
  $preset->api_version = 1;
  $preset->name = "ordered_list";
  $preset->admin_title = "Ordered list";
  $preset->description = "Display the content as an ordered list";
  $preset->data = array(
    "field_element" => "ol",
    "field_class" => "",
    "field_prefix" => "",
    "field_suffix" => "",
    "label_element_above" => "span",
    "label_class_above" => "",
    "label_suffix_above" => "",
    "label_element_inline" => "span",
    "label_class_inline" => "",
    "label_suffix_inline" => ":",
    "multiple_items_element" => "",
    "multiple_items_class" => "",
    "multiple_item_element" => "li",
    "multiple_item_class" => "",
    "multiple_item_separator" => "",
    "use_singlevalue_settings" => 0,
    "single_item_element" => "li",
    "single_item_class" => "",
    "last_every_nth" => "0",
    "first_class" => "first",
    "last_class" => "last",
    "striping_classes" => "odd even",
  );
  return $preset;
}
function testPreset($name) {
  $preset = array();
  $preset['admin_title'] = $name;
  $preset['name'] = 'ipsum';
  $preset['description'] = 'Ipsum preset';
  $preset['semantic_field_settings[field_element]'] = 'div';
  $preset['semantic_field_settings[field_class]'] = 'field-class';
  $preset['semantic_field_settings[field_prefix]'] = 'field prefix';
  $preset['semantic_field_settings[field_suffix]'] = 'field suffix';
  $preset['semantic_field_settings[label_element_above]'] = 'h3';
  $preset['semantic_field_settings[label_class_above]'] = 'label-class-above';
  $preset['semantic_field_settings[label_suffix_above]'] = 'label suffix above';
  $preset['semantic_field_settings[label_element_inline]'] = 'span';
  $preset['semantic_field_settings[label_class_inline]'] = 'label-class-inline';
  $preset['semantic_field_settings[label_suffix_inline]'] = ':';
  $preset['semantic_field_settings[multiple_items_element]'] = 'div';
  $preset['semantic_field_settings[multiple_items_class]'] = 'multiple-items-class';
  $preset['semantic_field_settings[multiple_item_element]'] = 'div';
  $preset['semantic_field_settings[multiple_item_class]'] = 'multiple-item-class';
  $preset['semantic_field_settings[multiple_item_separator]'] = 'multiple item seperator';
  $preset['semantic_field_settings[single_item_element]'] = 'div';
  $preset['semantic_field_settings[single_item_class]'] = 'single-item-class';
  $preset['semantic_field_settings[last_every_nth]'] = '0';
  $preset['semantic_field_settings[first_class]'] = 'first';
  $preset['semantic_field_settings[last_class]'] = 'last';
  $preset['semantic_field_settings[striping_classes]'] = 'odd even';
  return $preset;
}

Functions

Classes