Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
CampaignGenerateDueCampaignItemsJobBenchmarkTest.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  ********************************************************************************/
37  {
38  protected $user;
39 
40  protected $singleItemExpectedTime = 0.007;
41 
42  public static function setUpBeforeClass()
43  {
44  parent::setUpBeforeClass();
45  SecurityTestHelper::createSuperAdmin();
46  }
47 
48  public function setUp()
49  {
50  parent::setUp();
51  $this->user = User::getByUsername('super');
52  Yii::app()->user->userModel = $this->user;
58  }
59 
60  public function testSingleItem()
61  {
62  $this->ensureTimeSpentIsLessOrEqualThanExpectedForCount(1);
63  }
64 
68  public function testTenItems()
69  {
70  $this->ensureTimeSpentIsLessOrEqualThanExpectedForCount(10);
71  }
72 
76  public function testFiftyItems()
77  {
78  $this->ensureTimeSpentIsLessOrEqualThanExpectedForCount(50);
79  }
80 
84  public function testHundredItems()
85  {
86  $this->ensureTimeSpentIsLessOrEqualThanExpectedForCount(100);
87  }
88 
92  public function testTwoFiftyItems()
93  {
94  $this->ensureTimeSpentIsLessOrEqualThanExpectedForCount(250);
95  }
96 
100  public function testFiveHundredItems()
101  {
102  $this->ensureTimeSpentIsLessOrEqualThanExpectedForCount(500);
103  }
104 
108  public function testThousandItems()
109  {
110  $this->ensureTimeSpentIsLessOrEqualThanExpectedForCount(1000);
111  }
112 
113  protected function ensureTimeSpentIsLessOrEqualThanExpectedForCount($count)
114  {
115  $timeSpent = $this->generateCampaignItemsForDueCampaigns($count);
116  echo PHP_EOL. $count . ' items took ' . $timeSpent . ' seconds';
117  // no need to multiply by $count
118  // this is all sql with no php in the core logic of generation so the time spent
119  // remains constant for the most part.
120  $this->assertLessThanOrEqual($this->singleItemExpectedTime, $timeSpent);
121  }
122 
123  public function generateCampaignItemsForDueCampaigns($count)
124  {
125  $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList Test',
126  'description goes here',
127  'fromName',
128  'from@domain.com');
129  $marketingListId = $marketingList->id;
130  $contacts = array();
131  $emails = array();
132  for ($i = 0; $i < $count; $i++)
133  {
134  $emails[$i] = new Email();
135  $emails[$i]->emailAddress = "demo$i@zurmo.com";
136  $account = AccountTestHelper::createAccountByNameForOwner('account ' . $i, $this->user);
137  $contact = ContactTestHelper::createContactWithAccountByNameForOwner('contact ' . $i , $this->user, $account);
138  $contact->primaryEmail = $emails[$i];
139  $this->assertTrue($contact->save());
140  $contacts[$i] = $contact;
141  MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList, $contact);
142  }
143  $marketingList->forgetAll();
144 
145  $marketingList = MarketingList::getById($marketingListId);
146  $content = <<<MTG
147 [[COMPANY^NAME]]
148 [[CREATED^DATE^TIME]]
149 [[DEPARTMENT]]
150 [[DESCRIPTION]]
151 [[FIRST^NAME]]
152 [[GOOGLE^WEB^TRACKING^ID]]
153 [[INDUSTRY]]
154 [[JOB^TITLE]]
155 [[LAST^NAME]]
156 [[LATEST^ACTIVITY^DATE^TIME]]
157 [[MOBILE^PHONE]]
158 [[MODIFIED^DATE^TIME]]
159 [[OFFICE^FAX]]
160 [[OFFICE^PHONE]]
161 [[TITLE]]
162 [[SOURCE]]
163 [[STATE]]
164 [[WEBSITE]]
165 [[MODEL^URL]]
166 [[BASE^URL]]
167 [[APPLICATION^NAME]]
168 [[CURRENT^YEAR]]
169 [[LAST^YEAR]]
170 [[OWNERS^AVATAR^SMALL]]
171 [[OWNERS^AVATAR^MEDIUM]]
172 [[OWNERS^AVATAR^LARGE]]
173 [[OWNERS^EMAIL^SIGNATURE]]
174 [[UNSUBSCRIBE^URL]]
175 [[MANAGE^SUBSCRIPTIONS^URL]]
176 [[PRIMARY^EMAIL__EMAIL^ADDRESS]]
177 [[PRIMARY^EMAIL__EMAIL^ADDRESS]]
178 [[SECONDARY^ADDRESS__CITY]]
179 [[SECONDARY^ADDRESS__COUNTRY]]
180 [[SECONDARY^ADDRESS__INVALID]]
181 [[SECONDARY^ADDRESS__LATITUDE]]
182 [[SECONDARY^ADDRESS__LONGITUDE]]
183 [[SECONDARY^ADDRESS__POSTAL^CODE]]
184 [[SECONDARY^ADDRESS__STATE]]
185 [[SECONDARY^ADDRESS__STREET1]]
186 [[SECONDARY^ADDRESS__STREET2]]
187 [[OWNER__DEPARTMENT]]
188 [[OWNER__FIRST^NAME]]
189 [[OWNER__IS^ACTIVE]]
190 [[OWNER__MOBILE^PHONE]]
191 [[OWNER__LAST^LOGIN^DATE^TIME]]
192 [[OWNER__LAST^NAME]]
193 [[CREATED^BY^USER__FIRST^NAME]]
194 [[CREATED^BY^USER__LAST^NAME]]
195 [[CREATED^BY^USER__MOBILE^PHONE]]
196 [[CREATED^BY^USER__TITLE]]
197 [[CREATED^BY^USER__USERNAME]]
198 [[ACCOUNT__ANNUAL^REVENUE]]
199 [[ACCOUNT__INDUSTRY]]
200 [[ACCOUNT__NAME]]
201 [[ACCOUNT__WEBSITE]]
202 [[ACCOUNT__BILLING^ADDRESS__COUNTRY]]
203 [[ACCOUNT__BILLING^ADDRESS__CITY]]
204 [[ACCOUNT__OWNER__FIRST^NAME]]
205  ' " ` " '
206 MTG;
207 
208  $sendOnDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - 600);
209  $campaign = CampaignTestHelper::createCampaign('campaign Test',
210  'subject',
211  $content,
212  $content,
213  null,
214  null,
215  null,
216  Campaign::STATUS_ACTIVE,
217  $sendOnDateTime,
218  null,
219  $marketingList,
220  false);
221  $fileNames = array('testImage.png', 'testZip.zip', 'testPDF.pdf');
222  $files = array();
223  foreach ($fileNames as $index => $fileName)
224  {
225  $file = ZurmoTestHelper::createFileModel($fileName);
226  $files[$index]['name'] = $fileName;
227  $files[$index]['type'] = $file->type;
228  $files[$index]['size'] = $file->size;
229  $files[$index]['contents'] = $file->fileContent->content;
230  $campaign->files->add($file);
231  }
232  $this->assertTrue($campaign->save(false));
233  $campaignId = $campaign->id;
234  $campaign->forgetAll();
235  $campaignItems = CampaignItem::getByProcessedAndCampaignId(0, $campaignId);
236  $this->assertEmpty($campaignItems);
237  //Process open campaigns.
238  Yii::app()->jobQueue->deleteAll();
239 
241  Yii::app()->jobQueue->deleteAll();
242  $this->assertCount(0, Yii::app()->jobQueue->getAll());
243  ForgetAllCacheUtil::forgetAllCaches();
245  $startedAt = microtime(true);
246  $this->assertTrue($job->run());
247  $timeTaken = microtime(true) - $startedAt;
248  ForgetAllCacheUtil::forgetAllCaches();
249  $campaign->forgetAll();
250  unset($campaign);
251  $campaign = Campaign::getById($campaignId);
252  $this->assertNotNull($campaign);
253  $this->assertEquals(Campaign::STATUS_PROCESSING, $campaign->status);
254  $campaignItems = CampaignItem::getByProcessedAndCampaignId(0, $campaignId);
255  $this->assertNotEmpty($campaignItems);
256  $this->assertCount($count, $campaignItems);
257  return $timeTaken;
258  }
259  }
260 ?>
Definition: Email.php:37
static getByProcessedAndCampaignId($processed, $campaignId, $pageSize=null)
static getByUsername($username)
Definition: User.php:49
static deleteAll()
static getById($id, $modelClassName=null)
Generated on Sun Aug 9 2020 07:10:29
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.