uc_ajax.test 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /**
  3. * @file
  4. * Tests for the UcAddress class.
  5. */
  6. /**
  7. * Tests for the Ubercart Ajax Attach.
  8. */
  9. class UbercartAjaxTestCase extends UbercartTestHelper {
  10. public static function getInfo() {
  11. return array(
  12. 'name' => 'Ajax functionality',
  13. 'description' => 'Ajax update of checkout and order pages.',
  14. 'group' => 'Ubercart',
  15. );
  16. }
  17. /**
  18. * Overrides DrupalWebTestCase::setUp().
  19. */
  20. protected function setUp($modules = array(), $permissions = array()) {
  21. module_load_include('inc', 'uc_store', 'includes/uc_ajax_attach');
  22. $modules = array('rules_admin', 'uc_payment', 'uc_payment_pack');
  23. $permissions = array('administer rules', 'bypass rules access');
  24. parent::setUp($modules, $permissions);
  25. $this->drupalLogin($this->adminUser);
  26. }
  27. /**
  28. * Set a zone-based condition for a particular payment method.
  29. *
  30. * @param $method
  31. * The method to set (e.g. 'check')
  32. * @param $zone
  33. * The zone id (numeric) to check for.
  34. * @param $negate
  35. * TRUE to negate the condition.
  36. */
  37. protected function addPaymentZoneCondition($method, $zone, $negate = FALSE) {
  38. $not = $negate ? 'NOT ' : '';
  39. $name = 'uc_payment_method_' . $method;
  40. $label = ucfirst($method) . ' conditions';
  41. $condition = array(
  42. 'LABEL' => $label,
  43. 'PLUGIN' => 'and',
  44. 'REQUIRES' => array('rules'),
  45. 'USES VARIABLES' => array(
  46. 'order' => array(
  47. 'label' => 'Order',
  48. 'type' => 'uc_order',
  49. ),
  50. ),
  51. 'AND' => array(
  52. array(
  53. $not . 'data_is' => array(
  54. 'data' => array('order:billing-address:zone'),
  55. 'value' => $zone,
  56. ),
  57. ),
  58. ),
  59. );
  60. $newconfig = rules_import(array($name => $condition));
  61. $oldconfig = rules_config_load($name);
  62. if ($oldconfig) {
  63. $newconfig->id = $oldconfig->id;
  64. unset($newconfig->is_new);
  65. $newconfig->status = ENTITY_CUSTOM;
  66. }
  67. $newconfig->save();
  68. entity_flush_caches();
  69. //$this->drupalGet('admin/config/workflow/rules/components/manage/' . $newconfig->id);
  70. }
  71. public function testCheckoutAjax() {
  72. // Enable two payment methods and set a condition on one.
  73. variable_set('uc_payment_method_check_checkout', TRUE);
  74. variable_set('uc_payment_method_other_checkout', TRUE);
  75. $this->addPaymentZoneCondition('other', '26');
  76. // Speciy that the billing zone should update the payment pane.
  77. $config = variable_get('uc_ajax_checkout', _uc_ajax_defaults('checkout'));
  78. $config['panes][billing][address][billing_zone'] = array('payment-pane' => 'payment-pane');
  79. variable_set('uc_ajax_checkout', $config);
  80. // Go to the checkout page, veriy that the conditional payment method is
  81. // not available.
  82. $product = $this->createProduct(array('shippable' => FALSE));
  83. $this->drupalPost('node/' . $product->nid, array(), t('Add to cart'));
  84. $this->drupalPost('cart', array('items[0][qty]' => 1), t('Checkout'));
  85. $this->assertNoText('Other');
  86. // Change the billing zone and veriy that payment pane updates.
  87. $edit = array();
  88. $edit['panes[billing][billing_zone]'] = '26';
  89. $result = $this->ucPostAjax(NULL, $edit, 'panes[billing][billing_zone]');
  90. $this->assertText("Other");
  91. $edit['panes[billing][billing_zone]'] = '1';
  92. $result = $this->ucPostAjax(NULL, $edit, 'panes[billing][billing_zone]');
  93. // Not in Kansas any more...
  94. $this->assertNoText("Other");
  95. }
  96. }