CRM-17563: Dedupe rules - changes not saved when editing existing rule
[civicrm-core.git] / tests / phpunit / WebTest / Contact / DupeContactTest.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_DupeContactTest
31 */
32 class WebTest_Contact_DupeContactTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 public function testDuplicateContactAdd() {
39 $this->webtestLogin();
40
41 $this->openCiviPage('contact/add', 'reset=1&ct=Individual');
42
43 $firstName = substr(sha1(rand()), 0, 7);
44 $lastName1 = substr(sha1(rand()), 0, 7);
45 $email = "{$firstName}@example.com";
46 $lastName2 = substr(sha1(rand()), 0, 7);
47
48 //contact details section
49 //select prefix
50 $this->click("prefix_id");
51 $this->select("prefix_id", "value=3");
52
53 //fill in first name
54 $this->type("first_name", "$firstName");
55
56 //fill in last name
57 $this->type("last_name", "$lastName1");
58
59 //fill in email
60 $this->type("email_1_email", "$email");
61
62 //check for matching contact
63 //$this->click("_qf_Contact_refresh_dedupe");
64 //$this->waitForPageToLoad($this->getTimeoutMsec());
65
66 // Clicking save.
67 $this->click("_qf_Contact_upload_view");
68 $this->waitForPageToLoad($this->getTimeoutMsec());
69 $this->waitForText('crm-notification-container', "Contact Saved");
70
71 $this->openCiviPage('contact/add', 'reset=1&ct=Individual');
72
73 //contact details section
74
75 //fill in first name
76 $this->type("first_name", "$firstName");
77
78 //fill in last name
79 $this->type("last_name", "$lastName1");
80
81 //fill in email
82 $this->type("email_1_email", "$email");
83
84 // Clicking save.
85 $this->click("_qf_Contact_upload_view");
86 $this->waitForPageToLoad($this->getTimeoutMsec());
87
88 $this->assertElementContainsText("css=.notify-content", "Please correct the following errors in the form fields below: One matching contact was found. You can View or Edit the existing contact.");
89 }
90
91 /**
92 *Edit Dedupe rule for individual
93 */
94 public function testEditRule() {
95 $this->webtestLogin();
96 $this->openCiviPage('contact/deduperules', 'action=add&contact_type=Individual&reset=1');
97 $ruleName = 'Rule_' . substr(sha1(rand()), 0, 7);
98
99 //Add Rule for individual
100 $this->type("title", "$ruleName");
101 $this->click("xpath=//table[@class='form-layout']/tbody/tr[@class='crm-dedupe-rules-form-block-used']/td[2]/label[text()='General']");
102
103 // Add first name
104 $this->select("xpath=//table[@class='form-layout-compressed']/tbody/tr[2]/td[1]/select", 'label=First Name');
105 $this->type("xpath=//table[@class='form-layout-compressed']/tbody/tr[2]/td[2]/input", 10);
106 $this->type("xpath=//table[@class='form-layout-compressed']/tbody/tr[2]/td[3]/input", 10);
107 // Add last name
108 $this->select("xpath=//table[@class='form-layout-compressed']/tbody/tr[3]/td[1]/select", 'label=Last Name');
109 $this->type("xpath=//table[@class='form-layout-compressed']/tbody/tr[3]/td[2]/input", 10);
110 $this->type("xpath=//table[@class='form-layout-compressed']/tbody/tr[3]/td[3]/input", 10);
111 // Add email
112 $this->select("xpath=//table[@class='form-layout-compressed']/tbody/tr[4]/td[1]/select", 'label=Email');
113 $this->type("xpath=//table[@class='form-layout-compressed']/tbody/tr[4]/td[2]/input", 10);
114 $this->type("xpath=//table[@class='form-layout-compressed']/tbody/tr[4]/td[3]/input", 10);
115 $this->click("_qf_DedupeRules_next-bottom");
116 $this->waitForText("crm-notification-container", "The rule '$ruleName' has been saved.");
117
118 // Edit the rule for individual.
119 $this->click("xpath=//div[@id='browseValues_Individual']/div[1]/div/table/tbody//tr/td[1][text()='$ruleName']/../td[3]/span//a[text()='Edit Rule']");
120 $this->waitForElementPresent("_qf_DedupeRules_cancel-bottom");
121
122 //edit length and weight for First Name
123 $this->type("xpath=//table[@class='form-layout-compressed']/tbody/tr[2]/td[2]/input", 7);
124 $this->type("xpath=//table[@class='form-layout-compressed']/tbody/tr[2]/td[3]/input", 5);
125
126 //edit length and weight for Last Name
127 $this->type("xpath=//table[@class='form-layout-compressed']/tbody/tr[3]/td[2]/input", 7);
128 $this->type("xpath=//table[@class='form-layout-compressed']/tbody/tr[3]/td[3]/input", 8);
129
130 //edit length and weight for Email
131 $this->type("xpath=//table[@class='form-layout-compressed']/tbody/tr[4]/td[2]/input", 20);
132 $this->type("xpath=//table[@class='form-layout-compressed']/tbody/tr[4]/td[3]/input", 10);
133
134 $this->click("_qf_DedupeRules_next-bottom");
135 $this->waitForAjaxContent();
136 $this->click("xpath=//div[@id='browseValues_Individual']/div[1]/div/table/tbody//tr/td[1][text()='$ruleName']/../td[3]/span//a[text()='Edit Rule']");
137 $this->waitForAjaxContent();
138
139 $lengthValueFname = $this->getAttribute("xpath=//table[@class='form-layout-compressed']/tbody/tr[2]/td[2]/input@value");
140 $weighthValueFname = $this->getAttribute("xpath=//table[@class='form-layout-compressed']/tbody/tr[2]/td[3]/input@value");
141 $lengthValueLname = $this->getAttribute("xpath=//table[@class='form-layout-compressed']/tbody/tr[3]/td[2]/input@value");
142 $lengthValueLname = $this->getAttribute("xpath=//table[@class='form-layout-compressed']/tbody/tr[3]/td[3]/input@value");
143 $lengthValueEmail = $this->getAttribute("xpath=//table[@class='form-layout-compressed']/tbody/tr[4]/td[2]/input@value");
144 $weighthValueEmail = $this->getAttribute("xpath=//table[@class='form-layout-compressed']/tbody/tr[4]/td[3]/input@value");
145
146 $this->assertTrue($this->isElementPresent("xpath=//table[@class='form-layout-compressed']/tbody/tr[2]/td[2]/input[@value=$lengthValueFname]"));
147 $this->assertTrue($this->isElementPresent("xpath=//table[@class='form-layout-compressed']/tbody/tr[2]/td[3]/input[@value=$weighthValueFname]"));
148 $this->assertTrue($this->isElementPresent("xpath=//table[@class='form-layout-compressed']/tbody/tr[3]/td[2]/input[@value=$lengthValueLname]"));
149 $this->assertTrue($this->isElementPresent("xpath=//table[@class='form-layout-compressed']/tbody/tr[3]/td[2]/input[@value=$lengthValueLname]"));
150 $this->assertTrue($this->isElementPresent("xpath=//table[@class='form-layout-compressed']/tbody/tr[4]/td[2]/input[@value=$lengthValueEmail]"));
151 $this->assertTrue($this->isElementPresent("xpath=//table[@class='form-layout-compressed']/tbody/tr[4]/td[2]/input[@value=$weighthValueEmail]"));
152 }
153
154 }