Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06a1bc01 | 4 | | CiviCRM version 4.5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06a1bc01 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License along with this program; if not, contact CiviCRM LLC | | |
21 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
22 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
23 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
24 | +--------------------------------------------------------------------+ | |
25 | */ | |
26 | ||
6a488035 | 27 | require_once 'CiviTest/CiviSeleniumTestCase.php'; |
e9479dcf EM |
28 | |
29 | /** | |
30 | * Class WebTest_Contact_TagSetSearchTest | |
31 | */ | |
6a488035 TO |
32 | class WebTest_Contact_TagSetSearchTest extends CiviSeleniumTestCase { |
33 | ||
34 | protected function setUp() { | |
35 | parent::setUp(); | |
36 | } | |
37 | ||
38 | function testTagSetSearch() { | |
6a488035 TO |
39 | $this->webtestLogin(); |
40 | ||
6a488035 TO |
41 | $tagSet1 = $this->_testAddTagSet(); |
42 | $tagSet2 = $this->_testAddTagSet(); | |
43 | ||
44 | // Individual 1 | |
45 | $contact1 = substr(sha1(rand()), 0, 7); | |
46 | $this->webtestAddContact($contact1, "Anderson", "{$contact1}@example.com"); | |
47 | ||
48 | $this->click('css=li#tab_tag a'); | |
8cc4f1ab | 49 | $this->waitForElementPresent("xpath=//*[@id='contact_taglist_{$tagSet1}']/../div/ul/li[1]/input"); |
6a488035 TO |
50 | |
51 | // Add tag1 for Individual 1 | |
52 | $tag1 = substr(sha1(rand()), 0, 5); | |
8cc4f1ab | 53 | $this->click("xpath=//*[@id='contact_taglist_{$tagSet1}']/../div/ul/li[1]/input"); |
54 | $this->keyDown("xpath=//*[@id='contact_taglist_{$tagSet1}']/../div/ul/li[1]/input", " "); | |
55 | $this->type("xpath=//*[@id='contact_taglist_{$tagSet1}']/../div/ul/li[1]/input", $tag1); | |
56 | $this->typeKeys("xpath=//*[@id='contact_taglist_{$tagSet1}']/../div/ul/li[1]/input", $tag1); | |
6a488035 | 57 | // ...waiting for drop down with results to show up... |
8cc4f1ab | 58 | $this->waitForElementPresent("xpath=//div[@class='select2-result-label']"); |
6a488035 | 59 | // ...need to use mouseDownAt on first result (which is a li element), click does not work |
8cc4f1ab | 60 | $this->clickAt("xpath=//div[@class='select2-result-label']"); |
6a488035 TO |
61 | $this->waitForTextPresent($tag1); |
62 | ||
63 | // Add tag2 for Individual 1 | |
64 | $tag2 = substr(sha1(rand()), 0, 5); | |
8cc4f1ab | 65 | $this->click("xpath=//*[@id='contact_taglist_{$tagSet2}']/../div/ul/li[1]/input"); |
66 | $this->keyDown("xpath=//*[@id='contact_taglist_{$tagSet2}']/../div/ul/li[1]/input", " "); | |
67 | $this->type("xpath=//*[@id='contact_taglist_{$tagSet2}']/../div/ul/li[1]/input", $tag2); | |
68 | $this->typeKeys("xpath=//*[@id='contact_taglist_{$tagSet2}']/../div/ul/li[1]/input", $tag2); | |
6a488035 | 69 | // ...waiting for drop down with results to show up... |
8cc4f1ab | 70 | $this->waitForElementPresent("xpath=//div[@class='select2-result-label']"); |
6a488035 | 71 | // ...need to use mouseDownAt on first result (which is a li element), click does not work |
8cc4f1ab | 72 | $this->clickAt("xpath=//div[@class='select2-result-label']"); |
6a488035 TO |
73 | $this->waitForTextPresent($tag2); |
74 | ||
6a488035 TO |
75 | // Individual 2 |
76 | $contact2 = substr(sha1(rand()), 0, 7); | |
77 | $this->webtestAddContact($contact2, "Anderson", "{$contact2}@example.com"); | |
78 | ||
79 | $this->click('css=li#tab_tag a'); | |
8cc4f1ab | 80 | $this->waitForElementPresent("xpath=//*[@id='contact_taglist_{$tagSet1}']/../div/ul/li[1]/input"); |
6a488035 TO |
81 | |
82 | // Add tag1 for Individual 2 | |
8cc4f1ab | 83 | $this->click("xpath=//*[@id='contact_taglist_{$tagSet1}']/../div/ul/li[1]/input"); |
84 | $this->keyDown("xpath=//*[@id='contact_taglist_{$tagSet1}']/../div/ul/li[1]/input", " "); | |
85 | $this->type("xpath=//*[@id='contact_taglist_{$tagSet1}']/../div/ul/li[1]/input", $tag1); | |
86 | $this->typeKeys("xpath=//*[@id='contact_taglist_{$tagSet1}']/../div/ul/li[1]/input", $tag1); | |
6a488035 | 87 | // ...waiting for drop down with results to show up... |
8cc4f1ab | 88 | $this->waitForElementPresent("xpath=//div[@class='select2-result-label']"); |
6a488035 | 89 | // ...need to use mouseDownAt on first result (which is a li element), click does not work |
8cc4f1ab | 90 | $this->clickAt("xpath=//div[@class='select2-result-label']"); |
6a488035 TO |
91 | $this->waitForTextPresent($tag1); |
92 | ||
6a488035 | 93 | // Go to Advance search. |
d8bd5fb9 | 94 | $this->openCiviPage('contact/search/advanced', 'reset=1'); |
6a488035 TO |
95 | |
96 | // Check both the tagset. | |
8cc4f1ab | 97 | $this->assertTrue($this->isElementPresent("contact_taglist_{$tagSet1}")); |
98 | $this->assertTrue($this->isElementPresent("contact_taglist_{$tagSet2}")); | |
6a488035 TO |
99 | |
100 | // Search contact using tags. | |
8cc4f1ab | 101 | $this->select2("contact_taglist_{$tagSet1}", $tag1, TRUE); |
6a488035 TO |
102 | |
103 | $this->waitForTextPresent($tag1); | |
8cc4f1ab | 104 | $this->select2("contact_taglist_{$tagSet2}", $tag2, TRUE); |
6a488035 TO |
105 | |
106 | $this->waitForTextPresent($tag2); | |
107 | ||
108 | $this->click("_qf_Advanced_refresh"); | |
109 | $this->waitForPageToLoad(2 * $this->getTimeoutMsec()); | |
110 | ||
111 | // Check result. | |
d8bd5fb9 RN |
112 | $this->assertElementContainsText('search-status', "2 Contacts"); |
113 | $this->assertElementContainsText('css=.crm-search-results table.selector', "Anderson, $contact1"); | |
114 | $this->assertElementContainsText('css=.crm-search-results table.selector', "Anderson, $contact2"); | |
6a488035 TO |
115 | } |
116 | ||
4cbe18b8 EM |
117 | /** |
118 | * @return array | |
119 | */ | |
6a488035 TO |
120 | function _testAddTagSet() { |
121 | // Go to add tag set url. | |
d8bd5fb9 | 122 | $this->openCiviPage('admin/tag', 'action=add&reset=1&tagset=1'); |
6a488035 TO |
123 | |
124 | // take a tagset name | |
125 | $tagSetName = 'tagset_' . substr(sha1(rand()), 0, 7); | |
126 | ||
127 | // fill tagset name | |
128 | $this->type("name", $tagSetName); | |
129 | ||
130 | // fill description | |
131 | $this->type("description", "Adding new tag set."); | |
132 | ||
133 | // select used for contact | |
134 | $this->select("used_for", "value=civicrm_contact"); | |
135 | ||
136 | // check reserved | |
137 | $this->click("is_reserved"); | |
138 | ||
139 | // Clicking save. | |
140 | $this->click("_qf_Tag_next"); | |
141 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
142 | ||
143 | // Is status message correct? | |
6c5f7368 | 144 | $this->waitForText('crm-notification-container', "The tag '$tagSetName' has been saved."); |
6a488035 TO |
145 | |
146 | // sort by ID desc | |
147 | $this->click("xpath=//table//tr/th[text()=\"ID\"]"); | |
148 | $this->waitForElementPresent("css=table.display tbody tr td"); | |
149 | ||
150 | // verify text | |
151 | $this->waitForElementPresent("xpath=//table//tbody/tr/td[1][text()= '$tagSetName']"); | |
152 | ||
0e32ba2d | 153 | $tagid = explode('&id=', $this->getAttribute("xpath=//table//tbody/tr/td[1][text()= '$tagSetName']/following-sibling::td[7]/span/a[text()= 'Edit']@href")); |
154 | $tagid = explode('&', $tagid[1]); | |
155 | $tagid = $tagid[0]; | |
6a488035 | 156 | |
0e32ba2d | 157 | return $tagid; |
6a488035 TO |
158 | } |
159 | } | |
160 |