'Products', 'description' => 'Ensure that the product content types provided function properly.', 'group' => 'Ubercart', ); } public function setUp() { parent::setUp('uc_product'); $this->privileged_user = $this->drupalCreateUser(array('administer products', 'administer product classes', 'create product content', 'edit any product content', 'delete any product content')); $this->drupalLogin($this->privileged_user); } public function testProductNodeForm() { $this->drupalGet('node/add/product'); foreach (array('model', 'list_price', 'cost', 'sell_price', 'shippable', 'weight', 'weight_units', 'dim_length', 'dim_width', 'dim_height', 'length_units', 'pkg_qty', 'default_qty', 'ordering') as $field) { $this->assertFieldByName($field); } $body_key = 'body[und][0][value]'; // Make a node with those fields. $edit = array( 'title' => $this->randomName(32), $body_key => $this->randomName(64), 'model' => $this->randomName(8), 'list_price' => mt_rand(1, 200), 'cost' => mt_rand(0, 100), 'sell_price' => mt_rand(1, 150), 'shippable' => mt_rand(0, 1), 'weight' => mt_rand(1, 50), 'weight_units' => array_rand(array( 'lb' => t('Pounds'), 'kg' => t('Kilograms'), 'oz' => t('Ounces'), 'g' => t('Grams'), )), 'dim_length' => mt_rand(1, 50), 'dim_width' => mt_rand(1, 50), 'dim_height' => mt_rand(1, 50), 'length_units' => array_rand(array( 'in' => t('Inches'), 'ft' => t('Feet'), 'cm' => t('Centimeters'), 'mm' => t('Millimeters'), )), ); $this->drupalPost('node/add/product', $edit, t('Save')); $this->assertText(t('Product @title has been created.', array('@title' => $edit['title']))); $this->assertText($edit[$body_key], 'Product body found.'); $this->assertText(t('SKU: @model', array('@model' => $edit['model'])), 'Product model found.'); $this->assertText(t('Price: @price', array('@price' => uc_currency_format($edit['sell_price']))), 'Product sell price found.'); $this->assertNoUniqueText(uc_currency_format($edit['sell_price']), 'Price appears more than once.'); } public function testProductClassForm() { // Try making a new product class. $class = $this->randomName(12); $type = strtolower($class); $edit = array( 'pcid' => $class, 'name' => $class, 'description' => $this->randomName(32), ); $this->drupalPost('admin/store/products/classes', $edit, t('Submit')); $this->assertText(t('Product class saved.'), 'Product class form submitted.'); $base = db_query('SELECT base FROM {node_type} WHERE type = :type', array(':type' => $type))->fetchField(); $this->assertEqual($base, 'uc_product', 'The new content type has been created in the database.'); // Make an existing node type a product class. $type = $this->drupalCreateContentType(); $edit = array( 'pcid' => $type->type, 'name' => $type->name, 'description' => $type->description, ); $this->drupalPost('admin/store/products/classes', $edit, t('Submit')); $this->assertText(t('Product class saved.'), 'Product class form submitted.'); $base = db_query('SELECT base FROM {node_type} WHERE type = :type', array(':type' => $type->type))->fetchField(); $this->assertEqual($base, 'uc_product', 'The new content type has been taken over by uc_product.'); } /** * @param $data * Data to potentially override the data used to create a product. * @return (stdClass) * The product object. */ public static function createProduct($data = array()) { $weight_units = array( 'lb', 'kg', 'oz', 'g', ); $weight_unit = $weight_units[array_rand($weight_units)]; $length_units = array( 'in', 'ft', 'cm', 'mm', ); $length_unit = $length_units[array_rand($length_units)]; $product = $data + array( 'model' => DrupalWebTestCase::randomName(8), 'list_price' => rand(0, 1000), 'cost' => rand(0, 1000), 'sell_price' => rand(0, 1000), 'weight' => rand(0, 1000), 'weight_units' => $weight_unit, 'length' => rand(0, 1000), 'width' => rand(0, 1000), 'height' => rand(0, 1000), 'length_units' => $length_unit, 'pkg_qty' => rand(0, 50), 'default_qty' => rand(0, 50), 'ordering' => rand(-10, 10), 'shippable' => rand(0, 1), 'type' => 'product', 'title' => DrupalWebTestCase::randomName(8), 'uid' => 1, ); $product = (object)$product; $product->unique_hash = md5($product->vid . $product->nid . $product->model . $product->list_price . $product->cost . $product->sell_price . $product->weight . $product->weight_units . $product->length . $product->width . $product->height . $product->length_units . $product->pkg_qty . $product->default_qty . $product->shippable . time()); node_save($product); return $product; } // Fix this after adding a proper API call for saving a product class. public static function createProductClass($data = array()) { $product_class = $data + array( 'pcid' => DrupalWebTestCase::randomName(8), 'name' => DrupalWebTestCase::randomName(8), 'description' => DrupalWebTestCase::randomName(8), ); $product_class = (object) $product_class; drupal_write_record('uc_product_classes', $product_class); return $product_class; // db_query("INSERT INTO {uc_product_classes} (pcid, name, description) VALUES ('%s', '%s', '%s')", $pcid, $form_state['values']['name'], $form_state['values']['description']); } }