function UpdatePathTest::testLogEntryWithNegativeId
Tests that, after update 12100, the 'wid' column is an unsigned integer.
File
-
core/
modules/ dblog/ tests/ src/ Functional/ UpdatePathTest.php, line 35
Class
- UpdatePathTest
- Tests update functions for the Database Logging module.
Namespace
Drupal\Tests\dblog\FunctionalCode
public function testLogEntryWithNegativeId() : void {
$connection = Database::getConnection();
// Insert a normal row first. On PostgreSQL, inserting an explicit value
// into a serial column resyncs the sequence to GREATEST(MAX(wid), <value>),
// which fails while the table is empty.
$this->insertLogEntry($connection);
// Before updates, a negative WID should be possible.
$this->insertLogEntry($connection, -1000);
$this->assertEquals(1, $connection->select('watchdog')
->condition('wid', 0, '<')
->countQuery()
->execute()
->fetchField());
$this->runUpdates();
// Check the primary key.
$method = new \ReflectionMethod($connection->schema(), 'findPrimaryKeyColumns');
$this->assertEquals([
'wid',
], $method->invoke($connection->schema(), 'watchdog'));
// After updates, a negative WID should not be allowed.
try {
$this->insertLogEntry($connection, -1000);
$this->fail('After updates, a negative WID should not be allowed.');
} catch (IntegrityConstraintViolationException|DatabaseExceptionWrapper) {
// Expected.
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.