Skip to content

Instantly share code, notes, and snippets.

@ryanwelcher
Forked from christophherr/forth-unit-test-35272.php
Last active October 27, 2016 00:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanwelcher/aef5a1f63f87143145d5fd8a3e153e77 to your computer and use it in GitHub Desktop.
Save ryanwelcher/aef5a1f63f87143145d5fd8a3e153e77 to your computer and use it in GitHub Desktop.
Forth unit test 35272
function test_class_not_applied_to_page_item() {
$page_id1 = self::factory()->post->create( array( 'post_type' => 'page', 'post_title' => 'Home Page' ) );
$page_id2 = self::factory()->post->create( array( 'post_type' => 'page', 'post_title' => 'Test Page' ) );
update_option( 'page_on_front', $page_id1 );
wp_update_nav_menu_item( $this->menu_id, 0, array(
'menu-item-type' => 'post_type',
'menu-item-object' => 'page',
'menu-item-object-id' => $page_id1,
'menu-item-status' => 'publish',
) );
wp_update_nav_menu_item( $this->menu_id, 0, array(
'menu-item-type' => 'post_type',
'menu-item-object' => 'page',
'menu-item-object-id' => $page_id2,
'menu-item-status' => 'publish',
) );
$menu_items = wp_get_nav_menu_items( $this->menu_id );
_wp_menu_item_classes_by_context( $menu_items );
$homepage_classes = $menu_items[0]->classes;
$testpage_classes = $menu_items[1]->classes;
delete_option( 'page_on_front' );
$this->assertContains( 'menu-item-home', $homepage_classes );
$this->assertNotContains( 'menu-item-home', $testpage_classes );
}
@ryanwelcher
Copy link
Author

ryanwelcher commented Oct 27, 2016

I made a couple of changes to the test.

First I removed the $this->goto call as I don't think it matters in this case what page we're actually viewing ( the test passed without it as well ). Also, I added another assertion to show the class is only being added to the page that has been set as the front page.
This is great work though - well done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment