Skip to content
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

jetpack: Fix tests against WordPress master #21175

Merged
merged 24 commits into from
Sep 27, 2021
Merged

Conversation

anomiex
Copy link
Contributor

@anomiex anomiex commented Sep 23, 2021

Changes proposed in this Pull Request:

Now that we have the infrastructure set up to run PHPUnit against WP's new
polyfilled setup, this fixes our tests against master to pass again.

  • Fix broken test suites

  • Switch setUp/tearDown for set_up/tear_down

    Looks like WP went with Yoast\PHPUnitPolyfills\TestCases\TestCase.

  • Replace assertInternalType() with polyfilled alternatives

  • Replace assertContains on strings with assertStringContainsString

  • Remove assertArraySubset. No polyfill is provided.

  • Replace assertRegExp with assertMatchesRegularExpression

  • Replace at(), deprecated with no polyfill

  • Don't use WordPress 5.8.1. They backported the polyfill stuff to 5.8, but
    not 5.8.1.

  • Fix WP_Test_Jetpack_Site_Json_Api_Endpoints::test_get_site

    The string "jetpack_connection_active_plugins" is a key, not a value. It
    only accidentally worked before because assertContains() used to do
    == by default and 0.0 == "jetpack_connection_active_plugins" is
    true.

  • Fix WP_Test_Jetpack_Sync_Full_Immediately::test_full_sync_can_sync_individual_comments

    assertContains now does ===, so we need to cast numeric-strings to
    ints.

  • Fix WP_Test_Jetpack_Sync_Themes::test_theme_callable_syncs_theme_supports_data

    No idea why this fixes it, but it does.

  • Fix WP_Test_Jetpack_Sync_Updates::test_sync_wp_version

    No idea why this fixes this either.

  • Don't write output in Test_CSS_Nudge_Customize_Control

    It's annoying to have that cluttering the PHPUnit output.

  • Fix broken multisite test suites.

    • Paths are relative to the file, so no tests/ prefix.
  • Require modules/subscriptions.php in subscriptions endpoint test

  • Add missing calls to parent::set_up() and so on

    The way they set things up in WP 5.8 broke a few tests because the tests
    were somehow relying on the WP base set up or tear down not happening.
    Let's make that happen, then fix it.

  • Fix pseudo-cache in WP_Test_Jetpack_Options

    This was broken in multiple ways:

    • It only hooked "added_option", not "updated_option" or
      "deleted_option". So it's not clear it was even testing what it
      claimed to be testing.
    • It would return whatever was in the cache for the option named
      "test_option", even though several of the tests were hooking for a
      different option name.
    • Some of the tests set "test_option" then checked that raw-setting some
      other option name didn't affect it.
    • It skipped the standard WP_UnitTestCase_Base::tearDown(), so
      the "test_option" option remained in the database, so "added_option"
      wasn't even being called to populate the cache.

    This fixes it by specifically hooking all four option-related events for
    the specific option name "test_option", and uses that in all the tests.

Jetpack product discussion

p9dueE-3io-p2

Does this pull request change what data or activity we track or use?

No

Testing instructions:

  • Is CI happy?

* Last calypsoify test was removed in #17826.
* Theme tools directory was typoed ever since it was added. Sigh.
* IDC test file was removed in #19126.
Looks like WP went with Yoast\PHPUnitPolyfills\TestCases\TestCase.
No polyfill is provided.
They backported the polyfill stuff to 5.8, but not 5.8.1.
The string "jetpack_connection_active_plugins" is a key, not a value. It
only accidentally worked before because `assertContains()` used to do
`==` by default and `0.0 == "jetpack_connection_active_plugins"` is
true.
…dividual_comments

`assertContains` now does `===`, so we need to cast numeric-strings to
ints.
…orts_data

No idea why this fixes it, but it does.
No idea why this fixes this either.
It's annoying to have that cluttering the PHPUnit output.
* Paths are relative to the file, so no `tests/` prefix.
@anomiex
Copy link
Contributor Author

anomiex commented Sep 23, 2021

On hold waiting for a resolution on https://core.trac.wordpress.org/ticket/53911#comment:41. At the moment the master tests pass, but previous and latest don't due to that issue.

@github-actions github-actions bot added [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ Actions GitHub actions used to automate some of the work around releases and repository management [Feature] Carousel A fullscreen modal appearing when clicking on an image in a gallery or tiled gallery. [Feature] Contact Form [Feature] Extra Sidebar Widgets [Feature] Geo Location [Feature] Google Analytics [Feature] Infinite Scroll labels Sep 23, 2021
@github-actions github-actions bot added Unit Tests [Feature] VideoPress A feature to help you upload and insert videos on your site. [Feature] WordPress.com Block Editor Csstidy labels Sep 23, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Sep 23, 2021

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ All commits were linted before commit.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Once your PR is ready for review, check one last time that all required checks (other than "Required review") appearing at the bottom of this PR are passing or skipped.
Then, add the "[Status] Needs Team review" label and ask someone from your team review the code.
Once you’ve done so, switch to the "[Status] Needs Review" label; someone from Jetpack Crew will then review this PR and merge it to be included in the next Jetpack release.


Jetpack plugin:

  • Next scheduled release: October 5, 2021.
  • Scheduled code freeze: September 28, 2021.

@matticbot
Copy link
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Hello anomiex! These changes need to be synced to WordPress.com - If you 're an a11n, please commandeer and confirm D67335-code works as expected before merging this PR. Once this PR is merged, please commit the changes to WP.com. Thank you!
This revision will be updated with each commit to this PR

The `Yoast\PHPUnitPolyfills\TestCases\TestCase` base class already pulls
them all in, and wpcom's tests don't seem to like them being explicitly
included.
The way they set things up in WP 5.8 broke a few tests because the tests
were somehow relying on the WP base set up or tear down not happening.
Let's make that happen, then fix it.
This was broken in multiple ways:

* It only hooked "added_option", not "updated_option" or
  "deleted_option". So it's not clear it was even testing what it
  claimed to be testing.
* It would return whatever was in the cache for the option named
  "test_option", even though several of the tests were hooking for a
  different option name.
* Some of the tests set "test_option" then checked that raw-setting some
  other option name didn't affect it.
* It skipped the standard `WP_UnitTestCase_Base::tearDown()`, so
  the "test_option" option remained in the database, so "added_option"
  wasn't even being called to populate the cache.

This fixes it by specifically hooking all four option-related events for
the specific option name "test_option", and uses that in all the tests.
@anomiex anomiex added [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. and removed [Status] Blocked / Hold labels Sep 24, 2021
Copy link
Contributor

@sdixon194 sdixon194 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's give it a go 👍

@sdixon194 sdixon194 added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. labels Sep 27, 2021
@anomiex anomiex merged commit d757250 into master Sep 27, 2021
@anomiex anomiex deleted the fix/tests-vs-master branch September 27, 2021 17:52
@github-actions github-actions bot added this to the jetpack/10.2 milestone Sep 27, 2021
@github-actions
Copy link
Contributor

Great news! One last step: head over to your WordPress.com diff, D67335-code, and commit it.
Once you've done so, come back to this PR and add a comment with your changeset ID.

Thank you!

@anomiex
Copy link
Contributor Author

anomiex commented Sep 27, 2021

r232368-wpcom

@kraftbj kraftbj removed the [Status] Ready to Merge Go ahead, you can push that green button! label Sep 29, 2021
jeherve added a commit that referenced this pull request Apr 26, 2022
jeherve added a commit that referenced this pull request May 3, 2022
…s WP 5.9 (#24086)

* General: remove backwards compatibility code for user queries

See #22559

* Update PHPUnit setup to remove WP < 5.9 oddities

See #21175, #21157

Primary issue: #24082

* Update docs/examples/bootstrap.php

Co-authored-by: Brad Jorsch <anomiex@users.noreply.github.com>

* Remove speed trap listener loder

* Update doc to remove mention of temporary PHPUnit situation

* Remove temporary line break workaround

See #15595

* Remove custom function in favor of the one that ships with core

* Remove old workaround for the Jetpack sidebar plugin icon

See #14327

* Remove PHP 5.2 workaround

See 99fffd8

* Add back necessary _wp_specialchars wrapping

Co-authored-by: Brad Jorsch <anomiex@users.noreply.github.com>
Co-authored-by: Brandon Kraft <public@brandonkraft.com>
jeherve added a commit that referenced this pull request May 19, 2022
…Jetpack requires WP 5.9 (#24086)

* General: remove backwards compatibility code for user queries

See #22559

* Update PHPUnit setup to remove WP < 5.9 oddities

See #21175, #21157

Primary issue: #24082

* Update docs/examples/bootstrap.php

Co-authored-by: Brad Jorsch <anomiex@users.noreply.github.com>

* Remove speed trap listener loder

* Update doc to remove mention of temporary PHPUnit situation

* Remove temporary line break workaround

See #15595

* Remove custom function in favor of the one that ships with core

* Remove old workaround for the Jetpack sidebar plugin icon

See #14327

* Remove PHP 5.2 workaround

See 99fffd8

* Add back necessary _wp_specialchars wrapping

Co-authored-by: Brad Jorsch <anomiex@users.noreply.github.com>
Co-authored-by: Brandon Kraft <public@brandonkraft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Actions GitHub actions used to automate some of the work around releases and repository management [Feature] Carousel A fullscreen modal appearing when clicking on an image in a gallery or tiled gallery. [Feature] Contact Form [Feature] Extra Sidebar Widgets [Feature] Geo Location [Feature] Google Analytics [Feature] Infinite Scroll [Feature] Likes [Feature] Masterbar WordPress.com Toolbar and Dashboard customizations [Feature] Post By Email [Feature] Publicize Now Jetpack Social, auto-sharing [Feature] Related Posts [Feature] Search For all things related to Search [Feature] Sharing Post sharing, sharing buttons [Feature] Shortcodes / Embeds [Feature] SSO [Feature] Subscriptions All subscription-related things such as paid and unpaid, user management, and newsletter settings. [Feature] VideoPress A feature to help you upload and insert videos on your site. [Feature] WordPress.com Block Editor [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Pri] Normal Touches WP.com Files [Type] Janitorial Unit Tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants