You are here

function LocationCCKTest::addLocationContentType in Location 7.5

Same name and namespace in other branches
  1. 6.3 tests/location_cck.test \LocationCCKTest::addLocationContentType()
  2. 7.3 tests/location_cck.test \LocationCCKTest::addLocationContentType()
  3. 7.4 tests/location_cck.test \LocationCCKTest::addLocationContentType()

Overrides LocationTestCase::addLocationContentType

7 calls to LocationCCKTest::addLocationContentType()
LocationCCKTest::testCOWConservation in tests/location_cck.test
LocationCCKTest::testCreateLocation in tests/location_cck.test
Create a location via cck.
LocationCCKTest::testLocpickOnly in tests/location_cck.test
LocationCCKTest::testMultipleLocationOnSingleNode in tests/location_cck.test
LocationCCKTest::testNodeRevisionCleanup in tests/location_cck.test

... See full list

File

tests/location_cck.test, line 42

Class

LocationCCKTest

Code

function addLocationContentType(&$settings, $add = array()) {
  $field_name = 'loctest';

  // Let the caller mess with some relevant cck stuff.
  $required = isset($add['cck_required']) ? $add['cck_required'] : FALSE;
  $multiple = isset($add['cck_multiple']) ? $add['cck_multiple'] : 0;
  unset($add['cck_required']);
  unset($add['cck_multiple']);

  // find a non-existent random type name.
  do {
    $name = strtolower($this
      ->randomName(3, 'type_'));
  } while (node_get_types('type', $name));
  $form = array(
    'name' => $name,
    'type' => $name,
  );
  $this
    ->flattenPostData($form);

  //$add = array('location_settings' => $add);

  //$this->flattenPostData($add);

  //$settings = array_merge($settings, $add);
  $this
    ->drupalPost('admin/content/types/add', $form, 'Save content type');
  $this
    ->refreshVariables();
  $form = array(
    '_add_new_field' => array(
      'label' => 'Location',
      'weight' => 10,
      //        'hidden_name' => '_add_new_field',
      'field_name' => $field_name,
      'type' => 'location',
      'widget_type' => 'location',
    ),
  );
  $this
    ->flattenPostData($form);
  $this
    ->drupalPost('admin/content/node-type/' . str_replace('_', '-', $name) . '/fields', $form, 'Save');
  $this
    ->refreshVariables();
  drupal_get_schema(NULL, TRUE);

  // Get the (settable) defaults.
  $defaults = $this
    ->getLocationFieldDefaults();
  $form = array(
    'required' => $required,
    'multiple' => $multiple,
    'location_settings' => array(
      'form' => array(
        'fields' => $defaults,
      ),
    ),
  );
  $this
    ->flattenPostData($form);
  $add = array(
    'location_settings' => $add,
  );
  $this
    ->flattenPostData($add);
  $this
    ->drupalPost(NULL, $form, 'Save field settings');

  // @@@ This is stupid, but I don't know the api for pulling this stuff up.
  // @@@ _content_type_info() perhaps?
  $result = db_query("SELECT global_settings FROM {content_node_field} WHERE field_name = 'field_%s' AND type = 'location'", $field_name);
  $row = db_fetch_object($result);
  $settings = array();
  $settings = unserialize($row->global_settings);
  $settings = $settings['location_settings'];
  $this
    ->refreshVariables();

  // Reset the schema again, if it was a multiple value field added,
  // schema has a new table to worry about.
  drupal_get_schema(NULL, TRUE);

  // Reset the content type info in the context of the test framework.
  // This took me way too long to figure out.
  _content_type_info(TRUE);
  return $name;
}