Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawehner created an issue. See original summary.

dawehner’s picture

Status: Active » Needs review
FileSize
12.42 KB

There we go.

dawehner’s picture

Status: Needs review » Needs work

Not a start actually

slashrsm’s picture

dawehner’s picture

Status: Needs work » Needs review
FileSize
11.64 KB
3.73 KB

Well, this nesting already doesn't work in HEAD.

Status: Needs review » Needs work

The last submitted patch, 5: 2626970-5.patch, failed testing.

dawehner’s picture

Maybe this works now.

dawehner’s picture

There we go

dawehner’s picture

Status: Needs work » Needs review

Let's fail

The last submitted patch, 5: 2626970-5.patch, failed testing.

The last submitted patch, 7: 2626970-7.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 8: 2626970-8.patch, failed testing.

The last submitted patch, 2: 2626970-2.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
FileSize
32.48 KB
1.78 KB

So one small thing I found, but in general, #tree => TRUE causes issues all over the place.

Status: Needs review » Needs work

The last submitted patch, 14: 2626970-14.patch, failed testing.

pjcdawkins’s picture

As a side note which may or may not help... in the UI, I've found this behavior with nested IEFs:

1. Set up parent_entity referencing child_entity referencing grandchild_entity.
2. Open the entity form to create a new parent_entity.
3. Click "Add a new child_entity". Then "Add a new grandchild_entity". Submit both IEFs.
4. Click "Add a new child_entity" again. The reference field to grandchild_entity in this IEF should be empty. But it is already populated with the grandchild created in (3).

slashrsm’s picture

Status: Needs work » Needs review
FileSize
22.76 KB
28.75 KB

I suggest that we make this issue do what it's title says it does. Let's add a test. We have a lot of problems in submit/validation area and @bojanz thinks that we'll need to do a major refactoring anyway. Having good test coverage will be very helpful when we will be doing that.

I suggest that we open separate issue for every bug that is found. Each issue should list clear steps to reproduce and ideally a test that demonstrates the problem.

While working on this patch I identified two problems:
- #2649710: Required nested IEF forms don't work
- #2649706: Double nested IEF can't be submitted if it's parent doesn't have required fields populated

Test in this patch can easily cover them by deleting one line and/or removing another.

bojanz’s picture

Status: Needs review » Needs work
+        $complete_form['submit']['#submit'] = array_unique($complete_form['submit']['#submit'], SORT_REGULAR);

Sorting submit callbacks feels very dangerous. We need a comment with the reasoning, at least.

+  static public function extractArraySequence($array, $list) {
+    if ($list) {
+      if (isset($array[$list[0]])) {
+        return [
+          $list[0] => static::extractArraySequence($array[$list[0]], array_slice($list, 1)),
+        ];
+      }
+      else {
+        return [];
+      }
+    }
+    return $array;
+  }

This needs a detailed docblock.

slashrsm’s picture

Status: Needs work » Needs review
FileSize
23.19 KB
790 bytes

1. It seems that this only applies to identical items in orded to decide which key to keep: http://php.net/manual/en/function.array-unique.php. I actually don't know why we added this. Hope that @dawehner remembers.
2. Added.

bojanz’s picture

Is the patch supposed to pass? Running tests locally I get:

Fatal error: Call to a member function label() on null in /var/www/d8/web/modules/contrib/inline_entity_form/src/Tests/InlineEntityFormComplexWebTest.php on line 248

Call Stack:
    0.0021     463416   1. {main}() /var/www/d8/web/core/scripts/run-tests.sh:0
    3.8334   17756136   2. simpletest_script_run_one_test() /var/www/d8/web/core/scripts/run-tests.sh:57
    3.8680   19396072   3. Drupal\simpletest\TestBase->run() /var/www/d8/web/core/scripts/run-tests.sh:728
  219.2663   66085800   4. Drupal\inline_entity_form\Tests\InlineEntityFormComplexWebTest->testNestedEntityCreationWithDifferentBundles() /var/www/d8/web/core/modules/simpletest/src/TestBase.php:1079

The offending line being:

      $this->assertEqual($nested3_title, $nested1_node->test_ref_nested1->entity->test_ref_nested2->entity->label(), "Second node's title looks correct.");
slashrsm’s picture

It was passing when I worked on this few weeks ago. Currently we have failing tests in 8.x-1.x. We should fix that before with continue with this patch. Will see if I can look at it this week.

  • bojanz committed 83ad099 on 8.x-1.x authored by slashrsm
    Make the build pass using the fixes from #2626970.
    

Status: Needs review » Needs work

The last submitted patch, 19: 2626970_19.patch, failed testing.

bojanz’s picture

Committed the fixes, they were needed to make the build pass.

The actual test is still failing. vasike said something about "a problem about the button Add vs create"
Attaching the updated patch.

tedbow’s picture

@bojanz I attached a version that split testNestedEntityCreationWithDifferentBundles into 2 tests

testNestedEntityCreationWithDifferentBundlesAjaxSubmit and testNestedEntityCreationWithDifferentBundlesNoAjaxSubmit

testNestedEntityCreationWithDifferentBundlesAjaxSubmit is the only test that fails. If the nested forms are not submitted via ajax but rather only the main node submit button then the test passes and 3 nodes are created.

I also fixed a couple places were the "second" and "third" nodes were both being referred to as the "second" node in assert messages.

I think I have better idea of what is going on now and will take another look at it tomorrow.

slashrsm’s picture

Status: Needs work » Needs review

The last submitted patch, 24: 2626970-23-nested-tests.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 25: 2626970-25-nested-tests.patch, failed testing.

tedbow’s picture

The patch from #25 failed for the reason I was getting locally

16:17:54 Fatal error: Call to a member function label() on a non-object in /var/www/html/modules/inline_entity_form/src/Tests/InlineEntityFormComplexWebTest.php on line 234

Basically in the case of the 2 level nested IEF form and the IEF forms are submitted before top level form is submitted and the node in first level IEF form get saved correctly but 2nd level node is not.

tedbow’s picture

I tracked down the problem error in #29

The reason it fails is because logic errors in \Drupal\inline_entity_form\Plugin\Field\FieldWidget\InlineEntityFormBase::isSubmitRelevant

Around line #420

 $trigger['#limit_validation_errors'],
        function ($item) use ($field_parents) {
          $union = $field_parents + $item;
          return $union == max(count($item), count($field_parents));
        }

$field_parents and $item are both arrays so $union will also so be an array.
$union == max(count($item), count($field_parents));
will always always be false because max is going to return an integer.

It am not positive what the intention was in that code block.

On this branch: https://github.com/tedbow/inline_entity_form/tree/2626970-nested-complex

I am playing around with seeing if isSubmitRelevant is needed
I have hardcoded it to return TRUE and the only test that fails is testEntityCreation
All others pass.

tedbow’s picture

Status: Needs work » Needs review
FileSize
19.61 KB
1.99 KB

Updating the patch to avoid the fatal PHP by checking if the nested nodes are not NULL before call ->title().

This at leasts lets the test finish out and demonstrates that all other tests are passing.

Status: Needs review » Needs work

The last submitted patch, 31: 2626970-31-nested-tests.patch, failed testing.

tedbow’s picture

Status: Needs work » Needs review
FileSize
19.67 KB

Re-rolled patch against 8.x-1.x
Tests now extend InlineEntityFormTestBase from #2661192: Create InlineEntityFormTestBase

Status: Needs review » Needs work

The last submitted patch, 33: 2626970-33-nested-tests.patch, failed testing.

slashrsm’s picture

Reroll after last few patches that were committed.

Status: Needs review » Needs work

The last submitted patch, 35: 2626970_35.patch, failed testing.

  • slashrsm committed 25a4747 on 8.x-1.x authored by dawehner
    Issue #2626970 by dawehner, slashrsm, tedbow, bojanz: Add testcase for...
slashrsm’s picture

Status: Needs work » Fixed

Committed. Thank you everyone!

Status: Fixed » Closed (fixed)

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