1 module.test | ModuleInstallTestCase::testBackdropWriteRecord() |
Test that calls to backdrop_write_record() work during module installation.
This is a useful function to test because modules often use it to insert initial data in their database tables when they are being installed or enabled. Furthermore, backdrop_write_record() relies on the module schema information being available, so this also checks that the data from one of the module's hook implementations, in particular hook_schema(), is properly available during this time. Therefore, this test helps ensure that modules are fully functional while Backdrop is installing and enabling them.
File
- core/
modules/ simpletest/ tests/ module.test, line 263 - Tests for the module API.
Class
- ModuleInstallTestCase
- Unit tests for module installation.
Code
function testBackdropWriteRecord() {
// Check for data that was inserted using backdrop_write_record() while the
// 'module_test' module was being installed and enabled.
$data = db_query("SELECT data FROM {module_test}")->fetchCol();
$this->assertTrue(in_array('Data inserted in hook_install()', $data), 'Data inserted using backdrop_write_record() in hook_install() is correctly saved.');
$this->assertTrue(in_array('Data inserted in hook_enable()', $data), 'Data inserted using backdrop_write_record() in hook_enable() is correctly saved.');
}