Problem/Motivation

This is probably the most important part of this module and yet we don't test it at all.

Proposed resolution

Add test for "multiple" widget. Check:
- if form inline form appears when field is empty
- if creation of entities works
- values of created entity
- if validation kicks in in case of errors
- if correct fields appear in the table
- if edit and remove buttons appear
- if editing entities work
- if removing entities work
- if referencing existing entities work
- if widget respects configuration (labels, reference existing, create new)
- if widget respects cardinality settings

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

slashrsm’s picture

Issue tags: -sprint +D8Media
slashrsm’s picture

Title: Write tests for IEF field widget » Write tests for IEF multiple field widget
Issue summary: View changes
slashrsm’s picture

Issue tags: +Tests
slashrsm’s picture

Issue summary: View changes
woprrr’s picture

Thanks for this task slashrsm; I tried to help you in this task ;) I follow.

dbolinovski’s picture

This is partially done. What is left:
- if validation kicks in in case of errors
- if widget respects configuration (labels, reference existing, create new)
- if widget respects cardinality settings

The test fails on deleting the node from the system, this can be an issue.

bojanz’s picture

Status: Active » Needs review
slashrsm’s picture

Status: Needs review » Needs work

This is amazing! I am very excited about this test as it is testing the most important part of this module. I have few comments, but they're mostly of cosmetic nature.

  1. +++ b/src/Tests/InlineEntityFormMultipleWebTest.php
    @@ -0,0 +1,328 @@
    +    $this->assertFieldByName('multi[form][inline_entity_form][title][0][value]');
    +    $this->assertFieldByName('multi[form][inline_entity_form][first_name][0][value]');
    +    $this->assertFieldByName('multi[form][inline_entity_form][last_name][0][value]');
    +    $this->assertFieldByXpath('//input[@type="submit" and @value="Create node"]', NULL, 'Found "Create node" submit button');
    

    Would be nice to have meaningful messages associated with all asserts.

    Applies to the entire test.

  2. +++ b/src/Tests/InlineEntityFormMultipleWebTest.php
    @@ -0,0 +1,328 @@
    +    // Now submit 'Add new node' button
    

    Comment should end with a period. Applies to the entire patch.

  3. +++ b/src/Tests/InlineEntityFormMultipleWebTest.php
    @@ -0,0 +1,328 @@
    +   * Tests if creation of entities works.
    +   * Checks values of created entity.
    +   * Tests if correct fields appear in the table.
    +   * Tests if edit and remove buttons appear.
    

    This comment seems strange. We should have meaningful first line and further explanation below it.

  4. +++ b/src/Tests/InlineEntityFormMultipleWebTest.php
    @@ -0,0 +1,328 @@
    +    $edit = [];
    

    No need to initialize empty array as we re-initialize it few lines below.

  5. +++ b/src/Tests/InlineEntityFormMultipleWebTest.php
    @@ -0,0 +1,328 @@
    +    $nodeMulti = $node->get('multi')->getValue();
    +    $this->assertTrue($nodeMulti[0]['target_id'] == $nodeId, 'Refererence node id set to '. $nodeId);
    

    We can probably simplify this to

    $node->multi->target_id == $node->id()
    
  6. +++ b/src/Tests/InlineEntityFormMultipleWebTest.php
    @@ -0,0 +1,328 @@
    +    $edit = [];
    

    Same as above (no need to init empty array).

  7. +++ b/src/Tests/InlineEntityFormMultipleWebTest.php
    @@ -0,0 +1,328 @@
    +    $title = $cell[0]->__toString();
    

    I think we shouldn't use __toString() directly. We can simply cast I believe. Applies to the entire patch.

  8. +++ b/src/Tests/InlineEntityFormMultipleWebTest.php
    @@ -0,0 +1,328 @@
    +    // Delete the third entity reference only, don't delete the node.
    +    // The third entity now is second referenced entity
    +    // because the second one is deleted in previous step.
    

    Let's make lines in comments 80 chars long.

  9. +++ b/src/Tests/InlineEntityFormMultipleWebTest.php
    @@ -0,0 +1,328 @@
    +      $title = 'Some reference '. $i;
    

    . should have space on both sides. Applies to the entire patch.

  10. +++ b/src/Tests/InlineEntityFormMultipleWebTest.php
    @@ -0,0 +1,328 @@
    +        'multi[form][entity_id]' => $title .' ('. $referenceNodes[$title] .')',
    

    Is this working as expected? Shouldn't we pass entity ID in the parenthesis?

  11. +++ b/src/Tests/InlineEntityFormMultipleWebTest.php
    @@ -0,0 +1,328 @@
    +   * @return array Array of created node ids keyed by labels.
    

    Description should be in next line.

  12. +++ b/src/Tests/InlineEntityFormMultipleWebTest.php
    @@ -0,0 +1,328 @@
    +  protected function createReferenceContent($numNodes = 3) {
    

    I think it would make sense to create base class for IEF tests and move helper functions in there (createReferenceContent(), setAllowExisting() and getButtonName()).

slashrsm’s picture

Status: Needs work » Needs review
FileSize
26.61 KB
21.64 KB

#8 fixed and chasing rename from multiple to complex.

  • slashrsm committed 1759505 on 8.x-1.x authored by dbolinovski
    Issue #2512678 by dbolinovski, slashrsm: Write tests for IEF multiple...
slashrsm’s picture

Status: Needs review » Fixed

Committed. @dbolinovski++

axe312’s picture

I am missing tests for IEF forms within IEF forms. Especially when opening multiple ief forms at once it seems to cause problems like the form is replaced with another one or validation kicks in for another one.

Let me know if i can help :)

slashrsm’s picture

Sure. Any improvements to tests are welcome. Feel free to open a new issue for that.

Issues with multiple IEF forms sound like a bug. Should we open a bug report for those too?

axe312’s picture

I am currently preparing a demo to demonstrate all bugs. Will update you later on.

Status: Fixed » Closed (fixed)

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