Merge pull request #10379 from seanmadsen/CRM-20301
[civicrm-core.git] / tests / phpunit / WebTest / Contact / ContactTagTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
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_ContactTagTest
31 */
32 class WebTest_Contact_ContactTagTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 public function testTagAContact() {
39 $this->webtestLogin();
40
41 $this->openCiviPage("admin/tag", "action=add&reset=1", "_qf_Tag_next");
42
43 // take a tag name
44 $tagName = 'tag_' . substr(sha1(rand()), 0, 7);
45
46 // fill tag name
47 $this->type("name", $tagName);
48
49 // fill description
50 $this->type("description", "Adding new tag.");
51
52 // select used for contact
53 $this->select("used_for", "value=civicrm_contact");
54
55 // check reserved
56 $this->click("is_reserved");
57
58 // Clicking save.
59 $this->click("_qf_Tag_next");
60 $this->waitForPageToLoad($this->getTimeoutMsec());
61
62 // Is status message correct?
63 $this->waitForText('crm-notification-container', "The tag '$tagName' has been saved.");
64
65 // Adding contact
66 // We're using Quick Add block on the main page for this.
67 $firstName = substr(sha1(rand()), 0, 7);
68 $this->webtestAddContact($firstName, "Anderson", "$firstName@anderson.name");
69
70 // visit tag tab
71 $this->click("css=li#tab_tag a");
72 $this->waitForElementPresent("css=div#tagtree");
73
74 // check tag we have created
75 $this->click("xpath=//ul/li/span/label[text()=\"$tagName\"]");
76 $this->checkCRMStatus();
77 }
78
79 public function testTagSetContact() {
80 $this->webtestLogin();
81
82 $this->openCiviPage("admin/tag", "action=add&reset=1&tagset=1");
83
84 // take a tagset name
85 $tagSetName = 'tagset_' . substr(sha1(rand()), 0, 7);
86
87 // fill tagset name
88 $this->type("name", $tagSetName);
89
90 // fill description
91 $this->type("description", "Adding new tag set.");
92
93 // select used for contact
94 $this->select("used_for", "value=civicrm_contact");
95
96 // check reserved
97 $this->click("is_reserved");
98
99 // Clicking save.
100 $this->click("_qf_Tag_next");
101 $this->waitForPageToLoad($this->getTimeoutMsec());
102
103 // Is status message correct?
104 $this->waitForText('crm-notification-container', "The tag '$tagSetName' has been saved.");
105
106 // Adding contact
107 // We're using Quick Add block on the main page for this.
108 $firstName = substr(sha1(rand()), 0, 7);
109 $this->webtestAddContact($firstName, "Anderson", "$firstName@anderson.name");
110
111 // visit tag tab
112 $this->click("css=li#tab_tag a");
113 $this->waitForElementPresent("css=div#tagtree");
114
115 //add Tagset to contact
116 $this->click("xpath=//div[@id='Tag']/div[2]/div/div/ul/li/input");
117 $this->keyDown("xpath=//div[@id='Tag']/div[2]/div/div/ul/li/input", " ");
118 $this->type("xpath=//div[@id='Tag']/div[2]/div/div/ul/li/input", 'tagset1');
119 $this->typeKeys("xpath=//div[@id='Tag']/div[2]/div/div/ul/li/input", 'tagset1');
120
121 // ...waiting for drop down with results to show up...
122 $this->waitForElementPresent("xpath=//div[@class='select2-result-label']");
123
124 // ...need to use mouseDownAt on first result (which is a li element), click does not work
125 $this->clickAt("xpath=//div[@class='select2-result-label']");
126 $this->waitForElementPresent("//div[@id='Tag']/div[2]/div/div/ul/li[1]/div[text()='tagset1']");
127 $this->click("xpath=//div[@id='Tag']/div[2]/div/div/ul/li[2]/input");
128 $this->keyDown("xpath=//div[@id='Tag']/div[2]/div/div/ul/li[2]/input", " ");
129 $this->type("xpath=//div[@id='Tag']/div[2]/div/div/ul/li[2]/input", 'tagset2');
130 $this->typeKeys("xpath=//div[@id='Tag']/div[2]/div/div/ul/li[2]/input", 'tagset2');
131
132 // ...waiting for drop down with results to show up...
133 $this->waitForElementPresent("xpath=//div[@class='select2-result-label']");
134
135 // ...need to use mouseDownAt on first result (which is a li element), click does not work
136 $this->clickAt("xpath=//div[@class='select2-result-label']");
137
138 // Type search name in autocomplete.
139 $this->click("css=input#sort_name_navigation");
140 $this->type("css=input#sort_name_navigation", $firstName);
141 $this->typeKeys("css=input#sort_name_navigation", $firstName);
142
143 // Wait for result list.
144 $this->waitForElementPresent("css=ul.ui-autocomplete li");
145
146 // Visit contact summary page.
147 $this->click("css=ul.ui-autocomplete li");
148 $this->waitForAjaxContent();
149 $this->waitForText('tags', "tagset1, tagset2");
150 }
151
152 }