|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Magium\Magento\Actions\Checkout\ShippingMethods; |
|
4
|
|
|
|
|
5
|
|
|
use Magium\AbstractTestCase; |
|
6
|
|
|
use Magium\Magento\AbstractMagentoTestCase; |
|
7
|
|
|
use Magium\Magento\MissingInformationException; |
|
8
|
|
|
use Magium\Magento\Themes\OnePageCheckout\AbstractThemeConfiguration; |
|
9
|
|
|
use Magium\WebDriver\ExpectedCondition; |
|
10
|
|
|
use Magium\WebDriver\WebDriver; |
|
11
|
|
|
|
|
12
|
|
|
class ByName implements ShippingMethodInterface |
|
13
|
|
|
{ |
|
14
|
|
|
const ACTION = 'Checkout\ShippingMethods\ByName'; |
|
15
|
|
|
protected $webDriver; |
|
16
|
|
|
protected $theme; |
|
17
|
|
|
protected $testCase; |
|
18
|
|
|
|
|
19
|
|
|
protected $name; |
|
20
|
|
|
|
|
21
|
|
|
public function __construct( |
|
22
|
|
|
WebDriver $webDriver, |
|
23
|
|
|
AbstractThemeConfiguration $themeConfiguration, |
|
24
|
|
|
AbstractMagentoTestCase $testCase |
|
25
|
|
|
) { |
|
26
|
|
|
$this->webDriver = $webDriver; |
|
27
|
|
|
$this->testCase = $testCase; |
|
28
|
|
|
$this->theme = $themeConfiguration; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function setName($name) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->name = $name; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function choose($required) |
|
37
|
|
|
{ |
|
38
|
|
|
if (!$this->name) { |
|
39
|
|
|
throw new MissingInformationException('Missing the names'); |
|
40
|
|
|
} |
|
41
|
|
|
$xpath = $this->theme->getShippingByNameXpath($this->name); |
|
42
|
|
|
try { |
|
43
|
|
|
$this->webDriver->wait()->until( |
|
44
|
|
|
ExpectedCondition::elementExists( |
|
45
|
|
|
$xpath, AbstractTestCase::BY_XPATH |
|
46
|
|
|
) |
|
47
|
|
|
); |
|
48
|
|
|
} catch (\Exception $e) { |
|
49
|
|
|
throw new NoSuchShippingMethodException('Unable to find the shipping method: ' . $this->name); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
// Some products, such as virtual products, do not get shipped |
|
53
|
|
|
if ($required) { |
|
54
|
|
|
$this->testCase->assertElementExists($xpath, AbstractTestCase::BY_XPATH); |
|
55
|
|
|
$this->testCase->assertElementDisplayed($xpath, AbstractTestCase::BY_XPATH); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
if ($this->webDriver->elementDisplayed($xpath, AbstractTestCase::BY_XPATH)) { |
|
59
|
|
|
$this->webDriver->byXpath($xpath)->click(); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
} |