blob: a3d5bac6539e12ccb0bb6bb153cc17f67529d5f7 [file] [log] [blame]
Taufan Aditya5b421662012-04-05 01:24:50 +07001<?php
2
3class Mock_Database_Schema_Skeleton {
Taufan Aditya55f622f2012-04-05 19:01:34 +07004
5 /**
6 * @var object Database Holder
7 */
8 public static $db;
9
10 /**
11 * @var object Forge Holder
12 */
13 public static $forge;
14
15 /**
16 * @var object Driver Holder
17 */
18 public static $driver;
19
20 /**
21 * Initialize both database and forge components
22 */
23 public static function init($driver)
24 {
25 if (empty(static::$db) && empty(static::$forge))
26 {
27 $config = Mock_Database_DB::config($driver);
28 $connection = new Mock_Database_DB($config);
29 $db = Mock_Database_DB::DB($connection->set_dsn($driver), TRUE);
30
31 CI_TestCase::instance()->ci_instance_var('db', $db);
32
33 $loader = new Mock_Core_Loader();
34 $loader->dbforge();
35 $forge = CI_TestCase::instance()->ci_instance_var('dbforge');
36
37 static::$db = $db;
38 static::$forge = $forge;
39 static::$driver = $driver;
40 }
41
42 return static::$db;
43 }
44
Taufan Aditya5b421662012-04-05 01:24:50 +070045
46 /**
47 * Create the dummy tables
48 *
49 * @return void
50 */
Taufan Aditya55f622f2012-04-05 19:01:34 +070051 public static function create_tables()
Taufan Aditya5b421662012-04-05 01:24:50 +070052 {
53 // Job Table
Taufan Aditya55f622f2012-04-05 19:01:34 +070054 static::$forge->add_field(array(
Taufan Aditya5b421662012-04-05 01:24:50 +070055 'id' => array(
Taufan Aditya1bfc0d92012-04-05 02:25:25 +070056 'type' => 'INTEGER',
Taufan Aditya5b421662012-04-05 01:24:50 +070057 'constraint' => 3,
58 ),
59 'name' => array(
60 'type' => 'VARCHAR',
61 'constraint' => 40,
62 ),
63 'description' => array(
64 'type' => 'TEXT',
Taufan Aditya5b421662012-04-05 01:24:50 +070065 ),
66 ));
Taufan Aditya55f622f2012-04-05 19:01:34 +070067 static::$forge->add_key('id', TRUE);
68 static::$forge->create_table('job', (strpos(static::$driver, 'pgsql') === FALSE));
Taufan Aditya5b421662012-04-05 01:24:50 +070069 }
70
71 /**
72 * Create the dummy datas
73 *
74 * @return void
75 */
Taufan Aditya55f622f2012-04-05 19:01:34 +070076 public static function create_data()
Taufan Aditya5b421662012-04-05 01:24:50 +070077 {
78 // Job Data
79 $data = array(
80 'job' => array(
81 array('id' => 1, 'name' => 'Developer', 'description' => 'Awesome job, but sometimes makes you bored'),
82 array('id' => 2, 'name' => 'Politician', 'description' => 'This is not really a job'),
83 array('id' => 3, 'name' => 'Accountant', 'description' => 'Boring job, but you will get free snack at lunch'),
84 array('id' => 4, 'name' => 'Musician', 'description' => 'Only Coldplay can actually called Musician'),
85 ),
86 );
87
88 foreach ($data as $table => $dummy_data)
89 {
Taufan Aditya55f622f2012-04-05 19:01:34 +070090 static::$db->truncate($table);
Taufan Aditya024098d2012-04-05 01:51:57 +070091
92 foreach ($dummy_data as $single_dummy_data)
Taufan Aditya5b421662012-04-05 01:24:50 +070093 {
Taufan Aditya55f622f2012-04-05 19:01:34 +070094 static::$db->insert($table, $single_dummy_data);
Taufan Aditya5b421662012-04-05 01:24:50 +070095 }
96 }
97 }
98}