add autogenerated comment blocks to tests dir
[civicrm-core.git] / tests / phpunit / WebTest / Import / TagTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
06a1bc01 4 | CiviCRM version 4.5 |
6a488035 5 +--------------------------------------------------------------------+
06a1bc01 6 | Copyright CiviCRM LLC (c) 2004-2014 |
6a488035
TO
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
6a488035 27require_once 'WebTest/Import/ImportCiviSeleniumTestCase.php';
e9479dcf
EM
28
29/**
30 * Class WebTest_Import_TagTest
31 */
6a488035
TO
32class WebTest_Import_TagTest extends ImportCiviSeleniumTestCase {
33
6a488035
TO
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 /*
39 * Test contact import for Individuals.
40 */
41 function testContactImportWithTag() {
6a488035
TO
42 $this->webtestLogin();
43
44 // Get sample import data.
45 list($headers, $rows) = $this->_contactTagCSVData();
46
47 // Creating a new Tag
48 $tagName = 'tag_' . substr(sha1(rand()), 0, 7);
49
50 // Import and check Individual contacts in Skip mode.
51 $other = array(
52 'createTag' => TRUE,
53 'createTagName' => $tagName,
54 );
55
56 $this->importContacts($headers, $rows, 'Individual', 'Skip', array(), $other);
57
071a6d2e 58 $this->openCiviPage("contact/search", "reset=1");
6a488035
TO
59 $this->select('tag', "label={$tagName}");
60 // click to search
61 $this->click('_qf_Basic_refresh');
62 $this->waitForPageToLoad($this->getTimeoutMsec());
63
64 // count rows
65 $countContacts = count($rows);
66 // Is status message correct?
67 $this->assertTrue($this->isTextPresent("{$countContacts} Contacts"));
68
69 // Get sample import data.
70 list($headers, $rows) = $this->_contactTagCSVData();
71
72 // Import and check Individual contacts in Skip mode.
73 // Sending Tag Name For Re-use
74 $other = array('selectTag' => array($tagName));
75
76 $this->importContacts($headers, $rows, 'Individual', 'Skip', array(), $other);
77
071a6d2e 78 $this->openCiviPage("contact/search", "reset=1");
6a488035
TO
79
80 $this->select('tag', "label={$tagName}");
81 // click to search
82 $this->click('_qf_Basic_refresh');
83 $this->waitForPageToLoad($this->getTimeoutMsec());
84
85 //Counting Contact rows old rows + new rows
86 $countContacts += count($rows);
87 // Is status message correct?
88 $this->assertTrue($this->isTextPresent("{$countContacts} Contacts"));
89 }
90
91 /*
92 * Helper function to provide data for contact import for sample.
93 */
4cbe18b8
EM
94 /**
95 * @return array
96 */
6a488035
TO
97 function _contactTagCSVData() {
98 $headers = array(
99 'first_name' => 'First Name',
100 'middle_name' => 'Middle Name',
101 'last_name' => 'Last Name',
102 'email' => 'Email',
103 'phone' => 'Phone',
104 'address_1' => 'Additional Address 1',
105 'address_2' => 'Additional Address 2',
106 'city' => 'City',
107 'state' => 'State',
108 'country' => 'Country',
109 );
110
111 $rows = array(
112 array('first_name' => substr(sha1(rand()), 0, 7),
113 'middle_name' => substr(sha1(rand()), 0, 7),
114 'last_name' => 'Anderson',
115 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
116 'phone' => '6949912154',
117 'address_1' => 'Add 1',
118 'address_2' => 'Add 2',
119 'city' => 'Watson',
120 'state' => 'NY',
121 'country' => 'United States',
122 ),
123 array('first_name' => substr(sha1(rand()), 0, 7),
124 'middle_name' => substr(sha1(rand()), 0, 7),
125 'last_name' => 'Summerson',
126 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
127 'phone' => '6944412154',
128 'address_1' => 'Add 1',
129 'address_2' => 'Add 2',
130 'city' => 'Watson',
131 'state' => 'NY',
132 'country' => 'United States',
133 ),
134 );
135
136 return array($headers, $rows);
137 }
138}
139