basic.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. /**
  3. * just make sure the test framework is working
  4. *
  5. * @group testsuite
  6. */
  7. class Tests_Basic extends WP_UnitTestCase {
  8. var $val;
  9. function setUp() {
  10. parent::setUp();
  11. $this->val = true;
  12. }
  13. function tearDown() {
  14. parent::tearDown();
  15. $this->val = false;
  16. }
  17. function test_true() {
  18. $this->assertTrue($this->val);
  19. }
  20. function test_readme() {
  21. $readme = file_get_contents( ABSPATH . 'readme.html' );
  22. preg_match( '#<br /> Version (.*)#', $readme, $matches );
  23. list( $version ) = explode( '-', $GLOBALS['wp_version'] );
  24. $this->assertEquals( $version, trim( $matches[1] ), "readme.html's version needs to be updated to $version." );
  25. }
  26. function test_package_json() {
  27. $package_json = file_get_contents( dirname( ABSPATH ) . '/package.json' );
  28. $package_json = json_decode( $package_json, true );
  29. list( $version ) = explode( '-', $GLOBALS['wp_version'] );
  30. // package.json uses x.y.z, so fill cleaned $wp_version for .0 releases
  31. if ( 1 == substr_count( $version, '.' ) ) {
  32. $version .= '.0';
  33. }
  34. $this->assertEquals( $version, $package_json['version'], "package.json's version needs to be updated to $version." );
  35. }
  36. // two tests for a lame bug in PHPUnit that broke the $GLOBALS reference
  37. function test_globals() {
  38. global $test_foo;
  39. $test_foo = array('foo', 'bar', 'baz');
  40. function test_globals_foo() {
  41. unset($GLOBALS['test_foo'][1]);
  42. }
  43. test_globals_foo();
  44. $this->assertEquals($test_foo, array(0=>'foo', 2=>'baz'));
  45. $this->assertEquals($test_foo, $GLOBALS['test_foo']);
  46. }
  47. function test_globals_bar() {
  48. global $test_bar;
  49. $test_bar = array('a', 'b', 'c');
  50. $this->assertEquals($test_bar, $GLOBALS['test_bar']);
  51. }
  52. // test some helper utility functions
  53. function test_strip_ws() {
  54. $this->assertEquals('', strip_ws(''));
  55. $this->assertEquals('foo', strip_ws('foo'));
  56. $this->assertEquals('', strip_ws("\r\n\t \n\r\t"));
  57. $in = "asdf\n";
  58. $in .= "asdf asdf\n";
  59. $in .= "asdf asdf\n";
  60. $in .= "\tasdf\n";
  61. $in .= "\tasdf\t\n";
  62. $in .= "\t\tasdf\n";
  63. $in .= "foo bar\n\r\n";
  64. $in .= "foo\n";
  65. $expected = "asdf\n";
  66. $expected .= "asdf asdf\n";
  67. $expected .= "asdf asdf\n";
  68. $expected .= "asdf\n";
  69. $expected .= "asdf\n";
  70. $expected .= "asdf\n";
  71. $expected .= "foo bar\n";
  72. $expected .= "foo";
  73. $this->assertEquals($expected, strip_ws($in));
  74. }
  75. function test_mask_input_value() {
  76. $in = <<<EOF
  77. <h2>Assign Authors</h2>
  78. <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>
  79. <p>If a new user is created by WordPress, the password will be set, by default, to "changeme". Quite suggestive, eh? ;)</p>
  80. <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]">
  81. EOF;
  82. // _wpnonce value should be replaced with 'xxx'
  83. $expected = <<<EOF
  84. <h2>Assign Authors</h2>
  85. <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>
  86. <p>If a new user is created by WordPress, the password will be set, by default, to "changeme". Quite suggestive, eh? ;)</p>
  87. <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]">
  88. EOF;
  89. $this->assertEquals($expected, mask_input_value($in));
  90. }
  91. function test_setting_nonexistent_arrays() {
  92. $page = 1;
  93. $field = 'settings';
  94. $empty_array[$page][$field] = 'foo';
  95. unset( $empty_array[$page]['bar']['baz'] );
  96. }
  97. }