paulgibbs / behat-wordpress-extension

WordHat: Behat for WordPress
https://wordhat.info
GNU General Public License v3.0
106 stars 20 forks source link

getContentFromTitle does not return the expected result when sticky posts are published #218

Closed ataylorme closed 5 years ago

ataylorme commented 6 years ago

Expected behavior

Describe the bug; what should happen?

getContentFromTitle does not return the correct post when using an exact-match title parameter.

Current behavior

What happens instead of the expected behavior?

A seemingly random, incorrect post is returned

Possible solution

Not obligatory, but you can suggest a fix/reason for the bug. Thanks!

Steps to reproduce

Provide a link to a live example or an unambiguous set of steps to reproduce this bug. Include code to reproduce, if relevant.

  1. Have a Give donation form with the title "San Diego Refugees Donation"
  2. Also have others content posts
  3. Use Given I am on the edit screen for "San Diego Refugees Donation" in the Background of a feature
  4. Add Then I should see "San Diego Refugees Donation" in the "title" element to the Scenario of the same feature
  5. The feature test will fail

Context

How has this issue affected you? What are you trying to accomplish? Providing context helps us come up with a solution that is most useful in the real world.

I am attempting to write custom tests for the Give donation form to provide a real-world WordHat example

I am using the wpcli driver but have tried the php driver locally as well.

I also created a custom step that passes $post_type as well to getContentFromTitle and still got an incorrect post back.

None of my tests are using JavaScript due to similar issues as outlined in #182 with admin login issues in a headless (Docker) environment.

In CircleCI the wpcli driver is being run against a remote URL on Pantheon, not a local URL. When testing locally the wpcli driver is used but against a local WordPress installation.

Your environment

Include as many relevant details about the environment you experienced the bug in:

ataylorme commented 6 years ago

@paulgibbs here is a better failure example.

I tracked this down to sticky posts. I am using the wp-cli driver and even when running wp-cli commands directly outside of Behat sticky a post shows up when I expect a different post as the result when using wp post list.

I think this is a result of wp-cli running WP_Query and the default functionality of WP_Query to be returning sticky posts unless ignore_sticky_posts is set to true.

I'm not familiar enough with the drivers to know:

paulgibbs commented 5 years ago

Hi. Yep, you found the correct fix.

I've tested this, and the underlying queries, as best as I can, and it is safe to always set ignore_sticky_posts for both drivers, so that's what I've done in the attached PR.

paulgibbs commented 5 years ago

Sorry for taking a while to look at this

ataylorme commented 5 years ago

Great, thanks @paulgibbs. It threw me off for a while before I figured out what was going on.