You are here

public function PropertiesAdministrationTestCase::testEditCategory in Dynamic properties 7

Tests for creating and editing a category.

File

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

Class

PropertiesAdministrationTestCase
Tests for fields integration.

Code

public function testEditCategory() {
  $this
    ->loginAdmin();

  /// Edit Attributes in Categories

  // Create 8 properties.
  $attributes = array();
  for ($i = 0; $i < 8; $i++) {
    $attributes[$i] = $this
      ->createAttribute();
  }

  // Create category with these existing attributes.
  $category = $this
    ->createCategory(drupal_strtolower($this
    ->randomName(8)), $this
    ->randomName(20), $attributes);

  // Create new attribute.
  $attribute = $this
    ->createAttribute();
  $inputfieldname = "attributes[" . $attributes[0]->name . "][attribute]";
  debug($inputfieldname);
  $editAttribute = array(
    $inputfieldname => $attribute->name,
  );

  // Replace existing attribute with the new attribute.
  $this
    ->drupalGet('admin/config/content/properties/categories');
  $this
    ->AssertText($category->name);
  $this
    ->clickLink(t('edit'));
  $this
    ->drupalPost(NULL, $editAttribute, t('Save'));

  // Now check if the attribute was added to that category.
  $cat = properties_sql_properties_category_load($category->name);
  $newAttributeInCategory = FALSE;
  $oldAttributeInCategory = FALSE;

  // As the order isn't given, I walk trough the list of attributes.
  foreach ($cat->attributes as $attr) {
    if ($attr->name === $attribute->name) {
      $newAttributeInCategory = TRUE;
    }
    if ($attr->name === $attributes[0]->name) {
      $oldAttributeInCategory = TRUE;
    }
  }
  $this
    ->AssertText(t('Category updated.'));

  // The new attribute should be in that category.
  $this
    ->AssertTrue(isset($cat->attributes[$attribute->name]));

  // The old shouldn't.
  $this
    ->AssertFalse(isset($cat->attributes[$attributes[0]->name]));

  // Delete created property again.
  $this
    ->drupalGet('admin/config/content/properties/categories');
  $this
    ->AssertText($category->name);
  $this
    ->clickLink(t('edit'));
  $inputfieldname = "attributes[" . $attribute->name . "][attribute]";
  $deleteAttribute = array(
    $inputfieldname => '',
  );
  $this
    ->drupalPost(NULL, $deleteAttribute, t('Save'));
  $cat = properties_sql_properties_category_load($category->name);
  $this
    ->AssertFalse(isset($cat->attributes[$attribute->name]));
}