|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace hipanel\tests\_support\Step\Acceptance; |
|
4
|
|
|
|
|
5
|
|
|
use Codeception\Scenario; |
|
6
|
|
|
use hipanel\tests\_support\AcceptanceTester; |
|
7
|
|
|
use hipanel\tests\_support\Page\Login; |
|
8
|
|
|
|
|
9
|
|
|
class Client extends AcceptanceTester |
|
|
|
|
|
|
10
|
|
|
{ |
|
11
|
|
|
public function __construct(Scenario $scenario) |
|
12
|
|
|
{ |
|
13
|
|
|
parent::__construct($scenario); |
|
14
|
|
|
$this->initCredentials(); |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
public $id; |
|
18
|
|
|
protected $username; |
|
19
|
|
|
protected $password; |
|
20
|
|
|
|
|
21
|
|
|
public function getUsername(): string |
|
22
|
|
|
{ |
|
23
|
|
|
return $this->username; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function login() |
|
27
|
|
|
{ |
|
28
|
|
|
$this->loadOrLogin(); |
|
29
|
|
|
|
|
30
|
|
|
return $this->findId(); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
protected function loadOrLogin() |
|
34
|
|
|
{ |
|
35
|
|
|
$sessionName = 'login-' . $this->getClientType(); |
|
36
|
|
|
try { |
|
37
|
|
|
if ($this->retrieveSession($sessionName)) { |
|
38
|
|
|
return $this; |
|
39
|
|
|
} |
|
40
|
|
|
} catch (\Facebook\WebDriver\Exception\UnknownServerException $exception) { |
|
|
|
|
|
|
41
|
|
|
// User is already logged in, but trying to open a session on a page that is not loaded |
|
42
|
|
|
return $this; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
$this->restartBrowser(); |
|
46
|
|
|
$hiam = new Login($this); |
|
47
|
|
|
$hiam->login($this->username, $this->password); |
|
48
|
|
|
$this->storeSession($sessionName); |
|
49
|
|
|
|
|
50
|
|
|
return $this; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
protected function findId(): self |
|
54
|
|
|
{ |
|
55
|
|
|
if (empty($this->id)) { |
|
56
|
|
|
$this->amOnPage('/site/healthcheck'); |
|
57
|
|
|
$this->id = $this->grabTextFrom('userId'); |
|
58
|
|
|
if (!$this->id) { |
|
59
|
|
|
throw new \Exception('failed detect user ID'); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
return $this; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
protected $clientType; |
|
67
|
|
|
|
|
68
|
|
|
protected function getClientType(): string |
|
69
|
|
|
{ |
|
70
|
|
|
if ($this->clientType === null) { |
|
71
|
|
|
$this->clientType = strtolower((new \ReflectionClass($this))->getShortName()); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
return $this->clientType; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
protected function initCredentials() |
|
78
|
|
|
{ |
|
79
|
|
|
$func = 'get' . $this->getClientType() . 'Credentials'; |
|
80
|
|
|
[$this->id, $this->username, $this->password] = $this->{$func}(); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|