All Data Structures Functions Variables Pages
TrackingDefaultControllerWalkthroughTest.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 
38  {
39  protected static $user;
40 
41  protected static $personId;
42 
43  protected static $autoresponderItemId;
44 
45  protected static $campaignItemId;
46 
47  const TRACK_ROUTE = '/tracking/default/track';
48 
49  public static function setUpBeforeClass()
50  {
51  parent::setUpBeforeClass();
52  SecurityTestHelper::createSuperAdmin();
53  static::$user = User::getByUsername('super');
54  Yii::app()->user->userModel = static::$user;
55 
56  $contact = ContactTestHelper::createContactByNameForOwner('contact 01', static::$user);
57  $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 01',
58  'description 01',
59  'fromName 01',
60  'fromAddress01@domain.com');
61  $autoresponder = AutoresponderTestHelper::createAutoresponder('subject 01',
62  'textContent 01',
63  'htmlContent 01',
64  10,
65  Autoresponder::OPERATION_SUBSCRIBE,
66  1,
67  $marketingList);
68  $processed = 0;
69  $processDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time()-100);
70  $autoresponderItem = AutoresponderItemTestHelper::createAutoresponderItem($processed,
71  $processDateTime,
72  $autoresponder,
73  $contact);
74  static::$personId = $contact->getClassId('Person');
75  static::$autoresponderItemId = $autoresponderItem->id;
76  $campaign = CampaignTestHelper::createCampaign('campaign 01',
77  'subject 01',
78  'text Content 01',
79  'html Content 01',
80  'fromName 01',
81  'fromAddress01@zurmo.com',
82  null,
83  Campaign::STATUS_ACTIVE,
84  null,
85  null,
86  $marketingList);
87  $processed = 0;
88  $campaignItem = CampaignItemTestHelper::createCampaignItem($processed, $campaign, $contact);
89  static::$campaignItemId = $campaignItem->id;
90 
92  }
93 
94  public function testGuestUserCanAccessTrackActionAndReturnsNothingWithoutHash()
95  {
96  $this->runControllerWithNoExceptionsAndGetContent(static::TRACK_ROUTE, true);
97  }
98 
103  {
104  $hash = 'Bo9iemeigh6muath8chu2leThohn8Abimoh5rebaihei4aiM1uFoThaith9eng1sei8aisuHu1ugoophiewoe1ieloo';
105  $this->setGetArray(array(
106  'id' => $hash,
107  ));
108  $this->runControllerWithNoExceptionsAndGetContent(static::TRACK_ROUTE, true);
109  }
110 
115  {
116  $hash = 'DEDF8F6C80D20528130EBBFBD293E49C9E2F0CBFDE8995FFE4EEAD8EC8F00B70';
117  $this->setGetArray(array(
118  'id' => $hash,
119  ));
120  $this->runControllerWithNoExceptionsAndGetContent(static::TRACK_ROUTE, true);
121  }
122 
127  {
128  $queryStringArray = array(
129  'keyOne' => 'valueOne',
130  'keyTwo' => 'valueTwo',
131  'keyThree' => 'ValueThree',
132  );
133  $hash = StringUtil::resolveHashForQueryStringArray($queryStringArray);
134  $this->setGetArray(array(
135  'id' => $hash,
136  ));
137  $this->runControllerWithNoExceptionsAndGetContent(static::TRACK_ROUTE, true);
138  }
139 
144  {
145  $queryStringArray = array(
146  'modelId' => 100,
147  'modelType' => 'AutoresponderItem',
148  'personId' => static::$personId,
149  );
150  $hash = StringUtil::resolveHashForQueryStringArray($queryStringArray);
151  $this->setGetArray(array(
152  'id' => $hash,
153  ));
154  $this->runControllerWithNoExceptionsAndGetContent(static::TRACK_ROUTE, true);
155  }
156 
161  {
162  $queryStringArray = array(
163  'modelId' => static::$autoresponderItemId,
164  'modelType' => 'AutoresponderItem',
165  'personId' => 200,
166  );
167  $hash = StringUtil::resolveHashForQueryStringArray($queryStringArray);
168  $this->setGetArray(array(
169  'id' => $hash,
170  ));
171  $this->runControllerWithNoExceptionsAndGetContent(static::TRACK_ROUTE, true);
172  }
173 
178  {
179  $queryStringArray = array(
180  'modelId' => static::$autoresponderItemId,
181  'modelType' => 'AutoresponderItem',
182  'personId' => static::$personId,
183  );
184  $hash = StringUtil::resolveHashForQueryStringArray($queryStringArray);
185  $this->setGetArray(array(
186  'id' => $hash,
187  ));
188  // Need @ to ignore the headers already sent error.
189  $content = @$this->runControllerWithExitExceptionAndGetContent(static::TRACK_ROUTE);
190  $image = imagecreatefromstring($content);
191  $this->assertTrue($image !== false);
192  $path = tempnam(sys_get_temp_dir() , '1x1-pixel') . '.png';
193  $createdPng = imagepng($image, $path);
194  $this->assertTrue($createdPng);
195  $autoresponderItemActivity = AutoresponderItemActivity::getByTypeAndModelIdAndPersonIdAndUrl(
196  AutoresponderItemActivity::TYPE_OPEN,
197  static::$autoresponderItemId,
198  static::$personId);
199  $this->assertNotEmpty($autoresponderItemActivity);
200  $this->assertCount(1, $autoresponderItemActivity);
201  $this->assertEquals(1, $autoresponderItemActivity[0]->quantity);
202  }
203 
208  {
209  $queryStringArray = array(
210  'modelId' => static::$autoresponderItemId,
211  'modelType' => 'AutoresponderItem',
212  'personId' => static::$personId,
213  'url' => 'http://www.zurmo.com',
214  );
215  $hash = StringUtil::resolveHashForQueryStringArray($queryStringArray);
216  $this->setGetArray(array(
217  'id' => $hash,
218  ));
219  $url = $this->runControllerWithRedirectExceptionAndGetUrl(static::TRACK_ROUTE);
220  $this->assertEquals($queryStringArray['url'], $url);
221  $autoresponderItemActivity = AutoresponderItemActivity::getByTypeAndModelIdAndPersonIdAndUrl(
222  AutoresponderItemActivity::TYPE_CLICK,
223  static::$autoresponderItemId,
224  static::$personId,
225  $queryStringArray['url']);
226  $this->assertNotEmpty($autoresponderItemActivity);
227  $this->assertCount(1, $autoresponderItemActivity);
228  $this->assertEquals(1, $autoresponderItemActivity[0]->quantity);
229  }
230 
235  {
236  $queryStringArray = array(
237  'modelId' => static::$campaignItemId,
238  'modelType' => 'CampaignItem',
239  'personId' => static::$personId,
240  );
241  $hash = StringUtil::resolveHashForQueryStringArray($queryStringArray);
242  $this->setGetArray(array(
243  'id' => $hash,
244  ));
245  // Need @ to ignore the headers already sent error.
246  $content = @$this->runControllerWithExitExceptionAndGetContent(static::TRACK_ROUTE);
247  $image = imagecreatefromstring($content);
248  $this->assertTrue($image !== false);
249  $path = tempnam(sys_get_temp_dir() , '1x1-pixel') . '.png';
250  $createdPng = imagepng($image, $path);
251  $this->assertTrue($createdPng);
252  $campaignItemActivity = CampaignItemActivity::getByTypeAndModelIdAndPersonIdAndUrl(
253  CampaignItemActivity::TYPE_OPEN,
254  static::$campaignItemId,
255  static::$personId);
256  $this->assertNotEmpty($campaignItemActivity);
257  $this->assertCount(1, $campaignItemActivity);
258  $this->assertEquals(1, $campaignItemActivity[0]->quantity);
259  }
260 
265  {
266  $queryStringArray = array(
267  'modelId' => static::$campaignItemId,
268  'modelType' => 'CampaignItem',
269  'personId' => static::$personId,
270  'url' => 'http://www.zurmo.com',
271  );
272  $hash = StringUtil::resolveHashForQueryStringArray($queryStringArray);
273  $this->setGetArray(array(
274  'id' => $hash,
275  ));
276  $url = $this->runControllerWithRedirectExceptionAndGetUrl(static::TRACK_ROUTE);
277  $this->assertEquals($queryStringArray['url'], $url);
278  $campaignItemActivity = CampaignItemActivity::getByTypeAndModelIdAndPersonIdAndUrl(
279  CampaignItemActivity::TYPE_CLICK,
280  static::$campaignItemId,
281  static::$personId,
282  $queryStringArray['url']);
283  $this->assertNotEmpty($campaignItemActivity);
284  $this->assertCount(1, $campaignItemActivity);
285  $this->assertEquals(1, $campaignItemActivity[0]->quantity);
286  }
287  }
288 ?>
static rebuild($overwriteExistingTables=true, $forcePhp=false, $messageStreamer=null)
static getByUsername($username)
Definition: User.php:49
runControllerWithNoExceptionsAndGetContent($route, $empty=false)
Generated on Fri Jun 5 2020 07:10:35