1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Magium\Magento\Actions\Admin\Tables; |
4
|
|
|
|
5
|
|
|
use Magium\Actions\OptionallyConfigurableActionInterface; |
6
|
|
|
use Magium\Magento\Actions\Admin\Widget\ClickActionButton; |
7
|
|
|
use Magium\Magento\Navigators\Admin\AdminMenu; |
8
|
|
|
use Magium\Magento\Themes\Admin\ThemeConfiguration; |
9
|
|
|
use Magium\Util\Translator\Translator; |
10
|
|
|
use Magium\WebDriver\WebDriver; |
11
|
|
|
|
12
|
|
|
class RemoveTermsAndConditions implements OptionallyConfigurableActionInterface |
13
|
|
|
{ |
14
|
|
|
|
15
|
|
|
const ACTION = 'Admin\Tables\RemoveTermsAndConditions'; |
16
|
|
|
|
17
|
|
|
protected $webDriver; |
18
|
|
|
protected $themeConfiguration; |
19
|
|
|
protected $navigator; |
20
|
|
|
protected $clickActionButton; |
21
|
|
|
protected $translator; |
22
|
|
|
|
23
|
|
View Code Duplication |
public function __construct( |
|
|
|
|
24
|
|
|
WebDriver $webDriver, |
25
|
|
|
ThemeConfiguration $themeConfiguration, |
26
|
|
|
AdminMenu $navigator, |
27
|
|
|
ClickActionButton $clickActionButton, |
28
|
|
|
Translator $translator |
29
|
|
|
) |
30
|
|
|
{ |
31
|
|
|
$this->webDriver = $webDriver; |
32
|
|
|
$this->themeConfiguration = $themeConfiguration; |
33
|
|
|
$this->navigator = $navigator; |
34
|
|
|
$this->clickActionButton = $clickActionButton; |
35
|
|
|
$this->translator = $translator; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function removeAll($navigate = false) |
39
|
|
|
{ |
40
|
|
|
if ($navigate) { |
41
|
|
|
$this->navigator->navigateTo('Sales/Terms and conditions'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
$xpath = $this->themeConfiguration->getFirstTermsRowXpath(); |
45
|
|
|
|
46
|
|
|
while ($this->webDriver->elementExists($xpath, WebDriver::BY_XPATH)) { |
47
|
|
|
$this->webDriver->byXpath($xpath)->click(); |
48
|
|
|
$this->clickActionButton->click($this->translator->translate('Delete Condition')); |
49
|
|
|
$this->webDriver->switchTo()->alert()->accept(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function execute($param = null) |
55
|
|
|
{ |
56
|
|
|
$this->removeAll($param); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
} |
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.