-
Notifications
You must be signed in to change notification settings - Fork 256
Issue #2827721 by mglaman: Expand test coverage for add to cart forms. #756
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue #2827721 by mglaman: Expand test coverage for add to cart forms. #756
Conversation
This needs matching Javascript test. |
6206312
to
5edc808
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can have slightly stronger test coverage, and hence stronger assurances in the future that the "add to cart" forms are actually being delivered via BigPipe :)
* {@inheritdoc} | ||
*/ | ||
public function buildForm(array $form, FormStateInterface $form_state) { | ||
// Sleep between 0.0 and 2.0 seconds. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why make this random? Why not just always 2 seconds? Or 1?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to https://www.drupal.org/node/2886614, there is a chance the forms could be built out of order. To ensure unique form IDs, we ended up using a static counter. If the forms are built out of order, this causes a bug in form submission. My goal is to reproduce the bug and test our assumed fix.
So I thought random times might cause the build to get weird. However by this time the form ID is known... so maybe slowdown happens elsewhere when rendering these formatter placeholders.
@@ -0,0 +1,12 @@ | |||
name: Commerce Cart Big Pipe |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EXCITING!
@@ -0,0 +1,12 @@ | |||
name: Commerce Cart Big Pipe | |||
type: module | |||
description: Provides a slow version of AddToCart form for testing Big Pipe streaming |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
*/ | ||
function commerce_cart_big_pipe_module_implements_alter(&$implementations, $hook) { | ||
if ($hook == 'entity_type_build') { | ||
// commerce_cart_big_pipe_entity_type_build() needs to run after |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specifying a module weight might be simpler than this.
$seen_ids[] = $form->getAttribute('id'); | ||
} | ||
$this->assertSession()->responseHeaderNotEquals('BigPipe-Test-Placeholders', '<none>'); | ||
$this->assertSession()->responseHeaderEquals('BigPipe-Test-No-Js-Placeholders', '<none>'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why you're testing these two things?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And if you are, you probably want to test the specific value of this header?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was some debugging, basically. But I am going to test the header, now!
/** | ||
* Tests that the form IDs are unique. | ||
*/ | ||
public function testUniqueAddToCartFormIds() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this test method is meant to test BigPipe-powered delivery?
I replied to your question on Twitter (https://twitter.com/wimleers/status/883262976576413696), but repeating here to prevent linkrot:
Recommendation:
- assert HTML placeholder
- wait for the BigPipe stop signal
- assert HTML placeholder has been replaced
See
\Drupal\Tests\big_pipe\FunctionalJavascript\BigPipeRegressionTest::testMultipleClosingBodies_2678662()
— waiting for the stop signal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With previous comment, the original issue was ensuring we had unique form IDs, then I also used it to debug BigPipe delivery.
fa7ffb3
to
cd17262
Compare
Committed in f37464b |
No description provided.