1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Magium\Magento\Actions\Checkout\Steps; |
4
|
|
|
|
5
|
|
|
use Facebook\WebDriver\WebDriverExpectedCondition; |
6
|
|
|
use Magium\AbstractTestCase; |
7
|
|
|
use Magium\Magento\AbstractMagentoTestCase; |
8
|
|
|
use Magium\Magento\Identities\Customer; |
9
|
|
|
use Magium\Magento\Themes\OnePageCheckout\AbstractThemeConfiguration; |
10
|
|
|
use Magium\WebDriver\ExpectedCondition; |
11
|
|
|
use Magium\WebDriver\WebDriver; |
12
|
|
|
|
13
|
|
|
class ShippingAddress implements StepInterface |
14
|
|
|
{ |
15
|
|
|
const ACTION = 'Checkout\Steps\ShippingAddress'; |
16
|
|
|
|
17
|
|
|
protected $webdriver; |
18
|
|
|
protected $theme; |
19
|
|
|
protected $customerIdentity; |
20
|
|
|
protected $testCase; |
21
|
|
|
protected $bypassNextStep = false; |
22
|
|
|
|
23
|
|
|
protected $enterNewAddress = false; |
24
|
|
|
|
25
|
|
|
public function __construct( |
26
|
|
|
WebDriver $webdriver, |
27
|
|
|
AbstractThemeConfiguration $theme, |
28
|
|
|
Customer $customerIdentity, |
29
|
|
|
AbstractMagentoTestCase $testCase |
30
|
|
|
) { |
31
|
|
|
$this->webdriver = $webdriver; |
32
|
|
|
$this->theme = $theme; |
33
|
|
|
$this->customerIdentity = $customerIdentity; |
34
|
|
|
$this->testCase = $testCase; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function enterNewAddress($newAddress = true) |
38
|
|
|
{ |
39
|
|
|
$this->enterNewAddress = $newAddress; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
protected function preExecute() |
43
|
|
|
{ |
44
|
|
|
if ($this->enterNewAddress) { |
45
|
|
|
$this->webdriver->wait()->until( |
46
|
|
|
ExpectedCondition::visibilityOf( |
47
|
|
|
$this->webdriver->byXpath($this->theme->getShippingNewAddressXpath()) |
48
|
|
|
) |
49
|
|
|
); |
50
|
|
|
$this->webdriver->byXpath($this->theme->getShippingNewAddressXpath())->click(); |
51
|
|
|
$this->webdriver->wait()->until( |
52
|
|
|
ExpectedCondition::visibilityOf( |
53
|
|
|
$this->webdriver->byXpath($this->theme->getShippingFirstNameXpath()) |
54
|
|
|
) |
55
|
|
|
); |
56
|
|
|
} |
57
|
|
|
// We will bypass ourself if the billing address is the same as the shipping address. |
58
|
|
|
if (!$this->webdriver->elementDisplayed($this->theme->getShippingFirstNameXpath(), AbstractTestCase::BY_XPATH)) { |
59
|
|
|
$this->bypassNextStep = true; |
60
|
|
|
return true; |
61
|
|
|
} |
62
|
|
|
return false; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
protected function sendData($xpath, $data) |
66
|
|
|
{ |
67
|
|
|
if ($xpath) { |
68
|
|
|
$this->testCase->byXpath($xpath)->clear(); |
69
|
|
|
$this->testCase->byXpath($xpath)->sendKeys($data); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function execute() |
74
|
|
|
{ |
75
|
|
|
if ($this->preExecute()) { |
76
|
|
|
return true; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
$this->sendData($this->theme->getShippingFirstNameXpath(), $this->customerIdentity->getShippingFirstName()); |
80
|
|
|
$this->sendData($this->theme->getShippingLastNameXpath(), $this->customerIdentity->getShippingLastName()); |
81
|
|
|
$this->sendData($this->theme->getShippingCompanyXpath(), $this->customerIdentity->getShippingCompany()); |
82
|
|
|
$this->sendData($this->theme->getShippingAddressXpath(), $this->customerIdentity->getShippingAddress()); |
83
|
|
|
$this->sendData($this->theme->getShippingAddress2Xpath(), $this->customerIdentity->getShippingAddress2()); |
84
|
|
|
$this->sendData($this->theme->getShippingCityXpath(), $this->customerIdentity->getShippingCity()); |
85
|
|
|
|
86
|
|
|
$regionXpath = $this->theme->getShippingRegionIdXpath($this->customerIdentity->getShippingRegionId()); |
87
|
|
|
if ($regionXpath) { |
88
|
|
|
$this->testCase->byXpath($regionXpath)->click(); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
$this->sendData($this->theme->getShippingPostCodeXpath(), $this->customerIdentity->getShippingPostCode()); |
92
|
|
|
|
93
|
|
|
$countryXpath = $this->theme->getShippingCountryIdXpath($this->customerIdentity->getShippingCountryId()); |
94
|
|
|
if ($countryXpath) { |
95
|
|
|
$this->testCase->byXpath($countryXpath)->click(); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
$this->sendData($this->theme->getShippingTelephoneXpath(), $this->customerIdentity->getShippingTelephone()); |
99
|
|
|
$this->sendData($this->theme->getShippingFaxXpath(), $this->customerIdentity->getShippingFax()); |
100
|
|
|
|
101
|
|
|
return true; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
View Code Duplication |
public function nextAction() |
|
|
|
|
105
|
|
|
{ |
106
|
|
|
if ($this->bypassNextStep) { |
107
|
|
|
return true; |
108
|
|
|
} |
109
|
|
|
$this->testCase->byXpath($this->theme->getShippingContinueButtonXpath())->click(); |
110
|
|
|
|
111
|
|
|
$this->webdriver->wait()->until(WebDriverExpectedCondition::not(WebDriverExpectedCondition::visibilityOf($this->webdriver->byXpath($this->theme->getShippingContinueCompletedXpath())))); |
112
|
|
|
return true; |
113
|
|
|
} |
114
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.