Skip to content

Commit bbee4a8

Browse files
author
gitlost
committed
A few more tests.
1 parent 56b4e8c commit bbee4a8

File tree

2 files changed

+88
-18
lines changed

2 files changed

+88
-18
lines changed

tests/db_checkTest.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1191,7 +1191,10 @@ function test_db_check_normalize_all() {
11911191
$option_id1 = intval( $wpdb->get_var( "SELECT option_id FROM {$wpdb->options} WHERE option_name IN ('option1') ORDER BY option_id ASC" ) );
11921192
$num_updates++;
11931193
add_option( 'option3', array( 'key1' => 'val3' . $decomposed_str1 ) );
1194-
$option_id2 = intval( $wpdb->get_var( "SELECT option_id FROM {$wpdb->options} WHERE option_name IN ('option3') ORDER BY option_id ASC" ) );
1194+
$option_id3 = intval( $wpdb->get_var( "SELECT option_id FROM {$wpdb->options} WHERE option_name IN ('option3') ORDER BY option_id ASC" ) );
1195+
$num_updates++;
1196+
add_option( 'option4', array( 'key1' => array( 'key2' => 'val4' . $decomposed_str1 ) ) );
1197+
$option_id4 = intval( $wpdb->get_var( "SELECT option_id FROM {$wpdb->options} WHERE option_name IN ('option4') ORDER BY option_id ASC" ) );
11951198
$num_updates++;
11961199

11971200
add_site_option( 'option1', 'val1' . $decomposed_str1 );
@@ -1293,6 +1296,27 @@ function test_db_check_normalize_all() {
12931296
remove_filter( 'unfc_batch_limit', array( $this, 'unfc_batch_limit_filter' ) );
12941297
remove_filter( 'pre_option_link_manager_enabled', '__return_true', 10 );
12951298

1299+
self::clear_func_args();
1300+
1301+
$_REQUEST = array();
1302+
$_REQUEST['unfc_db_check_normalize_all'] = 'unfc_db_check_normalize_all';
1303+
$_REQUEST['_wpnonce_normalize_all'] = wp_create_nonce( UNFC_DB_CHECK_MENU_SLUG . '-normalize_all' );
1304+
$this->assertTrue( 1 === wp_verify_nonce( $_REQUEST['_wpnonce_normalize_all'], UNFC_DB_CHECK_MENU_SLUG . '-normalize_all' ) );
1305+
1306+
$_SERVER['REQUEST_URI'] = 'http://example.org/wp-admin/tools.php?page=' . UNFC_DB_CHECK_MENU_SLUG;
1307+
1308+
$_REQUEST['unfc_type'] = 'post:asdf';
1309+
1310+
try {
1311+
do_action( 'load-' . $hook_suffix );
1312+
} catch ( WPDieException $e ) {
1313+
unset( $e );
1314+
}
1315+
$this->assertSame( 1, count( self::$func_args['wp_die'] ) );
1316+
$args = self::$func_args['wp_die'][0]['args'];
1317+
$this->assertSame( 1, count( $args ) );
1318+
$this->assertTrue( false !== stripos( $args[0][1], 'nothing' ) );
1319+
12961320
global $wpdb;
12971321
$ready = $wpdb->ready;
12981322
$last_result = $wpdb->last_result;

tests/toolsTest.php

Lines changed: 63 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -131,23 +131,8 @@ function test_utf8_rand_chr() {
131131

132132
$out = unfc_utf8_rand_str();
133133
$this->assertTrue( ! isset( $out[ strspn( $out, $ASCII ) ] ) );
134-
}
135-
136-
/**
137-
* @ticket unfc_list_pluck
138-
*/
139-
function test_list_pluck() {
140-
$obj1 = new stdclass;
141-
$obj1->id = 1;
142-
$obj2 = new stdclass;
143-
$obj2->id = 2;
144-
$obj3 = new stdclass;
145-
$obj4 = new stdclass;
146-
$obj4->id = 4;
147-
148-
$list = array( $obj1, $obj2, $obj3, $obj4 );
149-
$out = unfc_list_pluck( $list, 'id' );
150-
$this->assertSame( array( 0 => 1, 1 => 2, 3 => 4 ), $out );
134+
$out = unfc_utf8_rand_str( 1000, 0x10000 );
135+
$this->assertTrue( unfc_is_valid_utf8( $out ) );
151136
}
152137

153138
/**
@@ -171,4 +156,65 @@ function test_utf8_ranges() {
171156
$this->assertSame( $expected, $actual );
172157
}
173158
}
159+
160+
/**
161+
* @ticket unfc_unicode_fmt
162+
*/
163+
function test_unicode_fmt() {
164+
$arr = array(
165+
/**/
166+
array( 0, '0x0', '\x00' ),
167+
array( 0xa, '0xa', '\x0a' ),
168+
array( 0x80, '0x80', '\x80' ),
169+
array( 0xff, '0xff', '\xff' ),
170+
array( 0x800, '0x800', '\x{800}' ),
171+
array( 0x10000, '0x10000', '\x{10000}' ),
172+
/**/
173+
);
174+
175+
foreach ( $arr as $item ) {
176+
list( $c, $expected, $expected_preg ) = $item;
177+
$actual = unfc_unicode_fmt( $c );
178+
$this->assertSame( $expected, $actual );
179+
$actual_preg = unfc_unicode_preg_fmt( $c );
180+
$this->assertSame( $expected_preg, $actual_preg );
181+
}
182+
}
183+
184+
/**
185+
* @ticket unfc_get_cb
186+
*/
187+
function test_get_cb() {
188+
$in = "\rasdfasdf\n\r";
189+
$expected = "\rasdfasdf\n";
190+
$out = unfc_get_cb( $in );
191+
$this->assertSame( $expected, $out );
192+
}
193+
194+
/**
195+
* @ticket unfc_array_map_recursive
196+
*/
197+
function test_array_map_recursive() {
198+
$arr = array( 'a' => array( 'b' => array( 'c' => 'a', 'd' => 'b' ), 'e' => 'c' ), 'f' => 'd', 'g' => array( 'h' => 'e' ) );
199+
$expected = array( 'a' => array( 'b' => array( 'c' => 'A', 'd' => 'B' ), 'e' => 'C' ), 'f' => 'D', 'g' => array( 'h' => 'E' ) );
200+
$out = unfc_array_map_recursive( 'strtoupper', $arr );
201+
$this->assertSame( $expected, $out );
202+
}
203+
204+
/**
205+
* @ticket unfc_list_pluck
206+
*/
207+
function test_list_pluck() {
208+
$obj1 = new stdclass;
209+
$obj1->id = 1;
210+
$obj2 = new stdclass;
211+
$obj2->id = 2;
212+
$obj3 = new stdclass;
213+
$obj4 = new stdclass;
214+
$obj4->id = 4;
215+
216+
$list = array( $obj1, $obj2, $obj3, $obj4 );
217+
$out = unfc_list_pluck( $list, 'id' );
218+
$this->assertSame( array( 0 => 1, 1 => 2, 3 => 4 ), $out );
219+
}
174220
}

0 commit comments

Comments
 (0)