You are here

protected function EckTestHelper::createEntity in Entity Construction Kit (ECK) 7.2

Create a test entity object.

Parameters

string $entity_type: The machine name of the entity type for this entity object; defaults to 'test_entity'.

string $bundle: The machine name of the bundle for this entity object; defaults to 'test_entity'.

array $args: Any arguments to be passed to the form. Key elements include.

  • title: Will be dynamically generated if not present.

Return value

object The entity that was created.

1 call to EckTestHelper::createEntity()
EckEntityTranslationTest::testTranslations in tests/EckEntityTranslationTest.test
Test translating an entity type.

File

tests/EckTestHelper.test, line 150
The EckTestHelper class.

Class

EckTestHelper
Helper logic for the other ECK tests.

Code

protected function createEntity($entity_type = 'test_entity', $bundle = 'test_entity', array $args = array()) {

  // Gotta have a title value.
  $args += array(
    'title' => $this
      ->randomSentence(3),
  );
  $this
    ->verbose(entity_get_info($entity_type));

  // Load the entity form.
  $this
    ->drupalGet("admin/structure/entity-type/{$entity_type}/{$bundle}/add");
  $this
    ->assertResponse(200);

  // Make sure all of the values have fields.
  foreach ($args as $field_name => $value) {
    $this
      ->assertFieldByName($field_name);
  }

  // Save the entity.
  $this
    ->drupalPost(NULL, $args, t('Save'));
  $this
    ->assertResponse(200);

  // Make sure the entity saved correctly.
  $this
    ->assertText($args['title']);

  // Return the entity ID.
  return $this
    ->getEntityIdFromPath();
}