phpcs - Fix error, "Expected 1 newline at end of file; XXX found".
[civicrm-core.git] / tests / phpunit / WebTest / Import / TagTest.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_TagTest
31 */
32 class WebTest_Import_TagTest extends ImportCiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 /*
39 * Test contact import for Individuals.
40 */
41 public function testContactImportWithTag() {
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
58 $this->openCiviPage("contact/search", "reset=1");
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
78 $this->openCiviPage("contact/search", "reset=1");
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 *
94 * @return array
95 */
96 public function _contactTagCSVData() {
97 $headers = array(
98 'first_name' => 'First Name',
99 'middle_name' => 'Middle Name',
100 'last_name' => 'Last Name',
101 'email' => 'Email',
102 'phone' => 'Phone',
103 'address_1' => 'Additional Address 1',
104 'address_2' => 'Additional Address 2',
105 'city' => 'City',
106 'state' => 'State',
107 'country' => 'Country',
108 );
109
110 $rows = array(
111 array(
112 '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(
124 'first_name' => substr(sha1(rand()), 0, 7),
125 'middle_name' => substr(sha1(rand()), 0, 7),
126 'last_name' => 'Summerson',
127 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
128 'phone' => '6944412154',
129 'address_1' => 'Add 1',
130 'address_2' => 'Add 2',
131 'city' => 'Watson',
132 'state' => 'NY',
133 'country' => 'United States',
134 ),
135 );
136
137 return array($headers, $rows);
138 }
139 }