uc_attribute_checkout.test 2.1 KB

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