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

Media: Update get_post_galleries() to return Gallery Blocks. #1864

Closed
wants to merge 32 commits into from

Conversation

costdev
Copy link
Contributor

@costdev costdev commented Nov 11, 2021

Galleries in Gutenberg don't use the [gallery] shortcode, so they are not returned by get_post_galleries().

This change makes get_post_galleries() also check for Gallery blocks and return them.

Trac ticket: https://core.trac.wordpress.org/ticket/43826

Tasks

src/wp-includes/media.php

  • Add original implementation.
  • Add new implementation.
  • Review and iterate for performance.
  • Ensure that all tests pass.

tests/phpunit/media.php

  • Tests: Reduce the use of assertEquals() in favour of stricter options.
  • Tests: Correct the placement of expected and actual values in tests added in this PR.
  • Tests: Move all get_post_galleries() tests to a separate file: tests/phpunit/tests/media/getPostGalleries.php.

tests/phpunit/media/getPostGalleries.php

  • Tests: Add appropriate @covers annotation to test class.
  • Tests: Add appropriate @group annotations for each test method.
  • Tests: Correct the placement of expected and actual values in pre-existing test methods.
  • Tests: Add message parameters to test methods with multiple assertions.
  • Tests: Rename test methods for clarity when running the tests.
  • Tests: Improve docblock comments for each test method.
  • Tests: Change assertSame() to assertSameSetsWithIndex().
  • Tests: Add assertions to prevent fatal errors.
  • Tests: Add more tests to improve coverage for get_post_galleries().

Tests: Reduce the number of test methods by using data providers where possible.
Data providers deferred until a later review of the test suite.

@costdev costdev force-pushed the #43826 branch 2 times, most recently from 2ab53eb to 7dc550a Compare November 11, 2021 07:19
@costdev costdev force-pushed the #43826 branch 3 times, most recently from 00d192f to e1127ac Compare November 11, 2021 20:43
costdev added 2 commits November 16, 2021 10:00
`foreach` was not detecting the changed length of `$post_blocks`.
A `while` loop does detect this.
@glendaviesnz
Copy link

This tested well for me on a site running the Arbutus theme which uses get_post_galleries to generate gallery excerpts. This updated call worked for a v1 and v2 gallery block, a gallery blocked nested 2 deep in group blocks, and also for a short code gallery:
Screen Shot 2021-11-16 at 11 00 31 PM

LGTM once the failing tests are sorted.

This assertion checked the first three elements of the actual value.
It should have been checking the last three elements.

See the assertion in `test_post_gallery_images()`, on which this new
test method is based.
Copy link
Contributor

@hellofromtonya hellofromtonya left a comment

Choose a reason for hiding this comment

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

Great job @costdev and @glendaviesnz 🎉 The PR to handle both v1 and v2 gallery block looks ready for commit 👍

@hellofromtonya
Copy link
Contributor

Committed via changeset https://core.trac.wordpress.org/changeset/52190.

@costdev costdev deleted the #43826 branch September 19, 2022 21:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants