Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
FillBillingInformationStep.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Checkout\Test\Page\CheckoutOnepage;
10 use Magento\Customer\Test\Fixture\Address;
11 use Magento\Mtf\TestStep\TestStepInterface;
14 use Magento\Mtf\ObjectManager;
15 
19 class FillBillingInformationStep implements TestStepInterface
20 {
26  protected $checkoutOnepage;
27 
33  protected $billingAddress;
34 
40  protected $shippingAddress;
41 
47  protected $customer;
48 
55 
62 
68  private $billingAddressCustomer;
69 
75  private $editBillingInformation;
76 
82  protected $objectManager;
83 
96  public function __construct(
97  CheckoutOnepage $checkoutOnepage,
99  Customer $customer,
100  ObjectManager $objectManager,
101  Address $billingAddress = null,
102  Address $shippingAddress = null,
103  $billingCheckboxState = null,
104  $billingAddressCustomer = null,
105  $editBillingInformation = true
106  ) {
107  $this->checkoutOnepage = $checkoutOnepage;
108  $this->billingAddress = $billingAddress;
109  $this->shippingAddress = $shippingAddress;
110  $this->assertBillingAddressCheckbox = $assertBillingAddressCheckbox;
111  $this->customer = $customer;
112  $this->objectManager = $objectManager;
113  $this->billingCheckboxState = $billingCheckboxState;
114  $this->billingAddressCustomer = $billingAddressCustomer;
115  $this->editBillingInformation = $editBillingInformation;
116  }
117 
123  public function run()
124  {
126  if ($this->billingCheckboxState) {
127  $this->assertBillingAddressCheckbox->processAssert($this->checkoutOnepage, $this->billingCheckboxState);
128  }
129  if ($this->billingCheckboxState === 'Yes' && !$this->editBillingInformation) {
130  return [
131  'billingAddress' => $this->shippingAddress
132  ];
133  }
134  if ($this->billingAddress) {
135  $selectedPaymentMethod = $this->checkoutOnepage->getPaymentBlock()->getSelectedPaymentMethodBlock();
136  if ($this->shippingAddress) {
137  $selectedPaymentMethod->getBillingBlock()->unsetSameAsShippingCheckboxValue();
138  }
139  $selectedPaymentMethod->getBillingBlock()->fillBilling($this->billingAddress);
141  }
142  if (isset($this->billingAddressCustomer['added'])) {
143  $addressIndex = $this->billingAddressCustomer['added'];
144  $billingAddress = $this->customer->getDataFieldConfig('address')['source']->getAddresses()[$addressIndex];
145  $address = $this->objectManager->create(
146  \Magento\Customer\Test\Block\Address\Renderer::class,
147  ['address' => $billingAddress, 'type' => 'html_for_select_element']
148  )->render();
149  $selectedPaymentMethod = $this->checkoutOnepage->getPaymentBlock()->getSelectedPaymentMethodBlock();
150  $selectedPaymentMethod->getBillingBlock()->unsetSameAsShippingCheckboxValue();
151  $this->checkoutOnepage->getCustomAddressBlock()->selectAddress($address);
152  $selectedPaymentMethod->getBillingBlock()->clickUpdate();
153  }
154 
155  return [
156  'billingAddress' => $billingAddress
157  ];
158  }
159 }
$address
Definition: customer.php:38
__construct(CheckoutOnepage $checkoutOnepage, AssertBillingAddressSameAsShippingCheckbox $assertBillingAddressCheckbox, Customer $customer, ObjectManager $objectManager, Address $billingAddress=null, Address $shippingAddress=null, $billingCheckboxState=null, $billingAddressCustomer=null, $editBillingInformation=true)