2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2013 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 SugarTestHelper::setUp('beanFiles');
57 SugarTestHelper::setUp('beanList');
58 SugarTestHelper::setUp('current_user', array(true, 1));
59 SugarTestHelper::setUp('mod_strings', array('ModuleBuilder'));
61 //lets retrieve the original jsgroupings file to populate the js_grouping array to compare against later on
62 include('jssource/JSGroupings.php');
64 //store the grouping value before any changes
65 $this->beforeArray = $js_groupings;
67 //create supporting files in seperate function
68 $this->createSupportingFiles();
70 //run repair so the extension files are created and updated
71 $rac = new RepairAndClear();
72 $rac->repairAndClearAll(array('rebuildExtensions'), array(), false, false);
78 * This function creates supporting directory structure and files to carry out the test
80 private function createSupportingFiles(){
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;
88 //create the first grouping file and define the first group
89 if( $fh = @fopen("custom/Extension/application/Ext/JSGroupings/Jgroup0.php", 'w+') )
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");
94 fputs( $fh, $jsgrpStr);
99 //now create a second custom grouping file
100 if( $fhAcc = @fopen("custom/Extension/application/Ext/JSGroupings/Jgroup1.php", 'w+') )
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");
105 fputs( $fhAcc, $jsgrpACCStr);
112 public function tearDown()
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');
119 if(file_exists('custom/Extension/application/Ext/JSGroupings/Jgroup1.php')){
120 unlink('custom/Extension/application/Ext/JSGroupings/Jgroup1.php');
122 if($this->removeJSG_Dir && file_exists("custom/Extension/application/Ext/JSGroupings")) {
123 @rmdir("custom/Extension/application/Ext/JSGroupings");
127 unset($this->beforeArray);
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();
135 public function testGetJSGroupingCustomEntries() {
137 //include jsgroupings file again, this time it should pick up the 2 new groups from the extensions.
138 include('jssource/JSGroupings.php');
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');
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');