Projet

Général

Profil

Paste
Télécharger (26,3 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / commerce / modules / checkout / tests / commerce_checkout.test @ b858700c

1
<?php
2

    
3
/**
4
 * @file
5
 * Functional tests for the commerce checkout module.
6
 */
7

    
8
/**
9
 * Test checkout process.
10
 */
11
class CommerceCheckoutTestProcess extends CommerceBaseTestCase {
12

    
13
  /**
14
   * Order object.
15
   */
16
  protected $order;
17

    
18
  /**
19
   * Implementation of getInfo().
20
   */
21
  public static function getInfo() {
22
    return array(
23
      'name' => 'Checkout process',
24
      'description' => 'Test the entire checkout process. Including anonymous checkout and checkout panes functionality.',
25
      'group' => 'Drupal Commerce',
26
    );
27
  }
28

    
29
  /**
30
   * Implementation of setUp().
31
   */
32
  function setUp() {
33
    $modules = parent::setUpHelper('all');
34
    parent::setUp($modules);
35

    
36
    // User creation for different operations.
37
    $this->site_admin = $this->createSiteAdmin();
38
    $this->store_admin = $this->createStoreAdmin();
39
    $this->store_customer = $this->createStoreCustomer();
40

    
41
    // The rule that sends a mail after checkout completion should be disabled
42
    //  as it returns an error caused by how mail messages are stored.
43
    $rules_config = rules_config_load('commerce_checkout_order_email');
44
    $rules_config->active = FALSE;
45
    $rules_config->save();
46
  }
47

    
48
  /**
49
   * Helper function to prepare an anonymous enviroment, it sets the user,
50
   *  products and prepares a cart.
51
   */
52
  protected function prepareAnonymousEnviroment() {
53
    // Login as admin user to grant permissions.
54
    $this->drupalLogin($this->site_admin);
55
    user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
56
      'access checkout' => TRUE,
57
    ));
58

    
59
    // Create a dummy product display content type.
60
    $this->createDummyProductDisplayContentType();
61
    // Create dummy product display nodes (and their corresponding product
62
    //  entities).
63
    $sku = 'PROD-01';
64
    $product_name = 'Product One';
65
    $this->product = $this->createDummyProduct($sku, $product_name);
66
    $this->product_node = $this->createDummyProductNode(array($this->product->product_id), $product_name);
67

    
68
    // Logout to test the checkout process with anonymous user.
69
    $this->drupalLogout();
70

    
71
    // Override user variable to get the enviroment fully set.
72
    global $user;
73
    $user = user_load(0);
74

    
75
    // Submit the add to cart form.
76
    $this->drupalPost('node/' . $this->product_node->nid, array(), t('Add to cart'));
77

    
78
    // Get the order for the anonymous user.
79
    $this->order = reset(commerce_order_load_multiple(array(), array('uid' => $user->uid, 'status' => 'cart'), TRUE));
80
    // Reset the cache as we don't want to keep the lock.
81
    entity_get_controller('commerce_order')->resetCache();
82
  }
83

    
84
  /**
85
   * Test changing the weight and page of a pane.
86
   */
87
  public function testCommerceCheckoutPanesForm() {
88
    // Log in as store customer.
89
    $this->drupalLogin($this->store_customer);
90
    // Access to the config page for checkout forms
91
    $this->drupalGet('admin/commerce/config/checkout/form');
92
    $this->assertResponse(403, t('A normal user is not able to access to the checkout configuration form page.'));
93

    
94
    // Log in as store admin.
95
    $this->drupalLogin($this->store_admin);
96
    // Access to the config page for checkout forms.
97
    $this->drupalGet('admin/commerce/config/checkout/form');
98
    $this->assertResponse(200, t('Store admin can access to the checkout configuration form page.'));
99

    
100
    // Modify weight of the panes
101
    $this->drupalPost('admin/commerce/config/checkout/form', array('panes[cart_contents][weight]'=> 1), t('Save configuration'));
102
    $this->assertOptionSelected('edit-panes-cart-contents-weight', 1, t('Pane weight changed'));
103

    
104
    // Change one pane to other page
105
    $this->drupalPost('admin/commerce/config/checkout/form', array('panes[checkout_review][page]'=> 'disabled'), t('Save configuration'));
106
    $this->assertOptionSelected('edit-panes-checkout-review-page', 'disabled', t('Pane page changed'));
107
  }
108

    
109
  /**
110
   * Test the checkout process using an authenticated user.
111
   */
112
  public function testCommerceCheckoutProcessAuthenticatedUser() {
113
    // Log in as normal user.
114
    $this->drupalLogin($this->store_customer);
115

    
116
    // Order creation, in cart status.
117
    $this->order = $this->createDummyOrder($this->store_customer->uid);
118

    
119
    // Access to checkout page.
120
    $this->drupalGet($this->getCommerceUrl('checkout'));
121

    
122
    // Check if the page resolves and if the default panes are present.
123
    $this->assertResponse(200, t('The owner of the order can access to the checkout page'));
124
    $this->assertTitle(t('Checkout') . ' | Drupal', t('Title of the checkout phase is correct'));
125
    $this->assertText(t('Shopping cart contents'), t('Shopping cart contents pane is present'));
126
    $this->assertText(t('Billing information'), t('Billing information pane is present'));
127

    
128
    // We are testing with authenticated user, so no account information
129
    // should appear.
130
    $this->assertNoText(t('Account information'), t('Account information pane is not present'));
131

    
132
    // Generate random information, as city, postal code, etc.
133
    $address_info = $this->generateAddressInformation();
134

    
135
    // Fill in the billing address information.
136
    $billing_pane = $this->xpath("//select[starts-with(@name, 'customer_profile_billing[commerce_customer_address]')]");
137
    $this->drupalPostAJAX(NULL, array((string) $billing_pane[0]['name'] => 'US'), (string) $billing_pane[0]['name']);
138

    
139
    // Check if the country has been selected correctly, this uses XPath as the
140
    //  ajax call replaces the element and the id may change.
141
    $this->assertFieldByXPath("//select[starts-with(@id, 'edit-customer-profile-billing-commerce-customer-address')]//option[@selected='selected']", 'US', t('Country selected'));
142

    
143
    // Fill in the required information for billing pane, with a random State.
144
    $info = array(
145
      'customer_profile_billing[commerce_customer_address][und][0][name_line]' => $address_info['name_line'],
146
      'customer_profile_billing[commerce_customer_address][und][0][thoroughfare]' => $address_info['thoroughfare'],
147
      'customer_profile_billing[commerce_customer_address][und][0][locality]' => $address_info['locality'],
148
      'customer_profile_billing[commerce_customer_address][und][0][administrative_area]' => 'KY',
149
      'customer_profile_billing[commerce_customer_address][und][0][postal_code]' => $address_info['postal_code'],
150
    );
151
    $this->drupalPost(NULL, $info, t('Continue to next step'));
152

    
153
    // Check for default panes and information in this checkout phase.
154
    $this->pass(t('Checking the default panes and the page information:'));
155
    $this->assertTitle(t('Review order') . ' | Drupal', t('Title of the checkout phase \'Review order\' is correct'));
156
    $this->assertText($address_info['name_line'], t('Billing information for \'name_line\' is correct'));
157
    $this->assertText($address_info['thoroughfare'], t('Billing information for \'thoroughfare\' is correct'));
158
    $this->assertText($address_info['locality'], t('Billing information for \'locality\' is correct'));
159
    $this->assertText(trim($address_info['postal_code']), t('Billing information for \'postal_code\' is correct'));
160
    $this->assertText('United States', t('Billing information country is correct'));
161
    $this->assertText('Example payment', t('Example payment method pane is present'));
162

    
163
    // Load the order to check the status.
164
    $order = commerce_order_load_multiple(array($this->order->order_id), array(), TRUE);
165
    // Reset the cache as we don't want to keep the lock.
166
    entity_get_controller('commerce_order')->resetCache();
167

    
168
    // At this point we should be in Checkout Review.
169
    $this->assertEqual(reset($order)->status, 'checkout_review', t('Order status is \'Checkout Review\' in the review phase.'));
170

    
171
    // Test the back & continue buttons.
172
    $this->drupalPost(NULL, array(), t('Go back'));
173
    $this->assertTitle(t('Checkout') . ' | Drupal', t('When clicking in the \'Back\' button, the title displayed corresponds with the current checkout phase: \'Checkout\''));
174
    $this->drupalPost(NULL, array(), t('Continue to next step'));
175
    $this->assertTitle(t('Review order') . ' | Drupal', t('When clicking in the \'Continue\' button, the title displayed corresponds with the current checkout phase: \'Review order\''));
176

    
177
    // Finish checkout process
178
    $this->drupalPost(NULL, array(), t('Continue to next step'));
179

    
180
    // Reload the order directly from db to update status.
181
    $order = commerce_order_load_multiple(array($this->order->order_id), array(), TRUE);
182

    
183
    // Order status should be pending when completing checkout process.
184
    $this->assertEqual(reset($order)->status, 'pending', t('Order status is \'Pending\' after completing checkout'));
185
    // Check if the completion message has been displayed.
186
    $this->assertTitle(t('Checkout complete') . ' | Drupal', t('Title of the page is \'Checkout complete\' when finishing the checkout process'));
187
    $this->assertText(t('Your order number is @order-number.', array('@order-number' => $this->order->order_number)), t('Completion message for the checkout is correctly displayed'));
188
  }
189

    
190
  /**
191
   * Test the checkout validation panes with anonymous user.
192
   */
193
  public function testCommerceCheckoutValidatePanesAnonymousUser() {
194
    // Prepare the cart for Anonymous.
195
    $this->prepareAnonymousEnviroment();
196
    // Access to checkout page.
197
    $this->drupalGet($this->getCommerceUrl('checkout'));
198

    
199
    // Test billing information and account information panes.
200
    $this->assertText(t('Billing information'), t('Billing information pane is present in the checkout page'));
201
    $this->assertText(t('Account information'), t('Account information pane is present in the checkout page'));
202

    
203
    // Test validation messages not filling any information.
204
    $this->drupalPost(NULL, array(), t('Continue to next step'));
205

    
206
    // Get all panes from the system to get their forms.
207
    $panes = commerce_checkout_panes();
208

    
209
    // Test the validation of Billing Information pane.
210
    $callback = commerce_checkout_pane_callback($panes['customer_profile_billing'], 'checkout_form');
211
    $pane_form = drupal_get_form($callback, $panes['customer_profile_billing'], $this->order);
212
    foreach (element_children($pane_form['commerce_customer_address'][LANGUAGE_NONE][0]) as $key) {
213
      $element = $pane_form['commerce_customer_address'][LANGUAGE_NONE][0][$key];
214
      if ($element['#required'] && empty($element['#default_value'])) {
215
        $this->assertText(t('!pane_message field is required', array('!pane_message' => $element['#title'])), t('Check required billing information pane messages'));
216
      }
217
    }
218

    
219
    // Test the validation of Account pane.
220
    $callback = commerce_checkout_pane_callback($panes['account'], 'checkout_form');
221
    $pane_form = drupal_get_form($callback, $panes['account'], $this->order);
222
    foreach (element_children($pane_form['login']) as $key) {
223
      if ($pane_form['login'][$key]['#required']) {
224
        $this->assertText(t('!pane_message field is required', array('!pane_message' => $pane_form['login'][$key]['#title'])), t('Check required account pane message.'));
225
      }
226
    }
227

    
228
    // Generate random information, as city name, postal code etc.
229
    $address_info = $this->generateAddressInformation();
230

    
231
    // Also generate a not-valid mail address.
232
    $user_mail = $this->randomName();
233

    
234
    // Fill in the billing address information
235
    $billing_pane = $this->xpath("//select[starts-with(@name, 'customer_profile_billing[commerce_customer_address]')]");
236
    $this->drupalPostAJAX(NULL, array((string) $billing_pane[0]['name'] => 'US'), (string) $billing_pane[0]['name']);
237

    
238
    // Fill in the required information for billing pane, with a random State.
239
    $info = array(
240
      'customer_profile_billing[commerce_customer_address][und][0][name_line]' => $address_info['name_line'],
241
      'customer_profile_billing[commerce_customer_address][und][0][thoroughfare]' => $address_info['thoroughfare'],
242
      'customer_profile_billing[commerce_customer_address][und][0][locality]' => $address_info['locality'],
243
      'customer_profile_billing[commerce_customer_address][und][0][administrative_area]' => 'KY',
244
      'customer_profile_billing[commerce_customer_address][und][0][postal_code]' => $address_info['postal_code'],
245
    );
246

    
247
    // Also add the mail for the account pane.
248
    $info += array(
249
      'account[login][mail]' => $user_mail,
250
    );
251

    
252
    // Go to the next checkout step with the required information.
253
    $this->drupalPost(NULL, $info, t('Continue to next step'));
254

    
255
    // Check if the wrong e-mail address fails validation.
256
    $this->assertRaw(t('The e-mail address %mail is not valid.', array('%mail' => $user_mail)), t('A warning message is displayed when the e-mail address for the anonymous user is not valid'));
257

    
258
    // Fix it and continue to next step.
259
    $user_mail = $this->randomName() . '@example.com';
260
    $info['account[login][mail]'] = $user_mail;
261
    $this->drupalPost(NULL, $info, t('Continue to next step'));
262

    
263
    $this->assertNoRaw(t('The e-mail address %mail is not valid.', array('%mail' => $user_mail)), t('A warning message is not displayed when the e-mail address for the anonymous user is valid'));
264

    
265
    // Finish checkout process for good.
266
    $this->drupalPost(NULL, array(), t('Continue to next step'));
267
  }
268

    
269
  /**
270
   * Test the checkout process with anonymous user.
271
   */
272
  public function testCommerceCheckoutProcessAnonymousUser() {
273
    // Prepare the cart for Anonymous.
274
    $this->prepareAnonymousEnviroment();
275
    // Access to checkout page.
276
    $this->drupalGet($this->getCommerceUrl('checkout'));
277

    
278
    // Check if the page resolves and if the default panes are present
279
    $this->assertResponse(200, t('Anonymous user can access to the checkout page for the order.'));
280
    $this->assertTitle(t('Checkout') . ' | Drupal', t('Title of the checkout phase is correct'));
281
    $this->assertText(t('Shopping cart contents'), t('Shopping cart contents pane is present'));
282
    $this->assertText(t('Billing information'), t('Billing information pane is present'));
283
    $this->assertText(t('Account information'), t('Account information pane is present'));
284

    
285
    // Generate random information, as user mail, city, etc.
286
    $user_mail = $this->randomName() . '@example.com';
287
    $address_info = $this->generateAddressInformation();
288

    
289
    // Fill in the billing address information
290
    $billing_pane = $this->xpath("//select[starts-with(@name, 'customer_profile_billing[commerce_customer_address]')]");
291
    $this->drupalPostAJAX(NULL, array((string) $billing_pane[0]['name'] => 'US'), (string) $billing_pane[0]['name']);
292

    
293
    // Check if the country has been selected correctly, this uses XPath as the
294
    //  ajax call replaces the element and the id may change
295
    $this->assertFieldByXPath("//select[starts-with(@id, 'edit-customer-profile-billing-commerce-customer-address')]//option[@selected='selected']", 'US', t('Country selected'));
296

    
297
    // Fill in the required information for billing pane, with a random State.
298
    $info = array(
299
      'customer_profile_billing[commerce_customer_address][und][0][name_line]' => $address_info['name_line'],
300
      'customer_profile_billing[commerce_customer_address][und][0][thoroughfare]' => $address_info['thoroughfare'],
301
      'customer_profile_billing[commerce_customer_address][und][0][locality]' => $address_info['locality'],
302
      'customer_profile_billing[commerce_customer_address][und][0][administrative_area]' => 'KY',
303
      'customer_profile_billing[commerce_customer_address][und][0][postal_code]' => $address_info['postal_code'],
304
    );
305

    
306
    // Also add the mail for the account pane.
307
    $info+= array(
308
      'account[login][mail]' => $user_mail,
309
    );
310

    
311
    // Go to the next checkout step with the required information.
312
    $this->drupalPost(NULL, $info, t('Continue to next step'));
313

    
314
    // Check for default panes and information in this checkout phase.
315
    $this->pass(t('Checking the default panes and the page information:'));
316
    $this->assertTitle(t('Review order') . ' | Drupal', t('Title of the checkout phase \'Review order\' is correct'));
317
    $this->assertText($address_info['name_line'], t('Billing information for \'name_line\' is correct'));
318
    $this->assertText($address_info['thoroughfare'], t('Billing information for \'thoroughfare\' is correct'));
319
    $this->assertText($address_info['locality'], t('Billing information for \'locality\' is correct'));
320
    $this->assertText(trim($address_info['postal_code']), t('Billing information for \'postal_code\' is correct'));
321
    $this->assertText('United States', t('Billing information country is correct'));
322
    $this->assertText('Example payment', t('Example payment method pane is present'));
323
    $this->assertText($user_mail, t('Account information is correct'));
324

    
325
    // Load the order to check the status.
326
    $order = commerce_order_load_multiple(array($this->order->order_id), array(), TRUE);
327
    // Reset the cache as we don't want to keep the lock.
328
    entity_get_controller('commerce_order')->resetCache();
329

    
330
    // At this point we should be in Checkout Review.
331
    $this->assertEqual(reset($order)->status, 'checkout_review', t('Order status is \'Checkout Review\' in the review phase.'));
332

    
333
    // Finish checkout process
334
    $this->drupalPost(NULL, array(), t('Continue to next step'));
335

    
336
    // Reload the order directly from db to check status.
337
    $order = commerce_order_load_multiple(array($this->order->order_id), array(), TRUE);
338

    
339
    // Order status should be pending when completing checkout process.
340
    $this->assertEqual(reset($order)->status, 'pending', t('Order status is \'Pending\' after completing checkout.'));
341

    
342
    // Check if the completion message has been displayed.
343
    $this->assertTitle(t('Checkout complete') . ' | Drupal', t('Title of the page is \'Checkout complete\' when finishing the checkout process'));
344
    // Check completion message.
345
    $this->assertText(t('Your order number is @order-number.', array('@order-number' => $this->order->order_number)), t('Completion message for the checkout is correctly displayed'));
346
  }
347

    
348
  /**
349
   * Test the checkout process with anonymous user using an e-mail address that
350
   * belongs to an existing user, the final result should be the order
351
   * assigned to the existing user.
352
   */
353
  public function testCommerceCheckoutProcessAnonymousExistingUser() {
354
    // Prepare the cart for Anonymous.
355
    $this->prepareAnonymousEnviroment();
356
    // Access to checkout page.
357
    $this->drupalGet($this->getCommerceUrl('checkout'));
358

    
359
    // Generate random information.
360
    $address_info = $this->generateAddressInformation();
361

    
362
    // Fill in the billing address information
363
    $billing_pane = $this->xpath("//select[starts-with(@name, 'customer_profile_billing[commerce_customer_address]')]");
364
    $this->drupalPostAJAX(NULL, array((string) $billing_pane[0]['name'] => 'US'), (string) $billing_pane[0]['name']);
365

    
366
    // Fill in the required information for billing pane, with a random State.
367
    $info = array(
368
      'customer_profile_billing[commerce_customer_address][und][0][name_line]' => $address_info['name_line'],
369
      'customer_profile_billing[commerce_customer_address][und][0][thoroughfare]' => $address_info['thoroughfare'],
370
      'customer_profile_billing[commerce_customer_address][und][0][locality]' => $address_info['locality'],
371
      'customer_profile_billing[commerce_customer_address][und][0][administrative_area]' => 'KY',
372
      'customer_profile_billing[commerce_customer_address][und][0][postal_code]' => $address_info['postal_code'],
373
    );
374

    
375
    // Also add the mail for the account pane.
376
    $info += array(
377
      'account[login][mail]' => $this->store_customer->mail,
378
    );
379

    
380
    // Go to the next checkout step with the required information.
381
    $this->drupalPost(NULL, $info, t('Continue to next step'));
382

    
383
    // Finish checkout process
384
    $this->drupalPost(NULL, array(), t('Continue to next step'));
385

    
386
    // Reload the order directly from db to check its owner.
387
    $order = commerce_order_load_multiple(array($this->order->order_id), array(), TRUE);
388

    
389
    // Assert that the owner of the order is the owner of the e-mail address used.
390
    $this->assertEqual($this->store_customer->uid, reset($order)->uid, t('The order has been correctly assigned to the user owner of the mail address'));
391
  }
392

    
393
  /**
394
   * Test the checkout process with anonymous user using an e-mail addres that
395
   * doesn't exists in the system, the final result is that the user gets the
396
   * account created and the order is assigned to that user.
397
   */
398
  public function testCommerceCheckoutProcessAnonymousNonExistingUser() {
399
    // Prepare the cart for Anonymous.
400
    $this->prepareAnonymousEnviroment();
401
    // Access to checkout page.
402
    $this->drupalGet($this->getCommerceUrl('checkout'));
403

    
404
    // Generate random information, as user mail, city, etc.
405
    $user_mail = $this->randomName() . '@example.com';
406
    $address_info = $this->generateAddressInformation();
407

    
408
    // Fill in the billing address information
409
    $billing_pane = $this->xpath("//select[starts-with(@name, 'customer_profile_billing[commerce_customer_address]')]");
410
    $this->drupalPostAJAX(NULL, array((string) $billing_pane[0]['name'] => 'US'), (string) $billing_pane[0]['name']);
411

    
412
    // Fill in the required information for billing pane, with a random State.
413
    $info = array(
414
      'customer_profile_billing[commerce_customer_address][und][0][name_line]' => $address_info['name_line'],
415
      'customer_profile_billing[commerce_customer_address][und][0][thoroughfare]' => $address_info['thoroughfare'],
416
      'customer_profile_billing[commerce_customer_address][und][0][locality]' => $address_info['locality'],
417
      'customer_profile_billing[commerce_customer_address][und][0][administrative_area]' => 'KY',
418
      'customer_profile_billing[commerce_customer_address][und][0][postal_code]' => $address_info['postal_code'],
419
    );
420

    
421
    // Also add the mail for the account pane.
422
    $info+= array(
423
      'account[login][mail]' => $user_mail,
424
    );
425

    
426
    // Go to the next checkout step with the required information.
427
    $this->drupalPost(NULL, $info, t('Continue to next step'));
428

    
429
    // Finish checkout process
430
    $this->drupalPost(NULL, array(), t('Continue to next step'));
431

    
432
    // Reload the order directly from db to check its owner.
433
    $order = commerce_order_load_multiple(array($this->order->order_id), array(), TRUE);
434

    
435
    // Check if the order completion triggered the user creation rule.
436
    $user = user_load(reset($order)->uid);
437
    $this->assertEqual($user->mail, $user_mail, t('The e-mail address of the owner of the order matches the one in the checkout input'));
438
    $this->assertTrue($this->store_customer->uid < $user->uid, t('User id of the new user is higher than the last user created then it is a new account'));
439
  }
440

    
441
  /**
442
   * Test order completion page access.
443
   */
444
  public function testCommerceCheckoutAccessOrder() {
445
    // Log in as normal user.
446
    $this->drupalLogin($this->store_customer);
447

    
448

    
449
    // Create dummy product.
450
    $product = $this->createDummyProduct('PROD-01', 'Product One');
451

    
452
    // Order creation, in complete status.
453
    $this->order = $this->createDummyOrder($this->store_customer->uid, array($product->product_id => 1), 'complete');
454

    
455

    
456
    // Access to the complete page, this one should be always accesible.
457
    $this->assertCheckoutPageAccessible($this->order, 'complete');
458
  }
459

    
460
  public function assertCheckoutPageAccessible($order, $page) {
461
    $path = $this->getCommerceUrl('checkout') . '/' . $order->order_id . ($page ? '/' . $page : '');
462
    $this->drupalGet($path);
463
    return $this->assertEqual($this->getUrl(), url($path, array('absolute' => TRUE)),  t('@page checkout page is accessible.', array('@page' => $page)));
464
  }
465

    
466
  public function assertCheckoutPageNotAccessible($order, $page) {
467
    $path = $this->getCommerceUrl('checkout') . '/' . $order->order_id . ($page ? '/' . $page : '');
468
    $this->drupalGet($path);
469
    return $this->assertNotEqual($this->getUrl(), url($path, array('absolute' => TRUE)),  t('@page checkout page is not accessible.', array('@page' => $page)));
470
  }
471

    
472
  /**
473
   * Test order completion page access.
474
   */
475
  public function testCommerceCheckoutAccessPages() {
476
    // Log in as normal user.
477
    $this->drupalLogin($this->store_customer);
478

    
479
    // Order creation, in cart status.
480
    $this->order = $this->createDummyOrder($this->store_customer->uid);
481

    
482
    // At this point, the rest of checkout pages shouldn't be accessible.
483
    $this->assertCheckoutPageAccessible($this->order, '');
484
    $this->assertCheckoutPageNotAccessible($this->order, 'review');
485
    $this->assertCheckoutPageNotAccessible($this->order, 'payment');
486
    $this->assertCheckoutPageNotAccessible($this->order, 'complete');
487

    
488
    // Generate random information, as city, postal code, etc.
489
    $address_info = $this->generateAddressInformation();
490

    
491
    // Fill in the billing address information
492
    $billing_pane = $this->xpath("//select[starts-with(@name, 'customer_profile_billing[commerce_customer_address]')]");
493
    $this->drupalPostAJAX(NULL, array((string) $billing_pane[0]['name'] => 'US'), (string) $billing_pane[0]['name']);
494

    
495
    // Check if the country has been selected correctly, this uses XPath as the
496
    //  ajax call replaces the element and the id may change
497
    $this->assertFieldByXPath("//select[starts-with(@id, 'edit-customer-profile-billing-commerce-customer-address')]//option[@selected='selected']", 'US', t('Country selected'));
498

    
499
    // Fill in the required information for billing pane, with a random State.
500
    $info = array(
501
      'customer_profile_billing[commerce_customer_address][und][0][name_line]' => $address_info['name_line'],
502
    	'customer_profile_billing[commerce_customer_address][und][0][thoroughfare]' => $address_info['thoroughfare'],
503
    	'customer_profile_billing[commerce_customer_address][und][0][locality]' => $address_info['locality'],
504
    	'customer_profile_billing[commerce_customer_address][und][0][administrative_area]' => 'KY',
505
    	'customer_profile_billing[commerce_customer_address][und][0][postal_code]' => $address_info['postal_code'],
506
    );
507
    $this->drupalPost(NULL, $info, t('Continue to next step'));
508

    
509
    // At this point, only first page and review should be accessible, but the
510
    //  rest shouldn't.
511
    $this->assertCheckoutPageAccessible($this->order, '');
512
    $this->assertCheckoutPageAccessible($this->order, 'review');
513
    $this->assertCheckoutPageNotAccessible($this->order, 'payment');
514
    $this->assertCheckoutPageNotAccessible($this->order, 'complete');
515

    
516
    // Fill in the payment method and continue the process.
517
    $this->drupalPost(NULL, array(), t('Continue to next step'));
518

    
519
    // At this point, only the complete page should be accessible.
520
    $this->assertCheckoutPageNotAccessible($this->order, '');
521
    $this->assertCheckoutPageNotAccessible($this->order, 'review');
522
    $this->assertCheckoutPageNotAccessible($this->order, 'payment');
523
    $this->assertCheckoutPageAccessible($this->order, 'complete');
524
  }
525

    
526
}