You are here

function PropertiesTestCase::testPropertyFieldCreation in Dynamic properties 7

Test field creation functionality.

File

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

Class

PropertiesTestCase
Tests for fields integration.

Code

function testPropertyFieldCreation() {
  $this
    ->loginAdmin();
  $this
    ->createProperties();
  $this
    ->createField();

  // Create a single, separate attribute.
  $attribute = $this
    ->createAttribute();

  // 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.
  $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);
    }
  }

  // Change order of categories category, third category first.
  $edit[$this->field_prefix . '[listing][' . $this->categories[2]->name . '][_weight]'] = -10;

  // Move an attribute to a different category.
  $edit[$this
    ->getAttributeFormName($this->categories[0], $this->attributes[0][1], 'category')] = $this->categories[1]->name;
  $edit[$this
    ->getAttributeFormName($this->categories[0], $this->attributes[0][1], '_weight')] = 4;

  // Change weight of an attribute.
  $edit[$this
    ->getAttributeFormName($this->categories[0], $this->attributes[0][0], '_weight')] = 2;
  $edit[$this
    ->getAttributeFormName($this->categories[0], $this->attributes[0][2], '_weight')] = 0;
  $this
    ->drupalPost(NULL, $edit, t('Save'));

  // Make sure that the third category comes before the first.
  $this
    ->assertPattern('/' . $this->categories[2]->label . '.*' . $this->categories[0]->label . '/s', t('Third category is displayed before first.'));

  // Make sure that the moved attribute is shown in the correct category.
  // Meaning, after the last attribute in that category.
  $this
    ->assertPattern('/' . $this->attributes[1][2]->label . '.*' . $this->attributes[0][1]->label . '/s', t('Moved attribute is shown in the correct place.'));

  // Make sure the default order in category 2 is correct.
  $this
    ->assertPattern('/' . $this->categories[2]->label . '.*' . $this->attributes[2][0]->label . '.*' . $this->attributes[2][1]->label . '.*' . $this->attributes[2][2]->label . '/s', t('Default order in category 2 is correct.'));

  // Make sure the changed order in category 0 is correct.
  $this
    ->assertPattern('/' . $this->attributes[0][2]->label . '.*' . $this->attributes[0][0]->label . '/s', t('Changed order in category 0 is correct.'));

  // Try editing the content.
  $this
    ->clickLink('Edit');

  // Add a new attribute.
  $edit = array(
    $this->field_prefix . '[actions][attribute_category]' => $this->categories[1]->name,
    $this->field_prefix . '[actions][new_attribute]' => $attribute->name,
  );
  $this
    ->drupalPost(NULL, $edit, t('Add attribute'));
  $edit = array(
    $this
      ->getAttributeFormName($this->categories[1], $this->attributes[0][1], 'category') => $this->categories[0]->name,
    $this
      ->getAttributeFormName($this->categories[1], $this->attributes[0][1], '_weight') => 10,
    $this
      ->getAttributeFormName($this->categories[1], $attribute) => $value = $this
      ->randomName(20),
    $this
      ->getAttributeFormName($this->categories[1], $attribute, '_weight') => -10,
  );
  $this
    ->drupalPost(NULL, $edit, t('Save'));

  // Verify that the attribute was added.
  $this
    ->assertPattern('/' . $this->categories[1]->label . '.*' . $attribute->label . '.*' . $this->attributes[1][2]->label . '/s', t('Newly added attribute is shown in the correct category.'));

  // Verify that the moved attribute has been moved back.
  $this
    ->assertPattern('/' . $this->categories[0]->label . '.*' . $this->attributes[0][2]->label . '.*' . $this->attributes[0][0]->label . '.*' . $this->attributes[0][1]->label . '.*' . $this->categories[1]->label . '/s', t('Changed order in category 0 is correct.'));
}