Merge pull request #3225 from JSProffitt/jcronfix
[civicrm-core.git] / tests / phpunit / WebTest / Contact / TagSetSearchTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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
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() {
35 $this->webtestLogin();
36
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');
45 $this->waitForElementPresent("xpath=//*[@id='contact_taglist_{$tagSet1}']/../div/ul/li[1]/input");
46
47 // Add tag1 for Individual 1
48 $tag1 = substr(sha1(rand()), 0, 5);
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);
53 // ...waiting for drop down with results to show up...
54 $this->waitForElementPresent("xpath=//div[@class='select2-result-label']");
55 // ...need to use mouseDownAt on first result (which is a li element), click does not work
56 $this->clickAt("xpath=//div[@class='select2-result-label']");
57 $this->waitForTextPresent($tag1);
58
59 // Add tag2 for Individual 1
60 $tag2 = substr(sha1(rand()), 0, 5);
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);
65 // ...waiting for drop down with results to show up...
66 $this->waitForElementPresent("xpath=//div[@class='select2-result-label']");
67 // ...need to use mouseDownAt on first result (which is a li element), click does not work
68 $this->clickAt("xpath=//div[@class='select2-result-label']");
69 $this->waitForTextPresent($tag2);
70
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');
76 $this->waitForElementPresent("xpath=//*[@id='contact_taglist_{$tagSet1}']/../div/ul/li[1]/input");
77
78 // Add tag1 for Individual 2
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);
83 // ...waiting for drop down with results to show up...
84 $this->waitForElementPresent("xpath=//div[@class='select2-result-label']");
85 // ...need to use mouseDownAt on first result (which is a li element), click does not work
86 $this->clickAt("xpath=//div[@class='select2-result-label']");
87 $this->waitForTextPresent($tag1);
88
89 // Go to Advance search.
90 $this->openCiviPage('contact/search/advanced', 'reset=1');
91
92 // Check both the tagset.
93 $this->assertTrue($this->isElementPresent("contact_taglist_{$tagSet1}"));
94 $this->assertTrue($this->isElementPresent("contact_taglist_{$tagSet2}"));
95
96 // Search contact using tags.
97 $this->select2("contact_taglist_{$tagSet1}", $tag1, TRUE);
98
99 $this->waitForTextPresent($tag1);
100 $this->select2("contact_taglist_{$tagSet2}", $tag2, TRUE);
101
102 $this->waitForTextPresent($tag2);
103
104 $this->click("_qf_Advanced_refresh");
105 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
106
107 // Check result.
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");
111 }
112
113 function _testAddTagSet() {
114 // Go to add tag set url.
115 $this->openCiviPage('admin/tag', 'action=add&reset=1&tagset=1');
116
117 // take a tagset name
118 $tagSetName = 'tagset_' . substr(sha1(rand()), 0, 7);
119
120 // fill tagset name
121 $this->type("name", $tagSetName);
122
123 // fill description
124 $this->type("description", "Adding new tag set.");
125
126 // select used for contact
127 $this->select("used_for", "value=civicrm_contact");
128
129 // check reserved
130 $this->click("is_reserved");
131
132 // Clicking save.
133 $this->click("_qf_Tag_next");
134 $this->waitForPageToLoad($this->getTimeoutMsec());
135
136 // Is status message correct?
137 $this->waitForText('crm-notification-container', "The tag '$tagSetName' has been saved.");
138
139 // sort by ID desc
140 $this->click("xpath=//table//tr/th[text()=\"ID\"]");
141 $this->waitForElementPresent("css=table.display tbody tr td");
142
143 // verify text
144 $this->waitForElementPresent("xpath=//table//tbody/tr/td[1][text()= '$tagSetName']");
145
146 $tagid = explode('&id=', $this->getAttribute("xpath=//table//tbody/tr/td[1][text()= '$tagSetName']/following-sibling::td[7]/span/a[text()= 'Edit']@href"));
147 $tagid = explode('&', $tagid[1]);
148 $tagid = $tagid[0];
149
150 return $tagid;
151 }
152 }
153