1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Magium\Magento\Navigators\Admin; |
4
|
|
|
|
5
|
|
|
use Magium\AbstractTestCase; |
6
|
|
|
use Magium\Actions\WaitForPageLoaded; |
7
|
|
|
use Magium\InvalidInstructionException; |
8
|
|
|
use Magium\Magento\AbstractMagentoTestCase; |
9
|
|
|
use Magium\Magento\Themes\Admin\ThemeConfiguration; |
10
|
|
|
use Magium\Navigators\ConfigurableNavigatorInterface; |
11
|
|
|
use Magium\WebDriver\ExpectedCondition; |
12
|
|
|
use Magium\WebDriver\WebDriver; |
13
|
|
|
class SystemConfiguration implements ConfigurableNavigatorInterface |
14
|
|
|
{ |
15
|
|
|
|
16
|
|
|
const NAVIGATOR = 'Admin\SystemConfiguration'; |
17
|
|
|
|
18
|
|
|
protected $webdriver; |
19
|
|
|
protected $themeConfiguration; |
20
|
|
|
protected $testCase; |
21
|
|
|
protected $loaded; |
22
|
|
|
|
23
|
|
|
public function __construct( |
24
|
|
|
ThemeConfiguration $theme, |
25
|
|
|
WebDriver $webdriver, |
26
|
|
|
AbstractMagentoTestCase $testCase, |
27
|
|
|
WaitForPageLoaded $loaded |
28
|
|
|
) { |
29
|
|
|
$this->themeConfiguration = $theme; |
30
|
|
|
$this->webdriver = $webdriver; |
31
|
|
|
$this->testCase = $testCase; |
32
|
|
|
$this->loaded = $loaded; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function navigateTo($path) |
36
|
|
|
{ |
37
|
|
|
$instructions = explode('/', $path, 2); |
38
|
|
|
if (count($instructions) !== 2) { |
39
|
|
|
throw new InvalidInstructionException('System Configuration instructions need to be in the format of "Tab/Section"'); |
40
|
|
|
} |
41
|
|
|
$tabXpath = $this->themeConfiguration->getSystemConfigTabsXpath($instructions[0]); |
42
|
|
|
$sectionDisplayXpath = $this->themeConfiguration->getSystemConfigSectionDisplayCheckXpath($instructions[1]); |
43
|
|
|
$sectionToggleXpath = $this->themeConfiguration->getSystemConfigSectionToggleXpath($instructions[1]); |
44
|
|
|
|
45
|
|
|
$this->testCase->assertElementExists($tabXpath, AbstractTestCase::BY_XPATH); |
46
|
|
View Code Duplication |
if (!$this->webdriver->elementDisplayed($sectionDisplayXpath, WebDriver::BY_XPATH)) { |
|
|
|
|
47
|
|
|
|
48
|
|
|
$this->webdriver->byXpath($tabXpath)->click(); |
49
|
|
|
|
50
|
|
|
$this->webdriver->wait()->until(ExpectedCondition::elementExists($sectionDisplayXpath, AbstractTestCase::BY_XPATH)); |
|
|
|
|
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
$this->testCase->assertElementExists($sectionToggleXpath, AbstractTestCase::BY_XPATH); |
54
|
|
|
if (!$this->webdriver->elementDisplayed($sectionDisplayXpath, AbstractTestCase::BY_XPATH)) { |
55
|
|
|
$element = $this->webdriver->byXpath($sectionToggleXpath); |
56
|
|
|
$element->click(); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
} |
61
|
|
|
|
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.