wordpress-develop/tests/phpunit/tests/menu/wpExpandNavMenuPostData.php
Sergey Biryukov 164b22cf6a Tests: First pass at using assertSame() instead of assertEquals() in most of the unit tests.
This ensures that not only the return values match the expected results, but also that their type is the same.

Going forward, stricter type checking by using `assertSame()` should generally be preferred to `assertEquals()` where appropriate, to make the tests more reliable.

Props johnbillion, jrf, SergeyBiryukov.
See #38266.

git-svn-id: https://develop.svn.wordpress.org/trunk@48937 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-02 00:35:36 +00:00

106 lines
2.5 KiB
PHP

<?php
/**
* @group menu
* @ticket 36590
*/
class Tests_Menu_WpExpandNavMenuPostData extends WP_UnitTestCase {
public function test_unnested_data_should_expand() {
require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
if ( empty( $_POST ) ) {
$_POST = array();
}
$data = array();
$data[0] = new StdClass;
$data[0]->name = 'yesorno';
$data[0]->value = 'yes';
$_POST['nav-menu-data'] = addslashes( json_encode( $data ) );
_wp_expand_nav_menu_post_data();
$expected = array(
'nav-menu-data' => $_POST['nav-menu-data'],
'yesorno' => 'yes',
);
$this->assertSame( $expected, $_POST );
}
public function test_multidimensional_nested_array_should_expand() {
require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
if ( empty( $_POST ) ) {
$_POST = array();
}
$data = array();
$data[0] = new StdClass;
$data[0]->name = 'would[1][do][the][trick]';
$data[0]->value = 'yes';
$_POST['nav-menu-data'] = addslashes( json_encode( $data ) );
_wp_expand_nav_menu_post_data();
$expected = array(
'nav-menu-data' => $_POST['nav-menu-data'],
'would' => array(
1 => array(
'do' => array(
'the' => array(
'trick' => 'yes',
),
),
),
),
);
$this->assertSame( $expected, $_POST );
}
public function test_multidimensional_nested_array_should_expand_and_merge() {
require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
if ( empty( $_POST ) ) {
$_POST = array();
}
$data = array();
$data[0] = new StdClass;
$data[0]->name = 'would[1][do][the][trick]';
$data[0]->value = 'yes';
$data[1] = new StdClass;
$data[1]->name = 'would[2][do][the][trick]';
$data[1]->value = 'yes';
$data[2] = new StdClass;
$data[2]->name = 'would[2][do][the][job]';
$data[2]->value = 'yes';
$_POST['nav-menu-data'] = addslashes( json_encode( $data ) );
_wp_expand_nav_menu_post_data();
$expected = array(
'nav-menu-data' => $_POST['nav-menu-data'],
'would' => array(
1 => array(
'do' => array(
'the' => array(
'trick' => 'yes',
),
),
),
2 => array(
'do' => array(
'the' => array(
'trick' => 'yes',
'job' => 'yes',
),
),
),
),
);
$this->assertSame( $expected, $_POST );
}
}