comparison core/modules/simpletest/src/Tests/KernelTestBaseTest.php @ 4:a9cd425dd02b

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:11:55 +0000
parents c75dbcec494b
children 12f9dff5fda9
comparison
equal deleted inserted replaced
3:307d7a7fd348 4:a9cd425dd02b
60 $this->assertIdentical(array_keys(\Drupal::moduleHandler()->getModuleList()), $modules); 60 $this->assertIdentical(array_keys(\Drupal::moduleHandler()->getModuleList()), $modules);
61 $this->assertIdentical(\Drupal::moduleHandler()->getImplementations('entity_bundle_info'), ['entity_test']); 61 $this->assertIdentical(\Drupal::moduleHandler()->getImplementations('entity_bundle_info'), ['entity_test']);
62 $this->assertIdentical(\Drupal::moduleHandler()->getImplementations('entity_type_alter'), ['entity_test']); 62 $this->assertIdentical(\Drupal::moduleHandler()->getImplementations('entity_type_alter'), ['entity_test']);
63 63
64 // Verify that no modules have been installed. 64 // Verify that no modules have been installed.
65 $this->assertFalse(db_table_exists($table), "'$table' database table not found."); 65 $this->assertFalse(Database::getConnection()->schema()->tableExists($table), "'$table' database table not found.");
66 66
67 // Verify that the settings.testing.php got taken into account. 67 // Verify that the settings.testing.php got taken into account.
68 $this->assertTrue(function_exists('simpletest_test_stub_settings_function')); 68 $this->assertTrue(function_exists('simpletest_test_stub_settings_function'));
69 69
70 // Ensure that the database tasks have been run during set up. Neither MySQL 70 // Ensure that the database tasks have been run during set up. Neither MySQL
112 $list = array_keys(\Drupal::moduleHandler()->getModuleList()); 112 $list = array_keys(\Drupal::moduleHandler()->getModuleList());
113 $this->assertFalse(in_array($module, $list), "$module module not found in the extension handler's module list."); 113 $this->assertFalse(in_array($module, $list), "$module module not found in the extension handler's module list.");
114 $list = \Drupal::moduleHandler()->getImplementations('hook_info'); 114 $list = \Drupal::moduleHandler()->getImplementations('hook_info');
115 $this->assertFalse(in_array($module, $list), "{$module}_hook_info() in \Drupal::moduleHandler()->getImplementations() not found."); 115 $this->assertFalse(in_array($module, $list), "{$module}_hook_info() in \Drupal::moduleHandler()->getImplementations() not found.");
116 116
117 $this->assertFalse(db_table_exists($table), "'$table' database table not found."); 117 $this->assertFalse(Database::getConnection()->schema()->tableExists($table), "'$table' database table not found.");
118 118
119 // Install the module. 119 // Install the module.
120 \Drupal::service('module_installer')->install([$module]); 120 \Drupal::service('module_installer')->install([$module]);
121 121
122 // Verify that the enabled module exists. 122 // Verify that the enabled module exists.
124 $list = array_keys(\Drupal::moduleHandler()->getModuleList()); 124 $list = array_keys(\Drupal::moduleHandler()->getModuleList());
125 $this->assertTrue(in_array($module, $list), "$module module found in the extension handler's module list."); 125 $this->assertTrue(in_array($module, $list), "$module module found in the extension handler's module list.");
126 $list = \Drupal::moduleHandler()->getImplementations('hook_info'); 126 $list = \Drupal::moduleHandler()->getImplementations('hook_info');
127 $this->assertTrue(in_array($module, $list), "{$module}_hook_info() in \Drupal::moduleHandler()->getImplementations() found."); 127 $this->assertTrue(in_array($module, $list), "{$module}_hook_info() in \Drupal::moduleHandler()->getImplementations() found.");
128 128
129 $this->assertTrue(db_table_exists($table), "'$table' database table found."); 129 $this->assertTrue(Database::getConnection()->schema()->tableExists($table), "'$table' database table found.");
130 $schema = drupal_get_module_schema($module, $table); 130 $schema = drupal_get_module_schema($module, $table);
131 $this->assertTrue($schema, "'$table' table schema found."); 131 $this->assertTrue($schema, "'$table' table schema found.");
132 } 132 }
133 133
134 /** 134 /**
154 public function testInstallSchema() { 154 public function testInstallSchema() {
155 $module = 'entity_test'; 155 $module = 'entity_test';
156 $table = 'entity_test_example'; 156 $table = 'entity_test_example';
157 // Verify that we can install a table from the module schema. 157 // Verify that we can install a table from the module schema.
158 $this->installSchema($module, $table); 158 $this->installSchema($module, $table);
159 $this->assertTrue(db_table_exists($table), "'$table' database table found."); 159 $this->assertTrue(Database::getConnection()->schema()->tableExists($table), "'$table' database table found.");
160 160
161 // Verify that the schema is known to Schema API. 161 // Verify that the schema is known to Schema API.
162 $schema = drupal_get_module_schema($module, $table); 162 $schema = drupal_get_module_schema($module, $table);
163 $this->assertTrue($schema, "'$table' table schema found."); 163 $this->assertTrue($schema, "'$table' table schema found.");
164 164
169 $this->fail('Exception for non-retrievable schema found.'); 169 $this->fail('Exception for non-retrievable schema found.');
170 } 170 }
171 catch (\Exception $e) { 171 catch (\Exception $e) {
172 $this->pass('Exception for non-retrievable schema found.'); 172 $this->pass('Exception for non-retrievable schema found.');
173 } 173 }
174 $this->assertFalse(db_table_exists($table), "'$table' database table not found."); 174 $this->assertFalse(Database::getConnection()->schema()->tableExists($table), "'$table' database table not found.");
175 $schema = drupal_get_module_schema($module, $table); 175 $schema = drupal_get_module_schema($module, $table);
176 $this->assertFalse($schema, "'$table' table schema not found."); 176 $this->assertFalse($schema, "'$table' table schema not found.");
177 177
178 // Verify that a table from a unknown module cannot be installed. 178 // Verify that a table from a unknown module cannot be installed.
179 $module = 'database_test'; 179 $module = 'database_test';
183 $this->fail('Exception for non-retrievable schema found.'); 183 $this->fail('Exception for non-retrievable schema found.');
184 } 184 }
185 catch (\Exception $e) { 185 catch (\Exception $e) {
186 $this->pass('Exception for non-retrievable schema found.'); 186 $this->pass('Exception for non-retrievable schema found.');
187 } 187 }
188 $this->assertFalse(db_table_exists($table), "'$table' database table not found."); 188 $this->assertFalse(Database::getConnection()->schema()->tableExists($table), "'$table' database table not found.");
189 $schema = drupal_get_module_schema($module, $table); 189 $schema = drupal_get_module_schema($module, $table);
190 $this->assertTrue($schema, "'$table' table schema found."); 190 $this->assertTrue($schema, "'$table' table schema found.");
191 191
192 // Verify that the same table can be installed after enabling the module. 192 // Verify that the same table can be installed after enabling the module.
193 $this->enableModules([$module]); 193 $this->enableModules([$module]);
194 $this->installSchema($module, $table); 194 $this->installSchema($module, $table);
195 $this->assertTrue(db_table_exists($table), "'$table' database table found."); 195 $this->assertTrue(Database::getConnection()->schema()->tableExists($table), "'$table' database table found.");
196 $schema = drupal_get_module_schema($module, $table); 196 $schema = drupal_get_module_schema($module, $table);
197 $this->assertTrue($schema, "'$table' table schema found."); 197 $this->assertTrue($schema, "'$table' table schema found.");
198 } 198 }
199 199
200 /** 200 /**
204 $entity = 'entity_test'; 204 $entity = 'entity_test';
205 // The entity_test Entity has a field that depends on the User module. 205 // The entity_test Entity has a field that depends on the User module.
206 $this->enableModules(['user']); 206 $this->enableModules(['user']);
207 // Verity that the entity schema is created properly. 207 // Verity that the entity schema is created properly.
208 $this->installEntitySchema($entity); 208 $this->installEntitySchema($entity);
209 $this->assertTrue(db_table_exists($entity), "'$entity' database table found."); 209 $this->assertTrue(Database::getConnection()->schema()->tableExists($entity), "'$entity' database table found.");
210 } 210 }
211 211
212 /** 212 /**
213 * Tests expected behavior of installConfig(). 213 * Tests expected behavior of installConfig().
214 */ 214 */
276 'mode' => 'default', 276 'mode' => 'default',
277 ]); 277 ]);
278 $field_storage = FieldStorageConfig::create([ 278 $field_storage = FieldStorageConfig::create([
279 'field_name' => 'test_field', 279 'field_name' => 'test_field',
280 'entity_type' => 'entity_test', 280 'entity_type' => 'entity_test',
281 'type' => 'test_field' 281 'type' => 'test_field',
282 ]); 282 ]);
283 $field_storage->save(); 283 $field_storage->save();
284 FieldConfig::create([ 284 FieldConfig::create([
285 'field_storage' => $field_storage, 285 'field_storage' => $field_storage,
286 'bundle' => 'entity_test', 286 'bundle' => 'entity_test',
352 // \Drupal\Core\Database\Driver\sqlite\Schema::findTables(). 352 // \Drupal\Core\Database\Driver\sqlite\Schema::findTables().
353 // @see \Drupal\Core\Database\Driver\sqlite\Connection::__construct() 353 // @see \Drupal\Core\Database\Driver\sqlite\Connection::__construct()
354 $info = Database::getConnectionInfo(); 354 $info = Database::getConnectionInfo();
355 $connection->query('ATTACH DATABASE :database AS :prefix', [ 355 $connection->query('ATTACH DATABASE :database AS :prefix', [
356 ':database' => $info['default']['database'] . '-' . $this->databasePrefix, 356 ':database' => $info['default']['database'] . '-' . $this->databasePrefix,
357 ':prefix' => $this->databasePrefix 357 ':prefix' => $this->databasePrefix,
358 ]); 358 ]);
359 359
360 $result = $connection->query("SELECT name FROM " . $this->databasePrefix . ".sqlite_master WHERE type = :type AND name LIKE :table_name AND name NOT LIKE :pattern", [ 360 $result = $connection->query("SELECT name FROM " . $this->databasePrefix . ".sqlite_master WHERE type = :type AND name LIKE :table_name AND name NOT LIKE :pattern", [
361 ':type' => 'table', 361 ':type' => 'table',
362 ':table_name' => '%', 362 ':table_name' => '%',