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