Projet

Général

Profil

Paste
Télécharger (6,18 ko) Statistiques
| Branche: | Révision:

root / drupal7 / modules / simpletest / tests / database_test.install @ 01dfd3b5

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_people_copy'] = $schema['test_people'];
91
  $schema['test_people_copy']['description'] = 'A duplicate version of the test_people table, used for additional tests.';
92

    
93
  $schema['test_one_blob'] = array(
94
    'description' => 'A simple table including a BLOB field for testing BLOB behavior.',
95
    'fields' => array(
96
      'id' => array(
97
        'description' => 'Simple unique ID.',
98
        'type' => 'serial',
99
        'not null' => TRUE,
100
      ),
101
      'blob1' => array(
102
        'description' => 'A BLOB field.',
103
        'type' => 'blob',
104
      ),
105
    ),
106
    'primary key' => array('id'),
107
    );
108

    
109
  $schema['test_two_blobs'] = array(
110
    'description' => 'A simple test table with two BLOB fields.',
111
    'fields' => array(
112
      'id' => array(
113
        'description' => 'Simple unique ID.',
114
        'type' => 'serial',
115
        'not null' => TRUE,
116
      ),
117
      'blob1' => array(
118
        'description' => 'A dummy BLOB field.',
119
        'type' => 'blob',
120
      ),
121
      'blob2' => array(
122
        'description' => 'A second BLOB field.',
123
        'type' => 'blob'
124
      ),
125
    ),
126
    'primary key' => array('id'),
127
    );
128

    
129
  $schema['test_task'] = array(
130
    'description' => 'A task list for people in the test table.',
131
    'fields' => array(
132
      'tid' => array(
133
        'description' => 'Task ID, primary key.',
134
        'type' => 'serial',
135
        'not null' => TRUE,
136
      ),
137
      'pid' => array(
138
        'description' => 'The {test_people}.pid, foreign key for the test table.',
139
        'type' => 'int',
140
        'unsigned' => TRUE,
141
        'not null' => TRUE,
142
        'default' => 0,
143
      ),
144
      'task' => array(
145
        'description' => 'The task to be completed.',
146
        'type' => 'varchar',
147
        'length' => 255,
148
        'not null' => TRUE,
149
        'default' => '',
150
      ),
151
      'priority' => array(
152
        'description' => 'The priority of the task.',
153
        'type' => 'int',
154
        'unsigned' => TRUE,
155
        'not null' => TRUE,
156
        'default' => 0,
157
      ),
158
    ),
159
    'primary key' => array('tid'),
160
  );
161

    
162
  $schema['test_null'] = array(
163
    'description' => 'Basic test table for NULL value handling.',
164
    'fields' => array(
165
      'id' => array(
166
        'type' => 'serial',
167
        'unsigned' => TRUE,
168
        'not null' => TRUE,
169
      ),
170
      'name' => array(
171
        'description' => "A person's name.",
172
        'type' => 'varchar',
173
        'length' => 255,
174
        'not null' => FALSE,
175
        'default' => '',
176
      ),
177
      'age' => array(
178
        'description' => "The person's age.",
179
        'type' => 'int',
180
        'unsigned' => TRUE,
181
        'not null' => FALSE,
182
        'default' => 0),
183
    ),
184
    'primary key' => array('id'),
185
    'unique keys' => array(
186
      'name' => array('name')
187
    ),
188
    'indexes' => array(
189
      'ages' => array('age'),
190
    ),
191
  );
192

    
193
  $schema['test_serialized'] = array(
194
    'description' => 'Basic test table for NULL value handling.',
195
    'fields' => array(
196
      'id' => array(
197
        'type' => 'serial',
198
        'unsigned' => TRUE,
199
        'not null' => TRUE,
200
      ),
201
      'name' => array(
202
        'description' => "A person's name.",
203
        'type' => 'varchar',
204
        'length' => 255,
205
        'not null' => FALSE,
206
        'default' => '',
207
      ),
208
      'info' => array(
209
        'description' => "The person's data in serialized form.",
210
        'type' => 'blob',
211
        'serialize' => TRUE,
212
      ),
213
    ),
214
    'primary key' => array('id'),
215
    'unique keys' => array(
216
      'name' => array('name')
217
    ),
218
  );
219

    
220
  $schema['virtual'] = array(
221
    'description' => 'Basic test table with a reserved name.',
222
    'fields' => array(
223
      'id' => array(
224
        'type' => 'serial',
225
        'unsigned' => TRUE,
226
        'not null' => TRUE,
227
      ),
228
      'function' => array(
229
        'description' => "A column with a reserved name.",
230
        'type' => 'varchar',
231
        'length' => 255,
232
        'not null' => FALSE,
233
        'default' => '',
234
      ),
235
    ),
236
    'primary key' => array('id'),
237
  );
238

    
239
  return $schema;
240
}