Comments

alexdmccabe created an issue. See original summary.

alexdmccabe’s picture

Issue summary: View changes
alexdmccabe’s picture

Issue tags: +Needs tests
alexdmccabe’s picture

Assigned: Unassigned » alexdmccabe
alexdmccabe’s picture

Status: Active » Needs review
StatusFileSize
new8.36 KB

Not actually done yet, just got the first test written and I wanted to see what the testbot thinks of it.

Status: Needs review » Needs work

The last submitted patch, 5: gender-field-tests-2960781-5-8.patch, failed testing. View results

alexdmccabe’s picture

Status: Needs work » Needs review
StatusFileSize
new8.25 KB
new324 bytes

Trying again...

alexdmccabe’s picture

Status: Needs review » Needs work

Cool, it passed, but I'm setting this back to Needs Work since it's not actually done yet.

alexdmccabe’s picture

Status: Needs work » Needs review
StatusFileSize
new9.48 KB
new8.39 KB

Uploading again for safekeeping and to see what testbot thinks again.

alexdmccabe’s picture

StatusFileSize
new12.32 KB
new5.76 KB

Okay, I think it's done! Testing...

agentrickard’s picture

Some review notes:

* I think it's now best practice to create test Traits rather than base test classes. That lets some setup methods be used by Functional/Kernel/Unit tests. That would move GenderTestBase to Traits/GenderTestTrait.

* Might be useful to move $user to $this->user in case we need to run any tests on that element. Might also be good to add a second user and save some gender data about that user.

* Why does the test work on a Node and not a User account? I would think User testing (including display) would be more relevant. From a functional perspective, however, this is irrelevant to the field's behavior.

* In testSelectListWidget() do we need to check the value of the saved option, and not just that the options exist? I _think_ this is covered in assertWidgetOptions.

* We should add a negative assertion -- e.g. that the value 'notarealvalue' does not appear in the options list.

* I think we need a test for field display.

alexdmccabe’s picture

StatusFileSize
new12.64 KB
new2.48 KB

I think it's now best practice to create test Traits rather than base test classes. That lets some setup methods be used by Functional/Kernel/Unit tests. That would move GenderTestBase to Traits/GenderTestTrait.

Hm... I tried to get this going, but most of the code in the base class is in the setUp method. Traits can't extend classes, so if I made a trait for that code, how is the trait supposed to call things like BrowserTestBase::createUser() or BrowserTestBase::drupalLogin()?

I haven't really worked with traits much or really at all even, so I'm open to new ideas, here. I found a few examples of traits in core tests, but I didn't see any that implement the setUp method. Other than the set up work, it's basically just a couple of properties.

Might be useful to move $user to $this->user in case we need to run any tests on that element. Might also be good to add a second user and save some gender data about that user.

That's easy, done.

Why does the test work on a Node and not a User account? I would think User testing (including display) would be more relevant. From a functional perspective, however, this is irrelevant to the field's behavior.

Mostly just because I was testing with a node. You're right though, it shouldn't really matter.

In testSelectListWidget() do we need to check the value of the saved option, and not just that the options exist? I _think_ this is covered in assertWidgetOptions.

Yes, this is covered. After the form is saved it goes back to the edit form and checks that the three original options and the new fourth option are all selected.

We should add a negative assertion -- e.g. that the value 'notarealvalue' does not appear in the options list.

Honestly, I thought I had - I must have deleted it for some reason. Added it back.

alexdmccabe’s picture

Oh, I missed one.

I think we need a test for field display.

That's what GenderFormatterTest does, it checks that the expected labels display on the node.

agentrickard’s picture

Status: Needs review » Reviewed & tested by the community

Nicely done. And I think you're right about the Traits here. THey could import some BrowserTestBase methods, but there i little point.

If you find yourself writing methods other than setup() in the test base, then I would add a Trait.

  • alexdmccabe committed 9066f08 on 8.x-1.x
    Issue #2960781 by alexdmccabe, agentrickard: Add tests for Drupal 8...
alexdmccabe’s picture

Status: Reviewed & tested by the community » Fixed

Will do. Thanks for all the help!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.