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 ********************************************************************************/
38 require_once('modules/DynamicFields/FieldCases.php');
41 * Test cases for URL Field
43 class RepairCustomFieldsTest extends Sugar_PHPUnit_Framework_TestCase
45 protected $modulename = 'Accounts';
46 protected $objectname = 'Account';
47 protected $table_name = 'accounts_cstm';
50 protected function repairDictionary()
53 $this->df->buildCache($this->modulename);
54 VardefManager::clearVardef();
55 VardefManager::refreshVardefs($this->modulename, $this->objectname);
56 $this->seed->field_defs = $GLOBALS['dictionary'][$this->objectname]['fields'];
60 public function setUp()
62 $this->markTestSkipped("Skipping for now...");
63 $this->field = get_widget('varchar');
64 $this->field->id = $this->modulename.'foo_c';
65 $this->field->name = 'foo_c';
66 $this->field->vanme = 'LBL_Foo';
67 $this->field->comments = NULL;
68 $this->field->help = NULL;
69 $this->field->custom_module = $this->modulename;
70 $this->field->type = 'varchar';
71 $this->field->label = 'LBL_FOO';
72 $this->field->len = 255;
73 $this->field->required = 0;
74 $this->field->default_value = NULL;
75 $this->field->date_modified = '2009-09-14 02:23:23';
76 $this->field->deleted = 0;
77 $this->field->audited = 0;
78 $this->field->massupdate = 0;
79 $this->field->duplicate_merge = 0;
80 $this->field->reportable = 1;
81 $this->field->importable = 'true';
82 $this->field->ext1 = NULL;
83 $this->field->ext2 = NULL;
84 $this->field->ext3 = NULL;
85 $this->field->ext4 = NULL;
86 $this->seed = new Account();
87 $this->df = new DynamicField($this->modulename);
88 $this->df->setup ( $this->seed ) ;
90 $this->field->save ( $this->df ) ;
91 $this->db = $GLOBALS['db'];
93 $this->repairDictionary();
97 public function tearDown()
99 if ( isset($this->field) && ( $this->field instanceOf TemplateField ) ) {
100 $this->field->delete ( $this->df ) ;
102 if ( isset($this->db) && ( $this->db instanceOf DBManager ) && $this->db->tableExists($this->table_name) ) {
103 $this->db->dropTableName($this->table_name);
107 public function testRepairRemovedFieldNoExecute()
109 //Remove the custom column
110 $this->db->query("ALTER TABLE {$this->table_name} DROP COLUMN {$this->field->name}");
112 $ret = $this->df->repairCustomFields(false);
113 $this->assertRegExp("/MISSING IN DATABASE - {$this->field->name} - ROW/", $ret);
114 $compareFieldDefs = $this->db->getHelper()->get_columns($this->table_name);
115 $this->assertArrayNotHasKey($this->field->name, $compareFieldDefs);
118 public function testRepairRemovedFieldExecute()
120 //Remove the custom column
121 $this->db->query("ALTER TABLE {$this->table_name} DROP COLUMN {$this->field->name}");
123 $ret = $this->df->repairCustomFields(true);
124 $this->assertRegExp("/MISSING IN DATABASE - {$this->field->name} - ROW/", $ret);
125 $compareFieldDefs = $this->db->getHelper()->get_columns($this->table_name);
126 $this->assertArrayHasKey($this->field->name, $compareFieldDefs);
129 public function testCreateTableNoExecute()
131 //Remove the custom table
132 $this->db->dropTableName($this->table_name);
134 $ret = $this->df->repairCustomFields(false);
135 //Test that the table is going to be created.
136 $this->assertRegExp("/Missing Table: {$this->table_name}/", $ret);
137 //Test that the custom field is going to be added.
138 $this->assertRegExp("/MISSING IN DATABASE - {$this->field->name} - ROW/", $ret);
139 //Assert that the table was NOT created
140 $this->assertFalse($this->db->tableExists($this->table_name),
141 "Asserting that the custom table is not created when repair is run with execute set false");
144 public function testCreateTableExecute()
146 //Remove the custom table
147 $this->db->dropTableName($this->table_name);
149 $ret = $this->df->repairCustomFields();
150 $this->assertRegExp("/MISSING IN DATABASE - {$this->field->name} - ROW/", $ret);
151 //Test that the table is going to be created.
152 $this->assertRegExp("/Missing Table: {$this->table_name}/", $ret);
153 //Test that the custom field is going to be added.
154 $this->assertRegExp("/MISSING IN DATABASE - {$this->field->name} - ROW/", $ret);
155 //Assert that the table was created
156 $this->assertTrue($this->db->tableExists($this->table_name),
157 "Asserting that the custom table is created when repair is run with execute not set");