Comments

bjaspan’s picture

A patch in #557924: Options widget broken presumably soon to be committed shows how to test Field API widgets. It turns out to be pretty easy. We will probably want to move the functions like getTagById() and getOptionByValue() etc. into FieldTestCase in field.test, which is trivial, and then it should be straightforward to crank out widget tests.

plach’s picture

Status: Active » Closed (duplicate)

This has been fixed in #557924: Options widget broken.

plach’s picture

Title: increase test coverage for Field API widgets » Add test coverage for Field API Number
Status: Closed (duplicate) » Active

Sorry, Number module still needs tests.

catch’s picture

bleen’s picture

Dave.Ingram’s picture

Assigned: Unassigned » Dave.Ingram

Number field still has no tests for integers and floats. I'll work on that.

Dave.Ingram’s picture

Status: Active » Needs review
StatusFileSize
new4.39 KB
mtift’s picture

Status: Needs review » Reviewed & tested by the community

Looks good. Ran tests locally with no problems.

chx’s picture

Status: Reviewed & tested by the community » Needs work

+ 'precision' => 8, 'scale' => 4, 'decimal_separator' => '.', multiline this please.

i cringe when i read + $this->assertFieldByName("{$this->field['field_name']}[$langcode][0][value]", '', t('Widget is displayed')); "{$this->field['field_name']}[$langcode][0][value]" => $value, cant we store that {} thing in $field_name so that the thing is, you know, readable.

mtift’s picture

Version: 7.x-dev » 8.x-dev
Assigned: Dave.Ingram » mtift
Status: Needs work » Needs review
StatusFileSize
new5.1 KB

I updated the patch per chx's instructions (I hope).

dabl’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests, +Fields in Core

The last submitted patch, numberfield_test_coverage-558362-11.patch, failed testing.

Letharion’s picture

Status: Needs work » Needs review
StatusFileSize
new5.51 KB

Me and dabl, updated the patch to account for the tests file being moved and the syntax having changed somewhat since the patch was initially written.

Status: Needs review » Needs work

The last submitted patch, numberfield_test_coverage-558362-14.patch, failed testing.

dabl’s picture

Assigned: mtift » Unassigned
Status: Needs work » Needs review
Letharion’s picture

Ok, so the invalid syntax is that the patch adds a function that already exists. Without looking in any detail on what the two functions actually do, it seems like this functionality has already gotten into core at some point, and this issue could probably be closed duplicate or works as designed.

yesct’s picture

Issue tags: +Needs manual testing

needs confirmation that the issue is no longer present?

star-szr’s picture

Status: Needs review » Needs work

A testNumberIntegerField() test method was added in #1002734: Multiple "Undefined index" notices in modules/field/modules/number/number.module. At a glance they look similar, but we should compare the coverage and see if we there's anything of value to be added to that test from the patch in #14. testNumberFloatField() and the changes to testNumberDecimalField() are still completely valid from what I can tell.

scor’s picture

StatusFileSize
new3.56 KB

I've merged #14 with core/modules/number/lib/Drupal/number/Tests/NumberFieldTest.php but it needs more work, as I'm realizing the tests in there are quite inconsistent with each other. I've found another test for number at core/modules/number/lib/Drupal/number/Tests/NumberItemTest.php but this file seems to be dealing with Entity API stuff rather than field and field UI.

star-szr’s picture

Status: Needs work » Needs review

Sending to testbot for now, thanks @scor!

Status: Needs review » Needs work
Issue tags: -Needs tests, -Needs manual testing

The last submitted patch, numberfield_test_coverage-558362-20.patch, failed testing.

Jamesap’s picture

Assigned: Unassigned » Jamesap
StatusFileSize
new3.58 KB

Changed LANGUAGE_NONE to LANGUAGE_NOT_SPECIFIED

Jamesap’s picture

Status: Needs work » Needs review
StatusFileSize
new3.87 KB

Changed LANGUAGE_NONE to LANGUAGE_NOT_SPECIFIED

Status: Needs review » Needs work

The last submitted patch, numberfield_test_coverage-558362-24.patch, failed testing.

swentel’s picture

Component: field system » number.module

Moving to right component.

star-szr’s picture

Assigned: Jamesap » Unassigned
Issue summary: View changes
Issue tags: +Needs reroll

Tagging for reroll and unassigning.

aaronott’s picture

StatusFileSize
new3.68 KB

Here is a re-roll of this test.

aaronott’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 28: numberfield_test_coverage-558362-28.patch, failed testing.

aaronott’s picture

Status: Needs work » Needs review
StatusFileSize
new8.3 KB

This is another reroll and passes all tests locally. I changed a few items to make it more consistent through out the tests.

swentel’s picture

Great, thanks for working on this. Quick review.

  1. +++ b/core/modules/number/lib/Drupal/number/Tests/NumberFieldTest.php
    @@ -150,45 +150,195 @@ function testNumberDecimalField() {
    +    $this->assertRaw(t('%name must be higher than or equal to %minimum.', array('%name' => $field_name, '%minimum' => $minimum)), 'Correctly failed to save integer value less than minimum allowed value.');
    

    We don't use t() anymore in tests. format_string() must be used now.

  2. +++ b/core/modules/number/lib/Drupal/number/Tests/NumberFieldTest.php
    @@ -150,45 +150,195 @@ function testNumberDecimalField() {
    +    // Try to create entries with minus sign not in the first position.
    +    $valid_entries = array(
    +      '-1234',
    +      '0',
    +      '1234',
    +    );
    

    This comment is weird compared to the value used in the $valid_entries array

aaronott’s picture

Thanks for letting me know about the t -> format_string change.

Huh... strange comment there. I've updated it to make it make sense now.

Thanks again!

swentel’s picture

Issue tags: -Needs reroll

Oh crap, I messed up with my t() comment - so sorry about that :/

The page which explains the t() usage is https://drupal.org/simpletest-tutorial-drupal7#t - I had to read it again just to make sure.
So basically, you can still use t(), but not in assertion messages. I must have been completely confused when reading the patch.
So you'll have to revert those, again, so sorry :/
But, after that, it's as good as RTBC from me though!

swentel’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new8.26 KB
new795 bytes

Back to the good one + the small text change, works for me.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 35: numberfield_test_coverage-558362-35.patch, failed testing.

swentel’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new8.27 KB
new1.47 KB

Small fix after the rename of field and field instance config entities. Still good to go.

alexpott’s picture

Version: 8.x-dev » 7.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)
Issue tags: +Needs backport to 7.x

Committed 3d4c167 and pushed to 8.x. Thanks!

Looks like Drupal 7 could still benefit from this coverage?

  • alexpott committed 3d4c167 on 8.3.x
    Issue #558362 by aaronott, swentel, Jamesap, scor, Letharion, mtift,...

  • alexpott committed 3d4c167 on 8.3.x
    Issue #558362 by aaronott, swentel, Jamesap, scor, Letharion, mtift,...

  • alexpott committed 3d4c167 on 8.4.x
    Issue #558362 by aaronott, swentel, Jamesap, scor, Letharion, mtift,...

  • alexpott committed 3d4c167 on 8.4.x
    Issue #558362 by aaronott, swentel, Jamesap, scor, Letharion, mtift,...
twod’s picture

Issue tags: -

For D7 this also needs to test just - as inputting just that currently leads to
PDOException: SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '-' for column 'FIELD_NAME' at row 1: INSERT IN ....

poker10’s picture

Version: 7.x-dev » 8.0.x-dev
Status: Patch (to be ported) » Fixed

Drupal 7 is now EOL. Moving back to Drupal 8, where it was fixed originally, so that credits are assigned correctly. Thanks everyone!

Status: Fixed » Closed (fixed)

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