| @@ 98-118 (lines=21) @@ | ||
| 95 | /** |
|
| 96 | * Check that updates to a class fields are reflected in the database |
|
| 97 | */ |
|
| 98 | public function testFieldsRequestChanges() |
|
| 99 | { |
|
| 100 | $schema = DB::get_schema(); |
|
| 101 | $test = $this; |
|
| 102 | DB::quiet(); |
|
| 103 | ||
| 104 | // Table will have been initially created by the $extraDataObjects setting |
|
| 105 | ||
| 106 | // Let's insert a new field here |
|
| 107 | TestObject::config()->update( |
|
| 108 | 'db', |
|
| 109 | array( |
|
| 110 | 'SecretField' => 'Varchar(100)' |
|
| 111 | ) |
|
| 112 | ); |
|
| 113 | ||
| 114 | // Verify that the above extra field triggered a schema update |
|
| 115 | $schema->schemaUpdate( |
|
| 116 | function () use ($test, $schema) { |
|
| 117 | $obj = new TestObject(); |
|
| 118 | $obj->requireTable(); |
|
| 119 | $needsUpdating = $schema->doesSchemaNeedUpdating(); |
|
| 120 | $schema->cancelSchemaUpdate(); |
|
| 121 | $test->assertTrue($needsUpdating); |
|
| @@ 167-189 (lines=23) @@ | ||
| 164 | /** |
|
| 165 | * Check that updates to a dataobject's indexes are reflected in DDL |
|
| 166 | */ |
|
| 167 | public function testIndexesRerequestChanges() |
|
| 168 | { |
|
| 169 | $schema = DB::get_schema(); |
|
| 170 | $test = $this; |
|
| 171 | DB::quiet(); |
|
| 172 | ||
| 173 | // Table will have been initially created by the $extraDataObjects setting |
|
| 174 | ||
| 175 | // Update the SearchFields index here |
|
| 176 | TestIndexObject::config()->update( |
|
| 177 | 'indexes', |
|
| 178 | array( |
|
| 179 | 'SearchFields' => array( |
|
| 180 | 'value' => 'Title' |
|
| 181 | ) |
|
| 182 | ) |
|
| 183 | ); |
|
| 184 | ||
| 185 | // Verify that the above index change triggered a schema update |
|
| 186 | $schema->schemaUpdate( |
|
| 187 | function () use ($test, $schema) { |
|
| 188 | $obj = new TestIndexObject(); |
|
| 189 | $obj->requireTable(); |
|
| 190 | $needsUpdating = $schema->doesSchemaNeedUpdating(); |
|
| 191 | $schema->cancelSchemaUpdate(); |
|
| 192 | $test->assertTrue($needsUpdating); |
|