bobbingwide / oik-batch

Batch interface to WordPress
https://www.oik-plugins.com/oik-plugins/oik-batch
GNU General Public License v2.0
0 stars 0 forks source link

Add some helper functions in BW_UnitTestCase #24

Closed bobbingwide closed 7 years ago

bobbingwide commented 7 years ago

During development of new test cases for the oik base plugin, as part of the i18n work, I developed some helper functions that allow the generated HTML to be treated as an array and for hardcoded or generated values to be replaced with generic values, or vice-versa.

This makes it slightly easier to construct the $expected output for assertions. These new methods could be generalised and implemented in oik-batch'es BW_UnitTestCase class.

New method Purpose
replace_admin_url replaces instances of admin_url() in $expected
replace_oik_url replaces instances of oik_url() in generated HTML
tag_break Inserts new line between tags then converts into an array
generated_expected Help to generate the expected array from actual test output
replace_nonse_with_nonsense Generalises WordPress generated hidden input nonce fields
replace_between Generalised string replace between before and after strings
replace_antispambot Replace randomised antispambot'd mailto links with known value
bobbingwide commented 7 years ago

I developed more functions to support tests using different locales ( especially bb_BB ). These should also be added to the BW_UnitTestCase class.

New method Purpose
assertArrayEqualsFile Asserts that the HTML array equals the file
prepareExpectedArray Converts to an array if required
prepareFile Returns the expected file name
find_test_name Finds the test name from the call stack
query_la_CY Queries the currently set locale
generate_expected_file Helps to generate the expected file from actual test output
bobbingwide commented 7 years ago

More methods to be added

New method Purpose
switch_to_locale Switch to a selected locale and reload domains
reload_domains reload domains and enable Just Translate It
bobbingwide commented 7 years ago

More methods added

New method Purpose
replace_created_nonce Replaces the created nonce with nonsense
arraytohtml Reduce a print_r'ed string
bobbingwide commented 7 years ago

More methods to be added

New method Purpose
replace_home_url replaces instances of home_url() and site_url() in $expected
replace_post_id replaces instances of "post=" . $post->ID with "post=42"

replace_post_id supports a $prefix parameter so you can use other this method to replace the post->ID in other parameter names e.g. 'id="link-'