public function FractionUpdateTest::testUpdateDenominatorSignedException in Fraction 8
Same name and namespace in other branches
- 2.x tests/src/Kernel/FractionUpdateTest.php \Drupal\Tests\fraction\Kernel\FractionUpdateTest::testUpdateDenominatorSignedException()
Tests that data over the limit triggers a message on update.
File
- tests/
src/ Kernel/ FractionUpdateTest.php, line 141
Class
- FractionUpdateTest
- Provides tests for updating the schema from signed to unsigned.
Namespace
Drupal\Tests\fraction\KernelCode
public function testUpdateDenominatorSignedException() {
// Unsigned fields should reject negative values.
foreach ($this->fieldsToUpdate as $field) {
$this
->assertFalse($this
->tryUnsignedInsert($field['table_name'], $field['columns']), 'Column rejected a negative value.');
}
// Insert a value higher than the signed int bounds so that, when checked
// will trigger the update exception.
$this->container
->get('database')
->insert('node__field_fraction_node')
->fields([
'entity_id' => 1,
'revision_id' => 1,
'delta' => 0,
'field_fraction_node_numerator' => 9,
'field_fraction_node_denominator' => 2147483699,
])
->execute();
try {
// Run the fraction update only.
$post_update_registry = $this->container
->get('update.post_update_registry');
foreach ($post_update_registry
->getModuleUpdateFunctions('fraction') as $function) {
$function();
}
// If the code reach this point, means that the update succeeded.
$this
->fail('Failed due to update going through when it should not.');
} catch (UpdateException $e) {
$this
->pass('Updating with field values higher than the limit thows a message.');
foreach ($this->fieldsToUpdate as $field) {
$this
->assertFalse($this
->tryUnsignedInsert($field['table_name'], $field['columns']), 'Column rejected a negative value.');
}
}
}