forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.php
More file actions
176 lines (140 loc) · 5.49 KB
/
basic.php
File metadata and controls
176 lines (140 loc) · 5.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<?php
/**
* just make sure the test framework is working
*
* @group testsuite
*/
class Tests_Basic extends WP_UnitTestCase {
function test_license() {
// This test is designed to only run on trunk/master
$this->skipOnAutomatedBranches();
$license = file_get_contents( ABSPATH . 'license.txt' );
preg_match( '#Copyright 2011-(\d+) by the contributors#', $license, $matches );
$this_year = date( 'Y' );
$this->assertEquals( $this_year, trim( $matches[1] ), "license.txt's year needs to be updated to $this_year." );
}
function test_package_json() {
$package_json = file_get_contents( dirname( ABSPATH ) . '/package.json' );
$package_json = json_decode( $package_json, true );
list( $version ) = explode( '-', $GLOBALS['wp_version'] );
// package.json uses x.y.z, so fill cleaned $wp_version for .0 releases
if ( 1 == substr_count( $version, '.' ) ) {
$version .= '.0';
}
$this->assertEquals( $version, $package_json['version'], "package.json's version needs to be updated to $version." );
return $package_json;
}
/**
* @depends test_package_json
*/
function test_package_json_node_engine( $package_json ) {
$this->assertArrayHasKey( 'engines', $package_json );
$this->assertArrayHasKey( 'node', $package_json['engines'] );
}
// two tests for a lame bug in PHPUnit that broke the $GLOBALS reference
function test_globals() {
global $test_foo;
$test_foo = array('foo', 'bar', 'baz');
function test_globals_foo() {
unset($GLOBALS['test_foo'][1]);
}
test_globals_foo();
$this->assertEquals($test_foo, array(0=>'foo', 2=>'baz'));
$this->assertEquals($test_foo, $GLOBALS['test_foo']);
}
function test_globals_bar() {
global $test_bar;
$test_bar = array('a', 'b', 'c');
$this->assertEquals($test_bar, $GLOBALS['test_bar']);
}
// test some helper utility functions
function test_strip_ws() {
$this->assertEquals('', strip_ws(''));
$this->assertEquals('foo', strip_ws('foo'));
$this->assertEquals('', 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->assertEquals($expected, strip_ws($in));
}
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&step=2&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&step=2&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->assertEquals($expected, mask_input_value($in));
}
/**
* @ticket 17884
*/
function test_setting_nonexistent_arrays() {
$page = 1;
$field = 'settings';
$empty_array[$page][$field] = 'foo';
// Assertion not strictly needed; we mainly want to show that a notice is not thrown.
unset( $empty_array[$page]['bar']['baz'] );
$this->assertFalse( isset( $empty_array[ $page ]['bar']['baz'] ) );
}
function test_magic_getter() {
$basic = new Basic_Object();
$this->assertEquals( 'bar', $basic->foo );
}
function test_subclass_magic_getter() {
$basic = new Basic_Subclass();
$this->assertEquals( 'bar', $basic->foo );
}
function test_call_method() {
$basic = new Basic_Object();
$this->assertEquals( 'maybe', $basic->callMe() );
}
function test_subclass_call_method() {
$basic = new Basic_Subclass();
$this->assertEquals( 'maybe', $basic->callMe() );
}
function test_subclass_isset() {
$basic = new Basic_Subclass();
$this->assertTrue( isset( $basic->foo ) );
}
function test_subclass_unset() {
$basic = new Basic_Subclass();
unset( $basic->foo );
$this->assertFalse( isset( $basic->foo ) );
}
function test_switch_order() {
$return = $this->_switch_order_helper( 1 );
$this->assertEquals( 'match', $return );
}
function _switch_order_helper( $var ) {
$return = 'no match';
switch ( $var ) {
default:
break;
case 1:
$return = 'match';
break;
}
return $return;
}
}