Problem/Motivation

There are a lot of totally same functions in ParagraphsTestBase and ParagraphsExperimentalTestBase.

Proposed resolution

Make trait with same functions.

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#38 new-patch-refactor-2855309-38.patch24.42 KBGinovski
#38 interdiff-2855309-36-38.txt1.93 KBGinovski
#36 new-patch-refactor-2855309-36.patch24.25 KBGinovski
#36 interdiff-2855309-34-36.txt1.71 KBGinovski
#34 new-patch-refactor-2855309-34.patch23.53 KBGinovski
#34 interdiff-2855309-32-34.txt762 bytesGinovski
#32 new-patch-refactor-28553089-32.patch22.79 KBGinovski
#32 interdiff-28553089-28-32.txt712 bytesGinovski
#32 test-passed.png157.71 KBGinovski
#29 new-patch-refactor-28553089-28.patch22.56 KBGinovski
#28 new-patch-refactor-28553089-28.patch22.56 KBGinovski
#27 create-refactor-2855309-27.patch22.56 KBGinovski
#24 create-2855309-24.patch40.79 KBGinovski
#24 interdiff-2855309-19-24.txt36.94 KBGinovski
#19 create-2855309-19.patch3.85 KBGinovski
#19 interdiff-2855309-11-19.txt1.43 KBGinovski
#11 interdiff-2855309-8-11.txt2.38 KBdrobnjak
#11 create-2855309-11.patch3.71 KBdrobnjak
#8 interdiff-2855309-7-8.txt2.33 KBdrobnjak
#8 create-2855309-8.patch3.5 KBdrobnjak
#7 create-2855309-7.patch3.25 KBdrobnjak
#5 interdiff-2855309-3-5.txt7.81 KBdrobnjak
#5 create-2855309-5.patch29.44 KBdrobnjak
#3 create-2855309-3.patch29.81 KBdrobnjak
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

CTaPByK created an issue. See original summary.

drobnjak’s picture

Assigned: Unassigned » drobnjak

Will work on this.

drobnjak’s picture

Duplicated code from test bases moved to the trait. This leads to Experimental test base being obsolete, and completely removed.
Now the tests from Experimental widget are extending ParagraphsTestBase. Trait is being used only in tests where needed.

Status: Needs review » Needs work

The last submitted patch, 3: create-2855309-3.patch, failed testing.

drobnjak’s picture

I made mistake with 'entity_reference_paragraphs' and 'paragraphs' and assigned them to wrong widgets.

Status: Needs review » Needs work

The last submitted patch, 5: create-2855309-5.patch, failed testing.

drobnjak’s picture

Status: Needs work » Needs review
FileSize
3.25 KB

All previous changes are dropped. After discussion with @Berdir we agreed that it is better to keep ExperimentalTestBase without changes, and keep the logic separated for two widgets. Here, we create the Trait for all future JS tests to be used.

drobnjak’s picture

Adding parameters to make difference between widgets.

toncic’s picture

Status: Needs review » Reviewed & tested by the community

This looks fine for me. We have some basic function that we can continue to work on other issue which are waiting this to be committed.

Primsi’s picture

Status: Reviewed & tested by the community » Needs work

Nice!

+++ b/tests/src/FunctionalJavascript/ParagraphsTestBaseTrait.php
@@ -0,0 +1,104 @@
+   * @param string $paragraphs_type
+   *   Declares if we use experimental or classic widget.
+   */

Maybe $widget_type is more appropriate here.

Also IMHO we should explicitly state which two options are available. Ie: "Options are: ..."

drobnjak’s picture

Addressing comment #10.

Primsi’s picture

Any more feedback here?

toncic’s picture

I am not pretty sure that name is ok for the trait. I think that should have something which will associate that is trait for JS testing.

drobnjak’s picture

I disagree with the comment #13. This trait can be later used for all of the tests, not only JS. We can just call the namespace and use it in both Experimental and Classic tests.

toncic’s picture

The general idea was to do not mix the experimental and classic widget, we are creating this trait only for JS tests.

miro_dietiker’s picture

Here's why the two worlds should not be mixed:
Say the new widget changes functionality, people start to mangle / alter the test trait. Then they will update the classic trait calls to make the classic still work. This risks that they update it just to make the tests pass - while possibly not understanding what was (and still is) broken.

So every change on the new widget should not interfere with the old widget. This can only be reached by separating traits and bases.
Review complexity and cost of all issues significantly rise and speed is reduced otherwise.

miro_dietiker’s picture

But in general, a common trait makes sense, as long as those methods are NOT using the widget UI - instead just use the entity API to create resources. :-)

Primsi’s picture

My proposal is then to have that in tests/src and rename it to something that carries the information that we just want to have entity api paragraphs creation stuff in there. Perhaps TestParagraphGeneratiopnTrait? If we find in the future that we could have other general trait stuff, we could have more traits if those are unrelated. Thoughts?

Ginovski’s picture

Added check for creating the field storage.

Primsi’s picture

If we take the approach from #17, do we want to update existing tests where relevant (even though we stated differently in #7)?

miro_dietiker’s picture

What we want to keep separate are widget interaction methods and test helpers. A common trait for those are the wrong direction.

Helpers to create entities through entity api (zero UI interaction) are a healthy trait to share and apply to both widgets.

Primsi’s picture

Status: Needs review » Needs work

Then I think moving this back to Needs work is fine

miro_dietiker’s picture

Agree. I see the trait here, but it's not used.
For sure, introducing this Trait only makes sense if we use it and through that, the patch will proof that the test code is getting more beautiful - for instance through less repetition.

Ginovski’s picture

Status: Needs work » Needs review
FileSize
36.94 KB
40.79 KB

Replaced the test bases methods with the trait and adjusted tests accordingly.

miro_dietiker’s picture

Status: Needs review » Needs work
+++ b/tests/src/FunctionalJavascript/ParagraphsTestBaseTrait.php
@@ -0,0 +1,111 @@
+  protected function addParagraphsField($entity_type_name, $paragraphs_field_name, $entity_type, $widget_type) {

IMHO we should default $widget_type to 'paragraphs' here and not change those calls above.

Also default the $paragraphs_field_name to something and unify it / skip it wherever possible to field_paragraphs. Currently we also have at least paragraphs and paragraphs_field.

Committing for the current improvements, back to work for the proposed transformation.
Chances are that we broke tests of Paragraphs Collection or other project tests building on top of our traits?

Ginovski’s picture

Status: Needs work » Needs review
FileSize
22.56 KB

Added defaults params and modified some function calls that didn't need a lot of changes.

Ginovski’s picture

Re-uploading with some minor changes

Ginovski’s picture

Retry for applying patch

miro_dietiker’s picture

Status: Needs review » Needs work
+++ b/src/Tests/Experimental/ParagraphsExperimentalAddModesTest.php
@@ -19,15 +19,15 @@ class ParagraphsExperimentalAddModesTest extends ParagraphsExperimentalTestBase
+    $this->addParagraphedContentType('paragraphed_test');

@@ -54,7 +54,7 @@ class ParagraphsExperimentalAddModesTest extends ParagraphsExperimentalTestBase
+    $this->addParagraphedContentType('paragraphed_test', 'paragraphs');

Why do we need to have here an own field and can't use the default field? (lots of similar locations)

miro_dietiker’s picture

Agree, this leads to lots of renames. We can commit some intermediate update without #30 rename.

I tried to apply the patch locally, but i have many errors from the test run. Need to investigate what the problem is here.

Ginovski’s picture

Fixed the error in ParagraphsExperimentalAddModesTest, now locally web tests are passing

Ginovski’s picture

Status: Needs review » Needs work

Needs refactoring after the container summary was committed.

Ginovski’s picture

Removed unneeded function in summary test.

Primsi’s picture

Status: Needs review » Needs work
+++ b/tests/src/FunctionalJavascript/ParagraphsTestBaseTrait.php
@@ -26,7 +26,7 @@ trait ParagraphsTestBaseTrait {
+  protected function addParagraphedContentType($content_type_name, $paragraphs_field_name = 'field_paragraphs', $widget_type = 'paragraphs') {

@@ -51,7 +51,7 @@ trait ParagraphsTestBaseTrait {
+  protected function addParagraphsField($entity_type_name, $paragraphs_field_name, $entity_type, $widget_type = 'paragraphs') {

If we are adding the defaults, we should change the docblock too.

Ginovski’s picture

Added default in the function docs.

mbovan’s picture

Status: Needs review » Reviewed & tested by the community

Triggered 8.3.x tests too. Looks good to me.

Ginovski’s picture

Optional in the function docs

  • Primsi committed c14d496 on 8.x-1.x authored by Ginovski
    Issue #2855309 by Ginovski, miro_dietiker, Primsi, mbovan: Create...
Primsi’s picture

Status: Needs review » Fixed

Committed, thanks.

Status: Fixed » Closed (fixed)

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