class UpdatePathTest
Same name and namespace in other branches
- 10 core/modules/dblog/tests/src/Functional/UpdatePathTest.php \Drupal\Tests\dblog\Functional\UpdatePathTest
Tests update functions for the Database Logging module.
Attributes
#[Group('dblog')]
#[RunTestsInSeparateProcesses]
Hierarchy
- class \Drupal\Tests\DrupalTestCase uses \Drupal\Tests\DrupalTestCaseTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\ExtensionListTestTrait extends \Drupal\Tests\DrupalTestCase
- class \Drupal\FunctionalTests\Update\UpdatePathTestBase uses \Drupal\Tests\UpdatePathTestTrait extends \Drupal\Tests\BrowserTestBase
- class \Drupal\Tests\dblog\Functional\UpdatePathTest extends \Drupal\FunctionalTests\Update\UpdatePathTestBase
- class \Drupal\FunctionalTests\Update\UpdatePathTestBase uses \Drupal\Tests\UpdatePathTestTrait extends \Drupal\Tests\BrowserTestBase
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\ExtensionListTestTrait extends \Drupal\Tests\DrupalTestCase
Expanded class hierarchy of UpdatePathTest
File
-
core/
modules/ dblog/ tests/ src/ Functional/ UpdatePathTest.php, line 19
Namespace
Drupal\Tests\dblog\FunctionalView source
class UpdatePathTest extends UpdatePathTestBase {
/**
* {@inheritdoc}
*/
protected function setDatabaseDumpFiles() : void {
$this->databaseDumpFiles = [
__DIR__ . '/../../../../system/tests/fixtures/update/drupal-11.3.0.bare.standard.php.gz',
];
}
/**
* Tests that, after update 12100, the 'wid' column is an unsigned integer.
*/
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.
}
}
/**
* Inserts a row into the watchdog table.
*
* @param \Drupal\Core\Database\Connection $connection
* The database connection.
* @param int|null $wid
* An explicit watchdog ID, or NULL to let the sequence assign one.
*/
private function insertLogEntry(Connection $connection, ?int $wid = NULL) : void {
global $base_root;
$fields = [
'message' => 'Dblog test log message',
'type' => 'test',
'variables' => '',
'severity' => RfcLogLevel::NOTICE,
'uid' => 1,
'location' => $base_root . \Drupal::request()->getRequestUri(),
'hostname' => $base_root,
'timestamp' => \Drupal::time()->getRequestTime(),
];
if ($wid !== NULL) {
$fields['wid'] = $wid;
}
$connection->insert('watchdog')
->fields($fields)
->execute();
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.