You are here

public function PropertiesTemplateTestCase::testPropertyFieldCreation in Dynamic properties 7

Create a content based on a template.

File

properties_template/properties_template.test, line 164
Contains tests for the properties_template.module

Class

PropertiesTemplateTestCase
Tests for fields integration.

Code

public function testPropertyFieldCreation() {
  $this
    ->loginAdmin();
  $this
    ->createProperties();
  $this
    ->createField();
  $template = $this
    ->createTemplate(NULL, NULL, $this->categories);
  $this
    ->loginTemplateUser();

  // Verify that buttons to add attributes and categories don't exist.
  $this
    ->drupalGet('node/add/page');

  // Select template.
  $node = array(
    'title' => $this
      ->randomName(),
    $this->field_prefix . '[actions][template]' => $template->name,
  );
  $this
    ->drupalPost(NULL, $node, t('Select template'));

  // Fill in values.
  $values = array();
  $edit = array();
  foreach ($this->categories as $cid => $category) {
    foreach ($this->attributes[$cid] as $attribute) {
      $edit[$this
        ->getAttributeFormName($category, $attribute)] = $values[$attribute->name] = $this
        ->randomString(20);
    }
  }

  // Save content.
  $this
    ->drupalPost(NULL, $edit, t('Save'));

  // Build verification pattern.
  $pattern = array();
  foreach ($this->categories as $cid => $category) {
    $pattern[] = $category->label;
    foreach ($this->attributes[$cid] as $attribute) {
      $pattern[] = $attribute->label;
      $pattern[] = preg_quote(check_plain($values[$attribute->name]), '/');
    }
  }
  $pattern = '/' . implode('.*', $pattern) . '/s';
  $this
    ->assertPattern($pattern, t('Properties are displayed in correct order.'));
}