2 require_once('modules/DynamicFields/FieldCases.php');
5 * Test cases for URL Field
7 class RepairCustomFieldsTest extends Sugar_PHPUnit_Framework_TestCase
9 protected $modulename = 'Accounts';
10 protected $objectname = 'Account';
11 protected $table_name = 'accounts_cstm';
14 protected function repairDictionary()
17 $this->df->buildCache($this->modulename);
18 VardefManager::clearVardef();
19 VardefManager::refreshVardefs($this->modulename, $this->objectname);
20 $this->seed->field_defs = $GLOBALS['dictionary'][$this->objectname]['fields'];
24 public function setUp()
26 $this->markTestSkipped("Skipping for now...");
27 $this->field = get_widget('varchar');
28 $this->field->id = $this->modulename.'foo_c';
29 $this->field->name = 'foo_c';
30 $this->field->vanme = 'LBL_Foo';
31 $this->field->comments = NULL;
32 $this->field->help = NULL;
33 $this->field->custom_module = $this->modulename;
34 $this->field->type = 'varchar';
35 $this->field->label = 'LBL_FOO';
36 $this->field->len = 255;
37 $this->field->required = 0;
38 $this->field->default_value = NULL;
39 $this->field->date_modified = '2009-09-14 02:23:23';
40 $this->field->deleted = 0;
41 $this->field->audited = 0;
42 $this->field->massupdate = 0;
43 $this->field->duplicate_merge = 0;
44 $this->field->reportable = 1;
45 $this->field->importable = 'true';
46 $this->field->ext1 = NULL;
47 $this->field->ext2 = NULL;
48 $this->field->ext3 = NULL;
49 $this->field->ext4 = NULL;
50 $this->seed = new Account();
51 $this->df = new DynamicField($this->modulename);
52 $this->df->setup ( $this->seed ) ;
54 $this->field->save ( $this->df ) ;
55 $this->db = $GLOBALS['db'];
57 $this->repairDictionary();
61 public function tearDown()
63 $this->field->delete ( $this->df ) ;
64 if ($this->db->tableExists($this->table_name))
66 $this->db->dropTableName($this->table_name);
70 public function testRepairRemovedFieldNoExecute()
72 //Remove the custom column
73 $this->db->query("ALTER TABLE {$this->table_name} DROP COLUMN {$this->field->name}");
75 $ret = $this->df->repairCustomFields(false);
76 $this->assertRegExp("/MISSING IN DATABASE - {$this->field->name} - ROW/", $ret);
77 $compareFieldDefs = $this->db->getHelper()->get_columns($this->table_name);
78 $this->assertArrayNotHasKey($this->field->name, $compareFieldDefs);
81 public function testRepairRemovedFieldExecute()
83 //Remove the custom column
84 $this->db->query("ALTER TABLE {$this->table_name} DROP COLUMN {$this->field->name}");
86 $ret = $this->df->repairCustomFields(true);
87 $this->assertRegExp("/MISSING IN DATABASE - {$this->field->name} - ROW/", $ret);
88 $compareFieldDefs = $this->db->getHelper()->get_columns($this->table_name);
89 $this->assertArrayHasKey($this->field->name, $compareFieldDefs);
92 public function testCreateTableNoExecute()
94 //Remove the custom table
95 $this->db->dropTableName($this->table_name);
97 $ret = $this->df->repairCustomFields(false);
98 //Test that the table is going to be created.
99 $this->assertRegExp("/Missing Table: {$this->table_name}/", $ret);
100 //Test that the custom field is going to be added.
101 $this->assertRegExp("/MISSING IN DATABASE - {$this->field->name} - ROW/", $ret);
102 //Assert that the table was NOT created
103 $this->assertFalse($this->db->tableExists($this->table_name),
104 "Asserting that the custom table is not created when repair is run with execute set false");
107 public function testCreateTableExecute()
109 //Remove the custom table
110 $this->db->dropTableName($this->table_name);
112 $ret = $this->df->repairCustomFields();
113 $this->assertRegExp("/MISSING IN DATABASE - {$this->field->name} - ROW/", $ret);
114 //Test that the table is going to be created.
115 $this->assertRegExp("/Missing Table: {$this->table_name}/", $ret);
116 //Test that the custom field is going to be added.
117 $this->assertRegExp("/MISSING IN DATABASE - {$this->field->name} - ROW/", $ret);
118 //Assert that the table was created
119 $this->assertTrue($this->db->tableExists($this->table_name),
120 "Asserting that the custom table is created when repair is run with execute not set");