Tests: Separate the tests in basic.php for clarity.

There were two kinds of tests in this file:

* Tests for content of some files in the root directory:
 * `license.txt`
 * `SECURITY.md`
 * `package.json`
* Tests for some utility functions of the test framework itself:
 * `strip_ws()`
 * `test_mask_input_value()`

The latter are now moved to their own file, `utils.php`.

Follow-up to [22/tests], [81/tests], [103/tests], [25240], [26940], [28064], [28480], [28493], [28523], [28631], [42381], [47403], [53683].

See #39265, #55652.

git-svn-id: https://develop.svn.wordpress.org/trunk@53686 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2022-07-07 23:55:13 +00:00
parent 5650aa623c
commit 5880ac84cc
2 changed files with 61 additions and 56 deletions

View File

@ -1,11 +1,9 @@
<?php
/**
* just make sure the test framework is working
* Test the content in some root directory files.
*
* No Covers as this checks for content in files
*
* @group testsuite
* @group basic
*/
class Tests_Basic extends WP_UnitTestCase {
@ -67,56 +65,4 @@ class Tests_Basic extends WP_UnitTestCase {
$this->assertArrayHasKey( 'engines', $package_json );
$this->assertArrayHasKey( 'node', $package_json['engines'] );
}
/**
* Test some helper utility functions.
*
* @coversNothing
*/
public function test_strip_ws() {
$this->assertSame( '', strip_ws( '' ) );
$this->assertSame( 'foo', strip_ws( 'foo' ) );
$this->assertSame( '', strip_ws( "\r\n\t \n\r\t" ) );
$in = "asdf\n";
$in .= "asdf asdf\n";
$in .= "asdf asdf\n";
$in .= "\tasdf\n";
$in .= "\tasdf\t\n";
$in .= "\t\tasdf\n";
$in .= "foo bar\n\r\n";
$in .= "foo\n";
$expected = "asdf\n";
$expected .= "asdf asdf\n";
$expected .= "asdf asdf\n";
$expected .= "asdf\n";
$expected .= "asdf\n";
$expected .= "asdf\n";
$expected .= "foo bar\n";
$expected .= 'foo';
$this->assertSame( $expected, strip_ws( $in ) );
}
/**
* @coversNothing
*/
public function test_mask_input_value() {
$in = <<<EOF
<h2>Assign Authors</h2>
<p>To make it easier for you to edit and save the imported posts and drafts, you may want to change the name of the author of the posts. For example, you may want to import all the entries as <code>admin</code>s entries.</p>
<p>If a new user is created by WordPress, the password will be set, by default, to "changeme". Quite suggestive, eh? ;)</p>
<ol id="authors"><form action="?import=wordpress&amp;step=2&amp;id=" method="post"><input type="hidden" name="_wpnonce" value="855ae98911" /><input type="hidden" name="_wp_http_referer" value="wp-test.php" /><li>Current author: <strong>Alex Shiels</strong><br />Create user <input type="text" value="Alex Shiels" name="user[]" maxlength="30"> <br /> or map to existing<select name="userselect[0]">
EOF;
// _wpnonce value should be replaced with 'xxx'.
$expected = <<<EOF
<h2>Assign Authors</h2>
<p>To make it easier for you to edit and save the imported posts and drafts, you may want to change the name of the author of the posts. For example, you may want to import all the entries as <code>admin</code>s entries.</p>
<p>If a new user is created by WordPress, the password will be set, by default, to "changeme". Quite suggestive, eh? ;)</p>
<ol id="authors"><form action="?import=wordpress&amp;step=2&amp;id=" method="post"><input type="hidden" name="_wpnonce" value="***" /><input type="hidden" name="_wp_http_referer" value="wp-test.php" /><li>Current author: <strong>Alex Shiels</strong><br />Create user <input type="text" value="Alex Shiels" name="user[]" maxlength="30"> <br /> or map to existing<select name="userselect[0]">
EOF;
$this->assertSame( $expected, mask_input_value( $in ) );
}
}

View File

@ -0,0 +1,59 @@
<?php
/**
* Test some helper utility functions of the test framework.
*
* @group testsuite
*/
class Tests_Utils extends WP_UnitTestCase {
/**
* @covers ::test_strip_ws
*/
public function test_strip_ws() {
$this->assertSame( '', strip_ws( '' ) );
$this->assertSame( 'foo', strip_ws( 'foo' ) );
$this->assertSame( '', strip_ws( "\r\n\t \n\r\t" ) );
$in = "asdf\n";
$in .= "asdf asdf\n";
$in .= "asdf asdf\n";
$in .= "\tasdf\n";
$in .= "\tasdf\t\n";
$in .= "\t\tasdf\n";
$in .= "foo bar\n\r\n";
$in .= "foo\n";
$expected = "asdf\n";
$expected .= "asdf asdf\n";
$expected .= "asdf asdf\n";
$expected .= "asdf\n";
$expected .= "asdf\n";
$expected .= "asdf\n";
$expected .= "foo bar\n";
$expected .= 'foo';
$this->assertSame( $expected, strip_ws( $in ) );
}
/**
* @covers ::mask_input_value
*/
public function test_mask_input_value() {
$in = <<<EOF
<h2>Assign Authors</h2>
<p>To make it easier for you to edit and save the imported posts and drafts, you may want to change the name of the author of the posts. For example, you may want to import all the entries as <code>admin</code>s entries.</p>
<p>If a new user is created by WordPress, the password will be set, by default, to "changeme". Quite suggestive, eh? ;)</p>
<ol id="authors"><form action="?import=wordpress&amp;step=2&amp;id=" method="post"><input type="hidden" name="_wpnonce" value="855ae98911" /><input type="hidden" name="_wp_http_referer" value="wp-test.php" /><li>Current author: <strong>Alex Shiels</strong><br />Create user <input type="text" value="Alex Shiels" name="user[]" maxlength="30"> <br /> or map to existing<select name="userselect[0]">
EOF;
// _wpnonce value should be replaced with 'xxx'.
$expected = <<<EOF
<h2>Assign Authors</h2>
<p>To make it easier for you to edit and save the imported posts and drafts, you may want to change the name of the author of the posts. For example, you may want to import all the entries as <code>admin</code>s entries.</p>
<p>If a new user is created by WordPress, the password will be set, by default, to "changeme". Quite suggestive, eh? ;)</p>
<ol id="authors"><form action="?import=wordpress&amp;step=2&amp;id=" method="post"><input type="hidden" name="_wpnonce" value="***" /><input type="hidden" name="_wp_http_referer" value="wp-test.php" /><li>Current author: <strong>Alex Shiels</strong><br />Create user <input type="text" value="Alex Shiels" name="user[]" maxlength="30"> <br /> or map to existing<select name="userselect[0]">
EOF;
$this->assertSame( $expected, mask_input_value( $in ) );
}
}