|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Magium\Magento\Actions\Customer; |
|
4
|
|
|
|
|
5
|
|
|
use Facebook\WebDriver\Exception\NoSuchElementException; |
|
6
|
|
|
use Magium\Magento\AbstractMagentoTestCase; |
|
7
|
|
|
use Magium\Magento\Identities\Customer; |
|
8
|
|
|
use Magium\Magento\Themes\Customer\AbstractThemeConfiguration; |
|
9
|
|
|
use Magium\Navigators\InstructionNavigator; |
|
10
|
|
|
use Magium\WebDriver\WebDriver; |
|
11
|
|
|
|
|
12
|
|
|
class Login |
|
13
|
|
|
{ |
|
14
|
|
|
const ACTION = 'Customer\Login'; |
|
15
|
|
|
|
|
16
|
|
|
protected $webdriver; |
|
17
|
|
|
protected $theme; |
|
18
|
|
|
protected $testCase; |
|
19
|
|
|
protected $instructionsNavigator; |
|
20
|
|
|
protected $customerIdentity; |
|
21
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
public function __construct( |
|
24
|
|
|
WebDriver $webdriver, |
|
25
|
|
|
AbstractThemeConfiguration $theme, |
|
26
|
|
|
InstructionNavigator $instructionsNavigator, |
|
27
|
|
|
Customer $customerIdentity, |
|
28
|
|
|
AbstractMagentoTestCase $testCase |
|
29
|
|
|
|
|
30
|
|
|
) { |
|
31
|
|
|
$this->webdriver = $webdriver; |
|
32
|
|
|
$this->theme = $theme; |
|
33
|
|
|
$this->testCase = $testCase; |
|
34
|
|
|
$this->instructionsNavigator = $instructionsNavigator; |
|
35
|
|
|
$this->customerIdentity = $customerIdentity; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* |
|
41
|
|
|
* Will log in to the specified customer account. If requireLogin is specified it will assert that |
|
42
|
|
|
* the login form MUST be there. Otherwise it will return if the login form is not there, presuming |
|
43
|
|
|
* that the current session is already logged in. |
|
44
|
|
|
* |
|
45
|
|
|
* @param string $username |
|
46
|
|
|
* @param string $password |
|
47
|
|
|
* @param bool $requireLogin Fail the test if there is an account currently logged in |
|
48
|
|
|
*/ |
|
49
|
|
|
|
|
50
|
|
|
public function login($username = null, $password = null, $requireLogin = false) |
|
51
|
|
|
{ |
|
52
|
|
|
|
|
53
|
|
|
if ($requireLogin) { |
|
54
|
|
|
$this->testCase->assertElementDisplayed($this->theme->getLoginUsernameField(), WebDriver::BY_XPATH); |
|
55
|
|
|
} else { |
|
56
|
|
|
try { |
|
57
|
|
|
$element = $this->webdriver->byXpath($this->theme->getLoginUsernameField()); |
|
58
|
|
|
if ($element === null || !$element->isDisplayed()) { |
|
59
|
|
|
return; |
|
60
|
|
|
} |
|
61
|
|
|
// If we're logged in we don't need to do the login process. Continue along. |
|
62
|
|
|
} catch (NoSuchElementException $e ) { |
|
63
|
|
|
return; |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
if ($username === null) { |
|
67
|
|
|
$username = $this->customerIdentity->getEmailAddress(); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
if ($password === null) { |
|
71
|
|
|
$password = $this->customerIdentity->getPassword(); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
$usernameElement = $this->webdriver->byXpath($this->theme->getLoginUsernameField()); |
|
75
|
|
|
$passwordElement = $this->webdriver->byXpath($this->theme->getLoginPasswordField()); |
|
76
|
|
|
$submitElement = $this->webdriver->byXpath($this->theme->getLoginSubmitButton()); |
|
77
|
|
|
|
|
78
|
|
|
$this->testCase->assertInstanceOf('Facebook\Webdriver\WebDriverElement', $usernameElement); |
|
79
|
|
|
$this->testCase->assertInstanceOf('Facebook\Webdriver\WebDriverElement', $passwordElement); |
|
80
|
|
|
$this->testCase->assertInstanceOf('Facebook\Webdriver\WebDriverElement', $submitElement); |
|
81
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
$usernameElement->sendKeys($username); |
|
84
|
|
|
$passwordElement->sendKeys($password); |
|
85
|
|
|
$submitElement->click(); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function execute($username = null, $password = null, $requireLogin = false) |
|
89
|
|
|
{ |
|
90
|
|
|
$this->login($username, $password, $requireLogin); |
|
91
|
|
|
} |
|
92
|
|
|
} |