All Data Structures Functions Variables Pages
ContactsSuperUserExportWalkthroughTest.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  *
13  * Zurmo is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  *
23  * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  *
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
36 
41  {
42  protected static $asynchronousThreshold;
43 
44  public static function setUpBeforeClass()
45  {
46  parent::setUpBeforeClass();
47  SecurityTestHelper::createSuperAdmin();
48  $super = User::getByUsername('super');
49  Yii::app()->user->userModel = $super;
50 
51  self::$asynchronousThreshold = ExportModule::$asynchronousThreshold;
52  ExportModule::$asynchronousThreshold = 3;
53  }
54 
55  public static function tearDownAfterClass()
56  {
57  ExportModule::$asynchronousThreshold = self::$asynchronousThreshold;
58  parent::tearDownAfterClass();
59  }
60 
65  {
66  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
67  $account = AccountTestHelper::createAccountByNameForOwner('superAccount', $super);
68 
69  $contacts = array();
70  for ($i = 0; $i < 2; $i++)
71  {
72  $contacts[] = ContactTestHelper::createContactWithAccountByNameForOwner('superContact' . $i, $super, $account);
73  }
74 
75  $this->runControllerWithNoExceptionsAndGetContent('contacts/default/list');
76  $this->setGetArray(array(
77  'Contact_page' => '1',
78  'export' => '',
79  'ajax' => '',
80  'selectAll' => '',
81  'selectedIds' => '')
82  );
83  $response = $this->runControllerWithRedirectExceptionAndGetUrl('contacts/default/export');
84  $this->assertTrue(strstr($response, 'contacts/default/index') !== false);
85 
86  $this->setGetArray(array(
87  'ContactsSearchForm' => array(
88  'anyMixedAttributesScope' => array(0 => 'All'),
89  'anyMixedAttributes' => '',
90  'fullName' => 'superContact',
91  'officePhone' => ''
92  ),
93  'multiselect_ContactsSearchForm_anyMixedAttributesScope' => 'All',
94  'Contact_page' => '1',
95  'export' => '',
96  'ajax' => '',
97  'selectAll' => '1',
98  'selectedIds' => '')
99  );
100  $response = $this->runControllerWithExitExceptionAndGetContent('contacts/default/export');
101  $this->assertEquals('Testing download.', $response);
102 
103  $this->setGetArray(array(
104  'ContactsSearchForm' => array(
105  'anyMixedAttributesScope' => array(0 => 'All'),
106  'anyMixedAttributes' => '',
107  'fullName' => 'superContact',
108  'officePhone' => ''
109  ),
110  'multiselect_ContactsSearchForm_anyMixedAttributesScope' => 'All',
111  'Contact_page' => '1',
112  'export' => '',
113  'ajax' => '',
114  'selectAll' => '',
115  'selectedIds' => "{$contacts[0]->id}, {$contacts[1]->id}")
116  );
117  $response = $this->runControllerWithExitExceptionAndGetContent('contacts/default/export');
118  $this->assertEquals('Testing download.', $response);
119 
120  // No mathces
121  $this->setGetArray(array(
122  'ContactsSearchForm' => array(
123  'anyMixedAttributesScope' => array(0 => 'All'),
124  'anyMixedAttributes' => '',
125  'fullName' => 'missingName',
126  'officePhone' => ''
127  ),
128  'multiselect_ContactsSearchForm_anyMixedAttributesScope' => 'All',
129  'Contact_page' => '1',
130  'export' => '',
131  'ajax' => '',
132  'selectAll' => '1',
133  'selectedIds' => '')
134  );
135  $response = $this->runControllerWithRedirectExceptionAndGetUrl('contacts/default/export');
136  $this->assertTrue(strstr($response, 'contacts/default/index') !== false);
137  }
138 
143  {
144  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
145  $account = AccountTestHelper::createAccountByNameForOwner('superAccount2', $super);
146  $notificationsBeforeCount = Notification::getCount();
147  $notificationMessagesBeforeCount = NotificationMessage::getCount();
148 
149  $contacts = Contact::getAll();
150  if (count($contacts))
151  {
152  foreach ($contacts as $contact)
153  {
154  $contact->delete();
155  }
156  }
157  $contacts = array();
158  for ($i = 0; $i <= (ExportModule::$asynchronousThreshold + 1); $i++)
159  {
160  $contacts[] = ContactTestHelper::createContactWithAccountByNameForOwner('superContact' . $i, $super, $account);
161  }
162 
163  $this->setGetArray(array(
164  'Contact_page' => '1',
165  'export' => '',
166  'ajax' => '',
167  'selectAll' => '1',
168  'selectedIds' => '')
169  );
170  $this->runControllerWithRedirectExceptionAndGetUrl('contacts/default/export');
171 
172  // Start background job
173  $job = new ExportJob();
174  $this->assertTrue($job->run());
175 
176  $exportItems = ExportItem::getAll();
177  $this->assertEquals(1, count($exportItems));
178  $fileModel = $exportItems[0]->exportFileModel;
179  $this->assertEquals(1, $exportItems[0]->isCompleted);
180  $this->assertEquals('csv', $exportItems[0]->exportFileType);
181  $this->assertEquals('contacts', $exportItems[0]->exportFileName);
182  $this->assertTrue($fileModel instanceOf ExportFileModel);
183 
184  $this->assertEquals($notificationsBeforeCount + 1, Notification::getCount());
185  $this->assertEquals($notificationMessagesBeforeCount + 1, NotificationMessage::getCount());
186 
187  // Check export job, when many ids are selected.
188  // This will probably never happen, but we need test for this case too.
189  $notificationsBeforeCount = Notification::getCount();
190  $notificationMessagesBeforeCount = NotificationMessage::getCount();
191 
192  // Now test case when multiple ids are selected
193  $exportItems = ExportItem::getAll();
194  if (count($exportItems))
195  {
196  foreach ($exportItems as $exportItem)
197  {
198  $exportItem->delete();
199  }
200  }
201 
202  $selectedIds = "";
203  foreach ($contacts as $contact)
204  {
205  $selectedIds .= $contact->id . ","; // Not Coding Standard
206  }
207  $this->setGetArray(array(
208  'ContactsSearchForm' => array(
209  'anyMixedAttributesScope' => array(0 => 'All'),
210  'anyMixedAttributes' => '',
211  'fullName' => '',
212  'officePhone' => ''
213  ),
214  'multiselect_ContactsSearchForm_anyMixedAttributesScope' => 'All',
215  'Contact_page' => '1',
216  'export' => '',
217  'ajax' => '',
218  'selectAll' => '',
219  'selectedIds' => "$selectedIds")
220  );
221 
222  $this->runControllerWithRedirectExceptionAndGetUrl('contacts/default/export');
223  // Start background job
224  $job = new ExportJob();
225  $this->assertTrue($job->run());
226 
227  $exportItems = ExportItem::getAll();
228  $this->assertEquals(1, count($exportItems));
229  $fileModel = $exportItems[0]->exportFileModel;
230  $this->assertEquals(1, $exportItems[0]->isCompleted);
231  $this->assertEquals('csv', $exportItems[0]->exportFileType);
232  $this->assertEquals('contacts', $exportItems[0]->exportFileName);
233  $this->assertTrue($fileModel instanceOf ExportFileModel);
234 
235  $this->assertEquals($notificationsBeforeCount + 1, Notification::getCount());
236  $this->assertEquals($notificationMessagesBeforeCount + 1, NotificationMessage::getCount());
237  }
238  }
239 ?>
static getByUsername($username)
Definition: User.php:49
static getCount(RedBeanModelJoinTablesQueryAdapter $joinTablesAdapter=null, $where=null, $modelClassName=null, $selectDistinct=false)
logoutCurrentUserLoginNewUserAndGetByUsername($username)
runControllerWithNoExceptionsAndGetContent($route, $empty=false)
static getAll($orderBy=null, $sortDescending=false, $modelClassName=null)
Generated on Fri Jun 5 2020 07:10:30