In preparation for #1732730: [meta] Implement the new entity field API for all field types it would be useful to have per field-type tests which we then can replicate to all field types that are ported. So let's do some tests for text.module, i.e. create all possible field types, make sure the properties get property intantiated, the right data defintiions are returned and all field values can be read and updated.

CommentFileSizeAuthor
#3 1793446.patch5.21 KBfmizzell
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

fmizzell’s picture

Assigned: Unassigned » fmizzell

Yesterday I started looking at the latest branch of the property api, so I could start working on this issue, but since this is my first time writing tests, I figure I would share what I was planning on doing before I get to deep into something unusable.

Create a test entity type and bundle to which to attach the test fields. I noticed that the field_test module has a test implementation of an entity type, but it does not use the EntityNG class (I believe this is necessary to get all of the functionality from the property api integration). I was also wondering if it would be good for this "test entity" to be a module in itself so other test could use it instead of creating their own (like field_test does). [Edit: found the entity_test module and where all the core tests are]

After creating the entity type and bundle, write the tests:
So this is what I am planning on doing:

  • Attach instances of the different text field types to the test bundle
  • Check that the field data is readable and writable through the magic setters and getters provided by tht entity integration with the property api

@fago please let me know if this is in line with what you would do, or if I am on the wrong path.

Also I was trying to find other tests related to the property api without luck, could someone point me in the right direction? Thanks. [Edit: Found the tests]

fago’s picture

Title: Add separate text module tests » Add separate entity field tests for text module
Project: D8 Entity API improvements » Drupal core
Version: » 8.x-dev
Component: Entity Property API » field system
Issue tags: +Entity Field API

yeah, this sounds good. Also, check the general Entity Field API tests and see what they are testing.

I think we should test:

  • reading and writing of the whole item
  • reading and writing of individual field item values/columns
  • loading/saving entities and making sure it works
  • checking that the required interfaces are implemented

Ideally, some of this code could even be written generic, so that for a new field type we'd just subclass the test and add some specific code that's required like custom setup logic or tests for certain custom stuff like whether a lazy-loaded enttiy object reflects updates to the id-value.

fmizzell’s picture

Status: Active » Needs review
FileSize
5.21 KB

Here is my first pass at the tests. I know that there is a lot of repetitive code, but I figured I would get some feedback on the methodology before cleaning up.
Also, I was not sure on how to test that the right interfaces are being implemented. Won't things break if the right interfaces are not used to integrate with the system?

fago’s picture

Status: Needs review » Closed (fixed)

We have something like that already now :)