]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/Campaigns/Bug41523Test.php
Release 6.4.4
[Github/sugarcrm.git] / tests / modules / Campaigns / Bug41523Test.php
1 <?php 
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
5  * 
6  * This program 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 SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  * 
13  * This program 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 SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
24  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
25  * 
26  * The interactive user interfaces in modified source and object code 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 "Powered by
32  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
33  * technical reasons, the Appropriate Legal Notices must display the words
34  * "Powered by SugarCRM".
35  ********************************************************************************/
36
37
38 require_once 'include/SubPanel/SubPanelTiles.php';
39
40 /**
41  * Bug #41523
42  * Subject Blank Rows Are Displayed In Campaign Status "Leads Created" Subpanel If Leads Are Deleted
43  *
44  * @ticket 41523
45  */
46 class Bug41523Test extends Sugar_PHPUnit_Framework_TestCase
47 {
48     /**
49      * @var Campaign
50      */
51     private $campaign;
52
53     /**
54      * @var MysqliManager
55      */
56     private $db;
57
58     public function setUp()
59     {
60         $this->markTestIncomplete("This test breaks on stack66 - working with dev to fix");
61         global $focus;
62
63         // Init session user settings
64         $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
65         $GLOBALS['current_user']->setPreference('max_tabs', 2);
66
67         $this->campaign = SugarTestCampaignUtilities::createCampaign();
68         $this->db       = $GLOBALS['db'];
69         $focus          = $this->campaign;
70
71         // Setting for SubPanel
72         $_SERVER['REQUEST_METHOD'] = 'GET';
73         $_REQUEST['module']        = 'Campaigns';
74         $_REQUEST['action']        = 'TrackDetailView';
75         $_REQUEST['record']        = $this->campaign->id;
76     }
77
78     public function tearDown()
79     {
80         // Delete created campaings
81         SugarTestCampaignUtilities::removeAllCreatedCampaigns();
82
83         // Delete users
84         SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
85     }
86
87     /**
88      * @group 41523
89      */
90     public function testDeletedLeadsOnCapmaingStatusPage()
91     {
92         // Create 2 leads
93         $lead1 = $this->createLeadFromWebForm('User1');
94         $lead2 = $this->createLeadFromWebForm('User2');
95
96         // Delete one lead
97         $lead1->mark_deleted($lead1->id);
98
99         $this->assertEquals($this->campaign->getDeletedCampaignLogLeadsCount(), 1);
100
101         // Test SubPanel output
102         $subpanel = new SubPanelTiles($this->campaign, 'Campaigns');
103         $html = $subpanel->display();
104
105         preg_match('|<div id="list_subpanel_lead">.*?<table.*?</table>.*?</table>.*?</tr>(.*?)</table>|s', $html, $match);
106         preg_match_all('|<tr|', $match[1], $match);
107
108         $this->assertEquals(count($match[0]), 2);
109     }
110
111     /**
112      * @param $lastName Last name for new lead
113      *
114      * @return Lead
115      */
116     private function createLeadFromWebForm($lastName)
117     {
118         $postData = array(
119             'last_name' => $lastName,
120             'campaign_id' => $this->campaign->id,
121         );
122
123         // Send request for add lead
124         $ch = curl_init();
125         curl_setopt($ch, CURLOPT_URL, $GLOBALS['sugar_config']['site_url'] . '/index.php?entryPoint=WebToLeadCapture');
126         curl_setopt($ch, CURLOPT_POST, true);
127         curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData));
128         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
129         $response = curl_exec($ch);
130
131         $this->assertEquals('Thank You For Your Submission.', $response);
132
133         curl_close($ch);
134
135         // Fetch last created lead
136         $createdLead = new Lead();
137         $query = 'SELECT * FROM leads ORDER BY date_entered DESC LIMIT 1';
138         $createdLead->fromArray($this->db->fetchOne($query));
139
140         return $createdLead;
141     }
142 }