commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-new / civicrm / tests / phpunit / WebTest / Contact / TagSetSearchTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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
29 /**
30 * Class WebTest_Contact_TagSetSearchTest
31 */
32 class WebTest_Contact_TagSetSearchTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 public function testTagSetSearch() {
39 $this->webtestLogin();
40
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');
49 $this->waitForElementPresent("xpath=//*[@id='contact_taglist_{$tagSet1}']/../div/ul/li[1]/input");
50
51 // Add tag1 for Individual 1
52 $tag1 = substr(sha1(rand()), 0, 5);
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);
57 // ...waiting for drop down with results to show up...
58 $this->waitForElementPresent("xpath=//div[@class='select2-result-label']");
59 // ...need to use mouseDownAt on first result (which is a li element), click does not work
60 $this->clickAt("xpath=//div[@class='select2-result-label']");
61 $this->waitForTextPresent($tag1);
62
63 // Add tag2 for Individual 1
64 $tag2 = substr(sha1(rand()), 0, 5);
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);
69 // ...waiting for drop down with results to show up...
70 $this->waitForElementPresent("xpath=//div[@class='select2-result-label']");
71 // ...need to use mouseDownAt on first result (which is a li element), click does not work
72 $this->clickAt("xpath=//div[@class='select2-result-label']");
73 $this->waitForTextPresent($tag2);
74
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');
80 $this->waitForElementPresent("xpath=//*[@id='contact_taglist_{$tagSet1}']/../div/ul/li[1]/input");
81
82 // Add tag1 for Individual 2
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);
87 // ...waiting for drop down with results to show up...
88 $this->waitForElementPresent("xpath=//div[@class='select2-result-label']");
89 // ...need to use mouseDownAt on first result (which is a li element), click does not work
90 $this->clickAt("xpath=//div[@class='select2-result-label']");
91 $this->waitForTextPresent($tag1);
92
93 // Go to Advance search.
94 $this->openCiviPage('contact/search/advanced', 'reset=1');
95
96 // Check both the tagset.
97 $this->assertTrue($this->isElementPresent("contact_taglist_{$tagSet1}"));
98 $this->assertTrue($this->isElementPresent("contact_taglist_{$tagSet2}"));
99
100 // Search contact using tags.
101 $this->select2("contact_taglist_{$tagSet1}", $tag1, TRUE);
102
103 $this->waitForTextPresent($tag1);
104 $this->select2("contact_taglist_{$tagSet2}", $tag2, TRUE);
105
106 $this->waitForTextPresent($tag2);
107
108 $this->click("_qf_Advanced_refresh");
109 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
110
111 // Check result.
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");
115 }
116
117 /**
118 * @return array
119 */
120 public function _testAddTagSet() {
121 // Go to add tag set url.
122 $this->openCiviPage('admin/tag', 'action=add&reset=1&tagset=1');
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?
144 $this->waitForText('crm-notification-container', "The tag '$tagSetName' has been saved.");
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->assertTrue($this->isTextPresent($tagSetName), 'Missing text: ' . $tagSetName);
152
153 $tagid = explode('&id=', $this->getAttribute("xpath=//table[@class='display dataTable no-footer']/tbody//tr/td[1]/div[text()= '$tagSetName']/../../td[8]/span/a[text()= 'Edit']@href"));
154 $tagid = explode('&', $tagid[1]);
155 $tagid = $tagid[0];
156
157 return $tagid;
158 }
159
160 }