Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 25 additions & 22 deletions uc_attribute/tests/uc_attribute.test
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@ require_once backdrop_get_path('module', 'uc_store') . '/tests/test_helper.inc';
*/
class UbercartAttributeTestCase extends UbercartTestHelper {

public static function getInfo() {
return array(
'name' => 'Attribute API',
'description' => 'Test the attribute API.',
'group' => 'Ubercart',
);
}

/**
* Overrides BackdropWebTestCase::setUp().
*/
Expand Down Expand Up @@ -60,7 +52,7 @@ class UbercartAttributeTestCase extends UbercartTestHelper {
$this->assertTrue(uc_attribute_subject_exists($attribute->aid, 'product', $product->nid));

// Test retrieval.
$loaded_attribute = uc_attribute_load($attribute->aid, $product->nid, 'product');
$loaded_attribute = uc_attribute_product_load($attribute->aid, $product->nid);

// Check the attribute integrity.
foreach (self::attributeFieldsToTest('product') as $field) {
Expand Down Expand Up @@ -88,7 +80,7 @@ class UbercartAttributeTestCase extends UbercartTestHelper {
$this->assertTrue(uc_attribute_subject_exists($attribute->aid, 'class', $product_class->pcid));

// Test retrieval.
$loaded_attribute = uc_attribute_load($attribute->aid, $product_class->pcid, 'class');
$loaded_attribute = uc_attribute_class_load($attribute->aid, $product_class->pcid);

// Check the attribute integrity.
foreach (self::attributeFieldsToTest('class') as $field) {
Expand Down Expand Up @@ -256,15 +248,17 @@ class UbercartAttributeTestCase extends UbercartTestHelper {
$this->assertFalse(uc_attribute_load($attribute->aid), t('Attribute was deleted properly.'));

// Sanity check!
$this->assertFalse(db_query("SELECT aid FROM {uc_attributes} WHERE aid = :aid", array(':aid' => $attribute->aid))->fetchField(), t('Attribute was seriously deleted properly!'));
$attribute_from_config = config_get('uc_attribute.attributes', "attributes.{$attribute->aid}");
$this->assertFalse(!empty($attribute_from_config), t('Attribute was seriously deleted properly!'));

// Test that options were deleted properly.
foreach ($options as $option) {
$this->assertFalse(db_query("SELECT oid FROM {uc_attribute_options} WHERE oid = :oid", array(':oid' => $option->oid))->fetchField(), t('Make sure options are deleted properly.'));
$option_from_config = config_get('uc_attribute.attributes', "attributes.{$attribute->aid}.options.{$option->oid}");
$this->assertFalse(!empty($option_from_config), t('Make sure options are deleted properly.'));
}

// Test the deletion applied to products too.
$loaded_product_attributes = uc_attribute_load_multiple(array(), 'product', $product->nid);
$loaded_product_attributes = uc_attribute_product_load_multiple(array(), $product->nid);

// We'll get all in $loaded_attributes above, without the original. (Which
// has been deleted.)
Expand Down Expand Up @@ -342,7 +336,14 @@ class UbercartAttributeTestCase extends UbercartTestHelper {
$types = _uc_attribute_display_types();
$this->assertRaw('<td>' . $types[$edit['display']] . '</td>', t('Verify display field.'));

$aid = db_query("SELECT aid FROM {uc_attributes} WHERE name = :name", array(':name' => $edit['name']))->fetchField();
$config = config('uc_attribute.attributes');
$attributes = $config->get('attributes');
foreach ($attributes as $attribute_aid => $attribute) {
if ($attribute['name'] = $edit['name']) {
$aid = $attribute_aid;
}
}

$this->assertTrue($aid, t('Attribute was created.'));

$attribute = uc_attribute_load($aid);
Expand Down Expand Up @@ -473,7 +474,7 @@ class UbercartAttributeTestCase extends UbercartTestHelper {

$this->backdropPost('admin/store/products/attributes/' . $attribute->aid . '/options/add', $edit, t('Submit'));

$option = db_query("SELECT * FROM {uc_attribute_options} WHERE aid = :aid", array(':aid' => $attribute->aid))->fetchObject();
$option = config_get('uc_attribute.attributes', "attributes.{$attribute->aid}.options");

$fields_ok = TRUE;
foreach ($edit as $field => $value) {
Expand Down Expand Up @@ -565,7 +566,7 @@ class UbercartAttributeTestCase extends UbercartTestHelper {
$this->showVar($edit);
$this->backdropPost('admin/store/products/classes/' . $class->pcid . '/attributes', $edit, t('Save changes'));

$attribute = uc_attribute_load($attribute->aid, $class->pcid, 'class');
$attribute = uc_attribute_class_load($attribute->aid, $class->pcid);

$fields_ok = TRUE;
foreach ($a as $field => $value) {
Expand Down Expand Up @@ -861,12 +862,14 @@ class UbercartAttributeTestCase extends UbercartTestHelper {
* @param $save
*/
public static function createAttributeOption($data = array(), $save = TRUE) {
$max_aid = db_select('uc_attributes', 'a')
->fields('a', array('aid'))
->orderBy('aid', 'DESC')
->range(0, 1)
->execute()
->fetchField();
$config = config('uc_attribute.attributes');
$attributes = $config->get('attributes');
$attribute_keys = is_array($attributes) ? array_keys($attributes) : array();
$max_aid = 1;
if (!empty($attribute_keys)) {
$max_aid = max($attribute_keys);
}

$option = $data + array(
'aid' => $max_aid,
'name' => BackdropWebTestCase::randomName(8),
Expand Down
Loading
Loading