You are here

public function PartyBaseTestCase::createTestProfile2 in Party 7

Same name and namespace in other branches
  1. 8.2 tests/party.test \PartyBaseTestCase::createTestProfile2()

Create a test profile2 type and return the profile2 type machine name.

2 calls to PartyBaseTestCase::createTestProfile2()
PartyAccessTestCase::setUp in tests/party_access.test
Set up the testing environment.
PartyPrimaryFieldsTestCase::setUp in tests/party_primary_fields.test
Set up the testing environment.

File

tests/party.test, line 50
Tests for the Party module.

Class

PartyBaseTestCase
Base class for all Party tests.

Code

public function createTestProfile2() {
  $label = 'Party Test Profile2';
  $machine_name = 'party_test_profile2';
  $profile_type = new ProfileType(array(
    'type' => $machine_name,
    'label' => $label,
    'weight' => 0,
  ));
  profile2_type_save($profile_type);

  // Clear Profile2 cache.
  profile2_load_multiple(FALSE, array(), TRUE);

  // Clear the Data Set cache.
  $this
    ->assertNotNull(party_get_data_set_info(NULL, TRUE), "Data Set has been created for profile2 type {$label}");

  // Add a field to Party Test type.
  $field = array(
    'field_name' => 'party_test_field',
    'type' => 'text',
    'cardinality' => 1,
    'translatable' => FALSE,
  );
  field_create_field($field);
  $instance = array(
    'entity_type' => 'profile2',
    'field_name' => 'party_test_field',
    'bundle' => $machine_name,
    'label' => 'Party Test Field',
    'description' => 'Party Test Field - Text type.',
    'widget' => array(
      'type' => 'text_textfield',
      'weight' => 0,
    ),
  );
  field_create_instance($instance);

  // Clear all caches
  drupal_flush_all_caches();

  // @todo: Check permission have been created for the new data set.
  $this
    ->checkPermissions(array(
    'attach party profile2_' . $machine_name,
  ), TRUE);
  return $machine_name;
}