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