Merge pull request #48 from dpradeep/merge-forward
[civicrm-core.git] / tests / phpunit / WebTest / Import / GroupTest.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 '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 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->click("_qf_Basic_refresh");
68 $this->waitForPageToLoad($this->getTimeoutMsec());
69
70 // To Check Number Of Imported Contacts
71 $this->assertTrue($this->isTextPresent("{$count} Contacts"), "Contacts Not Found");
72
73 // To Add New Contacts In Already Existing Group
74 $other = array('selectGroup' => $groupName);
75
76 // Create New Individual Record
77 list($headers, $rows) = $this->_individualGroupCSVData();
78
79 // Import Contacts In Existing Group
80 $this->importContacts($headers, $rows, 'Individual', 'Skip', array(), $other);
81 $count += count($rows);
82
83 // Direct URL To Search
84 $this->openCiviPage("contact/search", "reset=1");
85
86 // Select GroupName
87 $this->select("group", "label={$groupName}");
88
89 $this->click("_qf_Basic_refresh");
90 $this->waitForPageToLoad($this->getTimeoutMsec());
91
92 // To Check Imported Contacts
93 $this->assertTrue($this->isTextPresent("{$count} Contacts"), "Contacts Not Found");
94 }
95
96 /*
97 * Helper function to provide data for contact import for Individuals.
98 */
99 /**
100 * @return array
101 */
102 function _individualGroupCSVData() {
103 $headers = array(
104 'first_name' => 'First Name',
105 'middle_name' => 'Middle Name',
106 'last_name' => 'Last Name',
107 'email' => 'Email',
108 'phone' => 'Phone',
109 'address_1' => 'Additional Address 1',
110 'address_2' => 'Additional Address 2',
111 'city' => 'City',
112 'state' => 'State',
113 'country' => 'Country',
114 );
115
116 $rows = array(
117 array('first_name' => substr(sha1(rand()), 0, 7),
118 'middle_name' => substr(sha1(rand()), 0, 7),
119 'last_name' => 'Anderson',
120 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
121 'phone' => '6949912154',
122 'address_1' => 'Add 1',
123 'address_2' => 'Add 2',
124 'city' => 'Watson',
125 'state' => 'NY',
126 'country' => 'United States',
127 ),
128 array('first_name' => substr(sha1(rand()), 0, 7),
129 'middle_name' => substr(sha1(rand()), 0, 7),
130 'last_name' => 'Summerson',
131 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
132 'phone' => '6944412154',
133 'address_1' => 'Add 1',
134 'address_2' => 'Add 2',
135 'city' => 'Watson',
136 'state' => 'NY',
137 'country' => 'United States',
138 ),
139 );
140 return array($headers, $rows);
141 }
142 }
143