You are here

function DropdownAttributeTestCase::testClassAttributeDependency in Dropdown Attributes 6

Tests for dropdown attributes in product classes.

File

tests/uc_dropdown_attributes.test, line 106
Dropdown Attribute Tests

Class

DropdownAttributeTestCase
Tests for Dropdown Attributes.

Code

function testClassAttributeDependency() {
  $class = 'services';
  self::createProductClass($class);
  $this
    ->drupalGet('admin/store/products/classes');

  // Create two attributes.
  $parent_attribute = self::createAttribute(array(
    'display' => 1,
  ));
  $child_attribute = self::createAttribute(array(
    'display' => 1,
  ));

  // Attach the attributes to a product class.
  uc_attribute_subject_save($parent_attribute, 'class', $class);
  uc_attribute_subject_save($child_attribute, 'class', $class);

  // Add some options.
  $parent_options = array();
  $options = array();
  for ($i = 0; $i < 3; $i++) {
    $option = self::createAttributeOption(array(
      'aid' => $parent_attribute->aid,
    ));
    $parent_options[$option->oid] = $option;
    if ($i < 2) {
      $options[$option->oid] = $option->oid;
    }
    if ($i == 0) {
      $oid = $option->oid;
    }
  }
  $child_options = array();
  for ($i = 0; $i < 3; $i++) {
    $option = self::createAttributeOption(array(
      'aid' => $child_attribute->aid,
    ));
    $child_options[$option->oid] = $option;
  }

  // Add a product.
  $this
    ->createProductClassProduct($class);
  $nid = 2;

  // Check product class name.
  $pcid = uc_dropdown_attributes_get_type($nid);
  $this
    ->assertEqual($pcid, $class);

  // Check for child attribute.
  $this
    ->drupalGet('node/' . $nid);
  $this
    ->assertText($child_attribute->label, t('No dependency:  Child attribute found.'));

  // Create dependent attribute.
  uc_dropdown_attributes_class_create_dependency($class, $child_attribute->aid, $parent_attribute->aid, $options, 1);

  // Check type of dependency.
  $type = uc_dropdown_attributes_dependency_type($nid);
  $this
    ->assertEqual($type, 'class');

  // Confirm that the database is correct.
  $sql = 'SELECT parent_aid, parent_values, required
      FROM {uc_dropdown_classes} WHERE pcid="%s" AND aid=%d';
  $result = db_query($sql, $class, $child_attribute->aid);
  if ($item = db_fetch_object($result)) {
    $this
      ->assertEqual($item->parent_aid, $parent_attribute->aid);
    $this
      ->assertEqual(unserialize($item->parent_values), $options);
    $this
      ->assertEqual($item->required, 1);
  }

  // Check for child attribute (currently this is not much of a test).

  //$this->drupalGet('node/' . $nid);

  //$this->assertRaw('id="edit-attributes-2-wrapper">',

  //  t('Dependency:  Child attribute not found.'));
}