]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/Campaigns/Bug41523Test.php
Release 6.5.9
[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         unset($_SERVER['REQUEST_METHOD']);
81
82         // Delete created campaings
83         SugarTestCampaignUtilities::removeAllCreatedCampaigns();
84
85         // Delete users
86         SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
87     }
88
89     /**
90      * @group 41523
91      */
92     public function testDeletedLeadsOnCapmaingStatusPage()
93     {
94         // Create 2 leads
95         $lead1 = $this->createLeadFromWebForm('User1');
96         $lead2 = $this->createLeadFromWebForm('User2');
97
98         // Delete one lead
99         $lead1->mark_deleted($lead1->id);
100
101         $this->assertEquals($this->campaign->getDeletedCampaignLogLeadsCount(), 1);
102
103         // Test SubPanel output
104         $subpanel = new SubPanelTiles($this->campaign, 'Campaigns');
105         $html = $subpanel->display();
106
107         preg_match('|<div id="list_subpanel_lead">.*?<table.*?</table>.*?</table>.*?</tr>(.*?)</table>|s', $html, $match);
108         preg_match_all('|<tr|', $match[1], $match);
109
110         $this->assertEquals(count($match[0]), 2);
111     }
112
113     /**
114      * @param $lastName Last name for new lead
115      *
116      * @return Lead
117      */
118     private function createLeadFromWebForm($lastName)
119     {
120         $postData = array(
121             'last_name' => $lastName,
122             'campaign_id' => $this->campaign->id,
123         );
124
125         // Send request for add lead
126         $ch = curl_init();
127         curl_setopt($ch, CURLOPT_URL, $GLOBALS['sugar_config']['site_url'] . '/index.php?entryPoint=WebToLeadCapture');
128         curl_setopt($ch, CURLOPT_POST, true);
129         curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData));
130         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
131         $response = curl_exec($ch);
132
133         $this->assertEquals('Thank You For Your Submission.', $response);
134
135         curl_close($ch);
136
137         // Fetch last created lead
138         $createdLead = new Lead();
139         $query = 'SELECT * FROM leads ORDER BY date_entered DESC LIMIT 1';
140         $createdLead->fromArray($this->db->fetchOne($query));
141
142         return $createdLead;
143     }
144 }