]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/jssource/Bug54472Test.php
Release 6.5.6
[Github/sugarcrm.git] / tests / jssource / Bug54472Test.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 /*
39 * This test will confirm that JSGroupings are concatenated using the Extensions Framework
40 *
41 */
42
43 require_once('modules/Administration/QuickRepairAndRebuild.php');
44
45
46
47 class Bug54472Test extends Sugar_PHPUnit_Framework_TestCase
48 {
49
50     private $beforeArray;
51     private $removeJSG_Dir = false;
52
53
54     public function setUp()
55     {
56         SugarTestHelper::setUp('beanFiles');
57         SugarTestHelper::setUp('beanList');
58         SugarTestHelper::setUp('current_user', array(true, 1));
59         SugarTestHelper::setUp('mod_strings', array('ModuleBuilder'));
60
61         //lets retrieve the original jsgroupings file to populate the js_grouping array to compare against later on
62         include('jssource/JSGroupings.php');
63
64         //store the grouping value before any changes
65         $this->beforeArray = $js_groupings;
66
67         //create supporting files in seperate function
68         $this->createSupportingFiles();
69
70         //run repair so the extension files are created and updated
71                                 $rac = new RepairAndClear();
72                                 $rac->repairAndClearAll(array('rebuildExtensions'), array(), false, false);
73
74     }
75
76
77     /*
78      * This function creates supporting directory structure and files to carry out the test
79      */
80     private function createSupportingFiles(){
81
82         //create the js group directory in the proper extension location if needed
83         if(!file_exists("custom/Extension/application/Ext/JSGroupings/")){
84             mkdir_recursive("custom/Extension/application/Ext/JSGroupings/", true);
85             $this->removeJSG_Dir = true;
86         }
87
88         //create the first grouping file and define the first group
89         if( $fh = @fopen("custom/Extension/application/Ext/JSGroupings/Jgroup0.php", 'w+') )
90         {
91         $jsgrpStr = '<?php
92 $js_groupings [\'testEntrySite\'] = array("include/javascript/calendar.js" => "include/javascript/sugar_test_grp1.js", "include/javascript/cookie.js" => "include/javascript/sugar_test_grp1.js");
93 ';
94                         fputs( $fh, $jsgrpStr);
95                         fclose( $fh );
96         }
97
98
99         //now create a second custom grouping file
100         if( $fhAcc = @fopen("custom/Extension/application/Ext/JSGroupings/Jgroup1.php", 'w+') )
101         {
102         $jsgrpACCStr = '<?php
103 $js_groupings [\'testEntryMod\'] = array("include/javascript/calendar.js" => "include/javascript/sugar_testAcc_grp1.js", "include/javascript/quickCompose.js" => "include/javascript/sugar_testAcc_grp1.js");
104 ';
105                         fputs( $fhAcc, $jsgrpACCStr);
106                         fclose( $fhAcc );
107         }
108
109
110     }
111
112     public function tearDown()
113     {
114
115         //remove the 2 grouping files and their directories
116         if(file_exists('custom/Extension/application/Ext/JSGroupings/Jgroup0.php')){
117             unlink('custom/Extension/application/Ext/JSGroupings/Jgroup0.php');
118         }
119         if(file_exists('custom/Extension/application/Ext/JSGroupings/Jgroup1.php')){
120             unlink('custom/Extension/application/Ext/JSGroupings/Jgroup1.php');
121         }
122         if($this->removeJSG_Dir && file_exists("custom/Extension/application/Ext/JSGroupings")) {
123             @rmdir("custom/Extension/application/Ext/JSGroupings");
124         }
125
126         //unset before array
127         unset($this->beforeArray);
128
129         //run repair so the extension files are reset back to original state
130         $trac = new RepairAndClear();
131         $trac->repairAndClearAll(array('rebuildExtensions'), array(), false, false);
132         SugarTestHelper::tearDown();
133     }
134
135     public function testGetJSGroupingCustomEntries() {
136
137         //include jsgroupings file again, this time it should pick up the 2 new groups from the extensions.
138         include('jssource/JSGroupings.php');
139
140         //assert that the array count has increased, this confirms it is grabbing the files correctly
141         $this->assertGreaterThan(count($this->beforeArray),count($js_groupings), 'JSGrouping array was not concatenated correctly, the number of elements should have increased');
142
143         //Check for the individual entries to confirm they are being concatenated and not overwritten
144         $this->assertArrayHasKey('testEntrySite', $js_groupings,'JSGrouping array was not concatenated correctly, site entry is missing');
145         $this->assertArrayHasKey('testEntryMod', $js_groupings,'JSGrouping array was not concatenated correctly, module entry is missing');
146
147     }
148
149 }