]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/UpgradeWizard/SugarMerge/Bug49955Test.php
Release 6.4.0
[Github/sugarcrm.git] / tests / modules / UpgradeWizard / SugarMerge / Bug49955Test.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2011 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 require_once 'include/dir_inc.php';
38 require_once('modules/UpgradeWizard/UpgradeRemoval.php');
39
40 class Bug49955Test extends Sugar_PHPUnit_Framework_TestCase  {
41         
42 var $merge;
43
44 function setUp() {
45    SugarTestMergeUtilities::setupFiles(array('Notes'), array('editviewdefs'), 'tests/modules/UpgradeWizard/SugarMerge/metadata_files');
46
47     if(file_exists('custom/backup/modules/DocumentRevisions'))
48     {
49            rmdir_recursive('custom/backup/modules/DocumentRevisions');
50     }
51
52     file_put_contents('modules/DocumentRevisions/EditView.html', 'test');
53     file_put_contents('modules/DocumentRevisions/DetailView.html', 'test');
54     file_put_contents('modules/DocumentRevisions/EditView.php', 'test');
55     file_put_contents('modules/DocumentRevisions/DetailView.php', 'test');
56 }
57
58
59 function tearDown() {
60    SugarTestMergeUtilities::teardownFiles();
61
62    if(file_exists('custom/backup/modules/DocumentRevisions'))
63    {
64            rmdir_recursive('custom/backup/modules/DocumentRevisions');
65    }
66
67    if(file_exists('modules/DocumentRevisions/EditView.html'))
68    {
69        unlink('modules/DocumentRevisions/EditView.html');
70    }
71
72    if(file_exists('modules/DocumentRevisions/DetailView.html'))
73    {
74        unlink('modules/DocumentRevisions/DetailView.html');
75    }
76
77    if(file_exists('modules/DocumentRevisions/EditView.php'))
78    {
79        unlink('modules/DocumentRevisions/EditView.php');
80    }
81
82    if(file_exists('modules/DocumentRevisions/DetailView.php'))
83    {
84        unlink('modules/DocumentRevisions/DetailView.php');
85    }
86 }
87
88 function test_filename_convert_merge() {
89    require_once 'modules/UpgradeWizard/SugarMerge/EditViewMerge.php';
90    $this->merge = new EditViewMerge();
91    $this->merge->merge('Notes', 'tests/modules/UpgradeWizard/SugarMerge/metadata_files/610/modules/Notes/metadata/editviewdefs.php','modules/Notes/metadata/editviewdefs.php','custom/modules/Notes/metadata/editviewdefs.php');
92    require('custom/modules/Notes/metadata/editviewdefs.php');
93
94    $foundFilename = 0;
95    $fileField = '';
96
97    foreach ( $viewdefs['Notes']['EditView']['panels'] as $panel ) {
98        foreach ( $panel as $row ) {
99            foreach ( $row as $col ) {
100                if ( is_array($col) ) {
101                    $fieldName = $col['name'];
102                } else {
103                    $fieldName = $col;
104                }
105                
106                if ( $fieldName == 'filename' ) {
107                    $fileField = $col;
108                    break;
109                }
110            }
111        }
112    }
113
114    $this->assertNotEmpty($fileField,'Filename field doesn\'t exit, it should');
115    $this->assertTrue(is_string($fileField) && $fileField == 'filename', 'Filename field not converted to string');
116
117    if ( file_exists('custom/modules/Notes/metadata/editviewdefs-testback.php') ) {
118        copy('custom/modules/Notes/metadata/editviewdefs-testback.php','custom/modules/Notes/metadata/editviewdefs.php');
119        unlink('custom/modules/Notes/metadata/editviewdefs-testback.php');
120    }
121
122    //Now test the DocumentRevisions cleanup
123     $instance = new UpgradeRemoval49955Mock();
124         $instance->processFilesToRemove($instance->getFilesToRemove(624));
125     $this->assertTrue(!file_exists('modules/DocumentRevisions/EditView.html'));
126     $this->assertTrue(!file_exists('modules/DocumentRevisions/DetaillView.html'));
127     $this->assertTrue(!file_exists('modules/DocumentRevisions/EditView.php'));
128     $this->assertTrue(!file_exists('modules/DocumentRevisions/DetailView.html'));
129
130 }
131
132 }
133
134 class UpgradeRemoval49955Mock extends UpgradeRemoval
135 {
136
137 public function getFilesToRemove($version)
138 {
139         $files = array();
140         $files[] = 'modules/DocumentRevisions/EditView.html';
141     $files[] = 'modules/DocumentRevisions/DetailView.html';
142     $files[] = 'modules/DocumentRevisions/EditView.php';
143     $files[] = 'modules/DocumentRevisions/DetailView.php';
144         return $files;
145 }
146
147
148 }