You are here

function PropertiesBaseTestCase::createEntity in Dynamic properties 7

Create a page node with properties attached to it.

Parameters

$path: Path the the create form, defaults to node/add/page.

$save: Name

2 calls to PropertiesBaseTestCase::createEntity()
PropertiesCompareTestCase::testPropertyFieldCreation in properties_compare/properties_compare.test
Test comparing to similiar nodes.
PropertiesTemplateTestCase::testExportAsTemplate in properties_template/properties_template.test
Test for exporting a content as template.

File

./properties.test, line 218
Contains tests for the properties.module

Class

PropertiesBaseTestCase
Base class for properties tests, provides helper methods.

Code

function createEntity($path = 'node/add/page', $save = NULL, $entity = 'node') {

  // Add first category.
  $node = array(
    'title' => $this
      ->randomName(),
    $this->field_prefix . '[actions][new_category]' => $this->categories[0]->name,
  );
  $this
    ->drupalPost('node/add/page', $node, t('Add category'));

  // Next category.
  $category = array(
    $this->field_prefix . '[actions][new_category]' => $this->categories[1]->name,
  );
  $this
    ->drupalPost(NULL, $category, t('Add category'));

  // Last category.
  $category = array(
    $this->field_prefix . '[actions][new_category]' => $this->categories[2]->name,
  );
  $this
    ->drupalPost(NULL, $category, t('Add category'));

  // Fill in values.
  $edit = array();
  foreach ($this->categories as $cid => $category) {
    foreach ($this->attributes[$cid] as $attribute) {
      $edit[$this
        ->getAttributeFormName($category, $attribute)] = $this
        ->randomString(20);
    }
  }
  if (empty($save)) {
    $save = t('Save');
  }
  $this
    ->drupalPost(NULL, $edit, $save);

  // Get node id and return it.
  if (preg_match('|node/([0-9]+)|', $this
    ->getUrl(), $match)) {
    $entity = entity_load($entity, array(
      $match[1],
    ));
    return reset($entity);
  }
}