1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OroCRM\Bundle\AccountBundle\Tests\Behat\Context; |
4
|
|
|
|
5
|
|
|
use Behat\Mink\Element\NodeElement; |
6
|
|
|
use Oro\Bundle\TestFrameworkBundle\Behat\Context\OroFeatureContext; |
7
|
|
|
use Oro\Bundle\TestFrameworkBundle\Behat\Element\OroElementFactoryAware; |
8
|
|
|
use Oro\Bundle\TestFrameworkBundle\Tests\Behat\Context\ElementFactoryDictionary; |
9
|
|
|
|
10
|
|
|
class FeatureContext extends OroFeatureContext implements OroElementFactoryAware |
11
|
|
|
{ |
12
|
|
|
use ElementFactoryDictionary; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @When /^(?:|I )select (?P<title>([\w\s]+)) as email attachment from record$/ |
16
|
|
|
*/ |
17
|
|
|
public function selectEmailAttachment($title) |
18
|
|
|
{ |
19
|
|
|
$page = $this->getPage(); |
20
|
|
|
$page->find('css', '.attach-file')->click(); |
21
|
|
|
$attachment = $page->findElementContains('AttachmentListRow', $title); |
22
|
|
|
self::assertTrue($attachment->isValid(), sprintf('"%s" attachment not found', $title)); |
23
|
|
|
|
24
|
|
|
$attachment->find('css', 'input')->check(); |
25
|
|
|
$page->find('css', 'a.attach')->click(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @Then /^(?P<contactsCount>(?:|one|two|\d+)) contacts added to form$/ |
30
|
|
|
*/ |
31
|
|
|
public function assertCountContactsAddedToForm($contactsCount) |
32
|
|
|
{ |
33
|
|
|
self::assertCount($this->getCount($contactsCount), $this->getFormContacts()); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @When /^(?:|I should )see (?P<contactsCount>(?:|one|two|\d+)) contact(?:|s)$/ |
38
|
|
|
*/ |
39
|
|
|
public function assertCountOfContacts($contactsCount) |
40
|
|
|
{ |
41
|
|
|
self::assertCount( |
42
|
|
|
$this->getCount($contactsCount), |
43
|
|
|
$this->getSession()->getPage()->findAll('css', '.contact-box') |
44
|
|
|
); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @When :name should be default contact |
49
|
|
|
*/ |
50
|
|
View Code Duplication |
public function assertDefaultContact($name) |
|
|
|
|
51
|
|
|
{ |
52
|
|
|
$contactBoxes = $this->getSession()->getPage()->findAll('css', '.contact-box'); |
53
|
|
|
|
54
|
|
|
/** @var NodeElement $box */ |
55
|
|
|
foreach ($contactBoxes as $box) { |
56
|
|
|
if (false !== strpos($box->getText(), $name)) { |
57
|
|
|
self::assertRegExp('/Default Contact/i', $box->getText()); |
58
|
|
|
return; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
self::fail(sprintf('Can\'t find contact with "%s" name', $name)); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @Then /^(?:|I )select ([\w\s]*) contact as default$/ |
68
|
|
|
*/ |
69
|
|
View Code Duplication |
public function selectContactAsDefault($name) |
|
|
|
|
70
|
|
|
{ |
71
|
|
|
foreach ($this->getFormContacts() as $contact) { |
72
|
|
|
if (false !== strpos($contact->getText(), $name)) { |
73
|
|
|
$contact->find('css', 'input[type="radio"]')->click(); |
74
|
|
|
|
75
|
|
|
return; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
self::fail(sprintf('Can\'t find contact with "%s" name', $name)); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @Then delete :name contact |
84
|
|
|
*/ |
85
|
|
View Code Duplication |
public function deleteContact($name) |
|
|
|
|
86
|
|
|
{ |
87
|
|
|
foreach ($this->getFormContacts() as $contact) { |
88
|
|
|
if (false !== strpos($contact->getText(), $name)) { |
89
|
|
|
$contact->find('css', 'i.icon-remove')->click(); |
90
|
|
|
|
91
|
|
|
return; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
self::fail(sprintf('Can\'t find contact with "%s" name', $name)); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @return NodeElement[] |
100
|
|
|
*/ |
101
|
|
|
protected function getFormContacts() |
102
|
|
|
{ |
103
|
|
|
$page = $this->getSession()->getPage(); |
104
|
|
|
|
105
|
|
|
return $page->findAll('css', 'div[id^="orocrm_account_form_contacts"] .list-group-item'); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @param int|string $count |
110
|
|
|
* @return int |
111
|
|
|
*/ |
112
|
|
View Code Duplication |
protected function getCount($count) |
|
|
|
|
113
|
|
|
{ |
114
|
|
|
switch (trim($count)) { |
115
|
|
|
case '': |
116
|
|
|
return 1; |
117
|
|
|
case 'one': |
118
|
|
|
return 1; |
119
|
|
|
case 'two': |
120
|
|
|
return 2; |
121
|
|
|
default: |
122
|
|
|
return (int) $count; |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
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.