uc_payment.test 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. * @file
  4. * Ubercart payment related tests.
  5. */
  6. /**
  7. * Tests the checkout payment pane.
  8. */
  9. class UbercartPaymentPaneTestCase extends UbercartTestHelper {
  10. public static function getInfo() {
  11. return array(
  12. 'name' => 'Payment checkout pane',
  13. 'description' => 'Ensures that the payment pane functions properly during checkout.',
  14. 'group' => 'Ubercart',
  15. );
  16. }
  17. /**
  18. * Overrides DrupalWebTestCase::setUp().
  19. */
  20. protected function setUp($modules = array(), $permissions = array()) {
  21. parent::setUp(array('uc_payment', 'uc_payment_pack'));
  22. $this->drupalLogin($this->adminUser);
  23. $this->drupalPost('node/' . $this->product->nid, array(), t('Add to cart'));
  24. }
  25. /**
  26. * Verifies checkout page presents all enabled payment methods.
  27. */
  28. public function testPaymentMethodOptions() {
  29. // No payment methods.
  30. variable_set('uc_payment_method_check_checkout', FALSE);
  31. $this->drupalGet('cart/checkout');
  32. $this->assertText('Checkout cannot be completed without any payment methods enabled. Please contact an administrator to resolve the issue.');
  33. // Single payment method.
  34. variable_set('uc_payment_method_check_checkout', TRUE);
  35. $this->drupalGet('cart/checkout');
  36. $this->assertNoText('Select a payment method from the following options.');
  37. $this->assertFieldByXPath("//input[@name='panes[payment][payment_method]' and @disabled='disabled']");
  38. // Multiple payment methods.
  39. variable_set('uc_payment_method_other_checkout', TRUE);
  40. $this->drupalGet('cart/checkout');
  41. $this->assertText('Select a payment method from the following options.');
  42. $this->assertNoFieldByXPath("//input[@name='panes[payment][payment_method]' and @disabled='disabled']");
  43. }
  44. /**
  45. * Tests operation of uc_payment_show_order_total_preview variable.
  46. */
  47. public function testOrderTotalPreview() {
  48. variable_set('uc_payment_show_order_total_preview', TRUE);
  49. $this->drupalGet('cart/checkout');
  50. $this->assertText('Order total:');
  51. variable_set('uc_payment_show_order_total_preview', FALSE);
  52. $this->drupalGet('cart/checkout');
  53. $this->assertNoText('Order total:');
  54. }
  55. /**
  56. * Tests free orders.
  57. */
  58. public function testFreeOrders() {
  59. $free_product = $this->createProduct(array('sell_price' => 0));
  60. variable_set('uc_payment_method_check_checkout', TRUE);
  61. // Check that paid products cannot be purchased for free.
  62. $this->drupalGet('cart/checkout');
  63. $this->assertText('Check or money order');
  64. $this->assertNoText('No payment required');
  65. $this->assertNoText('Subtotal: $0.00');
  66. // Check that a mixture of free and paid products
  67. // cannot be purchased for free.
  68. $this->drupalPost('node/' . $free_product->nid, array(), t('Add to cart'));
  69. $this->drupalGet('cart/checkout');
  70. $this->assertText('Check or money order');
  71. $this->assertNoText('No payment required');
  72. $this->assertNoText('Subtotal: $0.00');
  73. // Check that free products can be purchased successfully with no payment.
  74. $this->drupalPost('cart', array(), t('Remove'));
  75. $this->drupalPost('cart', array(), t('Remove'));
  76. $this->drupalPost('node/' . $free_product->nid, array(), t('Add to cart'));
  77. $this->drupalGet('cart/checkout');
  78. $this->assertNoText('Check or money order');
  79. $this->assertText('No payment required');
  80. $this->assertText('Subtotal: $0.00');
  81. // Check that this is the only available payment method.
  82. $this->assertNoText('Select a payment method from the following options.');
  83. $this->assertFieldByXPath("//input[@name='panes[payment][payment_method]' and @disabled='disabled']");
  84. }
  85. }