Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
as requested by @alexpott in #1847280-15: Simpletest web tests misnamed as "Unit"
See also comment #11 there
"The class TermUnitTest can't be renamed, because TermTest already exists. This function should be renamed or take another action to this file fulfill the tests code standards."
Proposed resolution
make TermUnitTest a KernelTestBase by moving createTerm and createVocabulary to a trait
Remaining tasks
Task | Novice task? | Contributor instructions | Complete? |
---|---|---|---|
Create a patch | Instructions | ||
Update the issue summary noting if allowed during the beta | Instructions | ||
Review patch to ensure that it fixes the issue, stays within scope, is properly documented, and follows coding standards | Instructions |
User interface changes
None.
API changes
Yes.
Comment | File | Size | Author |
---|---|---|---|
#16 | interdiff-14-16.txt | 894 bytes | martin107 |
#16 | term-2431477-16.patch | 6.75 KB | martin107 |
#14 | interdiff-11-14.txt | 2.21 KB | martin107 |
#14 | term-2431477-14.patch | 6.75 KB | martin107 |
#11 | interdiff-8-10.txt | 1.14 KB | martin107 |
Comments
Comment #1
martin107 CreditAttribution: martin107 commentedThis looks like something worth doing ... I am working on this now.
Naming things is hard, so while I tackle the guts of the code can we talk about the name for the trait
I am frequently accused of creating variable names longer that war and peace. so my prefered name is
TaxonomyTestHelperTrait
But I am open to shorter suggestions?
Comment #2
martin107 CreditAttribution: martin107 commentedI am posting early and asking for help.
I have added the trait, and want to test that all the WebTests function as expected...
I am asking a question about TermUnitTest which fails locally at the moment.
To get this to work I am going to have to implement or Mock the creation of an entity type
see for example testTermDelete
looking inside entity_load_multiple_by_properties I would have to mock the entityManager and the thing rapidly become a
complex unreviewable pile of spaghetti.
So the other route seems to be generating a new entity type in a unit test
Can anyone point me a similar code?
Comment #4
martin107 CreditAttribution: martin107 commentedFixed trivial thing.
Comment #6
BerdirWe already have CommentTestTrait and FieldUITestTrait, so I'd just go with TaxonomyTestTrait.
Comment #7
BerdirOn the test fails: A kernel test is *not* a unit test, it is still simpletest. Kernel tests do not (and currently can not) mock.
The first thing that you are missing now in the test is the taxonomy_term module, because you no longer extend from TaxonomyTestBase. And next, because kernel tests don't care about module dependencies, you also need to specify text.module and probably a few others. Just keep re-running it, find out which module provides that it reports as missing and enable it. Like filter, because filter formats.
Looking at the code, it will fail on not having any filter formats, because they are not installed by default. $this->installConfig(array('filter')).
Then, after that, you need to install the database tables, because that also doesn't happen by default, for entities, that goes like this: $this->installEntitySchema('taxonomy_term') (vocabulary is a config entity and doesn't need this).
That's going to require a few definitions and lines of code. So you probably want to start a new TaxonomyKernelTestBase class that contains that and extend from that.
Comment #8
martin107 CreditAttribution: martin107 commentedThank you Bedir, I noticed this isn't the first time you have straightened out my thoughts.
Bedir++
I followed your advice and it all came out as you figured.
1) renamed TaxonomyHelperTestTrait => TaxonomyTestTrait
2) rename TaxonomyUnitTest TaxonomyKernelTest
3) added relevant modules variable and trivial lines to setUp
It may be appropriate down the road to split the two lines in the setup function into a TaxonomyKernelTestBase class but for now I have just gone with the attitude of minimal changes are often best.
Locally TermKernelTest pass
Bedir for president!
Comment #9
martin107 CreditAttribution: martin107 commentedJust making notes for the next iteration.
TermKernelTest line 14 is still talking about Unit tests.
Comment #11
martin107 CreditAttribution: martin107 commentedFixed code comment.
Fixed HelperTrait
Sorry, coding too close to bed, is never productive.
Comment #12
martin107 CreditAttribution: martin107 commentedtest now runs in 10 secs
Comment #13
BerdirContains \Drupal\taxonomy... is the "new" (like two years old) standard.
Same. don't change files/lines you don't touch already, but we happen to touch this anyway.
There should be an empty line between the last use and /**.
Comment #14
martin107 CreditAttribution: martin107 commented1, 2, and 3 fixed.
And spotted a few more nits.
Fixed the visibility of a couple of test functions.
Added a comment to testTermDelete().
Comment #15
Berdiralmost correct, the Contains lines should have a leading \, \Drupal\..., not Drupal\...
Comment #16
martin107 CreditAttribution: martin107 commentedCorrect, fixed.
Comment #17
BerdirGreat, looks good.
Comment #18
alexpottTest code is not frozen in beta. Committed a0e9ed1 and pushed to 8.0.x. Thanks!