Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions tests/phpunit/tests/customize/nav-menu-item-setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public function test_value_type_post_type() {
$value = $setting->value();
$this->assertSame( $menu_item->title, $value['title'] );
$this->assertSame( $menu_item->type, $value['type'] );
$this->assertEquals( $menu_item->object_id, $value['object_id'] );
$this->assertSame( (int) $menu_item->object_id, $value['object_id'] );
$this->assertSame( $menu_id, $value['nav_menu_term_id'] );
$this->assertSame( 'Hello World', $value['original_title'] );

Expand Down Expand Up @@ -273,7 +273,7 @@ public function test_value_type_taxonomy() {
$value = $setting->value();
$this->assertSame( $menu_item->title, $value['title'] );
$this->assertSame( $menu_item->type, $value['type'] );
$this->assertEquals( $menu_item->object_id, $value['object_id'] );
$this->assertSame( (int) $menu_item->object_id, $value['object_id'] );
$this->assertSame( $menu_id, $value['nav_menu_term_id'] );
$this->assertSame( 'Salutations', $value['original_title'] );
}
Expand Down Expand Up @@ -632,8 +632,17 @@ public function test_sanitize() {
$post = get_post( $nav_menu_item_id );
$nav_menu_item = wp_setup_nav_menu_item( clone $post );

/*
* Keep assertEquals() because sanitize() returns object_id as an integer
* while wp_setup_nav_menu_item() retrieves it as a string from post meta.
*/
$this->assertEquals( $expected_sanitized['object_id'], $nav_menu_item->object_id );
$this->assertSame( $expected_sanitized['object'], $nav_menu_item->object );

/*
* Keep assertEquals() because sanitize() returns menu_item_parent as an integer,
* while wp_setup_nav_menu_item() retrieves it as a string from post meta.
*/
$this->assertEquals( $expected_sanitized['menu_item_parent'], $nav_menu_item->menu_item_parent );
$this->assertSame( $expected_sanitized['position'], $post->menu_order );
$this->assertSame( $expected_sanitized['type'], $nav_menu_item->type );
Expand Down Expand Up @@ -697,6 +706,11 @@ public function test_save_updated() {
$updated_item = $menu_items[ $i ];
$post_value['post_status'] = $post_value['status'];
unset( $post_value['status'] );

/*
* Keep assertEquals() because object_id is an integer in $post_value
* but is returned as a string from post meta by wp_setup_nav_menu_item().
*/
foreach ( $post_value as $key => $value ) {
$this->assertEquals( $value, $updated_item->$key, "Key $key mismatch" );
}
Expand Down Expand Up @@ -770,6 +784,11 @@ public function test_save_inserted() {
unset( $post_value['status'] );
$post_value['menu_order'] = $post_value['position'];
unset( $post_value['position'] );

/*
* Keep assertEquals() because object_id is an integer in $post_value
* but is returned as a string from post meta by wp_setup_nav_menu_item().
*/
foreach ( $post_value as $key => $value ) {
$this->assertEquals( $value, $last_item->$key, "Mismatch for $key property." );
}
Expand Down
4 changes: 4 additions & 0 deletions tests/phpunit/tests/customize/nav-menu-setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ public function test_preview_updated() {
$this->assertSameSets( $value, wp_array_slice_assoc( $term, array_keys( $value ) ) );

$menu_object = wp_get_nav_menu_object( $menu_id );

// Keep assertEquals() because the objects are intentionally compared by value.
$this->assertEquals( (object) $term, $menu_object );
$this->assertSame( $post_value['name'], $menu_object->name );

Expand Down Expand Up @@ -277,6 +279,8 @@ public function test_preview_inserted() {
$this->assertSame( $menu_id, $term['term_taxonomy_id'] );

$menu_object = wp_get_nav_menu_object( $menu_id );

// Keep assertEquals() because the objects are intentionally compared by value.
$this->assertEquals( (object) $term, $menu_object );
$this->assertSame( $post_value['name'], $menu_object->name );

Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit/tests/customize/widgets.php
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,8 @@ public function test_sanitize_widget_instance_raw_instance() {
$this->assertSame( '', $sanitized_for_js['title'] );
$this->assertTrue( $sanitized_for_js['is_widget_customizer_js_value'] );
$this->assertArrayHasKey( 'instance_hash_key', $sanitized_for_js );

// Keep assertEquals() because the objects are intentionally compared by value.
$this->assertEquals( (object) $block_instance, $sanitized_for_js['raw_instance'] );

$unsanitized_from_js = $this->manager->widgets->sanitize_widget_instance( $sanitized_for_js );
Expand Down
Loading