]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/UpgradeWizard/RepairDatabaseTest.php
Release 6.2.0
[Github/sugarcrm.git] / tests / modules / UpgradeWizard / RepairDatabaseTest.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  
38 require_once 'include/database/DBManagerFactory.php';
39
40 class RepairDatabaseTest extends Sugar_PHPUnit_Framework_TestCase
41 {
42
43 var $db;        
44         
45 public function setUp()
46 {
47         
48         $this->markTestSkipped('Skip for now'); 
49     $this->db = DBManagerFactory::getInstance();        
50     if($this->db->dbType == 'mysql')
51     {
52        $sql =  'ALTER TABLE meetings ALTER COLUMN status SET DEFAULT NULL';
53        $sql2 = 'ALTER TABLE calls ALTER COLUMN status SET DEFAULT NULL';
54        $sql3 = 'ALTER TABLE tasks ALTER COLUMN status SET DEFAULT NULL';
55
56            //Run the SQL
57            $this->db->query($sql);  
58            $this->db->query($sql2);  
59            $this->db->query($sql3);       
60     }
61     
62          
63 }       
64
65 public function tearDown()
66 {
67         if($this->db->dbType == 'mysql')
68     {   
69         $sql = "ALTER TABLE meetings ALTER COLUMN status SET DEFAULT 'Planned'";
70         $sql2 = "ALTER TABLE calls ALTER COLUMN status SET DEFAULT 'Planned'";
71         $sql3 = "ALTER TABLE tasks ALTER COLUMN status SET DEFAULT 'Not Started'";
72             //Run the SQL
73             $this->db->query($sql);
74             $this->db->query($sql2); 
75             $this->db->query($sql3);            
76     }           
77 }
78
79 public function testRepairTableParams()
80 {
81             if($this->db->dbType != 'mysql')
82             {
83                $this->markTestSkipped('Skip if not mysql db');
84                return;  
85             }
86         
87             $bean = new Meeting();
88             $result = $this->getRepairTableParamsResult($bean);
89             $this->assertRegExp('/ALTER TABLE meetings\s+?modify column status varchar\(100\)  DEFAULT \'Planned\' NULL/i', $result);
90             
91             /*
92             $bean = new Call();
93             $result = $this->getRepairTableParamsResult($bean);
94             $this->assertTrue(!empty($result));
95             $this->assertRegExp('/ALTER TABLE calls\s+?modify column status varchar\(100\)  DEFAULT \'Planned\' NULL/i', $result);
96             */
97             
98             $bean = new Task();
99             $result = $this->getRepairTableParamsResult($bean);
100             $this->assertTrue(!empty($result));     
101             $this->assertRegExp('/ALTER TABLE tasks\s+?modify column status varchar\(100\)  DEFAULT \'Not Started\' NULL/i', $result);
102  
103 }
104
105 private function getRepairTableParamsResult($bean)
106 {
107         $indices   = $bean->getIndices();
108         $fielddefs = $bean->getFieldDefinitions();
109         $tablename = $bean->getTableName();
110
111                 //Clean the indicies to prevent duplicate definitions
112                 $new_indices = array();
113                 foreach($indices as $ind_def)
114                 {
115                         $new_indices[$ind_def['name']] = $ind_def;
116                 }
117                 
118         global $dictionary;
119         $engine=null;
120         if (isset($dictionary[$bean->getObjectName()]['engine']) && !empty($dictionary[$bean->getObjectName()]['engine']) )
121         {
122             $engine = $dictionary[$bean->getObjectName()]['engine'];    
123         }
124         
125         
126             $result = $this->db->repairTableParams($bean->table_name, $fielddefs, $new_indices, false, $engine);
127             return $result;     
128 }
129         
130 }