All Data Structures Functions Variables Pages
LeadsSuperUserExportWalkthroughTest.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  $leads = array();
70  for ($i = 0; $i < 2; $i++)
71  {
72  $leads[] = LeadTestHelper::createLeadWithAccountByNameForOwner('superContact' . $i, $super, $account);
73  }
74 
75  $this->runControllerWithNoExceptionsAndGetContent('leads/default/list');
76  $this->setGetArray(array(
77  'Contact_page' => '1',
78  'export' => '',
79  'ajax' => '',
80  'selectAll' => '',
81  'selectedIds' => '')
82  );
83  $response = $this->runControllerWithRedirectExceptionAndGetUrl('leads/default/export');
84  $this->assertTrue(strstr($response, 'leads/default/index') !== false);
85 
86  $this->setGetArray(array(
87  'LeadsSearchForm' => 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('leads/default/export');
101  $this->assertEquals('Testing download.', $response);
102 
103  $this->setGetArray(array(
104  'LeadsSearchForm' => 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' => "{$leads[0]->id}, {$leads[1]->id}")
116  );
117  $response = $this->runControllerWithExitExceptionAndGetContent('leads/default/export');
118  $this->assertEquals('Testing download.', $response);
119 
120  // No mathces
121  $this->setGetArray(array(
122  'LeadsSearchForm' => 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('leads/default/export');
136  $this->assertTrue(strstr($response, 'leads/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 
150  $leads = array();
151  for ($i = 0; $i <= (ExportModule::$asynchronousThreshold + 1); $i++)
152  {
153  $leads[] = LeadTestHelper::createLeadWithAccountByNameForOwner('superContact' . $i, $super, $account);
154  }
155 
156  $this->setGetArray(array(
157  'Contact_page' => '1',
158  'export' => '',
159  'ajax' => '',
160  'selectAll' => '1',
161  'selectedIds' => '')
162  );
163  $this->runControllerWithRedirectExceptionAndGetUrl('leads/default/export');
164 
165  // Start background job
166  $job = new ExportJob();
167  $this->assertTrue($job->run());
168 
169  $exportItems = ExportItem::getAll();
170  $this->assertEquals(1, count($exportItems));
171  $fileModel = $exportItems[0]->exportFileModel;
172  $this->assertEquals(1, $exportItems[0]->isCompleted);
173  $this->assertEquals('csv', $exportItems[0]->exportFileType);
174  $this->assertEquals('leads', $exportItems[0]->exportFileName);
175  $this->assertTrue($fileModel instanceOf ExportFileModel);
176 
177  $this->assertEquals($notificationsBeforeCount + 1, Notification::getCount());
178  $this->assertEquals($notificationMessagesBeforeCount + 1, NotificationMessage::getCount());
179 
180  // Check export job, when many ids are selected.
181  // This will probably never happen, but we need test for this case too.
182  $notificationsBeforeCount = Notification::getCount();
183  $notificationMessagesBeforeCount = NotificationMessage::getCount();
184 
185  // Now test case when multiple ids are selected
187 
188  $selectedIds = "";
189  foreach ($leads as $lead)
190  {
191  $selectedIds .= $lead->id . ","; // Not Coding Standard
192  }
193  $this->setGetArray(array(
194  'LeadsSearchForm' => array(
195  'anyMixedAttributesScope' => array(0 => 'All'),
196  'anyMixedAttributes' => '',
197  'fullName' => '',
198  'officePhone' => ''
199  ),
200  'multiselect_ContactsSearchForm_anyMixedAttributesScope' => 'All',
201  'Contact_page' => '1',
202  'export' => '',
203  'ajax' => '',
204  'selectAll' => '',
205  'selectedIds' => "$selectedIds")
206  );
207 
208  $this->runControllerWithRedirectExceptionAndGetUrl('leads/default/export');
209  // Start background job
210  $job = new ExportJob();
211  $this->assertTrue($job->run());
212 
213  $exportItems = ExportItem::getAll();
214  $this->assertEquals(1, count($exportItems));
215  $fileModel = $exportItems[0]->exportFileModel;
216  $this->assertEquals(1, $exportItems[0]->isCompleted);
217  $this->assertEquals('csv', $exportItems[0]->exportFileType);
218  $this->assertEquals('leads', $exportItems[0]->exportFileName);
219  $this->assertTrue($fileModel instanceOf ExportFileModel);
220 
221  $this->assertEquals($notificationsBeforeCount + 1, Notification::getCount());
222  $this->assertEquals($notificationMessagesBeforeCount + 1, NotificationMessage::getCount());
223  }
224  }
225 ?>
static getByUsername($username)
Definition: User.php:49
static deleteAll()
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 May 29 2020 07:10:32