1

I like to know how to test the html output of a post. Like WP would output it on the frontend in reality.

My specific case at this point is to test oembed caching as I want to test re-caching. AFAIK WP does only cache oembed results if they are associated with a post. So I can not just run some text though the_content filter. I like to test the real post processioning for this and in general for other cases that may come up.

So far in my search I only found tutorials how to create a post in unit testing but not how to actually run tests on it.

1
  • Did you find the solution? I need the way to archieve this, too. – Terry Lin Nov 12 '20 at 4:59
0

In your test, you can create a post, start output buffering with ob_start(), output post content as usual, get output buffer into your variable with ob_end_clean().

Now your can process real post output string and compare it with the expected value.

4
  • 1
    This is not really helping me. Can you post some code? So I need to start the loop like in a theme? How do I output a specific post as if someone would access it from the frontend? – NextGenThemes Feb 12 '20 at 5:07
  • Someone, really? :) Tests intended to be run in isolated environment, on separate install, and never on the live site. Please look like output is tested in WordPress core tests: github.com/WordPress/wordpress-develop/blob/… – KAGG Design Feb 12 '20 at 7:19
  • You failed to get what I meant with "Someone". I know well how unit tests work and what you liked to is helpful to some extent because it shows how they generate a post to use in the unit tests. But It seems like that is the process if unit testing the features WP has that turns every site into an oembed provider and then displays posts from other sites in a little preview. What I want to test is embedding videos that run though embed and the entire process as if they were assessed like in normal posts. I think I just want to test a normal post output they include '/theme-compat/embed.php'; – NextGenThemes Apr 18 '20 at 21:25
  • I guess I need something else instead just to emulate a normal post content output and processing. – NextGenThemes Apr 18 '20 at 21:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.