|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Magium\Magento\Actions\Admin\Configuration; |
|
4
|
|
|
|
|
5
|
|
|
use Facebook\WebDriver\WebDriverElement; |
|
6
|
|
|
use Facebook\WebDriver\WebDriverSelect; |
|
7
|
|
|
use Magium\Magento\AbstractMagentoTestCase; |
|
8
|
|
|
use Magium\Magento\Navigators\Admin\SystemConfiguration; |
|
9
|
|
|
use Magium\Magento\Themes\Admin\ThemeConfiguration; |
|
10
|
|
|
use Magium\WebDriver\FastSelectElement; |
|
11
|
|
|
use Magium\WebDriver\WebDriver; |
|
12
|
|
|
|
|
13
|
|
|
class SettingModifier |
|
14
|
|
|
{ |
|
15
|
|
|
|
|
16
|
|
|
const ACTION = 'Admin\Configuration\SettingModifier'; |
|
17
|
|
|
|
|
18
|
|
|
const SETTING_OPTION_YES = 1; |
|
19
|
|
|
const SETTING_OPTION_NO = 0; |
|
20
|
|
|
|
|
21
|
|
|
protected $webDriver; |
|
22
|
|
|
protected $testCase; |
|
23
|
|
|
protected $systemConfigurationNavigator; |
|
24
|
|
|
protected $themeConfiguration; |
|
25
|
|
|
protected $save; |
|
26
|
|
|
|
|
27
|
|
|
protected $dataChanged = false; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* SettingModifier constructor. |
|
31
|
|
|
* @param $webDriver |
|
32
|
|
|
* @param $testCase |
|
33
|
|
|
* @param $systemConfigurationNavigator |
|
34
|
|
|
* @param $themeConfiguration |
|
35
|
|
|
*/ |
|
36
|
|
|
public function __construct( |
|
37
|
|
|
WebDriver $webDriver, |
|
38
|
|
|
AbstractMagentoTestCase $testCase, |
|
39
|
|
|
SystemConfiguration $systemConfigurationNavigator, |
|
40
|
|
|
ThemeConfiguration $themeConfiguration, |
|
41
|
|
|
Save $save |
|
42
|
|
|
) |
|
43
|
|
|
{ |
|
44
|
|
|
$this->webDriver = $webDriver; |
|
45
|
|
|
$this->testCase = $testCase; |
|
46
|
|
|
$this->systemConfigurationNavigator = $systemConfigurationNavigator; |
|
47
|
|
|
$this->themeConfiguration = $themeConfiguration; |
|
48
|
|
|
$this->save = $save; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Changes a system configuration setting based off of the identifier. The identifier can be specified in 4 |
|
53
|
|
|
* possible ways. |
|
54
|
|
|
* |
|
55
|
|
|
* * Tab/Section::setting_id (will ensure that the correct section is navigated to) |
|
56
|
|
|
* * setting_id (will not navigate (no section information) |
|
57
|
|
|
* * Tab/Section::name=Text Of Setting (will ensure that the correct section is navigated to, uses setting name (exact), not ID) |
|
58
|
|
|
* * name=Text Of Setting (will not navigate, uses setting name (exact) not ID) |
|
59
|
|
|
* |
|
60
|
|
|
* @param $identifier |
|
61
|
|
|
* @param $value |
|
62
|
|
|
* @throws \Magium\InvalidInstructionException |
|
63
|
|
|
*/ |
|
64
|
|
|
|
|
65
|
|
|
public function set($identifier, $value, $save = false) |
|
66
|
|
|
{ |
|
67
|
|
|
$parts = explode('::', $identifier); |
|
68
|
|
|
$setting = null; |
|
|
|
|
|
|
69
|
|
|
if (count($parts) === 2) { |
|
70
|
|
|
$this->systemConfigurationNavigator->navigateTo($parts[0]); |
|
71
|
|
|
$setting = $parts[1]; |
|
72
|
|
|
} else { |
|
73
|
|
|
$setting = $parts[0]; |
|
74
|
|
|
} |
|
75
|
|
|
$matches = null; |
|
76
|
|
|
if (preg_match('/^label=(.+)$/', $setting, $matches)) { |
|
77
|
|
|
$xpath = ''; |
|
78
|
|
|
if (count($xpath) === 2) { |
|
79
|
|
|
$nav = explode('/', $parts[0]); |
|
80
|
|
|
$xpath = $this->themeConfiguration->getSystemConfigSectionDisplayCheckXpath($nav[1]) . '/descendant::'; |
|
81
|
|
|
} |
|
82
|
|
|
$xpath .= $this->themeConfiguration->getSystemConfigSettingLabelXpath($matches[1]); |
|
83
|
|
|
$labelElement = $this->webDriver->byXpath($xpath); |
|
84
|
|
|
$setting = $labelElement->getAttribute('for'); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
$this->handleElementSetting($setting, $value); |
|
88
|
|
|
if ($save) { |
|
89
|
|
|
$this->save->save(); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
protected function handleElementSetting($elementId, $value) |
|
94
|
|
|
{ |
|
95
|
|
|
$element = $this->webDriver->byId($elementId); |
|
96
|
|
|
|
|
97
|
|
|
if (strtolower($element->getTagName()) === 'select') { |
|
98
|
|
|
if (!is_array($value)) { |
|
99
|
|
|
$value = [$value]; |
|
100
|
|
|
} |
|
101
|
|
|
$xpath = sprintf('//select[@id="%s"]', $elementId); |
|
102
|
|
|
$select = new FastSelectElement($this->webDriver, $xpath); |
|
103
|
|
|
// $options = $select->getAllSelectedOptions(); |
|
|
|
|
|
|
104
|
|
|
$select->clearSelectedOptions(); |
|
105
|
|
|
foreach ($value as $v) { |
|
106
|
|
|
$xpath = sprintf('//select[@id="%s"]', $elementId); |
|
107
|
|
|
$matches = null; |
|
108
|
|
|
if (preg_match('/^label=(.+)$/', $v, $matches)) { |
|
109
|
|
|
$xpath .= sprintf('/descendant::option[.="%s"]', str_replace('"', '\"', $matches[1])); |
|
110
|
|
|
$this->webDriver->byXpath($xpath)->click(); |
|
111
|
|
|
} else { |
|
112
|
|
|
$xpath .= sprintf('/descendant::option[@value="%s"]', str_replace('"', '\"', $v)); |
|
113
|
|
|
$this->webDriver->byXpath($xpath)->click(); |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
} else if (strtolower($element->getTagName()) === 'input') { |
|
118
|
|
|
if ($element->getAttribute('value') != $value) { |
|
119
|
|
|
$element->clear(); |
|
120
|
|
|
$element->sendKeys($value); |
|
121
|
|
|
$this->dataChanged = true; |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
} |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.