Mercurial > hg > rr-repo
comparison modules/simpletest/tests/database_test.install @ 0:ff03f76ab3fe
initial version
| author | danieleb <danielebarchiesi@me.com> |
|---|---|
| date | Wed, 21 Aug 2013 18:51:11 +0100 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:ff03f76ab3fe |
|---|---|
| 1 <?php | |
| 2 | |
| 3 /** | |
| 4 * @file | |
| 5 * Install, update and uninstall functions for the database_test module. | |
| 6 */ | |
| 7 | |
| 8 /** | |
| 9 * Implements hook_schema(). | |
| 10 * | |
| 11 * The database tests use the database API which depends on schema | |
| 12 * information for certain operations on certain databases. | |
| 13 * Therefore, the schema must actually be declared in a normal module | |
| 14 * like any other, not directly in the test file. | |
| 15 */ | |
| 16 function database_test_schema() { | |
| 17 $schema['test'] = array( | |
| 18 'description' => 'Basic test table for the database unit tests.', | |
| 19 'fields' => array( | |
| 20 'id' => array( | |
| 21 'type' => 'serial', | |
| 22 'unsigned' => TRUE, | |
| 23 'not null' => TRUE, | |
| 24 ), | |
| 25 'name' => array( | |
| 26 'description' => "A person's name", | |
| 27 'type' => 'varchar', | |
| 28 'length' => 255, | |
| 29 'not null' => TRUE, | |
| 30 'default' => '', | |
| 31 'binary' => TRUE, | |
| 32 ), | |
| 33 'age' => array( | |
| 34 'description' => "The person's age", | |
| 35 'type' => 'int', | |
| 36 'unsigned' => TRUE, | |
| 37 'not null' => TRUE, | |
| 38 'default' => 0, | |
| 39 ), | |
| 40 'job' => array( | |
| 41 'description' => "The person's job", | |
| 42 'type' => 'varchar', | |
| 43 'length' => 255, | |
| 44 'not null' => TRUE, | |
| 45 'default' => 'Undefined', | |
| 46 ), | |
| 47 ), | |
| 48 'primary key' => array('id'), | |
| 49 'unique keys' => array( | |
| 50 'name' => array('name') | |
| 51 ), | |
| 52 'indexes' => array( | |
| 53 'ages' => array('age'), | |
| 54 ), | |
| 55 ); | |
| 56 | |
| 57 // This is an alternate version of the same table that is structured the same | |
| 58 // but has a non-serial Primary Key. | |
| 59 $schema['test_people'] = array( | |
| 60 'description' => 'A duplicate version of the test table, used for additional tests.', | |
| 61 'fields' => array( | |
| 62 'name' => array( | |
| 63 'description' => "A person's name", | |
| 64 'type' => 'varchar', | |
| 65 'length' => 255, | |
| 66 'not null' => TRUE, | |
| 67 'default' => '', | |
| 68 ), | |
| 69 'age' => array( | |
| 70 'description' => "The person's age", | |
| 71 'type' => 'int', | |
| 72 'unsigned' => TRUE, | |
| 73 'not null' => TRUE, | |
| 74 'default' => 0, | |
| 75 ), | |
| 76 'job' => array( | |
| 77 'description' => "The person's job", | |
| 78 'type' => 'varchar', | |
| 79 'length' => 255, | |
| 80 'not null' => TRUE, | |
| 81 'default' => '', | |
| 82 ), | |
| 83 ), | |
| 84 'primary key' => array('job'), | |
| 85 'indexes' => array( | |
| 86 'ages' => array('age'), | |
| 87 ), | |
| 88 ); | |
| 89 | |
| 90 $schema['test_one_blob'] = array( | |
| 91 'description' => 'A simple table including a BLOB field for testing BLOB behavior.', | |
| 92 'fields' => array( | |
| 93 'id' => array( | |
| 94 'description' => 'Simple unique ID.', | |
| 95 'type' => 'serial', | |
| 96 'not null' => TRUE, | |
| 97 ), | |
| 98 'blob1' => array( | |
| 99 'description' => 'A BLOB field.', | |
| 100 'type' => 'blob', | |
| 101 ), | |
| 102 ), | |
| 103 'primary key' => array('id'), | |
| 104 ); | |
| 105 | |
| 106 $schema['test_two_blobs'] = array( | |
| 107 'description' => 'A simple test table with two BLOB fields.', | |
| 108 'fields' => array( | |
| 109 'id' => array( | |
| 110 'description' => 'Simple unique ID.', | |
| 111 'type' => 'serial', | |
| 112 'not null' => TRUE, | |
| 113 ), | |
| 114 'blob1' => array( | |
| 115 'description' => 'A dummy BLOB field.', | |
| 116 'type' => 'blob', | |
| 117 ), | |
| 118 'blob2' => array( | |
| 119 'description' => 'A second BLOB field.', | |
| 120 'type' => 'blob' | |
| 121 ), | |
| 122 ), | |
| 123 'primary key' => array('id'), | |
| 124 ); | |
| 125 | |
| 126 $schema['test_task'] = array( | |
| 127 'description' => 'A task list for people in the test table.', | |
| 128 'fields' => array( | |
| 129 'tid' => array( | |
| 130 'description' => 'Task ID, primary key.', | |
| 131 'type' => 'serial', | |
| 132 'not null' => TRUE, | |
| 133 ), | |
| 134 'pid' => array( | |
| 135 'description' => 'The {test_people}.pid, foreign key for the test table.', | |
| 136 'type' => 'int', | |
| 137 'unsigned' => TRUE, | |
| 138 'not null' => TRUE, | |
| 139 'default' => 0, | |
| 140 ), | |
| 141 'task' => array( | |
| 142 'description' => 'The task to be completed.', | |
| 143 'type' => 'varchar', | |
| 144 'length' => 255, | |
| 145 'not null' => TRUE, | |
| 146 'default' => '', | |
| 147 ), | |
| 148 'priority' => array( | |
| 149 'description' => 'The priority of the task.', | |
| 150 'type' => 'int', | |
| 151 'unsigned' => TRUE, | |
| 152 'not null' => TRUE, | |
| 153 'default' => 0, | |
| 154 ), | |
| 155 ), | |
| 156 'primary key' => array('tid'), | |
| 157 ); | |
| 158 | |
| 159 $schema['test_null'] = array( | |
| 160 'description' => 'Basic test table for NULL value handling.', | |
| 161 'fields' => array( | |
| 162 'id' => array( | |
| 163 'type' => 'serial', | |
| 164 'unsigned' => TRUE, | |
| 165 'not null' => TRUE, | |
| 166 ), | |
| 167 'name' => array( | |
| 168 'description' => "A person's name.", | |
| 169 'type' => 'varchar', | |
| 170 'length' => 255, | |
| 171 'not null' => FALSE, | |
| 172 'default' => '', | |
| 173 ), | |
| 174 'age' => array( | |
| 175 'description' => "The person's age.", | |
| 176 'type' => 'int', | |
| 177 'unsigned' => TRUE, | |
| 178 'not null' => FALSE, | |
| 179 'default' => 0), | |
| 180 ), | |
| 181 'primary key' => array('id'), | |
| 182 'unique keys' => array( | |
| 183 'name' => array('name') | |
| 184 ), | |
| 185 'indexes' => array( | |
| 186 'ages' => array('age'), | |
| 187 ), | |
| 188 ); | |
| 189 | |
| 190 $schema['test_serialized'] = array( | |
| 191 'description' => 'Basic test table for NULL value handling.', | |
| 192 'fields' => array( | |
| 193 'id' => array( | |
| 194 'type' => 'serial', | |
| 195 'unsigned' => TRUE, | |
| 196 'not null' => TRUE, | |
| 197 ), | |
| 198 'name' => array( | |
| 199 'description' => "A person's name.", | |
| 200 'type' => 'varchar', | |
| 201 'length' => 255, | |
| 202 'not null' => FALSE, | |
| 203 'default' => '', | |
| 204 ), | |
| 205 'info' => array( | |
| 206 'description' => "The person's data in serialized form.", | |
| 207 'type' => 'blob', | |
| 208 'serialize' => TRUE, | |
| 209 ), | |
| 210 ), | |
| 211 'primary key' => array('id'), | |
| 212 'unique keys' => array( | |
| 213 'name' => array('name') | |
| 214 ), | |
| 215 ); | |
| 216 | |
| 217 return $schema; | |
| 218 } |
