2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
39 * This test will confirm that JSGroupings are concatenated using the Extensions Framework
43 require_once('modules/Administration/QuickRepairAndRebuild.php');
47 class Bug54472Test extends Sugar_PHPUnit_Framework_TestCase
51 private $removeJSG_Dir = false;
54 public function setUp()
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;
60 //lets retrieve the original jsgroupings file to populate the js_grouping array to compare against later on
61 include('jssource/JSGroupings.php');
63 //store the grouping value before any changes
64 $this->beforeArray = $js_groupings;
66 //create supporting files in seperate function
67 $this->createSupportingFiles();
69 //run repair so the extension files are created and updated
70 $rac = new RepairAndClear();
71 $rac->repairAndClearAll(array('rebuildExtensions'), array(), false, false);
77 * This function creates supporting directory structure and files to carry out the test
79 private function createSupportingFiles(){
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;
87 //create the first grouping file and define the first group
88 if( $fh = @fopen("custom/Extension/application/Ext/JSGroupings/Jgroup0.php", 'w+') )
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");
93 fputs( $fh, $jsgrpStr);
98 //now create a second custom grouping file
99 if( $fhAcc = @fopen("custom/Extension/application/Ext/JSGroupings/Jgroup1.php", 'w+') )
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");
104 fputs( $fhAcc, $jsgrpACCStr);
111 public function tearDown()
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');
118 if(file_exists('custom/Extension/application/Ext/JSGroupings/Jgroup1.php')){
119 unlink('custom/Extension/application/Ext/JSGroupings/Jgroup1.php');
121 if($this->removeJSG_Dir && file_exists("custom/Extension/application/Ext/JSGroupings")) {
122 @rmdir("custom/Extension/application/Ext/JSGroupings");
126 unset($this->beforeArray);
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);
134 public function testGetJSGroupingCustomEntries() {
136 //include jsgroupings file again, this time it should pick up the 2 new groups from the extensions.
137 include('jssource/JSGroupings.php');
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');
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');