uc_attribute_checkout.test 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * @file
  4. * Ubercart attribute checkout tests.
  5. */
  6. class UbercartAttributeCheckoutTestCase extends UbercartTestHelper {
  7. public static function getInfo() {
  8. return array(
  9. 'name' => 'Attribute Checkout',
  10. 'description' => 'Test ordering products with attributes.',
  11. 'group' => 'Ubercart',
  12. );
  13. }
  14. /**
  15. * Overrides DrupalWebTestCase::setUp().
  16. */
  17. function setUp() {
  18. parent::setUp(array('uc_attribute', 'uc_cart'), array('administer attributes', 'administer product attributes', 'administer product options'));
  19. $this->drupalLogin($this->adminUser);
  20. }
  21. /**
  22. * Tests that product in cart has the selected attribute option.
  23. */
  24. function testAttributeAddToCart() {
  25. for ($display = 0; $display <= 3; ++$display) {
  26. // Set up an attribute.
  27. $data = array(
  28. 'display' => $display,
  29. );
  30. $attribute = UbercartAttributeTestCase::createAttribute($data);
  31. if ($display) {
  32. // Give the attribute an option.
  33. $option = UbercartAttributeTestCase::createAttributeOption(array('aid' => $attribute->aid));
  34. }
  35. $attribute = uc_attribute_load($attribute->aid);
  36. // Put the attribute on a product.
  37. $product = $this->createProduct();
  38. uc_attribute_subject_save($attribute, 'product', $product->nid, TRUE);
  39. // Add the product to the cart.
  40. if ($display == 3) {
  41. $edit = array("attributes[$attribute->aid][$option->oid]" => $option->oid);
  42. }
  43. elseif (isset($option)) {
  44. $edit = array("attributes[$attribute->aid]" => $option->oid);
  45. }
  46. else {
  47. $option = new stdClass();
  48. $option->name = self::randomName();
  49. $option->price = 0;
  50. $edit = array("attributes[$attribute->aid]" => $option->name);
  51. }
  52. $this->drupalPost('node/' . $product->nid, $edit, t('Add to cart'));
  53. $this->assertText("$attribute->label: $option->name", t('Option selected on cart item.'));
  54. $this->assertText(uc_currency_format($product->sell_price + $option->price), t('Product has adjusted price.'));
  55. }
  56. }
  57. }