3

I have a core patch (https://www.drupal.org/node/2342699) which ensures that SQL updates do not include the primary key in the field list. I need to write a unit test for this issue and EntityApiTest.php looks like the ideal place for this. This test class has a section

$entities = array_values($storage->loadByProperties(['name' => 'test']));
$entities[0]->name->value = 'test3';
$entities[0]->save();

The way I see it, I will need to examine the entity schema to find the database column name of the 'id' entity key, and then examine the SQL update object to ensure that the entity key is not in the field list. Any advice on how to do either of these steps?

0

Just write a test that attempts to update a primary key, and assert that it fails to do so.

There's no need to test the SQL generation mechanism of the storage class.

  • 1
    So I would have to create an entity, insert it into the database, then try to edit the Entity by forcing the id to a new value. When I requery the database, I should see the original, not the updated value for the id. Good idea, test the actual database, not the object on its way to the database. – Kevin Nowaczyk Aug 14 '18 at 22:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.