Merge pull request #4818 from pratikshad/CRM-15770
[civicrm-core.git] / tests / phpunit / WebTest / Import / GroupTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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 'WebTest/Import/ImportCiviSeleniumTestCase.php';
28
29 /**
30 * Class WebTest_Import_GroupTest
31 */
32 class WebTest_Import_GroupTest extends ImportCiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 /**
39 * Test contact import for Individuals.
40 */
41 public function testIndividualImportWithGroup() {
42 $this->webtestLogin();
43
44 // Get sample import data.
45 list($headers, $rows) = $this->_individualGroupCSVData();
46
47 // Group Name
48 $groupName = substr(sha1(rand()), 0, 7);
49
50 // Import and check Individual Contacts in Skip mode and Add them in Group
51 $other = array(
52 'createGroup' => TRUE,
53 'createGroupName' => $groupName,
54 );
55
56 // Create New Group And Import Contacts In Group
57 $this->importContacts($headers, $rows, 'Individual', 'Skip', array(), $other);
58
59 $count = count($rows);
60
61 // Direct URL To Search
62 $this->openCiviPage("contact/search", "reset=1");
63
64 // Select GroupName
65 $this->select("group", "label={$groupName}");
66
67 $this->clickLink("_qf_Basic_refresh");
68
69 // To Check Number Of Imported Contacts
70 $this->assertTrue($this->isTextPresent("{$count} Contacts"), "Contacts Not Found");
71
72 // To Add New Contacts In Already Existing Group
73 $other = array('selectGroup' => $groupName);
74
75 // Create New Individual Record
76 list($headers, $rows) = $this->_individualGroupCSVData();
77
78 // Import Contacts In Existing Group
79 $this->importContacts($headers, $rows, 'Individual', 'Skip', array(), $other);
80 $count += count($rows);
81
82 // Direct URL To Search
83 $this->openCiviPage("contact/search", "reset=1");
84
85 // Select GroupName
86 $this->select("group", "label={$groupName}");
87
88 $this->clickLink("_qf_Basic_refresh");
89
90 // To Check Imported Contacts
91 $this->assertTrue($this->isTextPresent("{$count} Contacts"), "Contacts Not Found");
92 }
93
94 /**
95 * Helper function to provide data for contact import for Individuals.
96 *
97 * @return array
98 */
99 public function _individualGroupCSVData() {
100 $headers = array(
101 'first_name' => 'First Name',
102 'middle_name' => 'Middle Name',
103 'last_name' => 'Last Name',
104 'email' => 'Email',
105 'phone' => 'Phone',
106 'address_1' => 'Additional Address 1',
107 'address_2' => 'Additional Address 2',
108 'city' => 'City',
109 'state' => 'State',
110 'country' => 'Country',
111 );
112
113 $rows = array(
114 array('first_name' => substr(sha1(rand()), 0, 7),
115 'middle_name' => substr(sha1(rand()), 0, 7),
116 'last_name' => 'Anderson',
117 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
118 'phone' => '6949912154',
119 'address_1' => 'Add 1',
120 'address_2' => 'Add 2',
121 'city' => 'Watson',
122 'state' => 'NY',
123 'country' => 'United States',
124 ),
125 array('first_name' => substr(sha1(rand()), 0, 7),
126 'middle_name' => substr(sha1(rand()), 0, 7),
127 'last_name' => 'Summerson',
128 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
129 'phone' => '6944412154',
130 'address_1' => 'Add 1',
131 'address_2' => 'Add 2',
132 'city' => 'Watson',
133 'state' => 'NY',
134 'country' => 'United States',
135 ),
136 );
137 return array($headers, $rows);
138 }
139 }