]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/ModuleBuilder/parsers/views/Bug50308Test.php
Release 6.5.10
[Github/sugarcrm.git] / tests / modules / ModuleBuilder / parsers / views / Bug50308Test.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2013 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 ('modules/ModuleBuilder/parsers/views/PopupMetaDataParser.php');
39
40 /*
41  * This test checks to see if custom elements can be defined in a popupdef and be handled by PopupMetaDataParser.php
42  * @ticket 50308
43  */
44 class Bug50308Test extends Sugar_PHPUnit_Framework_TestCase {
45
46     var $customFilePath = 'custom/modules/Users/metadata/popupdefs.php';
47     var $customFileDir = 'custom/modules/Users/metadata';
48     var $originalPopupMeta = array();
49     var $newPopupMeta = array('moduleMain'=>array('one','two'), 'varName'=>array('one','two') , 'orderBy'=>array('one','two'), 'whereClauses'=>array('one','two'), 'searchInputs'=>array('one','two'), 'create'=>array('one','two'));
50
51     public function setUp()
52     {
53         //back up users popup if it exists
54         if(is_file($this->customFilePath)){
55             include($this->customFilePath);
56             $this->originalPopupMeta = $popupMeta;
57             $this->newPopupMeta = $popupMeta;
58         }else{
59             //lets create the directory if it does not exist
60             if(!is_dir($this->customFileDir)){
61                 sugar_mkdir($this->customFileDir);
62             }
63         }
64
65         //define and add the new elements
66         $this->newPopupMeta['addToReserve'] = array('whereStatement', 'templateMeta');
67         $this->newPopupMeta['whereStatement'] = 'select money from yourWallet where deposit = "myPocket"';
68         $this->newPopupMeta['templateMeta'] = array('one','two');
69         $this->newPopupMeta['disappear'] = 'this element was not defined and should be processed';
70
71     }
72
73     public function tearDown() {
74
75         //remove custom file
76         unlink($this->customFilePath);
77         //recreate custom file using old data if it was collected
78         if(!empty($this->originalPopupMeta)){
79             $meta = "<?php\n \$popupMeta = array (\n";
80             foreach( $this->originalPopupMeta as $k=>$v){
81                         $meta .= "    '$k' => ". var_export_helper ($v) . ",\n";
82             }
83             $meta .=");\n";
84
85             sugar_file_put_contents($this->customFilePath, $meta);
86         }
87
88         unset($this->customFilePath);
89         unset($this->customFileDir);
90         unset($this->originalPopupMeta);
91         unset($this->newPopupMeta);
92
93     }
94
95     /*
96      * This method writes out the custom popupdef file to custom users directory, then runs the save function on the  popup metadata parser
97      * the tests assert that the custom elements are preserved by the parser
98      */
99     public function testUsingCustomPopUpElements() {
100         
101         //declare the vars global and then include the modules file to make sure they are available during testing
102         global $moduleList, $beanList, $beanFiles;
103         include('include/modules.php');
104
105         if (empty($GLOBALS['app_list_strings'])){
106             $language = $GLOBALS['current_language'];
107             $GLOBALS['app_list_strings'] = return_app_list_strings_language($language);
108         }
109         //write out to file and assert that the file was written, or we shouldn't continue
110             $meta = "<?php\n \$popupMeta = array (\n";
111             foreach( $this->newPopupMeta as $k=>$v){
112                         $meta .= "    '$k' => ". var_export_helper ($v) . ",\n";
113             }
114             $meta .=");\n";
115
116         $writeResult = sugar_file_put_contents($this->customFilePath, $meta);
117         $this->assertGreaterThan(0,$writeResult, 'there was an error writing custom popup meta to file using this path: '.$this->customFilePath);
118
119         //create new instance of popupmetadata parser
120         $parserFactory = new ParserFactory();
121         $parser = $parserFactory->getParser(MB_POPUPLIST, 'Users');
122
123         //run save to write out the file using the new array elements.
124         $parser->handleSave(false);
125
126         //assert the file still exists
127         $this->assertTrue(is_file($this->customFilePath),' PopupMetaDataParser::handleSave() could not write out the file as expected.');
128
129         //include the file again to get the new popup meta array
130         include($this->customFilePath);
131         $popupKeys = array_keys($popupMeta);
132         //assert that one of the new elements is there
133         $this->assertContains('whereStatement', $popupKeys,'an element that was defined in addToReserve was not processed and save within PopupMetaDataParser::handleSave()');
134
135         //assert that the element that was written but not defined in 'addToReserve' is no longer there
136         $this->assertNotContains('disappear', $popupKeys, 'an element that was added but NOT defined in addToReserve was incorrectly processed and saved within PopupMetaDataParser::handleSave().');
137     }
138 }