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 TO |
27 | require_once 'CiviTest/CiviSeleniumTestCase.php'; |
28 | class WebTest_Contact_TagSetSearchTest extends CiviSeleniumTestCase { | |
29 | ||
30 | protected function setUp() { | |
31 | parent::setUp(); | |
32 | } | |
33 | ||
34 | function testTagSetSearch() { | |
6a488035 TO |
35 | $this->webtestLogin(); |
36 | ||
6a488035 TO |
37 | $tagSet1 = $this->_testAddTagSet(); |
38 | $tagSet2 = $this->_testAddTagSet(); | |
39 | ||
40 | // Individual 1 | |
41 | $contact1 = substr(sha1(rand()), 0, 7); | |
42 | $this->webtestAddContact($contact1, "Anderson", "{$contact1}@example.com"); | |
43 | ||
44 | $this->click('css=li#tab_tag a'); | |
8cc4f1ab | 45 | $this->waitForElementPresent("xpath=//*[@id='contact_taglist_{$tagSet1}']/../div/ul/li[1]/input"); |
6a488035 TO |
46 | |
47 | // Add tag1 for Individual 1 | |
48 | $tag1 = substr(sha1(rand()), 0, 5); | |
8cc4f1ab | 49 | $this->click("xpath=//*[@id='contact_taglist_{$tagSet1}']/../div/ul/li[1]/input"); |
50 | $this->keyDown("xpath=//*[@id='contact_taglist_{$tagSet1}']/../div/ul/li[1]/input", " "); | |
51 | $this->type("xpath=//*[@id='contact_taglist_{$tagSet1}']/../div/ul/li[1]/input", $tag1); | |
52 | $this->typeKeys("xpath=//*[@id='contact_taglist_{$tagSet1}']/../div/ul/li[1]/input", $tag1); | |
6a488035 | 53 | // ...waiting for drop down with results to show up... |
8cc4f1ab | 54 | $this->waitForElementPresent("xpath=//div[@class='select2-result-label']"); |
6a488035 | 55 | // ...need to use mouseDownAt on first result (which is a li element), click does not work |
8cc4f1ab | 56 | $this->clickAt("xpath=//div[@class='select2-result-label']"); |
6a488035 TO |
57 | $this->waitForTextPresent($tag1); |
58 | ||
59 | // Add tag2 for Individual 1 | |
60 | $tag2 = substr(sha1(rand()), 0, 5); | |
8cc4f1ab | 61 | $this->click("xpath=//*[@id='contact_taglist_{$tagSet2}']/../div/ul/li[1]/input"); |
62 | $this->keyDown("xpath=//*[@id='contact_taglist_{$tagSet2}']/../div/ul/li[1]/input", " "); | |
63 | $this->type("xpath=//*[@id='contact_taglist_{$tagSet2}']/../div/ul/li[1]/input", $tag2); | |
64 | $this->typeKeys("xpath=//*[@id='contact_taglist_{$tagSet2}']/../div/ul/li[1]/input", $tag2); | |
6a488035 | 65 | // ...waiting for drop down with results to show up... |
8cc4f1ab | 66 | $this->waitForElementPresent("xpath=//div[@class='select2-result-label']"); |
6a488035 | 67 | // ...need to use mouseDownAt on first result (which is a li element), click does not work |
8cc4f1ab | 68 | $this->clickAt("xpath=//div[@class='select2-result-label']"); |
6a488035 TO |
69 | $this->waitForTextPresent($tag2); |
70 | ||
6a488035 TO |
71 | // Individual 2 |
72 | $contact2 = substr(sha1(rand()), 0, 7); | |
73 | $this->webtestAddContact($contact2, "Anderson", "{$contact2}@example.com"); | |
74 | ||
75 | $this->click('css=li#tab_tag a'); | |
8cc4f1ab | 76 | $this->waitForElementPresent("xpath=//*[@id='contact_taglist_{$tagSet1}']/../div/ul/li[1]/input"); |
6a488035 TO |
77 | |
78 | // Add tag1 for Individual 2 | |
8cc4f1ab | 79 | $this->click("xpath=//*[@id='contact_taglist_{$tagSet1}']/../div/ul/li[1]/input"); |
80 | $this->keyDown("xpath=//*[@id='contact_taglist_{$tagSet1}']/../div/ul/li[1]/input", " "); | |
81 | $this->type("xpath=//*[@id='contact_taglist_{$tagSet1}']/../div/ul/li[1]/input", $tag1); | |
82 | $this->typeKeys("xpath=//*[@id='contact_taglist_{$tagSet1}']/../div/ul/li[1]/input", $tag1); | |
6a488035 | 83 | // ...waiting for drop down with results to show up... |
8cc4f1ab | 84 | $this->waitForElementPresent("xpath=//div[@class='select2-result-label']"); |
6a488035 | 85 | // ...need to use mouseDownAt on first result (which is a li element), click does not work |
8cc4f1ab | 86 | $this->clickAt("xpath=//div[@class='select2-result-label']"); |
6a488035 TO |
87 | $this->waitForTextPresent($tag1); |
88 | ||
6a488035 | 89 | // Go to Advance search. |
d8bd5fb9 | 90 | $this->openCiviPage('contact/search/advanced', 'reset=1'); |
6a488035 TO |
91 | |
92 | // Check both the tagset. | |
8cc4f1ab | 93 | $this->assertTrue($this->isElementPresent("contact_taglist_{$tagSet1}")); |
94 | $this->assertTrue($this->isElementPresent("contact_taglist_{$tagSet2}")); | |
6a488035 TO |
95 | |
96 | // Search contact using tags. | |
8cc4f1ab | 97 | $this->select2("contact_taglist_{$tagSet1}", $tag1, TRUE); |
6a488035 TO |
98 | |
99 | $this->waitForTextPresent($tag1); | |
8cc4f1ab | 100 | $this->select2("contact_taglist_{$tagSet2}", $tag2, TRUE); |
6a488035 TO |
101 | |
102 | $this->waitForTextPresent($tag2); | |
103 | ||
104 | $this->click("_qf_Advanced_refresh"); | |
105 | $this->waitForPageToLoad(2 * $this->getTimeoutMsec()); | |
106 | ||
107 | // Check result. | |
d8bd5fb9 RN |
108 | $this->assertElementContainsText('search-status', "2 Contacts"); |
109 | $this->assertElementContainsText('css=.crm-search-results table.selector', "Anderson, $contact1"); | |
110 | $this->assertElementContainsText('css=.crm-search-results table.selector', "Anderson, $contact2"); | |
6a488035 TO |
111 | } |
112 | ||
4cbe18b8 EM |
113 | /** |
114 | * @return array | |
115 | */ | |
6a488035 TO |
116 | function _testAddTagSet() { |
117 | // Go to add tag set url. | |
d8bd5fb9 | 118 | $this->openCiviPage('admin/tag', 'action=add&reset=1&tagset=1'); |
6a488035 TO |
119 | |
120 | // take a tagset name | |
121 | $tagSetName = 'tagset_' . substr(sha1(rand()), 0, 7); | |
122 | ||
123 | // fill tagset name | |
124 | $this->type("name", $tagSetName); | |
125 | ||
126 | // fill description | |
127 | $this->type("description", "Adding new tag set."); | |
128 | ||
129 | // select used for contact | |
130 | $this->select("used_for", "value=civicrm_contact"); | |
131 | ||
132 | // check reserved | |
133 | $this->click("is_reserved"); | |
134 | ||
135 | // Clicking save. | |
136 | $this->click("_qf_Tag_next"); | |
137 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
138 | ||
139 | // Is status message correct? | |
6c5f7368 | 140 | $this->waitForText('crm-notification-container', "The tag '$tagSetName' has been saved."); |
6a488035 TO |
141 | |
142 | // sort by ID desc | |
143 | $this->click("xpath=//table//tr/th[text()=\"ID\"]"); | |
144 | $this->waitForElementPresent("css=table.display tbody tr td"); | |
145 | ||
146 | // verify text | |
147 | $this->waitForElementPresent("xpath=//table//tbody/tr/td[1][text()= '$tagSetName']"); | |
148 | ||
0e32ba2d | 149 | $tagid = explode('&id=', $this->getAttribute("xpath=//table//tbody/tr/td[1][text()= '$tagSetName']/following-sibling::td[7]/span/a[text()= 'Edit']@href")); |
150 | $tagid = explode('&', $tagid[1]); | |
151 | $tagid = $tagid[0]; | |
6a488035 | 152 | |
0e32ba2d | 153 | return $tagid; |
6a488035 TO |
154 | } |
155 | } | |
156 |